re PR c++/79657 (ICE on invalid c++ code in finish_underlying_type cp/semantics.c...
authorMarek Polacek <polacek@redhat.com>
Wed, 22 Feb 2017 19:33:13 +0000 (19:33 +0000)
committerMarek Polacek <mpolacek@gcc.gnu.org>
Wed, 22 Feb 2017 19:33:13 +0000 (19:33 +0000)
PR c++/79657
* semantics.c (finish_underlying_type): Bail out for incomplete enums.

* g++.dg/ext/underlying_type12.C: New test.

From-SVN: r245658

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

index 38b60bc..c036f8c 100644 (file)
@@ -6,6 +6,9 @@
        * pt.c (tsubst_attribute): If tsubst_pack_expansion fails, return
        error_mark_node.
 
+       PR c++/79657
+       * semantics.c (finish_underlying_type): Bail out for incomplete enums.
+
 2017-02-21  Jason Merrill  <jason@redhat.com>
 
        PR c++/50308 - wrong deprecated warning with ADL
index 6ba7c13..67f8b92 100644 (file)
@@ -3838,7 +3838,8 @@ finish_underlying_type (tree type)
       return underlying_type;
     }
 
-  complete_type (type);
+  if (!complete_type_or_else (type, NULL_TREE))
+    return error_mark_node;
 
   if (TREE_CODE (type) != ENUMERAL_TYPE)
     {
index 628529b..31e7b4f 100644 (file)
@@ -4,6 +4,9 @@
        * g++.dg/cpp0x/alignas10.C: New test.
        * g++.dg/cpp0x/alignas9.C: New test.
 
+       PR c++/79657
+       * g++.dg/ext/underlying_type12.C: New test.
+
 2017-02-22  Jakub Jelinek  <jakub@redhat.com>
 
        PR target/70465
diff --git a/gcc/testsuite/g++.dg/ext/underlying_type12.C b/gcc/testsuite/g++.dg/ext/underlying_type12.C
new file mode 100644 (file)
index 0000000..050ecf2
--- /dev/null
@@ -0,0 +1,6 @@
+// PR c++/79657
+// { dg-do compile { target c++11 } }
+
+enum A { x };
+enum B { a = (__underlying_type (A)) 1 };
+enum C { b = (__underlying_type (C)) 1 }; // { dg-error "incomplete" }