From 8b1346a80ab539a680eb7d010a1de5f18c53a9d5 Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Wed, 18 Jan 2017 16:05:12 -0500 Subject: [PATCH] PR c++/68666 - member variable template-id * typeck.c (finish_class_member_access_expr): Handle variable template-id. * pt.c (lookup_and_finish_template_variable): No longer static. * cp-tree.h: Declare it. From-SVN: r244599 --- gcc/cp/ChangeLog | 8 ++++++++ gcc/cp/cp-tree.h | 1 + gcc/cp/pt.c | 2 +- gcc/cp/typeck.c | 5 ++++- gcc/testsuite/g++.dg/concepts/var-templ3.C | 12 ++++++++++++ gcc/testsuite/g++.dg/cpp1y/var-templ55.C | 12 ++++++++++++ 6 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/g++.dg/concepts/var-templ3.C create mode 100644 gcc/testsuite/g++.dg/cpp1y/var-templ55.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 11dfbad2430..f8377e25b4c 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,11 @@ +2017-01-18 Jason Merrill + + PR c++/68666 - member variable template-id + * typeck.c (finish_class_member_access_expr): Handle variable + template-id. + * pt.c (lookup_and_finish_template_variable): No longer static. + * cp-tree.h: Declare it. + 2017-01-18 Nathan Sidwell PR c++/78488 diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index 98e4cbd05de..9c4436710dd 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -6449,6 +6449,7 @@ extern cp_expr perform_koenig_lookup (cp_expr, vec *, tsubst_flags_t); extern tree finish_call_expr (tree, vec **, bool, bool, tsubst_flags_t); +extern tree lookup_and_finish_template_variable (tree, tree, tsubst_flags_t = tf_warning_or_error); extern tree finish_template_variable (tree, tsubst_flags_t = tf_warning_or_error); extern cp_expr finish_increment_expr (cp_expr, enum tree_code); extern tree finish_this_expr (void); diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 6fd03a5379a..c679133850e 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -9035,7 +9035,7 @@ finish_template_variable (tree var, tsubst_flags_t complain) /* Construct a TEMPLATE_ID_EXPR for the given variable template TEMPL having TARGS template args, and instantiate it if it's not dependent. */ -static tree +tree lookup_and_finish_template_variable (tree templ, tree targs, tsubst_flags_t complain) { diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index b84f8beef53..579c580adb2 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -2875,7 +2875,10 @@ finish_class_member_access_expr (cp_expr object, tree name, bool template_p, tree templ = member; if (BASELINK_P (templ)) - templ = lookup_template_function (templ, template_args); + member = lookup_template_function (templ, template_args); + else if (variable_template_p (templ)) + member = (lookup_and_finish_template_variable + (templ, template_args, complain)); else { if (complain & tf_error) diff --git a/gcc/testsuite/g++.dg/concepts/var-templ3.C b/gcc/testsuite/g++.dg/concepts/var-templ3.C new file mode 100644 index 00000000000..b882b08d181 --- /dev/null +++ b/gcc/testsuite/g++.dg/concepts/var-templ3.C @@ -0,0 +1,12 @@ +// PR c++/68666 +// { dg-options "-std=c++1z -fconcepts" } + +struct A { + template + static constexpr bool val = true; +}; + +template +concept bool C = A::val; + +C{T} struct B {}; diff --git a/gcc/testsuite/g++.dg/cpp1y/var-templ55.C b/gcc/testsuite/g++.dg/cpp1y/var-templ55.C new file mode 100644 index 00000000000..0840df3d4f0 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1y/var-templ55.C @@ -0,0 +1,12 @@ +// { dg-do compile { target c++14 } } + +template struct A { + template static const U x = 1; + static const int y = 2; +}; + +int main() { + A a; + int y = a.y; // OK + int x = a.x; // ??? +} -- 2.30.2