commit f1f2cd02b7e4549657cf6eeab1d7eae0466ac7a8
Author: Jason Merrill <jason@redhat.com>
Date: Wed Aug 5 11:46:48 2015 -0400
PR c++/65195
PR c++/66619
* semantics.c (finish_id_expression): Call convert_from_reference
for variable template.
@@ -3564,6 +3564,7 @@ finish_id_expression (tree id_expression,
{
decl = finish_template_variable (decl);
mark_used (decl);
+ decl = convert_from_reference (decl);
}
else if (scope)
{
new file mode 100644
@@ -0,0 +1,23 @@
+// PR c++/65195
+// { dg-do compile { target c++14 } }
+
+template<typename T>
+T constant {};
+
+template<typename T>
+struct foo {
+ int operator()() const
+ { return 3; }
+};
+
+template<typename T>
+auto& f = constant<foo<T>>;
+
+int main()
+{
+ // fine
+ auto& ref = f<int>; ref();
+
+ // error: f<int> cannot be used as a function
+ f<int>();
+}
new file mode 100644
@@ -0,0 +1,9 @@
+// PR c++/66619
+// { dg-do compile { target c++14 } }
+
+int y;
+template<class T> T val1 = y;
+auto&& x1 = val1<int&>;
+
+template<class T> T val2 = 0;
+auto&& x2 = val2<int&&>;