[cfe-dev] Clang not generating the destructor
David Blaikie via cfe-dev
cfe-dev at lists.llvm.org
Fri Apr 30 15:47:13 PDT 2021
Yeah, fair - does seem buggy.
Here's a simpler example at least:
extern void unknown();
template <typename T>
struct C {
~C() {}
};
union U {
explicit U() : ci() { unknown(); }
~U() {}
C<int> ci; // destructor C<int>::~C() not generated
};
int main() {
U u;
}
With 'unknown' defined in another translation unit.
On Fri, Apr 30, 2021 at 5:50 AM Nathan Sidwell via cfe-dev <
cfe-dev at lists.llvm.org> wrote:
> On 4/28/21 9:55 PM, Riyaz Puthiyapurayil via cfe-dev wrote:
> > The following test case fails to compile with clang++ because it does
> > not generate code for a destructor (as indicated below). Is this a bug
> > or am I missing something? Gcc works fine.
>
> smells like a bug.
>
> >
> > Wandbox permlink: https://wandbox.org/permlink/H7BcjQzXwoqZclj3
> > <https://wandbox.org/permlink/H7BcjQzXwoqZclj3>
> >
> > // prog.cpp
> >
> > #include "D.h"
> >
> > D *f(char c) {
> >
> > return c ? new D(c) : new D(-1);
> >
> > }
> >
> > D *x;
> >
> > int main() {
> >
> > x = f('a');
> >
> > return 0;
> >
> > }
> >
> > // D.h
> >
> > #ifndef D_H
> >
> > #define D_H
> >
> > extern void unknown();
> >
> > template<typename T>
> >
> > class C {
> >
> > T t;
> >
> > public:
> >
> > explicit C(T t_) : t(t_) {}
> >
> > ~C() {}
> >
> > };
> >
> > class D {
> >
> > union U
> >
> > {
> >
> > explicit U(int i) : ci(i) { unknown(); }
> >
> > explicit U(char c) : cc(c) {}
> >
> > ~U() {}
> >
> > C<int> ci; // destructor C<int>::~C() not generated
> >
> > C<char> cc;
> >
> > };
> >
> > U u;
> >
> > bool uIsInt;
> >
> > public:
> >
> > explicit D(int i) : u(i), uIsInt(true) {}
> >
> > explicit D(char c) : u(c), uIsInt(false) {}
> >
> > ~D(); // explicit destruction of u
> >
> > };
> >
> > D* f(char c);
> >
> > #endif // D_H
> >
> > // unk.cpp
> >
> > #include "D.h"
> >
> > void unknown() {}
> >
> > D::~D() {
> >
> > if (uIsInt)
> >
> > u.ci.~C();
> >
> > else
> >
> > u.cc.~C();
> >
> > }
> >
> > $ clang++ prog.cpp unk.cpp
> >
> > /tmp/prog-bfa5e6.o: In function `D::U::U(int)':
> >
> > prog.cc:(.text._ZN1D1UC2Ei[_ZN1D1UC2Ei]+0x3e): undefined reference to
> > `C<int>::~C()'
> >
> > clang-11: error: linker command failed with exit code 1 (use -v to see
> > invocation)
> >
> >
> > _______________________________________________
> > cfe-dev mailing list
> > cfe-dev at lists.llvm.org
> > https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
> >
>
>
> --
> Nathan Sidwell
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20210430/b064abbc/attachment.html>
More information about the cfe-dev
mailing list