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 38b60bc695f3595128983eac573dd2ceeb952c87..c036f8cf0e066bee23965dc61181fab087dfdd76 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 6ba7c13d6ec5ee29894f4647178c09124f7be5f6..67f8b9264f169cf6282cdd7189fca248b9a930e3 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 628529b535cd0ad99cf0fd5273d2ed4f09015ff5..31e7b4fb79e0ce753d7156128164e996cc1f8b04 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" }