]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR c++/39608 ('expr' cannot appear in a constant-expression.)
authorJason Merrill <jason@redhat.com>
Fri, 3 Apr 2009 17:24:46 +0000 (13:24 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Fri, 3 Apr 2009 17:24:46 +0000 (13:24 -0400)
        PR c++/39608
        * semantics.c (finish_id_expression): Don't assume a dependent
        member of the current instantiation isn't a valid integral
        constant expression.  Check dependent_scope_p.
        * pt.c (dependent_scope_p): Check TYPE_P.

From-SVN: r145508

gcc/cp/ChangeLog
gcc/cp/pt.c
gcc/cp/semantics.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/template/const2.C [new file with mode: 0644]

index 5cba9d0747a97dc82ccf3cfa72800c443193332d..9bc48b6baf4364593c209973680db433433a48c2 100644 (file)
@@ -1,3 +1,12 @@
+2009-04-03  Jason Merrill  <jason@redhat.com>
+
+       PR c++/39608
+       * semantics.c (finish_id_expression): Don't assume a dependent
+       member of the current instantiation isn't a valid integral
+       constant expression.  Check dependent_scope_p.
+       * pt.c (dependent_scope_p): Check TYPE_P.
+       (tsubst_copy): If args is null, just return.
+
 2009-04-02  Jason Merrill  <jason@redhat.com>
 
        PR c++/25185
index 8b2fa6e7e17c21f15c5f1d160c972c3bc2403633..90be6bcf9c05560d7905877bb8079cf098224e57 100644 (file)
@@ -9999,7 +9999,7 @@ tsubst_copy (tree t, tree args, tsubst_flags_t complain, tree in_decl)
   enum tree_code code;
   tree r;
 
-  if (t == NULL_TREE || t == error_mark_node)
+  if (t == NULL_TREE || t == error_mark_node || args == NULL_TREE)
     return t;
 
   code = TREE_CODE (t);
@@ -16168,7 +16168,8 @@ dependent_type_p (tree type)
 bool
 dependent_scope_p (tree scope)
 {
-  return dependent_type_p (scope) && !currently_open_class (scope);
+  return (scope && TYPE_P (scope) && dependent_type_p (scope)
+         && !currently_open_class (scope));
 }
 
 /* Returns TRUE if EXPRESSION is dependent, according to CRITERION.  */
index ee8c0ccfafa4071ea2463dcb012c4c6c37ed2b23..337b6373b28361b10027d9819b09f428134b44d3 100644 (file)
@@ -2857,11 +2857,6 @@ finish_id_expression (tree id_expression,
             dependent.  */
          if (scope)
            {
-             /* Since this name was dependent, the expression isn't
-                constant -- yet.  No error is issued because it might
-                be constant when things are instantiated.  */
-             if (integral_constant_expression_p)
-               *non_integral_constant_expression_p = true;
              if (TYPE_P (scope))
                {
                  if (address_p && done)
@@ -2869,7 +2864,7 @@ finish_id_expression (tree id_expression,
                                                     done, address_p,
                                                     template_p,
                                                     template_arg_p);
-                 else if (dependent_type_p (scope))
+                 else if (dependent_scope_p (scope))
                    decl = build_qualified_name (/*type=*/NULL_TREE,
                                                 scope,
                                                 id_expression,
index ded87d66bdad5a52276c0dfbd6e90289764e2b27..2d697b1ea9732b21d7532833c6ba7ef0c930d86d 100644 (file)
@@ -1,3 +1,8 @@
+2009-04-03  Jason Merrill  <jason@redhat.com>
+
+       PR c++/39608
+       * g++.dg/template/const2.C: New test.
+
 2009-04-03  Richard Guenther  <rguenther@suse.de>
 
        PR tree-optimization/2480
diff --git a/gcc/testsuite/g++.dg/template/const2.C b/gcc/testsuite/g++.dg/template/const2.C
new file mode 100644 (file)
index 0000000..5188fe2
--- /dev/null
@@ -0,0 +1,16 @@
+// PR c++/39608
+// We were improperly considering dependent members of the current
+// instantiation to be non-constant (and therefore invalid template
+// non-type arguments).
+
+template <int I>
+struct C {};
+
+template <class T>
+struct A
+{
+  static const T x = 1;
+  C<A<T>::x> c;                        // { dg-bogus "invalid" }
+};
+
+A<int> a;