diff options
author | Jakub Jelinek <jakub@redhat.com> | 2021-11-26 10:11:13 +0100 |
---|---|---|
committer | Jakub Jelinek <jakub@redhat.com> | 2021-11-26 10:16:20 +0100 |
commit | 8dedf065aff22b09bd4e48e1be0b77c58d297100 (patch) | |
tree | f9063b4c4b6aad9b441a7916cfdce755ae1eaab7 /gcc/cp/tree.c | |
parent | 90cb088ece8d8cc1019d25629d1585e5b0234179 (diff) | |
download | gcc-8dedf065aff22b09bd4e48e1be0b77c58d297100.zip gcc-8dedf065aff22b09bd4e48e1be0b77c58d297100.tar.gz gcc-8dedf065aff22b09bd4e48e1be0b77c58d297100.tar.bz2 |
c++: Fix up taking address of an immediate function diagnostics [PR102753]
On Wed, Oct 20, 2021 at 07:16:44PM -0400, Jason Merrill wrote:
> or an unevaluated operand, or a subexpression of an immediate invocation.
>
> Hmm...that suggests that in consteval23.C, bar(foo) should also be OK,
The following patch handles that by removing the diagnostics about taking
address of immediate function from cp_build_addr_expr_1, and instead diagnoses
it in cp_fold_r. To do that with proper locations, the patch attempts to
ensure that ADDR_EXPRs of immediate functions get EXPR_LOCATION set and
adds a PTRMEM_CST_LOCATION for PTRMEM_CSTs. Also, evaluation of
std::source_location::current() is moved from genericization to cp_fold.
2021-11-26 Jakub Jelinek <jakub@redhat.com>
PR c++/102753
* cp-tree.h (struct ptrmem_cst): Add locus member.
(PTRMEM_CST_LOCATION): Define.
* tree.c (make_ptrmem_cst): Set PTRMEM_CST_LOCATION to input_location.
(cp_expr_location): Return PTRMEM_CST_LOCATION for PTRMEM_CST.
* typeck.c (build_x_unary_op): Overwrite PTRMEM_CST_LOCATION for
PTRMEM_CST instead of calling maybe_wrap_with_location.
(cp_build_addr_expr_1): Don't diagnose taking address of
immediate functions here. Instead when taking their address make
sure the returned ADDR_EXPR has EXPR_LOCATION set.
(expand_ptrmemfunc_cst): Copy over PTRMEM_CST_LOCATION to ADDR_EXPR's
EXPR_LOCATION.
(convert_for_assignment): Use cp_expr_loc_or_input_loc instead of
EXPR_LOC_OR_LOC.
* pt.c (tsubst_copy): Use build1_loc instead of build1. Ensure
ADDR_EXPR of immediate function has EXPR_LOCATION set.
* cp-gimplify.c (cp_fold_r): Diagnose taking address of immediate
functions here. For consteval if don't walk THEN_CLAUSE.
(cp_genericize_r): Move evaluation of calls to
std::source_location::current from here to...
(cp_fold): ... here. Don't assert calls to immediate functions must
be source_location_current_p, instead only constant evaluate
calls to source_location_current_p.
* g++.dg/cpp2a/consteval20.C: Add some extra tests.
* g++.dg/cpp2a/consteval23.C: Likewise.
* g++.dg/cpp2a/consteval25.C: New test.
* g++.dg/cpp2a/srcloc20.C: New test.
Diffstat (limited to 'gcc/cp/tree.c')
-rw-r--r-- | gcc/cp/tree.c | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c index 7c58e23..1471ed8 100644 --- a/gcc/cp/tree.c +++ b/gcc/cp/tree.c @@ -5196,6 +5196,7 @@ make_ptrmem_cst (tree type, tree member) tree ptrmem_cst = make_node (PTRMEM_CST); TREE_TYPE (ptrmem_cst) = type; PTRMEM_CST_MEMBER (ptrmem_cst) = member; + PTRMEM_CST_LOCATION (ptrmem_cst) = input_location; return ptrmem_cst; } @@ -6040,6 +6041,8 @@ cp_expr_location (const_tree t_) return STATIC_ASSERT_SOURCE_LOCATION (t); case TRAIT_EXPR: return TRAIT_EXPR_LOCATION (t); + case PTRMEM_CST: + return PTRMEM_CST_LOCATION (t); default: return EXPR_LOCATION (t); } |