pt.c (lookup_template_variable): Make dependent variable templates have unknown type.
authorAndrew Sutton <andrew.n.sutton@gmail.com>
Wed, 13 Aug 2014 14:16:48 +0000 (14:16 +0000)
committerAndrew Sutton <asutton@gcc.gnu.org>
Wed, 13 Aug 2014 14:16:48 +0000 (14:16 +0000)
2014-08-13  Andrew Sutton  <andrew.n.sutton@gmail.com>

        * pt.c (lookup_template_variable): Make dependent variable templates
        have unknown type.

From-SVN: r213910

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

index 9d24958ee491b0b54faf87107474665b5bab34c5..0889ea6e7fe42e2805d51634aa528736c56726b3 100644 (file)
@@ -1,3 +1,8 @@
+2014-08-13  Andrew Sutton  <andrew.n.sutton@gmail.com>
+
+       * pt.c (lookup_template_variable): Make dependent variable templates 
+       have unknown type.
+
 2014-08-13  Paolo Carlini  <paolo.carlini@oracle.com>
 
        * parser.c (cp_parser_elaborated_type_specifier): Handle
index 90b2720ef9c8e7bec09b6e757dfb31073275dfcc..be16ca8a0c91d1ce132032906ac0480c2f790f67 100644 (file)
@@ -7965,13 +7965,22 @@ lookup_template_class (tree d1, tree arglist, tree in_decl, tree context,
   return ret;
 }
 
-/* Return a TEMPLATE_ID_EXPR for the given variable template and ARGLIST. */
+/* Return a TEMPLATE_ID_EXPR for the given variable template and ARGLIST. 
+   If the ARGLIST refers to any template parameters, the type of the
+   expression is the unknown_type_node since the template-id could
+   refer to an explicit or partial specialization. */
 
 tree
 lookup_template_variable (tree templ, tree arglist)
 {
-  return build2 (TEMPLATE_ID_EXPR, TREE_TYPE (templ), templ, arglist);
+  tree type;
+  if (uses_template_parms (arglist))
+    type = unknown_type_node;
+  else
+    type = TREE_TYPE (templ);
+  return build2 (TEMPLATE_ID_EXPR, type, templ, arglist);
 }
+
 \f
 struct pair_fn_data
 {
diff --git a/gcc/testsuite/g++.dg/cpp1y/var-templ6.C b/gcc/testsuite/g++.dg/cpp1y/var-templ6.C
new file mode 100644 (file)
index 0000000..2125d6c
--- /dev/null
@@ -0,0 +1,12 @@
+// { dg-options "-std=c++1y" }
+
+template<typename T>
+  constexpr bool Class = __is_class(T);
+
+template<typename T>
+  constexpr bool Test = Class<T>;
+
+struct S { };
+
+static_assert(!Test<int>, "");
+static_assert(Test<S>, "");