Skip to content

[func.wrap.ref.deduct] simplify wording#8955

Open
zhihaoy wants to merge 1 commit intocplusplus:mainfrom
zhihaoy:patch-3
Open

[func.wrap.ref.deduct] simplify wording#8955
zhihaoy wants to merge 1 commit intocplusplus:mainfrom
zhihaoy:patch-3

Conversation

@zhihaoy
Copy link
Copy Markdown
Contributor

@zhihaoy zhihaoy commented Apr 20, 2026

No description provided.

@frederick-vs-ja
Copy link
Copy Markdown
Contributor

This seems to be a functional change and thus perhaps requires an LWG issue.

The 2nd template argument of constant_wrapper is possibly provided by the user (and thus can be a function type whatever c is), and the change will affect such (pathological, IMO) uses. Presumably these deduction guides should rely on constant_wrapper::value_type.

@eisenwave eisenwave added lwg Issue must be reviewed by LWG. not-editorial Issue is not deemed editorial; the editorial issue is kept open for tracking. labels Apr 20, 2026
@eisenwave
Copy link
Copy Markdown
Member

Yeah right, https://eel.is/c++draft/const.wrap.class#lib:constant_wrapper doesn't put any Constraints or Mandates on the second template parameter; so it could be literally anything.

Concretely, the proposed change makes it invalid to use the deduction guide with constant_wrapper</* ... */, int()> because remove_pointer_t accepts non-pointers, but F* would fail deduction.

@zhihaoy
Copy link
Copy Markdown
Contributor Author

zhihaoy commented Apr 20, 2026

Concretely, the proposed change makes it invalid to use the deduction guide with constant_wrapper</* ... */, int()> because remove_pointer_t accepts non-pointers, but F* would fail deduction.

Then we got a bigger problem: function_ref(std::constant_wrapper<nullptr, int()>{}) can bypass the ctor's Mandates and break the class invariant.

@eisenwave
Copy link
Copy Markdown
Member

@zhihaoy Have you submitted an LWG issue yet?

@lichray
Copy link
Copy Markdown
Contributor

lichray commented Apr 27, 2026

@zhihaoy Have you submitted an LWG issue yet?

Now sent.

@frederick-vs-ja
Copy link
Copy Markdown
Contributor

P4206R0 seems relevant to this.

@zhihaoy
Copy link
Copy Markdown
Contributor Author

zhihaoy commented Apr 28, 2026

P4206R0 seems relevant to this.

Yes, it happens to offer a drive-by fix for the issue I sent.

@jwakely
Copy link
Copy Markdown
Member

jwakely commented Apr 28, 2026

Yes:

If a specialization of constant_wrapper is instantiated with a type T such that is_same_v<T, value_type> is false, the program is ill-formed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lwg Issue must be reviewed by LWG. not-editorial Issue is not deemed editorial; the editorial issue is kept open for tracking.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants