According to cppreference (my attention):
Kernel constant expression - any expression that does not have one of the following in any subexpression
(...)
- An expression whose evaluation leads to any form of the main language undefined behavior (including integer overflow of integers, division by zero, arithmetic of pointers outside the bounds of the array, etc.). Is the standard library undefined detected unspecified.
On the other hand, there are several expressions on pointers with a result that is not undefined but unspecified (see [expr.rel] / 3 ), for example:
struct A { int v; }; struct B { int v; }; struct C: A, B {} c; int main() { constexpr bool result = &c.A::v < &c.B::v; (void)result; }
The code compiles without problems with gcc , but not in clang , which says that it is undoubtedly true that:
comparing the addresses of subobjects of different base classes has an unspecified
But (as I understand it), according to cppreference, it should not stop the compiler from compiling the code.
Which compiler is gcc or clang here? Am I compacting cppreference?
source share