Clang accepts invalid static_cast from derived type to private base type in case of rvalue reference (original) (raw)
Clang does not report any error for the following code:
struct A { int a;}; struct X : private A{};
int main() { X x; int a=static_cast<A&&>(x).a; }
Please note that this can be correctly rejected if the target type is not a rvalue reference.
GCC, EDG, and MSVC reject it:
: In function 'int main()': :6:29: error: 'A' is an inaccessible base of 'X' 6 | int a=static_cast(x).a; |Please see https://godbolt.org/z/aW1s6a7ec