Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

clang fails to diagnose an ambiguous "using" clause #36770

Open Quuxplusone opened 6 years ago

Quuxplusone commented 6 years ago
Bugzilla Link PR37797
Status NEW
Importance P normal
Reported by David Pickens (pickensd@synopsys.com)
Reported on 2018-06-13 17:45:34 -0700
Last modified on 2018-06-14 11:29:40 -0700
Version trunk
Hardware PC Linux
CC dblaikie@gmail.com, dgregor@apple.com, llvm-bugs@lists.llvm.org, pickensd@synopsys.com, richard-llvm@metafoo.co.uk
Fixed by commit(s)
Attachments
Blocks
Blocked by
See also
The following C++ code should cause a compilation error, but it does not.
clang 3.8 did properly diagnose the error, but it somehow regressed since then.
-------------------------------------------

namespace A { struct x {}; }
namespace B { int x = 13; }
namespace C { using A::x; using B::x; }
namespace D { using A::x; }
using namespace C;
using namespace D;
int main(){ return x; }  //<-- x should be ambiguous!
Quuxplusone commented 6 years ago
Clang 3.8 and before generate a bogus diagnostic on the second using-
declaration in C ("target of using declaration conflicts with declaration in
scope"). The two using-declarations in C are valid: the variable declaration
hides the type declaration, per [basic.scope.declarative]p4.

That said, this should be ill-formed, because the variable does *not* hide the
type when they're both found in the global namespace via the using-directives
(hiding only happens between declarations that introduce names into the same
declarative region).

Reversing the order of the using-directives produces the desired error, as does
removing the (hidden) using A::x; from namespace C. I expect we're throwing out
the D::x lookup result because it matches the C::x lookup result, without
noticing that C::x would be hidden and D::x would not.