blob: 3b56ae1085ad3f2ec8ea6ae39e164603a1a944a5 [file] [log] [blame]
John McCall768439e2013-05-06 07:40:34 +00001// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
2
3// rdar://13784901
4
5struct S0 {
6 int x;
7 static const int test0 = __alignof__(x); // expected-error {{invalid application of 'alignof' to a field of a class still being defined}}
8 static const int test1 = __alignof__(S0::x); // expected-error {{invalid application of 'alignof' to a field of a class still being defined}}
9 auto test2() -> char(&)[__alignof__(x)]; // expected-error {{invalid application of 'alignof' to a field of a class still being defined}}
10};
11
Matt Beaumont-Gay35779952013-06-25 22:19:15 +000012struct S1; // expected-note 6 {{forward declaration}}
John McCall768439e2013-05-06 07:40:34 +000013extern S1 s1;
14const int test3 = __alignof__(s1); // expected-error {{invalid application of 'alignof' to an incomplete type 'S1'}}
15
16struct S2 {
17 S2();
18 S1 &s;
19 int x;
20
21 int test4 = __alignof__(x); // ok
22 int test5 = __alignof__(s); // expected-error {{invalid application of 'alignof' to an incomplete type 'S1'}}
23};
24
25const int test6 = __alignof__(S2::x);
26const int test7 = __alignof__(S2::s); // expected-error {{invalid application of 'alignof' to an incomplete type 'S1'}}
27
28// Arguably, these should fail like the S1 cases do: the alignment of
29// 's2.x' should depend on the alignment of both x-within-S2 and
30// s2-within-S3 and thus require 'S3' to be complete. If we start
31// doing the appropriate recursive walk to do that, we should make
32// sure that these cases don't explode.
33struct S3 {
34 S2 s2;
35
36 static const int test8 = __alignof__(s2.x);
37 static const int test9 = __alignof__(s2.s); // expected-error {{invalid application of 'alignof' to an incomplete type 'S1'}}
38 auto test10() -> char(&)[__alignof__(s2.x)];
39 static const int test11 = __alignof__(S3::s2.x);
40 static const int test12 = __alignof__(S3::s2.s); // expected-error {{invalid application of 'alignof' to an incomplete type 'S1'}}
41 auto test13() -> char(&)[__alignof__(s2.x)];
42};
43
44// Same reasoning as S3.
45struct S4 {
46 union {
47 int x;
48 };
49 static const int test0 = __alignof__(x);
50 static const int test1 = __alignof__(S0::x);
51 auto test2() -> char(&)[__alignof__(x)];
52};
Matt Beaumont-Gay35779952013-06-25 22:19:15 +000053
54// Regression test for asking for the alignment of a field within an invalid
55// record.
56struct S5 {
57 S1 s; // expected-error {{incomplete type}}
58 int x;
59};
60const int test8 = __alignof__(S5::x);
Rafael Espindola71eccb32013-08-08 19:53:46 +000061
62long long int test14[2];
63
64static_assert(alignof(test14) == 8, "foo"); // expected-warning {{'alignof' applied to an expression is a GNU extension}}
Richard Smithc3fbf682014-06-10 21:11:26 +000065
66// PR19992
67alignas(32) extern int test15[];
68static_assert(alignof(int[]) == alignof(int), ""); // ok
69// FIXME: We should accept this.
70static_assert(alignof(test15) == 32, ""); // expected-warning {{GNU extension}} expected-error {{incomplete type}}