演绎指南、模板和子对象:哪个编译器是正确的?

Deduction guides, templates and subobjects: which compiler is right?

考虑以下片段:

struct S {
    S() {}

    template<typename B>
    struct T {
        T(B &&) {}
    };

    template<typename B>
    T(B &&) -> T<B>;
};

int main() {
    S::T t{0};
}

Clang accepts it while GCC rejects the code 出现以下错误:

prog.cc:10:5: error: deduction guide 'S::T(B&&) -> S::T' must be declared at namespace scope

这个代码有效吗?哪个编译器是正确的,GCC 还是 Clang?

根据http://en.cppreference.com/w/cpp/language/class_template_argument_deduction

User-defined deduction guides must name a class template and must be introduced within the same semantic scope of the class template (which could be namespace or enclosing class) and, for a member class template, must have the same access, but deduction guides do not become members of that scope.

所以 clang 似乎是正确的。