]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/testsuite/g++.dg/cpp0x/constexpr-cast.C
e0c7ed33ac7159304fea4b6f493cf4c344e2b7f0
[thirdparty/gcc.git] / gcc / testsuite / g++.dg / cpp0x / constexpr-cast.C
1 // Test to verify that evaluating reinterpret_cast is diagnosed in
2 // constant expressions.
3 // { dg-do compile { target c++11 } }
4
5 int i;
6
7 // The following was accepted due to bug 49171.
8 constexpr void *q = reinterpret_cast<void*>(&i); // { dg-error "not a constant expression" }
9
10 constexpr void *r0 = reinterpret_cast<void*>(1); // { dg-error "not a constant expression|reinterpret_cast from integer to pointer" }
11 constexpr void *r1 = reinterpret_cast<void*>(sizeof 'x'); // { dg-error ".reinterpret_cast<void\\*>\\(1\[ul\]\*\\). is not a constant expression" }
12
13 template <class T>
14 constexpr bool f ()
15 {
16 #if __cplusplus > 201103L
17 T *p = reinterpret_cast<T*>(sizeof (T));
18 return p;
19 #else
20 return *reinterpret_cast<T*>(sizeof (T));
21 #endif
22 }
23
24 constexpr bool b = f<int>(); // { dg-error "not a constant expression|in .constexpr. expansion of " }