diff options
author | Patrick Palka <ppalka@redhat.com> | 2022-03-26 10:20:18 -0400 |
---|---|---|
committer | Patrick Palka <ppalka@redhat.com> | 2022-03-26 10:20:18 -0400 |
commit | ff465bd8a0f0f96a00d3067018442917b194b7af (patch) | |
tree | f15d80be7e43b2fc92aa879bd2eec915bada60b4 /gcc/cp/constexpr.cc | |
parent | 04f19580e8dbdbc7366d0f5fd068aa0cecafdc9d (diff) | |
download | gcc-ff465bd8a0f0f96a00d3067018442917b194b7af.zip gcc-ff465bd8a0f0f96a00d3067018442917b194b7af.tar.gz gcc-ff465bd8a0f0f96a00d3067018442917b194b7af.tar.bz2 |
c++: diagnosing if-stmt with non-constant branches [PR105050]
When an if-stmt is determined to be non-constant because both of its
branches are non-constant, we issue a somewhat generic error which,
since the error also points to the 'if' token, misleadingly suggests
the condition is at fault:
constexpr-105050.C:8:3: error: expression ‘<statement>’ is not a constant expression
8 | if (p != q && *p < 0)
| ^~
This patch clarifies the error message to instead read:
constexpr-105050.C:8:3: error: neither branch of ‘if’ is a constant expression
8 | if (p != q && *p < 0)
| ^~
PR c++/105050
gcc/cp/ChangeLog:
* constexpr.cc (potential_constant_expression_1) <case IF_STMT>:
Clarify error message when a if-stmt is non-constant because its
branches are non-constant.
gcc/testsuite/ChangeLog:
* g++.dg/cpp1y/constexpr-105050.C: New test.
Diffstat (limited to 'gcc/cp/constexpr.cc')
-rw-r--r-- | gcc/cp/constexpr.cc | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/gcc/cp/constexpr.cc b/gcc/cp/constexpr.cc index 778680b..9c40b05 100644 --- a/gcc/cp/constexpr.cc +++ b/gcc/cp/constexpr.cc @@ -9439,7 +9439,12 @@ potential_constant_expression_1 (tree t, bool want_rval, bool strict, bool now, } } if (flags & tf_error) - error_at (loc, "expression %qE is not a constant expression", t); + { + if (TREE_CODE (t) == IF_STMT) + error_at (loc, "neither branch of %<if%> is a constant expression"); + else + error_at (loc, "expression %qE is not a constant expression", t); + } return false; case VEC_INIT_EXPR: |