[llvm-bugs] [Bug 48587] New: Clang incorrectly discards destructor if there is only a constant evaluated branch
via llvm-bugs
llvm-bugs at lists.llvm.org
Wed Dec 23 14:22:12 PST 2020
https://bugs.llvm.org/show_bug.cgi?id=48587
Bug ID: 48587
Summary: Clang incorrectly discards destructor if there is only
a constant evaluated branch
Product: clang
Version: 11.0
Hardware: PC
OS: Windows NT
Status: NEW
Severity: normal
Priority: P
Component: C++2a
Assignee: unassignedclangbugs at nondot.org
Reporter: mschellenbergercosta at googlemail.com
CC: blitzrakete at gmail.com, erik.pilkington at gmail.com,
llvm-bugs at lists.llvm.org, richard-llvm at metafoo.co.uk
This is an issue that came up with the implementation of constexpr vector and
constexpr string for MSVCs standard library.
The regression is that the destructor of iterators is not executed properly,
which lets the iterator debug machinery of the STL crash.
A minimal reproducer of he issue is the following code:
```
struct conditionalDestructor {
constexpr conditionalDestructor(int& val_) noexcept : val(val_) {}
constexpr ~conditionalDestructor() noexcept {
if (!__builtin_is_constant_evaluated()) {
++val;
}
}
int& val;
};
int main() {
int destructorsCalled = 0;
{
[[maybe_unused]] volatile conditionalDestructor
test(destructorsCalled);
}
if (destructorsCalled != 1) {
return -1;
}
}
```
Here, the destructor of `conditionalDestructor` is never executed, despite it
being runtime only.
Note that if there is code in the else branch of the
`__builtin_is_constant_evaluated` clause, the destructor is not discarded.
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20201223/748fa663/attachment.html>
More information about the llvm-bugs
mailing list