[docs] Add LICENSE.txt to the root of the mono-repo
[llvm-project.git] / clang / test / Lexer / c2x_digit_separators.c
blob3eff8f7cf7004aca6a5b95031e72952d8a563521
1 // RUN: %clang_cc1 -std=c2x -verify %s
3 _Static_assert(1'2'3 == 12'3, "");
4 _Static_assert(1'000'000 == 0xf'4240, "");
5 _Static_assert(0'004'000'000 == 0x10'0000, "");
6 _Static_assert(0b0101'0100 == 0x54, "");
8 int a0 = 123'; //'; // expected-error {{expected ';'}}
9 int b0 = 0'xff; // expected-error {{digit separator cannot appear at end of digit sequence}} expected-error {{suffix 'xff' on integer}}
10 int c0 = 0x'ff; // expected-error {{suffix 'x'ff' on integer}}
11 int d0 = 0'1234; // ok, octal
12 int e0 = 0'b1010; // expected-error {{digit 'b' in octal constant}}
13 int f0 = 0b'1010; // expected-error {{invalid digit 'b' in octal}}
14 int h0 = 0x1e+1; // expected-error {{invalid suffix '+1' on integer constant}}
15 int i0 = 0x1'e+1; // ok, 'e+' is not recognized after a digit separator
17 float a1 = 1'e1; // expected-error {{digit separator cannot appear at end of digit sequence}}
18 float b1 = 1'0e1;
19 float c1 = 1.'0e1; // expected-error {{digit separator cannot appear at start of digit sequence}}
20 float d1 = 1.0'e1; // expected-error {{digit separator cannot appear at end of digit sequence}}
21 float e1 = 1e'1; // expected-error {{digit separator cannot appear at start of digit sequence}}
22 float g1 = 0.'0; // expected-error {{digit separator cannot appear at start of digit sequence}}
23 float h1 = .'0; // '; // expected-error {{expected expression}}, lexed as . followed by character literal
24 float i1 = 0x.'0p0; // expected-error {{digit separator cannot appear at start of digit sequence}}
25 float j1 = 0x'0.0p0; // expected-error {{invalid suffix 'x'0.0p0'}}
26 float k1 = 0x0'.0p0; // '; // expected-error {{expected ';'}}
27 float l1 = 0x0.'0p0; // expected-error {{digit separator cannot appear at start of digit sequence}}
28 float m1 = 0x0.0'p0; // expected-error {{digit separator cannot appear at end of digit sequence}}
29 float n1 = 0x0.0p'0; // expected-error {{digit separator cannot appear at start of digit sequence}}
30 float p1 = 0'e1; // expected-error {{digit separator cannot appear at end of digit sequence}}
31 float q1 = 0'0e1;
32 float r1 = 0.'0e1; // expected-error {{digit separator cannot appear at start of digit sequence}}
33 float s1 = 0.0'e1; // expected-error {{digit separator cannot appear at end of digit sequence}}
34 float t1 = 0.0e'1; // expected-error {{digit separator cannot appear at start of digit sequence}}
35 float u1 = 0x.'p1f; // expected-error {{hexadecimal floating constant requires a significand}}
36 float v1 = 0e'f; // expected-error {{exponent has no digits}}
37 float w1 = 0x0p'f; // expected-error {{exponent has no digits}}
38 float x1 = 0'e+1; // expected-error {{digit separator cannot appear at end of digit sequence}}
39 float y1 = 0x0'p+1; // expected-error {{digit separator cannot appear at end of digit sequence}}
41 #line 123'456
42 _Static_assert(__LINE__ == 123456, "");
44 // UCNs can appear before digit separators but not after.
45 int a2 = 0\u1234'5; // expected-error {{invalid suffix '\u1234'5' on integer constant}}
46 int b2 = 0'\u12345; // '; // expected-error {{expected ';'}}
48 // extended characters can appear before digit separators but not after.
49 int a3 = 0'5; // expected-error {{invalid suffix ''5' on integer constant}}
50 int b3 = 0'5; // '; // expected-error {{expected ';'}}