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

  • A+

Consider the following snippet:

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 with the following error: error: deduction guide 'S::T(B&&) -> S::T' must be declared at namespace scope

Is this valid code? Which compiler is right, GCC or Clang?


According to

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.

So clang seems correct.


:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: