blob: fd7a6bf3d72f94d3dc0a5899e1b91ac38688a6a3 [file] [log] [blame]
Daniel Dunbara5728872009-12-15 20:14:24 +00001// RUN: %clang_cc1 %s -verify -fsyntax-only -pedantic
Chris Lattner65383472007-12-18 07:15:40 +00002
3int test1() {
4 typedef int x[test1()]; // vla
Chris Lattnerd8803632008-08-10 01:58:45 +00005 static int y = sizeof(x); // expected-error {{not a compile-time constant}}
Chris Lattner65383472007-12-18 07:15:40 +00006}
7
Eli Friedmanb0c05542008-05-21 05:06:46 +00008// PR2347
9void f (unsigned int m)
10{
Eli Friedman6b2564c2008-05-21 05:37:55 +000011 int e[2][m];
Eli Friedmanb0c05542008-05-21 05:06:46 +000012
13 e[0][0] = 0;
14}
15
Chris Lattner67027a72008-11-12 21:25:45 +000016// PR3048
Chris Lattner0947b4e2008-11-24 01:28:17 +000017int x = sizeof(struct{char qq[x];}); // expected-error {{fields must have a constant size}}
Chris Lattner67027a72008-11-12 21:25:45 +000018
Anders Carlsson96e05bc2008-12-07 00:20:55 +000019// PR2352
20void f2(unsigned int m)
21{
Douglas Gregor8f301052009-02-24 19:23:27 +000022 extern int e1[2][m]; // expected-error {{variable length array declaration can not have 'extern' linkage}}
Anders Carlsson96e05bc2008-12-07 00:20:55 +000023
Douglas Gregor8f301052009-02-24 19:23:27 +000024 e1[0][0] = 0;
Anders Carlsson96e05bc2008-12-07 00:20:55 +000025
26}
27
28// PR2361
29int i;
Chris Lattner211316f2008-12-07 00:59:53 +000030int c[][i]; // expected-error {{variably modified type declaration not allowed at file scope}}
31int d[i]; // expected-error {{variable length array declaration not allowed at file scope}}
Anders Carlsson96e05bc2008-12-07 00:20:55 +000032
Chris Lattner211316f2008-12-07 00:59:53 +000033int (*e)[i]; // expected-error {{variably modified type declaration not allowed at file scope}}
Anders Carlsson96e05bc2008-12-07 00:20:55 +000034
35void 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 Gregor8f301052009-02-24 19:23:27 +000040 extern int (*c1)[i]; // expected-error {{variably modified type declaration can not have 'extern' linkage}}
Anders Carlsson96e05bc2008-12-07 00:20:55 +000041 static int (*d)[i];
42}
43
Eli Friedmanbc592e62009-02-26 03:58:54 +000044// PR3663
Chris Lattnere1eed382011-06-14 06:38:10 +000045static 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 Friedmanf91f5c82009-04-26 21:57:51 +000046
47int a[*]; // expected-error {{star modifier used outside of function prototype}}
48int f4(int a[*][*]);
Eli Friedman88f7b572009-05-16 12:15:55 +000049
50// PR2044
51int pr2044(int b) {int (*c(void))[b];**c() = 2;} // expected-error {{variably modified type}}
52int pr2044b;
53int (*pr2044c(void))[pr2044b]; // expected-error {{variably modified type}}
Mike Stump4f54f4e2009-05-29 16:34:15 +000054
55const int f5_ci = 1;
Chris Lattnere1eed382011-06-14 06:38:10 +000056void f5() { char a[][f5_ci] = {""}; } // expected-warning {{variable length array folded to constant array as an extension}}
Sam Weinigd17e3402010-02-01 05:02:49 +000057
58// PR5185
59void pr5185(int a[*]);
60void pr5185(int a[*]) // expected-error {{variable length array must be bound in function definition}}
61{
62}