Details
- Reviewers
rsmith hubert.reinterpretcast aaron.ballman cor3ntin - Group Reviewers
Restricted Project Restricted Project
Diff Detail
- Repository
- rG LLVM Github Monorepo
Unit Tests
Event Timeline
clang/lib/Sema/SemaInit.cpp | ||
---|---|---|
4258–4259 | This change unfortunately exposes the still-open CWG2311 but allows T{ object_of_type_T } to consider user declared constructors. I am working on a separate fix for CWG2311 (Consider constructors as below, but then if the chosen constructor is not an initializer-list constructor, elide it). | |
clang/lib/Sema/SemaOverload.cpp | ||
1470–1480 | This allows with struct T { T(const T&); } t; void f(T); for f({ t }) is an exact match standard conversion instead of a user-defined conversion |
Removing "SelfInitIsNotListInit" test case: copy-list-init for non-aggregate classes remains as copy-list-inits, only aggregates copies are converted into copy-inits (which I don't think is observable)
clang/test/CXX/drs/dr14xx.cpp | ||
---|---|---|
433 | This relies on the old wording. "If T is a class type and the initializer list has a single element of type cv U, where U is T or a class derived from T, the object is initialized from that element (by copy-initialization for copy-list-initialization, or by direct-initialization for direct-list-initialization)". "If T is a class type" -> "If T is an aggregate class type", so this copy-list-initialization remains copy-list-initialization (and should fail for picking the explicit constructor) |
clang/lib/Sema/SemaInit.cpp | ||
---|---|---|
4258–4259 | Fix will be here: https://reviews.llvm.org/D156062 auto{ prvalue } will elide a copy for aggregate types again. It will do so after checking constructors for non-aggregate classes now. |
Add CWG2311 fix too
Too much code and tests rely on elision of T{ T_prvalue } in C++17, so add change to allow that to be elided when this does not pick a initializer-list constructor.
Btw, it looks like precommit CI may have found issues in libc++ related to your changes.
It seems there were two places which relied on T x = { xvalue_of_type_T } being a copy-initialization: The test at https://reviews.llvm.org/D156032#inline-1509544 and that one pair constructor test.
GCC seems to allow it but I don't think that's standard. I also have a pretty short patch to implement this behaviour if we decide that it needs to be supported (maybe this is a standard defect?)
clang/test/CXX/drs/dr23xx.cpp | ||
---|---|---|
9 | Wouldn't work in c++98 mode this file is being run in. I've copied this from other tests in this directory. I guess I can put a #if __cplusplus >= 201103L instead? | |
50 | CWG2311 is still open, but clang did support list-initialization elision before this patch. The committee still needs to decide how exactly this elision is going to work, which might be different from how this patch implements it, so hesitant to mark this as done. |
I only looked at the libc++ changes. The libc++ AIX CI failures are unrelated to your patch. LGTM modulo one nit.
libcxx/test/std/utilities/utility/pairs/pairs.pair/ctor.pair_U_V_move.pass.cpp | ||
---|---|---|
134 ↗ | (On Diff #549145) | Please remove this line. |
clang/lib/Sema/SemaInit.cpp | ||
---|---|---|
4258–4259 | As this was abandoned in favor of doing the fix here, the patch title, summary, and release notes should all be updated to talk about CWG2311. | |
4261–4262 | ||
4332 | ||
4335 | ||
4340 | ||
clang/test/CXX/drs/dr23xx.cpp | ||
9 | The current form seems fine to me. | |
50 | CC @Endill -- do we have a special marking for "issue still open in WG21, but we implement the current suggested resolution?" | |
54 |
clang/test/CXX/drs/dr23xx.cpp | ||
---|---|---|
50 | 18 open sould work |
Address comments; better implementation for elision (check after considering only initializer list constructors)
rebased onto fast-forwarded main branch
(trying to fix seemingly unrelated CI build failure)
LGTM modulo one nit.
@hubert.reinterpretcast If you want to make sure this is conforming
clang/docs/ReleaseNotes.rst | ||
---|---|---|
73 |