OK, now three experts have replied, but unfortunately I'm even more confused...
I clarify a bit because it seems I'm somehow still misunderstood.
I really wanted example A to be invalid. I really know that it's an ODR violation in C++11/14. And I expected it to be just the same in C++17 because my interpretation of 10.1.5 p1 s2 is (1), that is, "in the class definition only".
Now, clang and gcc do report the violation in C++11/14 mode as I expected. But they do not in C++17 mode. Instead they produce an executable.
So, obviously something has changed from C++11/14 mode to C++17 mode. The question before me is now: is it because A::i in main.cpp is now an inline variable? That is, is the interpretation (2) of 10.1.5 p1 s2 correct?
Your comment on example A implies that interpretation (2) is correct.
And the executable produced by clang and gcc is pure coincidence and freedom of choice because after all it is completely invalid code.
So, please let me know:
Is A::i in main.cpp implicitly an inline variable because it is declared constexpr?
That is, is interpretation (2) of 10.1.5 p2 s1 correct?
If this question must be answered "yes" then I'm really very surprised, for the following reasons:
First, example B shows a breaking change in the language from C++11/14 to C++17. Can this be the intent of the committee?
Second, the completely invalid example A shows a breaking change in the outcome (at least with clang and gcc): an executable instead of an error. Of course, one can argue that this is simply internal compiler stuff and bad luck for the programmer.
Third, I really don't see a substantial difference between
B::i and i in example C, yet B::i in B.cpp is now an inline variable and i in C.cpp is not.
And finally I really did think that this example in C++11/14
struct S
{
static int constexpr i = 42; // must be defined exactly once if odr-used
};
just naturally evolved per (1) in C++17:
S::i is now language-wise an inline variable, so (contrary to C++11/14) no more definition required if odr-used (though still possible but deprecated)
Richard, you're in the committee, would you share some insight
into what speaks against interpretation (1)? Or why (2) is better than
(1)?
Thanks so far.