const foo& - what is const - ReferenceType or ReferenceType::baseType ?

floris flo.ruijt at gmail.com
Wed Mar 2 16:40:24 UTC 2011


On Wed, 2011-03-02 at 17:24 +0100, Milian Wolff wrote:
> Hey David,
> 
> just spotted an issue in the shortenedTypeIdentifier, it checks whether the 
> identifier is a const ref using this code:
> 
>   bool isReference = false;
>   bool isConstReference = false;
>   if(type.cast<ReferenceType>()) {
>     isReference = true;
>     isConstReference = type.cast<ReferenceType>()->modifiers() & 
> AbstractType::ConstModifier;
>     type = type.cast<ReferenceType>()->baseType();
>   }
> 
> But the reality shows: Not the ReferenceType is const, but it's baseType! So 
> I'll fix it here, but I wonder whether this could not be hit elsewhere? Should 
> the ReferenceType maybe return the same modifiers as it's baseType to prevent 
> such problems?
> 
> bye
they should both return const: a the reference of a reference type is
ALWAYS const: you can't reseat a reference type.

int &foo =bar;
foo=baz;//bar==baz now, foo still refers to bar

but the could should really check the base type because that's what the
modifier belongs to.

and for pointer types such a change would be devastating as const int* !
= int * const

Floris





More information about the KDevelop-devel mailing list