aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp/pt.c
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2021-11-26 10:11:13 +0100
committerJakub Jelinek <jakub@redhat.com>2021-11-26 10:16:20 +0100
commit8dedf065aff22b09bd4e48e1be0b77c58d297100 (patch)
treef9063b4c4b6aad9b441a7916cfdce755ae1eaab7 /gcc/cp/pt.c
parent90cb088ece8d8cc1019d25629d1585e5b0234179 (diff)
downloadgcc-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/pt.c')
-rw-r--r--gcc/cp/pt.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 221628a..7432370 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -17012,9 +17012,16 @@ tsubst_copy (tree t, tree args, tsubst_flags_t complain, tree in_decl)
{
tree type = tsubst (TREE_TYPE (t), args, complain, in_decl);
tree op0 = tsubst_copy (TREE_OPERAND (t, 0), args, complain, in_decl);
- r = build1 (code, type, op0);
+ r = build1_loc (EXPR_LOCATION (t), code, type, op0);
if (code == ALIGNOF_EXPR)
ALIGNOF_EXPR_STD_P (r) = ALIGNOF_EXPR_STD_P (t);
+ /* For addresses of immediate functions ensure we have EXPR_LOCATION
+ set for possible later diagnostics. */
+ if (code == ADDR_EXPR
+ && EXPR_LOCATION (r) == UNKNOWN_LOCATION
+ && TREE_CODE (op0) == FUNCTION_DECL
+ && DECL_IMMEDIATE_FUNCTION_P (op0))
+ SET_EXPR_LOCATION (r, input_location);
return r;
}