diff --git a/gcc/cp/constexpr.cc b/gcc/cp/constexpr.cc index abf6ee560c5..3de60cfd0f8 100644 --- a/gcc/cp/constexpr.cc +++ b/gcc/cp/constexpr.cc @@ -8796,6 +8796,10 @@ maybe_constant_init_1 (tree t, tree decl, bool allow_non_constant, && (TREE_STATIC (decl) || DECL_EXTERNAL (decl))); if (is_static) manifestly_const_eval = true; + + if (cp_unevaluated_operand && !manifestly_const_eval) + return fold_to_constant (t); + t = cxx_eval_outermost_constant_expr (t, allow_non_constant, !is_static, mce_value (manifestly_const_eval), false, decl); diff --git a/gcc/testsuite/g++.dg/cpp2a/constexpr-inst2.C b/gcc/testsuite/g++.dg/cpp2a/constexpr-inst2.C new file mode 100644 index 00000000000..7676b625321 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/constexpr-inst2.C @@ -0,0 +1,12 @@ +// { dg-do compile { target c++11 } } + +struct __as_receiver { + int empty_env; +}; + +template +constexpr int f(T t) { + return t.fail; +}; + +using type = decltype(__as_receiver{f(0)}); // OK, f not instantiated