]> gcc.gnu.org Git - gcc.git/blob - gcc/testsuite/g++.dg/cpp0x/constexpr-cast.C
PR c++/92590 - wrong handling of inherited default ctor.
[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)); // { dg-error "not a constant expression" "" { target c++14 } }
18 return p;
19 #else
20 return *reinterpret_cast<T*>(sizeof (T)); // { dg-error "not a constant expression" "" { target c++11_only } }
21 #endif
22 }
23
24 constexpr bool b = f<int>(); // { dg-message "in .constexpr. expansion of " }
This page took 0.034242 seconds and 5 git commands to generate.