Alf said:
* Harald van Dijk:
No, s is not of aggregate type. But that's just a nit... ;-) Put in a
default constructor and leave out the initializer.
Is the standard's wording different from the draft? That says
"An aggregate is an array or a class (clause 9) with no user-declared
constructors (12.1), no private or protected non-static data members
(clause 11), no base classes (clause 10), and no virtual functions
(10.3)."
Anyway, if that's not allowed, thanks for the info. It didn't seem
directly relevant to the question, so I simply relied on my compilers.
Two of them don't complain about it regardless of options, and a third
gives a highly misleading error message ("A non-const reference can't
be initialized using an rvalue"). But pretend I used a constructor,
then.
Undefined behavior is undefined even if a compiler defines it.
Right, but that's not what I meant. I didn't mean it would "work", I
asked at what point the behaviour would be undefined. Any object can be
read from and written to as an array of (unsigned) char, right? Sure,
reading the object afterwards is not allowed if a non-value is written,
but I specifically said s.r would never be used. (If it makes a
difference, s would never be used.)
Naturally, because otherwise there would be /no/ undefined behavior: any
construct that has formally undefined behavior results in some concrete
behavior on a concrete system, and that concrete behavior is a
definition of the behavior on that system.
Yeah, anyone can define anything, and definitions aren't authoritative
unless the C++ standard says they are. No problem, that I get.