Interesting. I think your code is correct because:
Your default constructor is implicitly inline due to:
[dcl.fct.def.default] / 5 :
... A user-provided function with an explicit default (i.e., explicitly the default after the first declaration) is defined at the point where it is clearly defaulted.
And [class.mfct] / 1 :
A member function can be defined ([dcl.fct.def]) in its class definition, in which case it is a built-in member function ([Dcl.fct.spec])
And thus it is freed from explicit template creation in accordance with [temp.explicit] / 10 (highlighted by me):
With the exception of built-in functions and variables , declarations with types are inferred from their initializer or return value ([dcl.spec.auto]), literal type constant variables, reference type variables and specialized class templates, declarations with an explicit manifest have the effect of suppressing implicit creation of an entity to which they relate. [Note: the goal is that the built-in function that is the object of the explicit declaration of creation will still be implicitly created using odr ([basic.def.odr]) so that the body can be considered for attachment, but that there is no external copy of the built-in functions will be generated in the translation. - final note]
In fact, if you try any optimization mode other than -O0 , the problem will disappear.
-O0 is a special mode in which built-in functions are not built-in. But it doesn’t matter, in this case the compiler should generate a default move inline constructor, as it does with another constructor.
So for me, this seems like a compiler error. See also LLVM # 22763 and GCC # 60796 .
I see at least 2 possible workarounds:
Solution 1
Do not use extern template ... at the moment (compilation time will suffer, but otherwise it does not really matter).
Decision 2
Trick the compiler into generating a depressed constructor in obj.cpp
template<> Obj<true>::Obj(Obj&&) noexcept = default;
This mode will only be used in -O0 mode. The production code will use the embedded version instead.