Is there a way to define a non-dynamic constructor which restricts the range of whichever default constructor lets me do
struct foo {
int *bar;
};
static __thread foo myfoo[10] = {nullptr};
?
i.e., I want to do
class baz {
public:
baz() = default;
constexpr baz(decltype(nullptr)) : qux(nullptr) { }
private:
int *qux;
};
static __thread baz mybaz[10] = {nullptr};
and have it work.
Currently, icpc tells me
main.cpp(9): error: thread-local variable cannot be dynamically initialized
static __thread baz mybaz[10] = {nullptr};
^
This:
is equivalent to:
Because this is general rule that implicit initialization of an array element is by default constructor.
So either do this:
Or make your default constructor also constexpr…