Skip to content

[2026-03 LWG Motion 16] P3948R1 constant_wrapper is the only tool needed#8878

Merged
tkoeppe merged 2 commits into
cplusplus:mainfrom
eisenwave:motions-2026-03-lwg-16
Apr 19, 2026
Merged

[2026-03 LWG Motion 16] P3948R1 constant_wrapper is the only tool needed#8878
tkoeppe merged 2 commits into
cplusplus:mainfrom
eisenwave:motions-2026-03-lwg-16

Conversation

@eisenwave

@eisenwave eisenwave commented Mar 28, 2026

Copy link
Copy Markdown
Member

Fixes NB FR-019-210 and FR-021-218 (C++26 CD).

Fixes #8850

Also fixes cplusplus/papers#2598
Also fixes https://github.com/cplusplus/nbballot/issues/779
Also fixes https://github.com/cplusplus/nbballot/issues/788

@eisenwave

eisenwave commented Mar 28, 2026

Copy link
Copy Markdown
Member Author

@jwakely @mattkretz we have goofed HARD. The paper deletes constant_arg_t but not the deduction guides that function_ref has for it.

https://eel.is/c++draft/func.wrap.ref.deduct

(will deal with overfull hboxes once home btw)

Comment thread source/utilities.tex Outdated
@jwakely

jwakely commented Mar 28, 2026

Copy link
Copy Markdown
Member

@jwakely @mattkretz we have goofed HARD. The paper deletes constant_arg_t but not the deduction guides that function_ref has for it.

Can we just delete that (which is fine as an editorial change, because the draft is inconsistent if it refers to a type which no longer exists), or does it need to be changed to use constant_wrapper?

@eisenwave

eisenwave commented Mar 28, 2026

Copy link
Copy Markdown
Member Author

I believe the purpose of the deduction guides is to make things possible like

void f();
// CTAD
std::function_ref ref = std::nontype<f>;

Or now equivalently with std::cw<f>. If this no longer works as a result of deleting the deduction guides, that seems like an inadvertent design change.

I suppose the only editorial way to get the draft into a working state is to delete the deduction guides editorially and to reintroduce them by LWG issue. Any LWG resolutions won't be merged into the DIS anyway, right? We need to ship these motions.

@eisenwave eisenwave added this to the post-2026-03 milestone Mar 28, 2026
@zhihaoy

zhihaoy commented Mar 28, 2026

Copy link
Copy Markdown
Contributor

Herb reminded us that accepting motion can also introduce editorial change, so I suggest just finishing the renaming here.

@Mick235711

Copy link
Copy Markdown
Contributor

Personally, I support treating this as an editorial wording defect in the proposal, as the intention is obviously to replace all usage of constant_arg mechanically. In other similar renaming proposals, if the author left over a few instances in the wording, they are also editorially applied without LWG issues as long as the intention is clear when polling the motions.

@Bronek

Bronek commented Mar 29, 2026

Copy link
Copy Markdown
Member

@Mick235711 @zhihaoy I think in this case the intention was clear, so I would agree that this change should just replace constant_arg with constant_wrapper, ensuring that this CTAD works std::function_ref ref = std::cw<foo>; as long as that used to work std::function_ref ref = std::constant_arg<foo>; , for some nullary foo; and treat this as a necessary editorial.

EDIT: The intention was unfortunately not captured as clearly as I would wish, but my memory is rather clear that we wanted to "replace all the uses of constant_arg with constant_wrapper and remove constant_arg" and this is also what the paper being accepted says in the subject ("constant_wrapper is the only tool needed", emphasis mine)

@mattkretz

mattkretz commented Mar 29, 2026

Copy link
Copy Markdown
Member
  1. Sorry!
  2. I did change the deduction guide in my libstdc++ patch, so I really should have noticed by looking through the patch. 🤦
  3. I'll provide wording that matches a tested implementation and then we can decide whether we call that editorial or not. I agree that the intent of the change is very clear (replace constant_arg_t by constant_wrapper) and that the removal of constant_arg_t forces a (editorial) change to the deduction guide.

@mattkretz

Copy link
Copy Markdown
Member

This would be the necessary change for CTAD:
mattkretz@92a7ba1
I implemented it and it passes all (CTAD) tests in libstdc++.

@Bronek

Bronek commented Mar 29, 2026

