xref: /llvm-project/clang/test/SemaCXX/_Alignas.cpp (revision c2fea4cf38991669030f4190d17b645cec27a7c0)
1 // RUN: %clang_cc1 %s -fsyntax-only -verify=expected,cpp
2 // RUN: %clang_cc1 -x c %s -fsyntax-only -verify=expected,c
3 
4 // Ensure that we correctly parse _Alignas as an extension in C++.
5 _Alignas(64) int i1;
6 _Alignas(long long) int i2;
7 int volatile _Alignas(64) i3; // Test strange ordering
8 
foo(void)9 void foo(void) {
10   // We previously rejected these valid declarations.
11   _Alignas(8) char i4;
12   _Alignas(char) char i5;
13 
14   (void)(int _Alignas(64))0; // expected-warning {{'_Alignas' attribute ignored when parsing type}}
15   // FIXME: C and C++ should both diagnose the same way, as being ignored.
16   (void)(_Alignas(64) int)0; // c-error {{expected expression}} \
17                                 cpp-warning {{'_Alignas' attribute ignored when parsing type}}
18 }
19 
20 struct S {
21   _Alignas(int) int i;
22   _Alignas(64) int j;
23 };
24 
25 void bar(_Alignas(8) char c1, char _Alignas(char) c2); // expected-error 2 {{'_Alignas' attribute cannot be applied to a function parameter}}
26