执行限定名称查找时 Clang 和 GCC 之间的不同行为

Different behaviour between Clang and GCC when performing qualified name lookup

考虑以下程序:

#include <iostream>

namespace N {
    int j = 1;
}

namespace M {
    typedef int N;
    void f() {
        std::cout << N::j << std::endl;
    }
}

int main() { M::f(); }

用 clang 编译它会出现以下编译器错误:

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 没有给出任何编译器错误。我想弄清楚我应该为哪个编译器提交错误报告。哪个编译器具有正确的行为以及原因(对 c++ 标准的引用)?

Wandbox - Clang:http://melpon.org/wandbox/permlink/s0hKOxCFPgq5aSmJ

Wandbox-GCC:http://melpon.org/wandbox/permlink/i2kOl3qTBVUcJVbZ

Clang 在这一点上是正确的。引用 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.

根据此子句,查找期间应考虑类型,因此应找到 typedef N。由于它没有指定名称空间、class、枚举或依赖类型,因此该程序格式错误。