This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/42021] New: Misleading error message when inheirited typedefs cause ambiguitiy


The following test case shows code that all compilers seem to reject, but G++
(I've tried several versions) gives a confusing error message.

Here are the error messages given by various compilers:
Visual C++ v8:
>sourceFile.cpp(27) : error C2385: ambiguous access of 'P3'
>        could be the 'P3' in base 'C1'
>        or could be the 'P3' in base 'B'

(The most clear and helpful error message of the bunch.)

Comeau/EDG:
>"sourceFile.cpp", line 27: error: 
>          "PolicySelector::P3" is ambiguous
>          Policies::P3::doPrint();
>                    ^

G++:
>sourceFile.cpp: In member 
>   function `void BreadSlicer::print()':
>sourceFile.cpp:27: no type 
>   named `P3' in `struct PolicySelector'


The G++ message is terribly misleading, since there is in fact not only one
type named P3 in struct PolicySelector, but more than one type with that name. 

The code in question is:
----BEGIN----
struct Policy1 {
    static void doPrint() {}
};

struct Policy2 {
    static void doPrint() {}
};

struct B {
    typedef Policy1 P3;
};

struct C1 : B {
    typedef Policy2 P3;  
};

struct C2 : B {
};

struct PolicySelector: C1, C2 {
};

struct BreadSlicer {
    typedef PolicySelector Policies;
    void print () {
        Policies::P3::doPrint();
    }
};

int main()
{
    BreadSlicer bc2;
    bc2.print();
}
-----END-----


-- 
           Summary: Misleading error message when inheirited typedefs cause
                    ambiguitiy
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: minor
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: unknown_kev_cat at hotmail dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42021


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]