Skip to content

[expr.const] Check the result object of a prvalue #6267

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 15, 2025

Conversation

frederick-vs-ja
Copy link
Contributor

Fixes #5422.

The remain issue (modulo CWG2558) is that we shouldn't imply a prvalue is an object, which is not true since C++17.

@lprv
Copy link
Contributor

lprv commented Jun 5, 2023

A prvalue may not have a result object, at least in the scalar case.

@frederick-vs-ja
Copy link
Contributor Author

A prvalue may not have a result object, at least in the scalar case.

Although temporary materialization doesn't happen in some cases, I think it's harmless to require the result object for the purpose of checking whether the prvalue is a constant expression.

@wg21bot wg21bot added the needs rebase The pull request needs a git rebase to resolve merge conflicts. label Apr 19, 2024
@frederick-vs-ja frederick-vs-ja force-pushed the constant-result-object branch from 1bdc388 to 7eb1d52 Compare April 23, 2024 02:07
@frederick-vs-ja

This comment was marked as outdated.

@frederick-vs-ja

This comment was marked as outdated.

@tkoeppe tkoeppe removed the needs rebase The pull request needs a git rebase to resolve merge conflicts. label Oct 17, 2024
@wg21bot wg21bot added the needs rebase The pull request needs a git rebase to resolve merge conflicts. label Dec 19, 2024
@frederick-vs-ja
Copy link
Contributor Author

Rebased and force-pushed. @jensmaurer @tkoeppe

Copy link
Member

@jensmaurer jensmaurer left a comment

Choose a reason for hiding this comment

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

I think this is an improvement.

@jensmaurer jensmaurer removed the needs rebase The pull request needs a git rebase to resolve merge conflicts. label Dec 30, 2024
@lprv
Copy link
Contributor

lprv commented Dec 30, 2024

Although temporary materialization doesn't happen in some cases, I think it's harmless to require the result object for the purpose of checking whether the prvalue is a constant expression.

I disagree.

Here, for example, we surely want f() to be a constant expression, but it does not have a result object:

consteval int f() { return 42; };
int x = f() + 1;

The existing wording isn't correct but this change takes it further in the wrong direction.

@jensmaurer
Copy link
Member

Ok. Maybe just "result"?

@jensmaurer jensmaurer self-requested a review December 30, 2024 15:31
@frederick-vs-ja
Copy link
Contributor Author

Although temporary materialization doesn't happen in some cases, I think it's harmless to require the result object for the purpose of checking whether the prvalue is a constant expression.

I disagree.

Here, for example, we surely want f() to be a constant expression, but it does not have a result object:

consteval int f() { return 42; };
int x = f() + 1;

The existing wording isn't correct but this change takes it further in the wrong direction.

What's the harm if we require a result object for the determination? Did you mean that if we can't even say "a prvalue whose result object..." without actual temporary materialization? But IIUC in the scalar case, addtional temporary materialization shoudn't be observable.

@lprv
Copy link
Contributor

lprv commented Jan 9, 2025

Ok. Maybe just "result"?

"Result" is synonymous with "value" here, so I don't think that would be an improvement over the current wording.

What's the harm if we require a result object for the determination?

f() in the example above is not "a prvalue ... whose result object ..." (because it doesn't have a result object), and thus not a constant expression under the proposed wording change.


If we want to avoid making drastic changes to the structure of the wording here, then I think having to go from 'value' to 'object' in some way or another is unavoidable (sadly), because we don't have a good framework for talking about values (not objects) of class and array types.

Perhaps phrasing the requirements in terms of the constituent values/references of "a hypothetical object initialized from the prvalue" (or something along those lines) could work?

(Then there's also the fact that this paragraph doesn't handle prvalues of type void, but that seems like a separate issue.)

@frederick-vs-ja
Copy link
Contributor Author

frederick-vs-ja commented Jan 9, 2025

"a hypothetical object initialized from the prvalue"

This is exactly what I'm meaning with "a prvalue whose result object...". Did you mean that we can't just say that if prvalue materialization doesn't happen?

(Then there's also the fact that this paragraph doesn't handle prvalues of type void, but that seems like a separate issue.)

IIUC this is not an issue. The status quo is clear pre-P2686R4 status was that a void expression may be a core constant expression, but is never a "constant expression". There doesn't seem any context where a constant expression is required and its type can be void. (If I'm wrong on this, then perhaps there should be a separate issue.)

Edit: Oops, it seems that P2686R4 accidently madevoid expressions come into picture.

@tkoeppe tkoeppe added the after-motions Pull request is to be applied after the pending edits from WG21 straw polls have been applied. label Feb 13, 2025
@tkoeppe
Copy link
Contributor

tkoeppe commented Feb 13, 2025

@jensmaurer Assuming this is still good. Let's merge after motions.

@tkoeppe tkoeppe merged commit 0dda846 into cplusplus:main Mar 15, 2025
2 checks passed
@frederick-vs-ja frederick-vs-ja deleted the constant-result-object branch March 16, 2025 03:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
after-motions Pull request is to be applied after the pending edits from WG21 straw polls have been applied.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[dcl.constexpr] Uninitialized non-static data members of fundamental type CWG2558
5 participants