https://gcc.gnu.org/bugzilla/show_bug.cgi?id=46283

--- Comment #3 from Tor Myklebust <tmyklebu at gmail dot com> ---
On Sat, Jul 24, 2021 at 6:45 AM pinskia at gcc dot gnu.org
<gcc-bugzi...@gcc.gnu.org> wrote:
>
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=46283
>
> --- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
> ((a *)0)->foo::x()
>
> ((T *)0)->foo::x()
>
> Both are those are undefined because you are calling a method of a NULL
> pointer.

That's true.  In both cases, one can modify this code, for instance by
writing (new a)->foo::x() or (new T)->foo::x(), or by statically
instantiating an object of the appropriate type, without changing the
relevant name lookup behaviour.

> (In reply to Andrew Pinski from comment #1)
> > I think the code should be rejected.  Here is what Comeau online says:
> > "ComeauTest.c", line 14: error: ambiguous class member reference -- type
> > "b::foo"
> >           (declared at line 4) used in preference to type "a::foo" (declared
> >           at line 10)
>
> And clang rejects this:
> <source>:14:41: error: lookup of 'foo' in member access expression is 
> ambiguous
> void b::go() { printf("%i\n", ((a *)0)->foo::x()); }
>                                         ^
> <source>:10:13: note: lookup in the object type 'a' refers here
>   typedef b foo;
>             ^
> <source>:4:20: note: lookup from the current scope refers here
>   typedef struct a foo;
>                    ^

It appears (through playing with Matt Godbolt's Compiler Explorer)
that a change was made between clang 5.0.1 and clang 6.0.0 that made
clang match gcc's behaviour.  5.0.1 gives the errors above, while
6.0.0 compiles the code without warnings or errors.

Reply via email to