Repository navigation
Reject explicit conversion functions for list-initialized reference temporaries (CWG 2267) [GH #344] #509
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
Open
daveedvdv-nvidia
wants to merge
1
commit into
main
Choose a base branch
from
fix/344
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Reject explicit conversion functions for list-initialized reference temporaries (CWG 2267) [GH #344] #509
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
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
36 changes: 36 additions & 0 deletions
36
src/pending_changes/gh-344-list-init-ref-explicit-conv.txt
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| [GH #344] | ||
| Explicit conversion functions and list-initialization of references | ||
|
|
||
| When a reference is list-initialized from an element whose type is not | ||
| reference-related to the referenced type, a temporary is created and the | ||
| reference is bound to that temporary. The resolution of Core issue 2267 | ||
| clarified that this temporary is copy-list-initialized even when the reference | ||
| itself is direct-list-initialized, so explicit conversion functions cannot be | ||
| used to initialize it. The front end nevertheless accepted them, even for | ||
| copy-list-initialization (including when passing an argument). That is now | ||
| fixed. For example: | ||
|
|
||
| struct A { explicit operator int() const; } a; | ||
| struct B { explicit operator int&&(); }; | ||
| void f(int&&); | ||
| int &&r1{a}; // Now an error. | ||
| int &&r2{B{}}; // Now an error. | ||
| int &&r3 = {a}; // Now an error in all modes. | ||
| void g() { | ||
| f({a}); // Now an error in all modes. | ||
| } | ||
|
|
||
| The change for EDGcpfe/23402 (in version 6.2) implemented the resolution of | ||
| Core issue 2267 for initializations with parentheses (e.g., "int &&r(a);"), | ||
| but not for list-initializations. Those were still governed by the change for | ||
| EDGcpfe/21369 (in version 5.1), which allowed explicit conversion functions to | ||
| initialize the temporary in every list-initialization of a reference (to | ||
| accept cases like r2 above). That allowance is now limited to the emulation | ||
| modes described below. | ||
|
|
||
| Because Clang, GCC before version 9, and Microsoft C++ in permissive mode | ||
| (and before version 19.29 also in non-permissive mode) accept the | ||
| direct-list-initialization cases, those are still accepted in the | ||
| corresponding emulation modes. GCC 14 and later accept them only when the | ||
| conversion function returns a reference (like r2 above), and so does the | ||
| front end when emulating those versions. | ||
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| fe_only -DTEST_NUMBER=1 --c++11 Test_name.c | ||
| "Test_name.c", line 21: error: no suitable conversion function from "E" to "int" exists | ||
| int &&r1{e}; | ||
| ^ | ||
|
|
||
| "Test_name.c", line 22: error: no suitable conversion function from "E" to "const int" exists | ||
| const int &r2{e}; | ||
| ^ | ||
|
|
||
| "Test_name.c", line 23: error: no suitable conversion function from "ER" to "int" exists | ||
| int &&r3{ER{}}; | ||
| ^ | ||
|
|
||
| "Test_name.c", line 26: error: no suitable conversion function from "E" to "int" exists | ||
| int &&r4 = {e}; | ||
| ^ | ||
|
|
||
| "Test_name.c", line 27: error: no suitable conversion function from "ER" to "int" exists | ||
| int &&r5 = {ER{}}; | ||
| ^ | ||
|
|
||
| "Test_name.c", line 29: error: no suitable conversion function from "E" to "int" exists | ||
| h({e}); | ||
| ^ | ||
|
|
||
| "Test_name.c", line 30: error: no suitable conversion function from "ER" to "int" exists | ||
| h({ER{}}); | ||
| ^ | ||
|
|
||
| "Test_name.c", line 31: error: no suitable conversion function from "E" to "const int" exists | ||
| hc({e}); | ||
| ^ | ||
|
|
||
| 8 errors detected in the compilation of "Test_name.c". |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| fe_only -DTEST_NUMBER=2 --c++20 Test_name.c | ||
| "Test_name.c", line 21: error: no suitable conversion function from "E" to "int" exists | ||
| int &&r1{e}; | ||
| ^ | ||
|
|
||
| "Test_name.c", line 22: error: no suitable conversion function from "E" to "const int" exists | ||
| const int &r2{e}; | ||
| ^ | ||
|
|
||
| "Test_name.c", line 23: error: no suitable conversion function from "ER" to "int" exists | ||
| int &&r3{ER{}}; | ||
| ^ | ||
|
|
||
| "Test_name.c", line 26: error: no suitable conversion function from "E" to "int" exists | ||
| int &&r4 = {e}; | ||
| ^ | ||
|
|
||
| "Test_name.c", line 27: error: no suitable conversion function from "ER" to "int" exists | ||
| int &&r5 = {ER{}}; | ||
| ^ | ||
|
|
||
| "Test_name.c", line 29: error: no suitable conversion function from "E" to "int" exists | ||
| h({e}); | ||
| ^ | ||
|
|
||
| "Test_name.c", line 30: error: no suitable conversion function from "ER" to "int" exists | ||
| h({ER{}}); | ||
| ^ | ||
|
|
||
| "Test_name.c", line 31: error: no suitable conversion function from "E" to "const int" exists | ||
| hc({e}); | ||
| ^ | ||
|
|
||
| 8 errors detected in the compilation of "Test_name.c". |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| fe_only -DTEST_NUMBER=3 --g++ --c++17 --gnu_version=80500 Test_name.c | ||
| "Test_name.c", line 26: error: no suitable conversion function from "E" to "int" exists | ||
| int &&r4 = {e}; | ||
| ^ | ||
|
|
||
| "Test_name.c", line 27: error: no suitable conversion function from "ER" to "int" exists | ||
| int &&r5 = {ER{}}; | ||
| ^ | ||
|
|
||
| "Test_name.c", line 29: error: no suitable conversion function from "E" to "int" exists | ||
| h({e}); | ||
| ^ | ||
|
|
||
| "Test_name.c", line 30: error: no suitable conversion function from "ER" to "int" exists | ||
| h({ER{}}); | ||
| ^ | ||
|
|
||
| "Test_name.c", line 31: error: no suitable conversion function from "E" to "const int" exists | ||
| hc({e}); | ||
| ^ | ||
|
|
||
| 5 errors detected in the compilation of "Test_name.c". |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| fe_only -DTEST_NUMBER=4 --g++ --c++17 --gnu_version=130300 Test_name.c | ||
| "Test_name.c", line 21: error: no suitable conversion function from "E" to "int" exists | ||
| int &&r1{e}; | ||
| ^ | ||
|
|
||
| "Test_name.c", line 22: error: no suitable conversion function from "E" to "const int" exists | ||
| const int &r2{e}; | ||
| ^ | ||
|
|
||
| "Test_name.c", line 23: error: no suitable conversion function from "ER" to "int" exists | ||
| int &&r3{ER{}}; | ||
| ^ | ||
|
|
||
| "Test_name.c", line 26: error: no suitable conversion function from "E" to "int" exists | ||
| int &&r4 = {e}; | ||
| ^ | ||
|
|
||
| "Test_name.c", line 27: error: no suitable conversion function from "ER" to "int" exists | ||
| int &&r5 = {ER{}}; | ||
| ^ | ||
|
|
||
| "Test_name.c", line 29: error: no suitable conversion function from "E" to "int" exists | ||
| h({e}); | ||
| ^ | ||
|
|
||
| "Test_name.c", line 30: error: no suitable conversion function from "ER" to "int" exists | ||
| h({ER{}}); | ||
| ^ | ||
|
|
||
| "Test_name.c", line 31: error: no suitable conversion function from "E" to "const int" exists | ||
| hc({e}); | ||
| ^ | ||
|
|
||
| 8 errors detected in the compilation of "Test_name.c". |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| fe_only -DTEST_NUMBER=5 --g++ --c++17 --gnu_version=150200 Test_name.c | ||
| "Test_name.c", line 21: error: no suitable conversion function from "E" to "int" exists | ||
| int &&r1{e}; | ||
| ^ | ||
|
|
||
| "Test_name.c", line 22: error: no suitable conversion function from "E" to "const int" exists | ||
| const int &r2{e}; | ||
| ^ | ||
|
|
||
| "Test_name.c", line 26: error: no suitable conversion function from "E" to "int" exists | ||
| int &&r4 = {e}; | ||
| ^ | ||
|
|
||
| "Test_name.c", line 27: error: no suitable conversion function from "ER" to "int" exists | ||
| int &&r5 = {ER{}}; | ||
| ^ | ||
|
|
||
| "Test_name.c", line 29: error: no suitable conversion function from "E" to "int" exists | ||
| h({e}); | ||
| ^ | ||
|
|
||
| "Test_name.c", line 30: error: no suitable conversion function from "ER" to "int" exists | ||
| h({ER{}}); | ||
| ^ | ||
|
|
||
| "Test_name.c", line 31: error: no suitable conversion function from "E" to "const int" exists | ||
| hc({e}); | ||
| ^ | ||
|
|
||
| 7 errors detected in the compilation of "Test_name.c". |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| fe_only -DTEST_NUMBER=6 --clang --c++17 --clang_version=180100 Test_name.c | ||
| "Test_name.c", line 26: error: no suitable conversion function from "E" to "int" exists | ||
| int &&r4 = {e}; | ||
| ^ | ||
|
|
||
| "Test_name.c", line 27: error: no suitable conversion function from "ER" to "int" exists | ||
| int &&r5 = {ER{}}; | ||
| ^ | ||
|
|
||
| "Test_name.c", line 29: error: no suitable conversion function from "E" to "int" exists | ||
| h({e}); | ||
| ^ | ||
|
|
||
| "Test_name.c", line 30: error: no suitable conversion function from "ER" to "int" exists | ||
| h({ER{}}); | ||
| ^ | ||
|
|
||
| "Test_name.c", line 31: error: no suitable conversion function from "E" to "const int" exists | ||
| hc({e}); | ||
| ^ | ||
|
|
||
| 5 errors detected in the compilation of "Test_name.c". |
Oops, something went wrong.
Oops, something went wrong.
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.