diff mbox

[C++] Fix ICE with scoped enums and -g (PR c++/72808)

Message ID 20161125173137.GL3541@tucnak.redhat.com
State New
Headers show

Commit Message

Jakub Jelinek Nov. 25, 2016, 5:31 p.m. UTC
Hi!

As mentioned in the PR, we ICE during type verification called from
dwarf2out, because a class has different TYPE_FIELDS from its variants.
In particular it contains an extra CONST_DECL.
While CONST_DECLs are ignored for C/C++ in dwarf2out.c, I think they aren't
ignored for Fortran/Ada, so ignoring them in the verifier might be too
risky.

This patch instead fixes the variants immediately.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

Another possibility would be just to update TYPE_FIELDS of the variants
instead of calling whole fixup_type_variants.

2016-11-25  Jakub Jelinek  <jakub@redhat.com>

	PR c++/72808
	* decl.c (build_enumerator): Call fixup_type_variants on
	current_class_type after finish_member_declaration.

	* g++.dg/debug/pr72808.C: New test.


	Jakub

Comments

Jason Merrill Nov. 28, 2016, 2:44 p.m. UTC | #1
On Fri, Nov 25, 2016 at 12:31 PM, Jakub Jelinek <jakub@redhat.com> wrote:
>         * decl.c (build_enumerator): Call fixup_type_variants on
>         current_class_type after finish_member_declaration.

Let's do this in finish_enum_value_list, in the block controlled by

  if (at_class_scope_p ()
      && COMPLETE_TYPE_P (current_class_type)
      && UNSCOPED_ENUM_P (enumtype))

Jason
diff mbox

Patch

--- gcc/cp/decl.c.jj	2016-11-23 19:44:40.000000000 +0100
+++ gcc/cp/decl.c	2016-11-25 13:15:46.407116179 +0100
@@ -14518,6 +14518,7 @@  incremented enumerator value is too larg
 	current_access_specifier = access_public_node;
 
       finish_member_declaration (decl);
+      fixup_type_variants (current_class_type);
 
       current_access_specifier = saved_cas;
     }
--- gcc/testsuite/g++.dg/debug/pr72808.C.jj	2016-11-25 13:17:06.777091600 +0100
+++ gcc/testsuite/g++.dg/debug/pr72808.C	2016-11-25 13:16:27.000000000 +0100
@@ -0,0 +1,24 @@ 
+// PR c++/72808
+// { dg-do compile }
+// { dg-options "-g -std=c++14" }
+
+struct A
+{
+  virtual void foo ();
+};
+
+struct B : A
+{
+  void foo ();
+  enum C : int;
+};
+
+enum B::C : int
+{
+  D
+};
+
+void
+B::foo ()
+{
+}