I have the following code, which I cannot get to work:
struct foo {};
foo foo1 = {};
template
class FooClass {};
template
This is precisely covered by CWG 2091:
According to 14.8.2.5 [temp.deduct.type] paragraph 17,
If
P
has a form that contains, and if the type of the corresponding value of
A
differs from the type ofi
, deduction fails.This gives the wrong result for an example like:
template
struct X; template void f(X &); int n; void g(X &x) { f(x); } Here,
P
isX
, which contains. The type of
i
isint&
. The corresponding value fromA
isn
, which is a glvalue of typeint
. Presumably this should be valid.I think this rule means to say something like,
If
P
has a form that contains, and the type of
i
differs from the type of the corresponding template parameter of the template named by the enclosing simple-template-id, deduction fails.
As noted by @dyp, [temp.deduct.type]/17 should be more permissive. In your example, the argument in FooClass
(F
) does not have reference type - it's an lvalue of type foo
. The template parameter of FooClass
is a reference. The DR was resolved last year.