Daniel Dunbar | a572887 | 2009-12-15 20:14:24 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 %s -verify -fsyntax-only -pedantic |
Chris Lattner | 6538347 | 2007-12-18 07:15:40 +0000 | [diff] [blame] | 2 | |
| 3 | int test1() { |
| 4 | typedef int x[test1()]; // vla |
Chris Lattner | d880363 | 2008-08-10 01:58:45 +0000 | [diff] [blame] | 5 | static int y = sizeof(x); // expected-error {{not a compile-time constant}} |
Chris Lattner | 6538347 | 2007-12-18 07:15:40 +0000 | [diff] [blame] | 6 | } |
| 7 | |
Eli Friedman | b0c0554 | 2008-05-21 05:06:46 +0000 | [diff] [blame] | 8 | // PR2347 |
| 9 | void f (unsigned int m) |
| 10 | { |
Eli Friedman | 6b2564c | 2008-05-21 05:37:55 +0000 | [diff] [blame] | 11 | int e[2][m]; |
Eli Friedman | b0c0554 | 2008-05-21 05:06:46 +0000 | [diff] [blame] | 12 | |
| 13 | e[0][0] = 0; |
| 14 | } |
| 15 | |
Chris Lattner | 67027a7 | 2008-11-12 21:25:45 +0000 | [diff] [blame] | 16 | // PR3048 |
Chris Lattner | 0947b4e | 2008-11-24 01:28:17 +0000 | [diff] [blame] | 17 | int x = sizeof(struct{char qq[x];}); // expected-error {{fields must have a constant size}} |
Chris Lattner | 67027a7 | 2008-11-12 21:25:45 +0000 | [diff] [blame] | 18 | |
Anders Carlsson | 96e05bc | 2008-12-07 00:20:55 +0000 | [diff] [blame] | 19 | // PR2352 |
| 20 | void f2(unsigned int m) |
| 21 | { |
Douglas Gregor | 8f30105 | 2009-02-24 19:23:27 +0000 | [diff] [blame] | 22 | extern int e1[2][m]; // expected-error {{variable length array declaration can not have 'extern' linkage}} |
Anders Carlsson | 96e05bc | 2008-12-07 00:20:55 +0000 | [diff] [blame] | 23 | |
Douglas Gregor | 8f30105 | 2009-02-24 19:23:27 +0000 | [diff] [blame] | 24 | e1[0][0] = 0; |
Anders Carlsson | 96e05bc | 2008-12-07 00:20:55 +0000 | [diff] [blame] | 25 | |
| 26 | } |
| 27 | |
| 28 | // PR2361 |
| 29 | int i; |
Chris Lattner | 211316f | 2008-12-07 00:59:53 +0000 | [diff] [blame] | 30 | int c[][i]; // expected-error {{variably modified type declaration not allowed at file scope}} |
| 31 | int d[i]; // expected-error {{variable length array declaration not allowed at file scope}} |
Anders Carlsson | 96e05bc | 2008-12-07 00:20:55 +0000 | [diff] [blame] | 32 | |
Chris Lattner | 211316f | 2008-12-07 00:59:53 +0000 | [diff] [blame] | 33 | int (*e)[i]; // expected-error {{variably modified type declaration not allowed at file scope}} |
Anders Carlsson | 96e05bc | 2008-12-07 00:20:55 +0000 | [diff] [blame] | 34 | |
| 35 | void f3() |
| 36 | { |
| 37 | static int a[i]; // expected-error {{variable length array declaration can not have 'static' storage duration}} |
| 38 | extern int b[i]; // expected-error {{variable length array declaration can not have 'extern' linkage}} |
| 39 | |
Douglas Gregor | 8f30105 | 2009-02-24 19:23:27 +0000 | [diff] [blame] | 40 | extern int (*c1)[i]; // expected-error {{variably modified type declaration can not have 'extern' linkage}} |
Anders Carlsson | 96e05bc | 2008-12-07 00:20:55 +0000 | [diff] [blame] | 41 | static int (*d)[i]; |
| 42 | } |
| 43 | |
Eli Friedman | bc592e6 | 2009-02-26 03:58:54 +0000 | [diff] [blame] | 44 | // PR3663 |
Chris Lattner | e1eed38 | 2011-06-14 06:38:10 +0000 | [diff] [blame] | 45 | static const unsigned array[((2 * (int)((((4) / 2) + 1.0/3.0) * (4) - 1e-8)) + 1)]; // expected-warning {{variable length array folded to constant array as an extension}} |
Eli Friedman | f91f5c8 | 2009-04-26 21:57:51 +0000 | [diff] [blame] | 46 | |
| 47 | int a[*]; // expected-error {{star modifier used outside of function prototype}} |
| 48 | int f4(int a[*][*]); |
Eli Friedman | 88f7b57 | 2009-05-16 12:15:55 +0000 | [diff] [blame] | 49 | |
| 50 | // PR2044 |
| 51 | int pr2044(int b) {int (*c(void))[b];**c() = 2;} // expected-error {{variably modified type}} |
| 52 | int pr2044b; |
| 53 | int (*pr2044c(void))[pr2044b]; // expected-error {{variably modified type}} |
Mike Stump | 4f54f4e | 2009-05-29 16:34:15 +0000 | [diff] [blame] | 54 | |
| 55 | const int f5_ci = 1; |
Chris Lattner | e1eed38 | 2011-06-14 06:38:10 +0000 | [diff] [blame] | 56 | void f5() { char a[][f5_ci] = {""}; } // expected-warning {{variable length array folded to constant array as an extension}} |
Sam Weinig | d17e340 | 2010-02-01 05:02:49 +0000 | [diff] [blame] | 57 | |
| 58 | // PR5185 |
| 59 | void pr5185(int a[*]); |
| 60 | void pr5185(int a[*]) // expected-error {{variable length array must be bound in function definition}} |
| 61 | { |
| 62 | } |
Eli Friedman | 56ff283 | 2012-02-06 23:29:57 +0000 | [diff] [blame] | 63 | |
| 64 | // Make sure this isn't treated as an error |
| 65 | int TransformBug(int a) { |
| 66 | return sizeof(*(int(*)[({ goto v; v: a;})]) 0); // expected-warning {{use of GNU statement expression extension}} |
| 67 | } |