re PR c++/65195 (Variable template cannot be used as a function)
authorJason Merrill <jason@redhat.com>
Wed, 5 Aug 2015 17:51:29 +0000 (13:51 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Wed, 5 Aug 2015 17:51:29 +0000 (13:51 -0400)
PR c++/65195
PR c++/66619
* semantics.c (finish_id_expression): Call convert_from_reference
for variable template.

From-SVN: r226641

gcc/cp/ChangeLog
gcc/cp/semantics.c
gcc/testsuite/g++.dg/cpp1y/var-templ37.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp1y/var-templ40.C [new file with mode: 0644]

index f51132cf8529ae540109a282d6aa0e723a2dfc34..382ad9a8a4bcb486aab39fdcd8e2ab2c70dbd61f 100644 (file)
@@ -1,3 +1,10 @@
+2015-08-05  Jason Merrill  <jason@redhat.com>
+
+       PR c++/65195
+       PR c++/66619
+       * semantics.c (finish_id_expression): Call convert_from_reference
+       for variable template.
+
 2015-08-04  Jason Merrill  <jason@redhat.com>
 
        * pt.c (lookup_template_class_1): Clear elt.spec.
index 44f9f7acaa36b5457601376adb13f9bf7c5cda79..d42838e78ccf3a9e33eae0801edf52f13186042c 100644 (file)
@@ -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)
        {
diff --git a/gcc/testsuite/g++.dg/cpp1y/var-templ37.C b/gcc/testsuite/g++.dg/cpp1y/var-templ37.C
new file mode 100644 (file)
index 0000000..11021a3
--- /dev/null
@@ -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>();
+}
diff --git a/gcc/testsuite/g++.dg/cpp1y/var-templ40.C b/gcc/testsuite/g++.dg/cpp1y/var-templ40.C
new file mode 100644 (file)
index 0000000..0a952c4
--- /dev/null
@@ -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&&>;