The only place I can see any room for question about your case would be whether or not your use of foo
qualifies as odr-used
or not. Perhaps the easiest way to clarify at least the intent would be to quote the corresponding section of n1337 (immediately followed the official standard, mostly cleaning up some phrasing, such as in this case):
[...] a name can refer to a const object with internal or no linkage if the object has the same literal type in all definitions of D, and the object is initialized with a constant expression (5.19), and the value (but not the address) of the object is used, and the object has the same value in all definitions of D;
Your use clearly meets all these requirements.
foo
has typeint
in every case.foo
is initialized with a constant expression.- you use only the value, not the address, of
foo
. foo
has the same value in all defintions ofwidget
.
That said, you'd probably be better off changing foos
to a std::vector
instead:
struct widget {
std::vector<int> bars;
widget : bars(foo) {}
};