public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Issue with using and const overloaded methods in GCC 3.0.3
@ 2002-04-15  9:34 Hunter, David J
  2002-04-17  8:22 ` Oliver Kullmann
  0 siblings, 1 reply; 2+ messages in thread
From: Hunter, David J @ 2002-04-15  9:34 UTC (permalink / raw)
  To: 'gcc-help@gcc.gnu.org'

The following code

struct A
{
   A( ) { }

    const void a( ) const { }  // Line A
          void a( )       { }        // Line B
};

struct B : public A
{
    B( ) : A( ) { }

    using A::a;
};

int main( unsigned int, char** )
{
    B b1;

    b1.a( );

    const B b2;

    b2.a( );
}

produces the error  "Test.c:XX: passing `const B' as `this' argument of
`void A::a()' discards qualifiers",
which seems to suggest that only the non const version of the method A::a is
brought into the B scope
by the using declaration in B. The error disappears when the line A and B
are reversed which seems
to imply that only the first A::a, whichever it is, is being brought into
scope B.

My understanding of the using declaration in B is that it should bring both
A::a methods into the B scope
and that the const resolution should work fine, am I in error in this or is
the compiler?

Note that I have test on GCC 3.0.3 on Linux 7.2 and Solaris 8. This code
compiles fine on Forte 6 update
2 on Solaris.

David Hunter






------------------------------------------------------------------------------
This message is intended only for the personal and confidential use of the designated recipient(s) named above.  If you are not the intended recipient of this message you are hereby notified that any review, dissemination, distribution or copying of this message is strictly prohibited.  This communication is for information purposes only and should not be regarded as an offer to sell or as a solicitation of an offer to buy any financial product, an official confirmation of any transaction, or as an official statement of Lehman Brothers.  Email transmission cannot be guaranteed to be secure or error-free.  Therefore, we do not represent that this information is complete or accurate and it should not be relied upon as such.  All information is subject to change without notice.


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Issue with using and const overloaded methods in GCC 3.0.3
  2002-04-15  9:34 Issue with using and const overloaded methods in GCC 3.0.3 Hunter, David J
@ 2002-04-17  8:22 ` Oliver Kullmann
  0 siblings, 0 replies; 2+ messages in thread
From: Oliver Kullmann @ 2002-04-17  8:22 UTC (permalink / raw)
  To: gcc-help

> The following code
>
> struct A
> {
>    A( ) { }
>
>     const void a( ) const { }  // Line A
>           void a( )       { }        // Line B
> };
>
> struct B : public A
> {
>     B( ) : A( ) { }
>
>     using A::a;
> };
>
> int main( unsigned int, char** )
> {
>     B b1;
>
>     b1.a( );
>
>     const B b2;
>
>     b2.a( );
> }
>
> produces the error  "Test.c:XX: passing `const B' as `this' argument of
> `void A::a()' discards qualifiers",
> which seems to suggest that only the non const version of the method A::a is
> brought into the B scope
> by the using declaration in B. The error disappears when the line A and B
> are reversed which seems
> to imply that only the first A::a, whichever it is, is being brought into
> scope B.
>
> My understanding of the using declaration in B is that it should bring both
> A::a methods into the B scope
> and that the const resolution should work fine, am I in error in this or is
> the compiler?
>
> Note that I have test on GCC 3.0.3 on Linux 7.2 and Solaris 8. This code
> compiles fine on Forte 6 update
> 2 on Solaris.
>
> David Hunter
>
>

Using g++, version 3.0.4 (the current stable version) the code also compiles without
problems. Considering section 7.3.3 on the the using declaration in ISO/IEC 14882:1998(E)
(especially the example on top of page 119), furthermore that in general a cv-qualified type
(that is, a type qualified with "constant" or "volatile") is a different type than the corresponding
unqualified type, and given the rules for function overloading, I also think your interpretation
is right (and thus also version 3.0.4 is correct here).

Oliver

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2002-04-17 14:49 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-04-15  9:34 Issue with using and const overloaded methods in GCC 3.0.3 Hunter, David J
2002-04-17  8:22 ` Oliver Kullmann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).