PR c++/68666 - member variable template-id
authorJason Merrill <jason@redhat.com>
Wed, 18 Jan 2017 21:05:12 +0000 (16:05 -0500)
committerJason Merrill <jason@gcc.gnu.org>
Wed, 18 Jan 2017 21:05:12 +0000 (16:05 -0500)
* 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
gcc/cp/cp-tree.h
gcc/cp/pt.c
gcc/cp/typeck.c
gcc/testsuite/g++.dg/concepts/var-templ3.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp1y/var-templ55.C [new file with mode: 0644]

index 11dfbad243038c5ab6b19f2350a98ea1addb4466..f8377e25b4ce59b9d634d5c121b85ba42a937208 100644 (file)
@@ -1,3 +1,11 @@
+2017-01-18  Jason Merrill  <jason@redhat.com>
+
+       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  <nathan@acm.org>
 
        PR c++/78488
index 98e4cbd05de79008e6189cc5025cb35b638dc6cf..9c4436710dda8711bf075ed17eb456623fcfa347 100644 (file)
@@ -6449,6 +6449,7 @@ extern cp_expr perform_koenig_lookup              (cp_expr, vec<tree, va_gc> *,
                                                 tsubst_flags_t);
 extern tree finish_call_expr                   (tree, vec<tree, va_gc> **, 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);
index 6fd03a5379a42936d188774296f930ce1b88b16d..c679133850e3b0fde4d931706a64555e322df890 100644 (file)
@@ -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)
 {
index b84f8beef53ee2fb39fdbc13a2d004f92a82b17b..579c580adb2eed8e94158d338b9052fdfb1e82fe 100644 (file)
@@ -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 (file)
index 0000000..b882b08
--- /dev/null
@@ -0,0 +1,12 @@
+// PR c++/68666
+// { dg-options "-std=c++1z -fconcepts" }
+
+struct A {
+  template <class>
+  static constexpr bool val = true;
+};
+
+template <class T>
+concept bool C = A::val<T>;
+
+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 (file)
index 0000000..0840df3
--- /dev/null
@@ -0,0 +1,12 @@
+// { dg-do compile { target c++14 } }
+
+template <class T> struct A {
+  template <class U> static const U x = 1;
+  static const int y = 2;
+};
+
+int main() {
+  A<int> a;
+  int y = a.y;         // OK
+  int x = a.x<int>;     // ???
+}