https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64293
Bug ID: 64293 Summary: [C++14] explicit instantiation declaration suppresses instantiation of constexpr constructor Product: gcc Version: 5.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: redi at gcc dot gnu.org template <typename T> struct Foo { constexpr Foo() { } constexpr Foo(T const& val) { for (auto& el : _data) { el = val; } } T _data[2]; }; extern template struct Foo<int>; #ifdef USE Foo<int> f = 1; #else template struct Foo<int>; #endif When compiled with -std=gnu++14 this does not instantiate the constructor: $ g++14 -c foo.cpp && nm -C foo.o U Foo<int>::Foo(int const&) 0000000000000000 W Foo<int>::Foo() 0000000000000000 W Foo<int>::Foo() And when compiled so it uses the constructor, the explicit instantiation declaration suppresses the instantiation of that constructor: $ g++14 -c foo.cpp -DUSE && nm -C foo.o 0000000000000038 t _GLOBAL__sub_I_f 0000000000000000 t __static_initialization_and_destruction_0(int, int) U Foo<int>::Foo(int const&) 0000000000000000 B f So neither the file that uses it nor the file that should define it has the symbol, leading to a linker error. The symbol is defined if: - the constructors are not constexpr, or - the constructor is not delegated to by the default constructor, or - the constructor does not contain a loop, or - the explicit instantation is not declared before being defined Oddly, clang 3.4 has almost exactly the same bug, the only difference is that the presence of the loop makes no difference, the constructor is not generated even if the body is empty. Clang 3.5 generates the constructor as I expect.