1 // RUN: %clang_cc1 -fsyntax-only -verify -pedantic %s
3 // C++-specific tests for integral constant expressions.
9 static const int value = static_cast<int>(4.0);
13 if (const int value = 17) {
19 const int t=t; // expected-note {{declared here}} expected-note {{read of object outside its lifetime}}
20 switch(1) { // expected-warning {{no case matching constant switch condition '1'}}
21 case t:; // expected-error {{not an integral constant expression}} expected-note {{initializer of 't' is not a constant expression}}
25 // PR6206: out-of-line definitions are legit
29 static const int kBar;
32 const int Foo::kBar = 20;
41 // PR6373: default arguments don't count.
42 void pr6373(const unsigned x = 0) {
43 unsigned max = 80 / x;
48 namespace rdar9204520 {
51 static const int B = int(0.75 * 1000 * 1000); // expected-warning {{not a constant expression; folding it to a constant is a GNU extension}}
54 int foo() { return A::B; }
59 int* y = reinterpret_cast<const char&>(x); // expected-error {{cannot initialize}}
61 // This isn't an integral constant expression, but make sure it folds anyway.
62 struct PR8836 { char _; long long a; }; // expected-warning {{long long}}
63 int PR8836test[(__typeof(sizeof(int)))&reinterpret_cast<const volatile char&>((((PR8836*)0)->a))]; // expected-warning {{folded to constant array as an extension}} expected-note {{cast that performs the conversions of a reinterpret_cast is not allowed in a constant expression}}
65 const int nonconst = 1.0; // expected-note {{declared here}}
66 int arr[nonconst]; // expected-warning {{folded to constant array as an extension}} expected-note {{initializer of 'nonconst' is not a constant expression}}
67 const int castfloat = static_cast<int>(1.0);
68 int arr2[castfloat]; // ok