gcc doesn't like foreach with const-ref containers
Thiago Macieira
thiago at kde.org
Wed Sep 5 21:24:31 CEST 2007
Christian Ehrlicher wrote:
>Andreas Pakulat schrieb:
>> On 05.09.07 19:17:20, Andreas Pakulat wrote:
>>> On 05.09.07 06:30:19, Christian Ehrlicher wrote:
>>>> Andreas Pakulat schrieb:
>>>>> Hi,
>>>>> while compiling kdevelop I got an error on some code in its
>>>>> language support which compiles fine with gcc 4.2 on linux. (I'm
>>>>> using mingw suite 5.1.3, i.e. gcc 3.4.5 on win32).
>>>>> The problem seems to be that findDeclarationsInternal on line 107
>>>>> in kdevelop/languages/cpp/duchainbuilder/cppducontext.h has a
>>>>> const-reference to a QList as parameter. The error (log attached)
>>>>> indicates that foreach() can't handle such a const-ref list, while
>>>>> doing the "standard" for( foo::const_iterator it = list.begin()...
>>>>> thing works fine.
>>>>> Does anybody know a "better" solution than to use an iterator-loop,
>>>>> or a reason why this is. Is it maybe a gcc bug?
>>>>
>>>> Plz make a testcase for this so I can take a look
>>>
>>> Seems like templates have to be involved as well. See the attached
>>> main.cpp (just use qmake -project;qmake;make to build).
>>>
>>> As soon as you remove the template from MyTest it compiles fine. Else
>>> I get that error.
>>
>> And here's the actual file :)
>
>Thx, I can reproduce this error.
>
>I wonder why this works on linux. A quick solution would be to remove
>the reference. It's implicit shared so it doesn't matter if you pass a
>reference or a copy here. And if this breaks BC, just use an internal
> copy:
>
>void foo(const QList<MyClass>& l_)
>{
> const QList<MyClass> l(l_);
> foreach(const MyClass& c, l)
> ...
>}
Yes, it's a GCC bug. It doesn't like const-refs as the second argument to
foreach.
Don't change the function signature, but create a local (cheap) copy of
it.
--
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
PGP/GPG: 0x6EF45358; fingerprint:
E067 918B B660 DBD1 105C 966C 33F5 F005 6EF4 5358
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part.
Url : http://mail.kde.org/pipermail/kde-windows/attachments/20070905/fdb2e2b7/attachment.pgp
More information about the Kde-windows
mailing list