Message ID | 5c61f1e5-5695-54d3-91e4-72f71cf39667@oracle.com |
---|---|
State | New |
Headers | show |
Series | [C++] PR 85028 ("[8 Regression] ICE on invalid C++ code: in tsubst_default_argument, at cp/pt.c:12340") | expand |
OK. On Wed, Mar 28, 2018 at 8:25 AM, Paolo Carlini <paolo.carlini@oracle.com> wrote: > Hi, > > as I said in the audit trail, in its way this error recovery issue is > somewhat interesting: Jason's r251422 added some code at the beginning of > tsubst_default_argument, included the gcc_assert that triggers here. In > fact, parmtype is only used in the assertion thus the error recovery check > could be moved inside the assertion, something like (appears to also pass > testing, lightly tested, so far): > > gcc_assert (parmtype == error_mark_node || > same_type_ignoring_top_level_qualifiers_p (type, parmtype)); > > and for this bug we would be back to the gcc-7 status, thus we would not ICE > and we would issue *2* errors, one for the parameter and then one more for > the default argument itself, at instantiation time. In fact, some other > compilers also do that. Or, as I have below, we can return early, after the > first error. Tested x86_64-linux. > > Thanks, Paolo. > > /////////////////// >
Index: cp/pt.c =================================================================== --- cp/pt.c (revision 258915) +++ cp/pt.c (working copy) @@ -12337,6 +12337,9 @@ tsubst_default_argument (tree fn, int parmnum, tre tree parmtype = TREE_TYPE (parm); if (DECL_BY_REFERENCE (parm)) parmtype = TREE_TYPE (parmtype); + if (parmtype == error_mark_node) + return error_mark_node; + gcc_assert (same_type_ignoring_top_level_qualifiers_p (type, parmtype)); tree *slot; Index: testsuite/g++.dg/other/default13.C =================================================================== --- testsuite/g++.dg/other/default13.C (nonexistent) +++ testsuite/g++.dg/other/default13.C (working copy) @@ -0,0 +1,11 @@ +// PR c++/85028 + +struct A; + +template < typename > struct B +{ + B (int, A = A()) : f (0) {} // { dg-error "incomplete type" } + int f; +}; + +B < int > b (0);