[llvm-bugs] [Bug 51695] New: Clang not emitting destructor call when assignment constructed with list
via llvm-bugs
llvm-bugs at lists.llvm.org
Tue Aug 31 16:25:01 PDT 2021
https://bugs.llvm.org/show_bug.cgi?id=51695
Bug ID: 51695
Summary: Clang not emitting destructor call when assignment
constructed with list
Product: clang
Version: trunk
Hardware: All
OS: All
Status: NEW
Severity: normal
Priority: P
Component: C++17
Assignee: unassignedclangbugs at nondot.org
Reporter: lxfind at gmail.com
CC: blitzrakete at gmail.com, erik.pilkington at gmail.com,
llvm-bugs at lists.llvm.org, richard-llvm at metafoo.co.uk
In the following code: https://godbolt.org/z/TK7ersK1M
#include <string>
#include <utility>
void doSomething();
class FooClass {
public:
FooClass() noexcept : ptr_() {}
FooClass(FooClass&& other) noexcept
: ptr_(std::exchange(other.ptr_, {})) {}
~FooClass() {
doSomething();
}
FooClass& operator=(FooClass other) noexcept {
std::swap(ptr_, other.ptr_);
return *this;
}
private:
void *ptr_;
};
template <typename T>
class WrapperClass {
public:
void run() noexcept {
wrapper_ = {};
}
private:
FooClass wrapper_;
};
void foo(WrapperClass<std::string> &A) {
A.run();
}
When compiled with either GCC (any std version) or Clang with C++14, the line
"wrapper_ = {};" in WrapperClass::run() will always generate a destructor call
in the end, which is expected.
However when compiled with Clang C++17, the destructor call is not generated,
which seems wrong to me.
--
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/20210831/bf1b9f8c/attachment.html>
More information about the llvm-bugs
mailing list