On Sun, Jan 19, 2020 at 03:34:48PM -0500, Marek Polacek wrote:
> 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))
Shouldn't it instead do
if (fndecl == NULL_TREE)
return false;
before the fndecl_built_in_p check?
While decl_in_std_namespace_p apparently will return false for NULL
argument, relying on that is werid.
Jakub