Here you moved the MyClassTemplates struct definition out of MyClass,
and defined a global object MyClassTemplates as well (poor choice of
object and class with the same name)
What is left within MyClass is a static constexpr declaration, with its
initializer in place, and type which is defined at the namespace level.
> Compiler-Bug?
Not at this stage.
The gcc error is correct, in the sense that the initializer is missing
in your original code.
However, if you modify it as:
struct MyClass
{
// does not work
constexpr static const struct
{ const MsgTemplate<const char*> SOMETHING_WENT_WRONG =
{ 1001, "Something went wrong: %s" };
// more templates ...
} Templates{}; // <== note the {} initializer
};
then you get a more obscure error:
constexpr.cc:26:15: error: constructor required before non-static data
member for ‘MyClass::<anonymous struct>::SOMETHING_WENT_WRONG’ has been
parsed
} Templates{};
^
and the same happens if you get rid of the <anonymnous struct>:
struct MyClass
{
// does not work
constexpr static const struct MyT
{ const MsgTemplate<const char*> SOMETHING_WENT_WRONG =
{ 1001, "Something went wrong: %s" };
// more templates ...
} Templates{}; // <== note the {} initializer
};
At this point, I /think/ the error is related to the fact that static
constexpr initializers are best handled at the namespace level (in fact,
if I understand what you are trying to do here a namespace could be an
option) - Bjarne writes (TC++PL p.506):
"However, for a few simple cases, it is possible to initialize a static
member in the class declaration. ..." and the following text gives more
detail, with which I still can't map an error to the case, though.
Maybe someone else can shed some more light on the puzzle.
>
>
> Marcel