Open wreien opened 10 months ago
@llvm/issue-subscribers-clang-frontend
Author: Nathaniel Shead (wreien)
@llvm/issue-subscribers-c-1
Author: Nathaniel Shead (wreien)
So it looks like in Sema::canThrow(...)
:
it does not take into account that it is marked zeroing
.
CC @zygoloid
So it looks like in
Sema::canThrow(...)
:it does not take into account that it is marked
zeroing
.CC @zygoloid
plausible fix:
if (CE->requiresZeroInitialization() && CE->getConstructor()->isTrivial() && CE->getConstructor()->isDefaultConstructor())
return CT_Cannot;
I ran check-clang
and the only tests that fail are identical to this test case for the noexcept
part of the issue.
and
and
I 100% disagree with this. I don't know whether it is the case that the standard currently requires this behaviour, but if I write struct S { S() noexcept(false) = default; };
I obviously want is_nothrow_default_constructible
to be false. If this is required by the standard, IMO this is a language defect and we should file a CWG issue instead. This should either be ill-formed or do what a user would expect.
I 100% disagree with this. I don't know whether it is the case that the standard currently requires this behaviour, but if I write
struct S { S() noexcept(false) = default; };
I obviously wantis_nothrow_default_constructible
to be false. If this is required by the standard, IMO this is a language defect and we should file a CWG issue instead. This should either be ill-formed or do what a user would expect.
The other implementations disagree with clang on except MSVC on the second case: https://godbolt.org/z/ed9bK48sv
The reading of the wording seems correct and I could not find a defect report but I would like to hear from Richard on this.
I imagine we could warn here. Something like "noexcept on the default constructor of an aggregate has no effect", something like that.
@shafik They're not exactly consistent with themselves in lots of cases: https://godbolt.org/z/xnovcrxK6
This seems worth filing as a core issue, to get this discussed and to point out the vendor inconsistency demonstrated by @philnik777's compiler explorer link.
(Personally, I think the "value initialization doesn't call a trivial default constructor" guarantee ought to never change program semantics -- it's really just an optimization that for whatever reason the language rules specify rather than leaving to as-if / QoI -- and any case where it causes visibly different program semantics, such as here, ought to be treated as a bug in the language rules. But CWG might not agree.)
I sent a query to core and we will see what the response is: https://lists.isocpp.org/core/current/15016.php
This now CWG2820, it should be live I am guessing after Kona sometime.
CWG2820 has been accepted as a DR, so the original issue is not a bug now. But something seems wrong with dtors...
Clang incorrectly fails these two static assertions.
For the former,
S()
is value-initialization, and so by https://eel.is/c++draft/dcl.init#general-9.1 it is zero-initialised without default-initialization, and the default constructor (being trivial) is not called. As such, because the default constructor is not implicitly invoked, it does not meet the requirements for https://eel.is/c++draft/except.spec#6.2 and the assertion should pass.For the latter, https://eel.is/c++draft/meta.unary.prop#9 checks effectively
S s();
(as not-a-function-declaration) notS s;
, and thus should check whether value-initialization is potentially-throwing, as above.