template<template<auto> class> struct A {};
template<int&> struct B {};
A<B> a;
int main() {}
All three compilers MSVC, GCC and Clang in their latest versions accept this code (https://godbolt.org/z/b7Pv7Ybxv). However, auto
cannot deduce to a reference type, so why would this be allowed? Or are the compilers incorrectly accepting it when looking at what the standard says?
I confused the argument and parameter in the above. My intention was to ask about
template<template<int&> class> struct A {};
template<auto> struct B {};
A<B> a;
int main() {}
which is also accepted by all of the compilers above. The original example is however also interesting because the template template parameter should be at least as specialized as the template argument, which it doesn't intuitively seem to be.
The second example is OK according to the rules. Let us quote them:
So our template-argument is
template<auto> class
and our template parameter istemplate<int&> class
. Let's invent a class templateX
:and rewrite as two function templates:
The second one seems to be at least as specialized as the first: every function call that would be satisfied by the second template would be also satisfied by the first one. (As far as I can tell the second template can never be satisfied because you cannot instantiate
X
with anint&
argument; not sure if this is IFNDR; probably not because the program per se does not containfunc
templates, they are invented in order to check other templates).Less obviously, the first example is also OK according to the same rules. Lety's invent class template
X
and rewrite again:Now the two templates satisfy exactly the same calls, so each one is at least specialized as the other one.