Clang not generating the destructor

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.

Wandbox permlink: 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

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 ci; // destructor C::~C() not generated

C 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::~C()’

clang-11: error: linker command failed with exit code 1 (use -v to see invocation)

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.

Yeah, fair - does seem buggy.

Here’s a simpler example at least:

extern void unknown();
template
struct C {
~C() {}
};
union U {
explicit U() : ci() { unknown(); }
~U() {}
C ci; // destructor C::~C() not generated
};
int main() {
U u;
}

With ‘unknown’ defined in another translation unit.