-
Notifications
You must be signed in to change notification settings - Fork 773
[stmt.return,class.{ctor,dtor}] Clarify no return operand #4737
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
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
[stmt.return,class.{ctor,dtor}] Clarify no return operand
Highlight that constructors and destructors do not have a return type and thus a return statement within a constructor or destructor cannot have an operand.
- Loading branch information
commit 516a4b38146760ba8e88c482bbb522f6ddb8f73b
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we claim that a constructor of a class does not have a return type, consider [dcl.init.general] p15
[expr.call] p14
These rules will be in conflict. How could the call of a constructor be a prvalue of the cv-unqualified version of the destination type?
Similarly, if a destructor does not have a return type, how does the following rule work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not seeing the quoted text in [dcl.init.general] p15.
A constructor invocation is not a syntactic function call as described in [expr.call] (it's an explicit type conversion instead), thus any statements about the type of the function call expression don't apply.
We can explicitly call a destructor in a function call expression, and the rule you're quoting overrides the general rule that the type of a function call expression is the return type of the called function.
I'm not seeing any conflicts.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is moved to dcl.init#general-16.6.3 in the current draft
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jensmaurer Final thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Constructors / destructors don't have a return type in the "function declaration" sense, and that absence makes "return something" syntactically ill-formed. I think the quoted stuff doesn't change that; it just means that a constructor call (in the context of copy-initialization, not in general) has (is considered to have) a certain type and value category. That has no bearing on the syntactic constraints on constructor declarations.
I thinks this should go in.