c++/10371: [3.4 regression] misleading error message for illegal member access

reichelt@igpm.rwth-aachen.de reichelt@igpm.rwth-aachen.de
Thu Apr 10 21:16:00 GMT 2003


>Number:         10371
>Category:       c++
>Synopsis:       [3.4 regression] misleading error message for illegal member access
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Thu Apr 10 21:16:01 UTC 2003
>Closed-Date:
>Last-Modified:
>Originator:     Volker Reichelt
>Release:        gcc 3.4-20030402
>Organization:
>Environment:
i686-pc-linux-gnu
>Description:
Compiling the following code with "g++ -c" I get an
error message which is quite misleading IMHO:

----------------------snip here---------------------
struct A
{
    int i;
};

template <int> struct B
{
    int foo() { return A::i; }
};

void bar() { B<0>().foo(); }
----------------------snip here---------------------

msg.cc: In member function `int B<<anonymous> >::foo() [with int 
   <anonymous> = 0]':
msg.cc:11:   instantiated from here
msg.cc:8: error: 'struct B<0>' has no member named 'i'

We try to access "A::i" which is a member of A and not
of B<0> in an illegal fashion. There are (at least)
two ways to make the code legal: a) make "i" static or b)
derive "B" from "A".

Compilers on the release branch at least give a hint w.r.t. b):

msg.cc: In member function `int B<<anonymous> >::foo() [with int 
   <anonymous> = 0]':
msg.cc:11:   instantiated from here
msg.cc:8: error: type `A' is not a base type for type `B<0>'

Although this is only correct in some cases, I rate the new
error message as a regression.

For related issues see PR 9443.
>How-To-Repeat:

>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:



More information about the Gcc-prs mailing list