]> gcc.gnu.org Git - gcc.git/commitdiff
re PR c++/55240 ([c++0x] ICE on non-static data member initialization using 'auto...
authorJason Merrill <jason@redhat.com>
Sun, 17 Mar 2013 02:34:45 +0000 (22:34 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Sun, 17 Mar 2013 02:34:45 +0000 (22:34 -0400)
PR c++/55240
* parser.c (parsing_nsdmi): New.
* semantics.c (outer_automatic_var_p): Check it.
(finish_id_expression): Likewise.
* cp-tree.h: Declare it.

From-SVN: r196727

gcc/cp/ChangeLog
gcc/cp/cp-tree.h
gcc/cp/parser.c
gcc/cp/semantics.c
gcc/testsuite/g++.dg/cpp0x/nsdmi-local.C [new file with mode: 0644]

index 5b278201f7b6234d419bd15a2d2bc2db7ff59623..04eab4a67d1a694b6a6b710acb0e3a9e9136b0d0 100644 (file)
@@ -1,5 +1,11 @@
 2013-03-16  Jason Merrill  <jason@redhat.com>
 
+       PR c++/55240
+       * parser.c (parsing_nsdmi): New.
+       * semantics.c (outer_automatic_var_p): Check it.
+       (finish_id_expression): Likewise.
+       * cp-tree.h: Declare it.
+
        PR c++/55241
        * error.c (dump_expr) [SIZEOF_EXPR]: Print sizeof... properly.
 
index c3b2aecf3b1cd1eb8b8948436a954e5dffc4a304..d9496d28c2a326b2c45b8daef93ed6dfff6def1d 100644 (file)
@@ -4259,6 +4259,7 @@ extern int comparing_specializations;
 
 extern int cp_unevaluated_operand;
 extern tree cp_convert_range_for (tree, tree, tree);
+extern bool parsing_nsdmi (void);
 
 /* in pt.c  */
 
index 12926e3d9d43da1d83492ff3dd2c6d0a6568cb37..0a3740db6dbea593fd1be52747d141b634db03d9 100644 (file)
@@ -16938,6 +16938,19 @@ inject_this_parameter (tree ctype, cp_cv_quals quals)
   current_class_ptr = this_parm;
 }
 
+/* Return true iff our current scope is a non-static data member
+   initializer.  */
+
+bool
+parsing_nsdmi (void)
+{
+  /* We recognize NSDMI context by the context-less 'this' pointer set up
+     by the function above.  */
+  if (current_class_ptr && DECL_CONTEXT (current_class_ptr) == NULL_TREE)
+    return true;
+  return false;
+}
+
 /* Parse a late-specified return type, if any.  This is not a separate
    non-terminal, but part of a function declarator, which looks like
 
index 3c76bad5a3d59ced69bbb8293fc6860da27de1ae..efe09bb14b2511f9839123f4c54dd52bc17a1335 100644 (file)
@@ -2884,7 +2884,8 @@ outer_var_p (tree decl)
 {
   return ((TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == PARM_DECL)
          && DECL_FUNCTION_SCOPE_P (decl)
-         && DECL_CONTEXT (decl) != current_function_decl);
+         && (DECL_CONTEXT (decl) != current_function_decl
+             || parsing_nsdmi ()));
 }
 
 /* As above, but also checks that DECL is automatic.  */
@@ -3041,12 +3042,14 @@ finish_id_expression (tree id_expression,
                return integral_constant_value (decl);
            }
 
+         if (parsing_nsdmi ())
+           containing_function = NULL_TREE;
          /* If we are in a lambda function, we can move out until we hit
             1. the context,
             2. a non-lambda function, or
             3. a non-default capturing lambda function.  */
-         while (context != containing_function
-                && LAMBDA_FUNCTION_P (containing_function))
+         else while (context != containing_function
+                     && LAMBDA_FUNCTION_P (containing_function))
            {
              lambda_expr = CLASSTYPE_LAMBDA_EXPR
                (DECL_CONTEXT (containing_function));
diff --git a/gcc/testsuite/g++.dg/cpp0x/nsdmi-local.C b/gcc/testsuite/g++.dg/cpp0x/nsdmi-local.C
new file mode 100644 (file)
index 0000000..9b84c8c
--- /dev/null
@@ -0,0 +1,8 @@
+// PR c++/55240
+// { dg-do compile { target c++11 } }
+
+int main()
+{
+    int q = 1;                          // { dg-error "declared here" }
+    struct test { int x = q; } instance; // { dg-error "local variable" }
+}
This page took 0.105472 seconds and 5 git commands to generate.