]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/CXX/expr/expr.post/expr.reinterpret.cast/p2.cpp
Vendor import of clang trunk r338150:
[FreeBSD/FreeBSD.git] / test / CXX / expr / expr.post / expr.reinterpret.cast / p2.cpp
1 // RUN: %clang_cc1 %s -verify
2
3 // The reinterpret_cast operator shall not cast away constness.
4 struct X {};
5 struct Y {};
6 void f(const int * X::* Y::* *p) {
7   // This applies for similar types...
8   (void)reinterpret_cast<int * X::* Y::* *>(p); // expected-error {{casts away qualifiers}}
9   // ... and for cases where the base type is different ...
10   (void)reinterpret_cast<float * X::* Y::* *>(p); // expected-error {{casts away qualifiers}}
11   // ... and for cases where pointers to members point to members of different classes ...
12   (void)reinterpret_cast<int * Y::* X::* *>(p); // expected-error {{casts away qualifiers}}
13   // ... and even for cases where the path is wholly different!
14   // (Though we accept such cases as an extension.)
15   (void)reinterpret_cast<double Y::* X::* * *>(p); // expected-warning {{casts away qualifiers}}
16
17   // If qualifiers are added, we need a 'const' at every level above.
18   (void)reinterpret_cast<const volatile double Y::* X::* * *>(p); // expected-warning {{casts away qualifiers}}
19   (void)reinterpret_cast<const volatile double Y::*const X::*const **>(p); // expected-warning {{casts away qualifiers}}
20   (void)reinterpret_cast<const volatile double Y::*const X::**const *>(p); // expected-warning {{casts away qualifiers}}
21   (void)reinterpret_cast<const volatile double Y::*X::*const *const *>(p); // expected-warning {{casts away qualifiers}}
22   (void)reinterpret_cast<const volatile double Y::*const X::*const *const *>(p); // ok
23
24   (void)reinterpret_cast<const double Y::*volatile X::**const *>(p); // expected-warning {{casts away qualifiers}}
25   (void)reinterpret_cast<const double Y::*volatile X::*const *const *>(p); // ok
26 }