PR c++/79580 - ICE with compound literal
authorJason Merrill <jason@redhat.com>
Mon, 20 Feb 2017 06:05:08 +0000 (01:05 -0500)
committerJason Merrill <jason@gcc.gnu.org>
Mon, 20 Feb 2017 06:05:08 +0000 (01:05 -0500)
* parser.c (cp_parser_class_head): If we're in the middle of an
expression, use ts_within_enclosing_non_class.

From-SVN: r245587

gcc/cp/ChangeLog
gcc/cp/parser.c
gcc/testsuite/g++.dg/ext/complit15.C [new file with mode: 0644]

index 9b071ebef9e8c6d52be63fc37b64c8132f0ac730..79fee99c4f389cf96bd805361924467e46785a2b 100644 (file)
@@ -1,5 +1,9 @@
 2017-02-19  Jason Merrill  <jason@redhat.com>
 
+       PR c++/79580 - ICE with compound literal
+       * parser.c (cp_parser_class_head): If we're in the middle of an
+       expression, use ts_within_enclosing_non_class.
+
        PR c++/79503 - inherited ctor taking base class
        * call.c (add_function_candidate): Also check that
        DECL_INHERITED_CTOR_BASE is reference-related to the parameter type.
index feeafcec6ad21c37b4e86db5b3b4fb07d14792d0..4656b4f02da1856749bfa8a2a435bbe12cbe6c28 100644 (file)
@@ -22771,7 +22771,10 @@ cp_parser_class_head (cp_parser* parser,
       /* If the class was unnamed, create a dummy name.  */
       if (!id)
        id = make_anon_name ();
-      type = xref_tag (class_key, id, /*tag_scope=*/ts_current,
+      tag_scope tag_scope = (parser->in_type_id_in_expr_p
+                            ? ts_within_enclosing_non_class
+                            : ts_current);
+      type = xref_tag (class_key, id, tag_scope,
                       parser->num_template_parameter_lists);
     }
 
diff --git a/gcc/testsuite/g++.dg/ext/complit15.C b/gcc/testsuite/g++.dg/ext/complit15.C
new file mode 100644 (file)
index 0000000..f12752d
--- /dev/null
@@ -0,0 +1,8 @@
+// PR c++/79580
+// { dg-options "-flto -std=c++98" }
+
+class a
+{
+  static const double b;
+};
+const double a::b ((union { double c; }){}.c);