re PR c++/84138 (ICE folding broken constant)
authorMarek Polacek <polacek@redhat.com>
Wed, 31 Jan 2018 15:37:18 +0000 (15:37 +0000)
committerMarek Polacek <mpolacek@gcc.gnu.org>
Wed, 31 Jan 2018 15:37:18 +0000 (15:37 +0000)
PR c++/84138
* cp-gimplify.c (cp_fold): Check if X is an error node before
calling useless_type_conversion_p.

* g++.dg/diagnostic/pr84138.C: New test.

From-SVN: r257240

gcc/cp/ChangeLog
gcc/cp/cp-gimplify.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/diagnostic/pr84138.C [new file with mode: 0644]

index ceb1e85632448674f789771241d906d0fa9b5692..f89f3ce0274cba71c76a89ebcb4311e3941fbf1c 100644 (file)
@@ -1,3 +1,9 @@
+2018-01-31  Marek Polacek  <polacek@redhat.com>
+
+       PR c++/84138
+       * cp-gimplify.c (cp_fold): Check if X is an error node before
+       calling useless_type_conversion_p.
+
 2018-01-30  Jason Merrill  <jason@redhat.com>
 
        PR c++/84091 - ICE with local class in lambda in template.
index 21859251795bb82fd875d7f10b674d41694e38e1..55a9d278dbe316972ca0b9651cfb40bc72e5e395 100644 (file)
@@ -2356,6 +2356,7 @@ cp_fold (tree x)
       /* A COND_EXPR might have incompatible types in branches if one or both
         arms are bitfields.  If folding exposed such a branch, fix it up.  */
       if (TREE_CODE (x) != code
+         && x != error_mark_node
          && !useless_type_conversion_p (TREE_TYPE (org_x), TREE_TYPE (x)))
        x = fold_convert (TREE_TYPE (org_x), x);
 
index a2ca981d3f537d849cac9b7102bd54c0f4b5068b..27c568508c9a417ce56796aa743315b207226913 100644 (file)
@@ -1,3 +1,8 @@
+2018-01-31  Marek Polacek  <polacek@redhat.com>
+
+       PR c++/84138
+       * g++.dg/diagnostic/pr84138.C: New test.
+
 2018-01-31  Janne Blomqvist  <jb@gcc.gnu.org>
 
        PR fortran/78534
diff --git a/gcc/testsuite/g++.dg/diagnostic/pr84138.C b/gcc/testsuite/g++.dg/diagnostic/pr84138.C
new file mode 100644 (file)
index 0000000..5c48b9b
--- /dev/null
@@ -0,0 +1,8 @@
+// PR c++/84138
+
+char
+foo()
+{
+  const int i = 0 = 0; // { dg-error "lvalue required as left operand" }
+  return 1 ? 0 : (char)i;
+} // { dg-warning "control reaches" }