Repository navigation
Conversation
Allow explicit conversion functions when matching the implicit copy constructor during single-argument direct-initialization, preventing premature C++20 aggregate fallback. Extend EDGcpfe24743 to cover explicit conversion functions. Signed-off-by: Yihan Wang <yronglin777@gmail.com>
eb4dc1c to
3251cbc
Compare
|
In case it is useful, here's a different repro of the same issue, that we hit in-house due to our use of MSVC's |
|
We still need a issue for this (via creating a discussion). The issue should also describe which language modes this applies to (C++11 or later?), or if there were any CWG issues related to this (maybe CWG 899?). Test cases should then show the fixed behavior in the earliest language versions this change is applicable to (and also for GCC, Clang and Microsoft emulation modes - maybe something like The PR will also need a Changes entry. |
| clear_arg_match_summary(&arg_match); | ||
| /* When matching the first reference parameter of a copy constructor | ||
| called with one argument in a direct-initialization context, explicit | ||
| conversion functions are considered ([over.match.copy]). */ |
There was a problem hiding this comment.
References to standard sections should also include the document number (e.g., N4861) for that particular reference. Ideally, it would be the first standard document with the relevant wording, so it's fairly obvious how far back the change should reach.
There was a problem hiding this comment.
Done. Since CWG899 introduce this rule, I have add reference to N3092.
|
Thanks for the review!
IIUC, we need a GitHub issue? But I don't have access to create it. |
Please create an Issue Triage discussion with the details, this will then be converted to an issue. |
…ore_agg_fallback [GH edgcpp#281] Signed-off-by: Yihan Wang <yronglin777@gmail.com>
| @@ -1,3 +1,20 @@ | |||
| 10/12/26 [GH #281] | |||
There was a problem hiding this comment.
The changes entry should be added after the "Version 7.1" header
| struct S { explicit operator D() const; }; | ||
| D f(S s) { | ||
| D d(s); // Previously an error in C++20 mode. Now okay. | ||
| return D(s); // Likewise. |
There was a problem hiding this comment.
To keep the Changes example as short as possible, you can just use D d(S{}); instead of the f function body
|
|
||
| That is now fixed. The rule allowing explicit conversion functions in this | ||
| context comes from Core issue 899 and applies in C++11 and later modes. The | ||
| failure occurred when C++20 parenthesized aggregate initialization was enabled. |
There was a problem hiding this comment.
The following example is now accepted in C++11 mode:
int f(int &&);
int f(int *);
struct A {
explicit operator int() const;
};
int i = f({A{}});Seems to be related to EDGcpfe/21369. g++/clang don't accept this. Needs some more investigation, and should be mentioned in the Changes entry (if we want to keep that behaviour).
| /*param_type_is_deduced=*/FALSE, | ||
| try_user_conversions_in_ovl_res, | ||
| /*allow_expl_conv_funcs=*/FALSE, | ||
| /*allow_expl_conv_funcs=*/ |
There was a problem hiding this comment.
That comment line can now be removed, as the expression is now sufficiently clear on its own.
| @@ -0,0 +1,22 @@ | |||
| //type:fn | |||
There was a problem hiding this comment.
Please rename to cwg899.sft.cpp (as that's the predominant naming convention for CWG tests) and split the negative cases into a separate file (cwg899b.sft.cpp).
| @@ -0,0 +1,20 @@ | |||
| //type:fp | |||
There was a problem hiding this comment.
I think the changes directory should just contain the Changes examples, and the regressions directory should be used for additional tests.
[over.match.ref]/1.1: when binding the
const float2¶meter of the copy constructor to the argument, "For direct-initialization, the permissible types for explicit conversion functions are...", the explicit operatorfloat2() constis therefore a legitimate candidate:float2(const float2&)is viable.https://godbolt.org/z/oKoMvEEdd
This PR allows explicit conversion functions when matching the implicit copy constructor during single-argument direct-initialization, preventing premature C++20 aggregate fallback rule.
Fixes #281.