blob: 4f2f1974678347af520142caaf83e4b1711b1359 [file] [log] [blame]
Daniel Dunbara5728872009-12-15 20:14:24 +00001// RUN: %clang_cc1 -fsyntax-only -verify %s
Sebastian Redl4a4251b2009-02-07 13:06:23 +00002
3// C++-specific tests for integral constant expressions.
4
5const int c = 10;
6int ar[c];
Douglas Gregor59600d82009-09-10 17:44:23 +00007
8struct X0 {
9 static const int value = static_cast<int>(4.0);
10};
Douglas Gregorf2991242009-09-10 23:31:45 +000011
12void f() {
13 if (const int value = 17) {
14 int array[value];
15 }
16}
Eli Friedmanc0131182009-12-03 20:31:57 +000017
18int a() {
19 const int t=t; // expected-note {{subexpression not valid}}
20 switch(1) {
21 case t:; // expected-error {{not an integer constant expression}}
22 }
23}
John McCall1f1b3b32010-02-06 01:07:37 +000024
25// PR6206: out-of-line definitions are legit
26namespace pr6206 {
27 class Foo {
28 public:
29 static const int kBar;
30 };
31
32 const int Foo::kBar = 20;
33
34 char Test() {
35 char str[Foo::kBar];
36 str[0] = '0';
37 return str[0];
38 }
39}