New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CLANG including struct names when looking up namespace name candidates #44561
Comments
This is a GCC bug. The lookup for the name on the left of :: "considers only namespaces, types, and templates whose specializations are types" according to the C++ standard, so following the normal unqualified lookup rules it should find both the namespace ::N1 and the struct N2::N1. Modified example showing why lookup to the left of :: should consider types: namespace N1 { namespace N2 { using namespace N2; using N1::f; // Clang: ambiguous, GCC: N1::f (OK) |
"When looking up a namespace-name in a using-directive, only namespace names are considered, see [basic.lookup.udir]. — end note" - http://eel.is/c++draft/namespace.udir So shouldn't the lookup for the name on the left of the :: scope resolution operator when used in the context of a using-declaration 'using ns_name::name;' look up only namespace names? Ref:
|
A using-directive is a declaration of the form using namespace NS; The case in this bug report is a using-declaration, not a using-directive, so that rule doesn't apply. |
GCC bug filed as https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94227 |
The case in this bug report is a using-declaration, not a using-directive. Agreed. One last question: //////////////////////////////////////////////////////////////////////////// using N1::f; #include<stdio.h> ... Refs: "using typename(optional) nested-name-specifier unqualified-id ; (until C++17)" |
A class name can be used as the left-most identifier in a using-declaration. For example: struct A { int x; }; struct C { enum { e }; }; |
Extended Description
The below code compiles on GCC but not on CLANG. Looks like CLANG is looking up struct identifier names as ns_name candidates in addition to namespace names in "using ns_name::name;".
https://wandbox.org/permlink/zG6JvMtNwxXK4yPn
////////////////////////////////////////////////////////////////////////////
#include<stdio.h>
namespace N1 {
const char* f() {
return "NamespaceN1::f()";
}
}
namespace N2 {
struct N1 {
static const char* f() {
return "NamespaceN2::StructN1::f()";
}
};
}
using namespace N2;
using N1::f;
int main()
{
printf("%s\n", f());
return 0;
}
////////////////////////////////////////////////////////////////////////////
Compilation Error on CLANG:
prog.cc:18:7: error: reference to 'N1' is ambiguous
using N1::f;
^
prog.cc:3:11: note: candidate found by name lookup is 'N1'
namespace N1 {
^
prog.cc:10:10: note: candidate found by name lookup is 'N2::N1'
struct N1 {
^
prog.cc:22:20: error: use of undeclared identifier 'f'; did you mean 'N1::f'?
printf("%s\n", f());
^
N1::f
prog.cc:4:16: note: 'N1::f' declared here
const char* f() {
^
2 errors generated.
////////////////////////////////////////////////////////////////////////////
Result on GCC:
NamespaceN1::f()
The text was updated successfully, but these errors were encountered: