annotate clang/test/Preprocessor/macro_fn_comma_swallow2.c @ 236:c4bab56944e8 llvm-original

LLVM 16
author kono
date Wed, 09 Nov 2022 17:45:10 +0900
parents 1d019706d866
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
150
anatofuz
parents:
diff changeset
1 // Test the __VA_ARGS__ comma swallowing extensions of various compiler dialects.
anatofuz
parents:
diff changeset
2
anatofuz
parents:
diff changeset
3 // RUN: %clang_cc1 -E %s | FileCheck -check-prefix=GCC -strict-whitespace %s
anatofuz
parents:
diff changeset
4 // RUN: %clang_cc1 -E -std=c99 %s | FileCheck -check-prefix=C99 -strict-whitespace %s
anatofuz
parents:
diff changeset
5 // RUN: %clang_cc1 -E -std=c11 %s | FileCheck -check-prefix=C99 -strict-whitespace %s
anatofuz
parents:
diff changeset
6 // RUN: %clang_cc1 -E -x c++ %s | FileCheck -check-prefix=GCC -strict-whitespace %s
anatofuz
parents:
diff changeset
7 // RUN: %clang_cc1 -E -std=gnu99 %s | FileCheck -check-prefix=GCC -strict-whitespace %s
anatofuz
parents:
diff changeset
8 // RUN: %clang_cc1 -E -fms-compatibility %s | FileCheck -check-prefix=MS -strict-whitespace %s
anatofuz
parents:
diff changeset
9 // RUN: %clang_cc1 -E -DNAMED %s | FileCheck -check-prefix=GCC -strict-whitespace %s
anatofuz
parents:
diff changeset
10 // RUN: %clang_cc1 -E -std=c99 -DNAMED %s | FileCheck -check-prefix=C99 -strict-whitespace %s
anatofuz
parents:
diff changeset
11
anatofuz
parents:
diff changeset
12
anatofuz
parents:
diff changeset
13 #ifndef NAMED
anatofuz
parents:
diff changeset
14 # define A(...) [ __VA_ARGS__ ]
anatofuz
parents:
diff changeset
15 # define B(...) [ , __VA_ARGS__ ]
anatofuz
parents:
diff changeset
16 # define C(...) [ , ## __VA_ARGS__ ]
anatofuz
parents:
diff changeset
17 # define D(A,...) [ A , ## __VA_ARGS__ ]
anatofuz
parents:
diff changeset
18 # define E(A,...) [ __VA_ARGS__ ## A ]
anatofuz
parents:
diff changeset
19 #else
anatofuz
parents:
diff changeset
20 // These are the GCC named argument versions of the C99-style variadic macros.
anatofuz
parents:
diff changeset
21 // Note that __VA_ARGS__ *may* be used as the name, this is not prohibited!
anatofuz
parents:
diff changeset
22 # define A(__VA_ARGS__...) [ __VA_ARGS__ ]
anatofuz
parents:
diff changeset
23 # define B(__VA_ARGS__...) [ , __VA_ARGS__ ]
anatofuz
parents:
diff changeset
24 # define C(__VA_ARGS__...) [ , ## __VA_ARGS__ ]
anatofuz
parents:
diff changeset
25 # define D(A,__VA_ARGS__...) [ A , ## __VA_ARGS__ ]
anatofuz
parents:
diff changeset
26 # define E(A,__VA_ARGS__...) [ __VA_ARGS__ ## A ]
anatofuz
parents:
diff changeset
27 #endif
anatofuz
parents:
diff changeset
28
anatofuz
parents:
diff changeset
29
anatofuz
parents:
diff changeset
30 1: A() B() C() D() E()
anatofuz
parents:
diff changeset
31 2: A(a) B(a) C(a) D(a) E(a)
anatofuz
parents:
diff changeset
32 3: A(,) B(,) C(,) D(,) E(,)
anatofuz
parents:
diff changeset
33 4: A(a,b,c) B(a,b,c) C(a,b,c) D(a,b,c) E(a,b,c)
anatofuz
parents:
diff changeset
34 5: A(a,b,) B(a,b,) C(a,b,) D(a,b,)
anatofuz
parents:
diff changeset
35
anatofuz
parents:
diff changeset
36 // The GCC ", ## __VA_ARGS__" extension swallows the comma when followed by
anatofuz
parents:
diff changeset
37 // empty __VA_ARGS__. This extension does not apply in -std=c99 mode, but
anatofuz
parents:
diff changeset
38 // does apply in C++.
anatofuz
parents:
diff changeset
39 //
anatofuz
parents:
diff changeset
40 // GCC: 1: [ ] [ , ] [ ] [ ] [ ]
anatofuz
parents:
diff changeset
41 // GCC: 2: [ a ] [ , a ] [ ,a ] [ a ] [ a ]
anatofuz
parents:
diff changeset
42 // GCC: 3: [ , ] [ , , ] [ ,, ] [ , ] [ ]
anatofuz
parents:
diff changeset
43 // GCC: 4: [ a,b,c ] [ , a,b,c ] [ ,a,b,c ] [ a ,b,c ] [ b,ca ]
anatofuz
parents:
diff changeset
44 // GCC: 5: [ a,b, ] [ , a,b, ] [ ,a,b, ] [ a ,b, ]
anatofuz
parents:
diff changeset
45
anatofuz
parents:
diff changeset
46 // Under C99 standard mode, the GCC ", ## __VA_ARGS__" extension *does not*
anatofuz
parents:
diff changeset
47 // swallow the comma when followed by empty __VA_ARGS__.
anatofuz
parents:
diff changeset
48 //
anatofuz
parents:
diff changeset
49 // C99: 1: [ ] [ , ] [ , ] [ ] [ ]
anatofuz
parents:
diff changeset
50 // C99: 2: [ a ] [ , a ] [ ,a ] [ a ] [ a ]
anatofuz
parents:
diff changeset
51 // C99: 3: [ , ] [ , , ] [ ,, ] [ , ] [ ]
anatofuz
parents:
diff changeset
52 // C99: 4: [ a,b,c ] [ , a,b,c ] [ ,a,b,c ] [ a ,b,c ] [ b,ca ]
anatofuz
parents:
diff changeset
53 // C99: 5: [ a,b, ] [ , a,b, ] [ ,a,b, ] [ a ,b, ]
anatofuz
parents:
diff changeset
54
anatofuz
parents:
diff changeset
55 // Microsoft's extension is on ", __VA_ARGS__" (without explicit ##) where
anatofuz
parents:
diff changeset
56 // the comma is swallowed when followed by empty __VA_ARGS__.
anatofuz
parents:
diff changeset
57 //
anatofuz
parents:
diff changeset
58 // MS: 1: [ ] [ ] [ ] [ ] [ ]
anatofuz
parents:
diff changeset
59 // MS: 2: [ a ] [ , a ] [ ,a ] [ a ] [ a ]
anatofuz
parents:
diff changeset
60 // MS: 3: [ , ] [ , , ] [ ,, ] [ , ] [ ]
anatofuz
parents:
diff changeset
61 // MS: 4: [ a,b,c ] [ , a,b,c ] [ ,a,b,c ] [ a ,b,c ] [ b,ca ]
anatofuz
parents:
diff changeset
62 // MS: 5: [ a,b, ] [ , a,b, ] [ ,a,b, ] [ a ,b, ]
anatofuz
parents:
diff changeset
63
anatofuz
parents:
diff changeset
64 // FIXME: Item 3(d) in MS output should be [ ] not [ , ]