This fixes an ICE-on-invalid, where we're passing error_mark_node to useless_type_conversion_p which can't handle that.
Bootstrapped/regtested on x86_64-linux, ok for trunk? 2018-01-31 Marek Polacek <pola...@redhat.com> 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. diff --git gcc/cp/cp-gimplify.c gcc/cp/cp-gimplify.c index 21859251795..55a9d278dbe 100644 --- gcc/cp/cp-gimplify.c +++ gcc/cp/cp-gimplify.c @@ -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); diff --git gcc/testsuite/g++.dg/diagnostic/pr84138.C gcc/testsuite/g++.dg/diagnostic/pr84138.C index e69de29bb2d..5c48b9b164a 100644 --- gcc/testsuite/g++.dg/diagnostic/pr84138.C +++ gcc/testsuite/g++.dg/diagnostic/pr84138.C @@ -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" } Marek