This is a crash with constexpr if, when trying to see if the call in the if-statement is std::is_constant_evaluated.
cp_get_callee_fndecl_nofold can return NULL_TREE and fndecl_built_in_p doesn't expect to get a null tree, so check FNDECL first. Bootstrapped/regtested on x86_64-linux, ok for trunk? * semantics.c (is_std_constant_evaluated_p): Check fndecl. * g++.dg/cpp1z/constexpr-if33.C: New test. --- gcc/cp/semantics.c | 4 ++-- gcc/testsuite/g++.dg/cpp1z/constexpr-if33.C | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp1z/constexpr-if33.C diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index 3669b247e34..9051a2863e0 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -734,8 +734,8 @@ is_std_constant_evaluated_p (tree fn) return false; tree fndecl = cp_get_callee_fndecl_nofold (fn); - if (fndecl_built_in_p (fndecl, CP_BUILT_IN_IS_CONSTANT_EVALUATED, - BUILT_IN_FRONTEND)) + if (fndecl && fndecl_built_in_p (fndecl, CP_BUILT_IN_IS_CONSTANT_EVALUATED, + BUILT_IN_FRONTEND)) return true; if (!decl_in_std_namespace_p (fndecl)) diff --git a/gcc/testsuite/g++.dg/cpp1z/constexpr-if33.C b/gcc/testsuite/g++.dg/cpp1z/constexpr-if33.C new file mode 100644 index 00000000000..e5ef659932b --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1z/constexpr-if33.C @@ -0,0 +1,16 @@ +// PR c++/93324 - ICE with -Wall on constexpr if. +// { dg-do compile { target c++17 } } +// { dg-options "-Wall" } + +struct { + template <int> + static constexpr bool a() { return 0; } +} e; + +template <typename> +void d() +{ + auto c(e); + using b = decltype(c); + if constexpr (b::a<2>()); +} base-commit: bcfc2227c556f2801a657ce3007374732baa8333 -- 2.24.1