Daniel Dunbar | a572887 | 2009-12-15 20:14:24 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s |
Sebastian Redl | 4a4251b | 2009-02-07 13:06:23 +0000 | [diff] [blame] | 2 | |
| 3 | // C++-specific tests for integral constant expressions. |
| 4 | |
| 5 | const int c = 10; |
| 6 | int ar[c]; |
Douglas Gregor | 59600d8 | 2009-09-10 17:44:23 +0000 | [diff] [blame] | 7 | |
| 8 | struct X0 { |
| 9 | static const int value = static_cast<int>(4.0); |
| 10 | }; |
Douglas Gregor | f299124 | 2009-09-10 23:31:45 +0000 | [diff] [blame] | 11 | |
| 12 | void f() { |
| 13 | if (const int value = 17) { |
| 14 | int array[value]; |
| 15 | } |
| 16 | } |
Eli Friedman | c013118 | 2009-12-03 20:31:57 +0000 | [diff] [blame] | 17 | |
| 18 | int 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 McCall | 1f1b3b3 | 2010-02-06 01:07:37 +0000 | [diff] [blame] | 24 | |
| 25 | // PR6206: out-of-line definitions are legit |
| 26 | namespace 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 | } |