Reputation: 552
Consider the following program:
#include <iostream>
namespace N {
int j = 1;
}
namespace M {
typedef int N;
void f() {
std::cout << N::j << std::endl;
}
}
int main() { M::f(); }
Compiling it with clang gives the following compiler error:
prog.cc:10:22: error: 'N' (aka 'int') is not a class, namespace, or
enumeration
std::cout << N::j << std::endl;
^ 1 error generated.
GCC does not give any compiler error. I'm trying to figure out for what compiler I should file the bug report for. Which compiler has the correct behaviour and why (references to the c++ standard)?
Wandbox - Clang: http://melpon.org/wandbox/permlink/s0hKOxCFPgq5aSmJ
Wandbox - GCC: http://melpon.org/wandbox/permlink/i2kOl3qTBVUcJVbZ
Upvotes: 9
Views: 456
Reputation: 171127
Clang is correct on this one. Quoting C++11, 3.4.3/1 [basic.lookup.qual]:
... If a
::
scope resolution operator in a nested-name-specifier is not preceded by a decltype-specifier, lookup of the name preceding that::
considers only namespaces, types, and templates whose specializations are types. If the name found does not designate a namespace or a class, enumeration, or dependent type, the program is ill-formed.
Per this clause, types are supposed to be considered during the lookup, so the typedef N
should be found. And since it does not designate a namespace, class, enumeration, or dependent type, the program is ill-formed.
Upvotes: 11