If get_target_expr_sfinae gets an expression whose type is incomplete, it's upset. digest_init returns error_mark_node if it gets an expression with incomplete type, so we need to respect that, and not call get_target_expr_sfinae on ORIG_CL in that case.
Bootstrapped/regtested on x86_64-linux, ok for trunk? 2019-02-28 Marek Polacek <pola...@redhat.com> PR c++/89532 - ICE with incomplete type in decltype. * semantics.c (finish_compound_literal): Return error_mark_node if digest_init_flags returns error_mark_node. * g++.dg/cpp2a/nontype-class14.C: New test. diff --git gcc/cp/semantics.c gcc/cp/semantics.c index d1a378acd98..c03e4ef247c 100644 --- gcc/cp/semantics.c +++ gcc/cp/semantics.c @@ -2859,6 +2859,9 @@ finish_compound_literal (tree type, tree compound_literal, compound_literal = digest_init_flags (type, compound_literal, LOOKUP_NORMAL | LOOKUP_NO_NARROWING, complain); + if (compound_literal == error_mark_node) + return error_mark_node; + /* If we're in a template, return the original compound literal. */ if (orig_cl) { diff --git gcc/testsuite/g++.dg/cpp2a/nontype-class14.C gcc/testsuite/g++.dg/cpp2a/nontype-class14.C new file mode 100644 index 00000000000..4b19f81f97a --- /dev/null +++ gcc/testsuite/g++.dg/cpp2a/nontype-class14.C @@ -0,0 +1,10 @@ +// PR c++/89532 +// { dg-do compile { target c++2a } } + +struct tuple; + +template <decltype(tuple {})> // { dg-error "invalid use of incomplete type" } +struct S { }; + +template<typename> +decltype(tuple {}) d; // { dg-error "invalid use of incomplete type" }