Skip to content
Snippets Groups Projects
Commit 8dedf065 authored by Jakub Jelinek's avatar Jakub Jelinek
Browse files

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.
parent 90cb088e
No related branches found
No related tags found
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment