This prevents segfault in ocp_convert. If the ENUM_UNDERLYING_TYPE is NULL, don't call int_fits_type_p on it. We give meaningful error message on the attached testcase; it's the same message as GCC 3.4/4.0.2/4.4 gave (these GCC didn't ICE on it).
Bootstrapped/regtested on x86_64-linux, ok for trunk/4.8/4.7? 2014-01-17 Marek Polacek <pola...@redhat.com> PR c++/59838 cp/ * cvt.c (ocp_convert): Don't segfault on non-existing ENUM_UNDERLYING_TYPE. testsuite/ * g++.dg/diagnostic/pr59838.C: New test. --- gcc/cp/cvt.c.mp3 2014-01-17 12:01:20.926793491 +0100 +++ gcc/cp/cvt.c 2014-01-17 12:01:55.297920771 +0100 @@ -753,6 +753,7 @@ ocp_convert (tree type, tree expr, int c unspecified. */ if ((complain & tf_warning) && TREE_CODE (e) == INTEGER_CST + && ENUM_UNDERLYING_TYPE (type) && !int_fits_type_p (e, ENUM_UNDERLYING_TYPE (type))) warning_at (loc, OPT_Wconversion, "the result of the conversion is unspecified because " --- gcc/testsuite/g++.dg/diagnostic/pr59838.C.mp3 2014-01-17 12:21:08.111663754 +0100 +++ gcc/testsuite/g++.dg/diagnostic/pr59838.C 2014-01-17 12:22:08.192886710 +0100 @@ -0,0 +1,4 @@ +// PR c++/59838 +// { dg-do compile } + +enum E { a, b = (E) a }; // { dg-error "conversion to incomplete type" } Marek