My understanding is that constexpr globals of class type are all but unusable because
Such an object must be defined in every TU, because
constexprdoes not permit forward declaration of an object.Default linkage as
staticwould cause naming the object (ODR-use or not) in an inline function to violate the ODR, because the respectiveinlinedefinitions would have different meaning.Declaration as
extern constexprwith one definition per TU would violate the ODR rule if the object is ODR-used, which occurs when a reference to it is taken.- A reference is taken for an implicit
thisparameter, even if it's unused by a member function. - Obviously happens if you try to pass the object by reference.
- Also happens if you try to pass the object by value, which implicitly uses a copy or move constructor, which by definition passes by reference.
- GCC and Clang both complain of ODR violations (multiple definitions) if an object is declared
extern constexpreven if not ODR-used.
- A reference is taken for an implicit
Is this all correct? Is there any way to have a constexpr global of class type without wrapping it in an inline function?