xref: /llvm-project/clang/test/Preprocessor/embed_parameter_suffix.c (revision 41c6e4379204ffc00948edd33d59ba5ebbceaba2)
1 // RUN: %clang_cc1 -std=c23 %s --embed-dir=%S/Inputs -fsyntax-only -verify
2 
3 const char data[] = {
4 #embed <single_byte.txt> suffix(, '\xA')
5 };
6 const char empty_data[] = {
7 #embed <media/empty> suffix(, '\xA')
8 1
9 };
10 static_assert(sizeof(data) == 2);
11 static_assert('b' == data[0]);
12 static_assert('\xA' == data[1]);
13 static_assert(sizeof(empty_data) == 1);
14 static_assert(1 == empty_data[0]);
15 
16 struct S {
17   int x, y, z;
18 };
19 
20 const struct S s = {
21 #embed <single_byte.txt> suffix( , .y = 100, .z = 10 )
22 };
23 
24 static_assert(s.x == 'b');
25 static_assert(s.y == 100);
26 static_assert(s.z == 10);
27 
28 // Ensure that an empty file does not produce any suffix tokens. If it did,
29 // there would be random tokens here that the parser would trip on.
30 #embed <media/empty> suffix(0)
31 
32 // Ensure we diagnose duplicate parameters even if they're the same value.
33 const unsigned char a[] = {
34 #embed <jk.txt> suffix(,1) prefix() suffix(,1)
35 // expected-error@-1 {{cannot specify parameter 'suffix' twice in the same '#embed' directive}}
36 ,
37 #embed <jk.txt> suffix(,1) if_empty() suffix(,2)
38 // expected-error@-1 {{cannot specify parameter 'suffix' twice in the same '#embed' directive}}
39 };
40