aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gcc/cp/pt.cc3
-rw-r--r--gcc/testsuite/g++.dg/cpp1y/var-templ80.C22
-rw-r--r--gcc/testsuite/g++.dg/cpp1y/var-templ81.C14
3 files changed, 38 insertions, 1 deletions
diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index 696233e..7fb3e75 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -10394,7 +10394,7 @@ lookup_and_finish_template_variable (tree templ, tree targs,
complain &= ~tf_partial;
var = finish_template_variable (var, complain);
mark_used (var);
- return convert_from_reference (var);
+ return var;
}
/* If the set of template parameters PARMS contains a template parameter
@@ -20462,6 +20462,7 @@ tsubst_copy_and_build (tree t,
{
tree r = lookup_and_finish_template_variable (templ, targs,
complain);
+ r = convert_from_reference (r);
r = maybe_wrap_with_location (r, EXPR_LOCATION (t));
RETURN (r);
}
diff --git a/gcc/testsuite/g++.dg/cpp1y/var-templ80.C b/gcc/testsuite/g++.dg/cpp1y/var-templ80.C
new file mode 100644
index 0000000..4439bee
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1y/var-templ80.C
@@ -0,0 +1,22 @@
+// PR c++/97340
+// { dg-do compile { target c++14 } }
+
+template<class>
+struct A {
+ template<class>
+ static constexpr const int& var = 0;
+};
+
+template<class T>
+struct B {
+ static constexpr int x1 = A<T>::template var<int>;
+ static constexpr int y1 = A<T>{}.template var<int>;
+
+ static constexpr int x2 = A<int>::template var<T>;
+ static constexpr int y2 = A<int>{}.template var<T>;
+
+ static constexpr int x3 = A<int>::template var<int>;
+ static constexpr int y3 = A<int>{}.template var<int>;
+};
+
+template struct B<int>;
diff --git a/gcc/testsuite/g++.dg/cpp1y/var-templ81.C b/gcc/testsuite/g++.dg/cpp1y/var-templ81.C
new file mode 100644
index 0000000..3efe779
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1y/var-templ81.C
@@ -0,0 +1,14 @@
+// Verify we don't ICE on an invalid dereference of a variable
+// template-id of reference type.
+// { dg-do compile { target c++14 } }
+
+template<class>
+static constexpr const int& var = 0;
+
+template<class T>
+struct B {
+ static constexpr int x = *var<T>; // { dg-error "argument of unary" }
+ static constexpr const int& y = *var<T>; // { dg-error "argument of unary" }
+};
+
+template struct B<int>;