Copy link
Copy Markdown
Member

This would be the necessary change for CTAD: mattkretz@92a7ba1 I implemented it and it passes all (CTAD) tests in libstdc++.

This looks like what we voted for in LEWG, i.e. design intent.

@Bronek

Bronek commented Mar 30, 2026

Copy link
Copy Markdown
Member

@jwakely @mattkretz we have goofed HARD. The paper deletes constant_arg_t but not the deduction guides that function_ref has for it.

Can we just delete that (which is fine as an editorial change, because the draft is inconsistent if it refers to a type which no longer exists), or does it need to be changed to use constant_wrapper?

I would argue that this needs to be changed to constant_wrapper like @mattkretz has demonstrated above, but it is your decision whether do it immediately or use a DR instead. Just a note that change to constant_wrapper reflects the design intent as approved by LEWG, which is why I personally think DR would be suboptimal.

@eisenwave eisenwave force-pushed the motions-2026-03-lwg-16 branch 2 times, most recently from 413817f to ef1752d Compare April 1, 2026 08:11
@eisenwave eisenwave requested a review from jwakely April 1, 2026 08:20
@eisenwave

Copy link
Copy Markdown
Member Author

I've incorporated Matthias' commit into the PR.

@eisenwave eisenwave force-pushed the motions-2026-03-lwg-16 branch from f7a4c11 to e4dda2f Compare April 1, 2026 08:22

@jwakely jwakely left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with the comments here that what LEWG approved did not include "and disable CTAD" so preserving support for CTAD is part of the intended change.

Thanks for the fixes to make the wording match that approved design.

Comment thread source/utilities.tex Outdated
vathpela pushed a commit to vathpela/gcc that referenced this pull request Apr 8, 2026
…nction_ref

This implements P3948R1: constant_wrapper is the only tool needed
for passing constant expressions via function arguments.

This changes function_ref from nontype_t to constant_wrapper and
implements the ambiguity check (static_asert in function_ref
from constant_wrapper constructor).

In addition to P3948R1 this also includes the (forgotten) deduction
guide changes suggested in the draft PR [1].

[1] cplusplus/draft#8878

libstdc++-v3/ChangeLog:

	* include/bits/funcref_impl.h (function_ref::function_ref):
	Change nontype_t parameter to constant_wrapper, and adjust
	accordingly. Add static_assert detecting ambigous semantics.
	(function_ref::operator=): Detect constant_wrapper rather than
	nontype_t.
	* include/bits/funcwrap.h (function_ref): Change nontype_t
	parameter to constant_wrapper in deduction guides.
	* include/bits/utility.h (std::nontype_t, std::nontype)
	(std::__is_nontype_v): Remove.
	(std::__is_constant_wrapper_v): Define.
	* src/c++23/std.cc.in (std::nontype_t, std::nontype):
	Remove exports.
	* testsuite/20_util/function_ref/cw_cons_neg.cc: New tests
	for ambiguity check.
	* testsuite/20_util/function_ref/assign.cc: Replace nontype_t
	with constant_wrapper and nontype with std::cw.
	* testsuite/20_util/function_ref/call.cc: Likewise.
	* testsuite/20_util/function_ref/cons.cc: Likewise.
	* testsuite/20_util/function_ref/cons_neg.cc: Likewise.
	* testsuite/20_util/function_ref/dangling.cc: Likewise.
	* testsuite/20_util/function_ref/deduction.cc: Likewise.
	* testsuite/20_util/function_ref/mutation.cc: Likewise.

Co-authored-by: Tomasz Kamiński <tkaminsk@redhat.com>
Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
Signed-off-by: Matthias Kretz <m.kretz@gsi.de>
Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
@tkoeppe tkoeppe force-pushed the motions-2026-03-lwg-16 branch from 6c248b5 to 9de2095 Compare April 19, 2026 13:21
… expressions via function arguments

Fixes NB FR 019-210 and FR 021-218 (C++26 CD).
@tkoeppe tkoeppe force-pushed the motions-2026-03-lwg-16 branch from 9de2095 to f45a38e Compare April 19, 2026 13:23
@tkoeppe

tkoeppe commented Apr 19, 2026

Copy link
Copy Markdown
Contributor

Thanks, everyone!

@tkoeppe tkoeppe merged commit 4ab5c4f into cplusplus:main Apr 19, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

8 participants