1 // RUN: %clang_cc1 -std=c++1y -verify %s
2 
3 int operator""ms(unsigned long long); // expected-warning {{reserved}}
4 float operator""ms(long double); // expected-warning {{reserved}}
5 
6 int operator""_foo(unsigned long long);
7 
8 namespace integral {
9   static_assert(1'2'3 == 12'3, "");
10   static_assert(1'000'000 == 0xf'4240, "");
11   static_assert(0'004'000'000 == 0x10'0000, "");
12   static_assert(0b0101'0100 == 0x54, "");
13 
14   int a = 123'; //'; // expected-error {{expected ';'}}
15   int b = 0'xff; // expected-error {{digit separator cannot appear at end of digit sequence}} expected-error {{suffix 'xff' on integer}}
16   int c = 0x'ff; // expected-error {{suffix 'x'ff' on integer}}
17   int d = 0'1234; // ok, octal
18   int e = 0'b1010; // expected-error {{digit 'b' in octal constant}}
19   int f = 0b'1010; // expected-error {{invalid digit 'b' in octal}}
20   int g = 123'ms; // expected-error {{digit separator cannot appear at end of digit sequence}}
21   int h = 0x1e+1; // expected-error {{invalid suffix '+1' on integer constant}}
22   int i = 0x1'e+1; // ok, 'e+' is not recognized after a digit separator
23 
24   int z = 0'123'_foo; //'; // expected-error {{cannot appear at end of digit seq}}
25 }
26 
27 namespace floating {
28   static_assert(0'123.456'7 == 123.4567, "");
29   static_assert(1e1'0 == 10'000'000'000, "");
30 
31   float a = 1'e1; // expected-error {{digit separator cannot appear at end of digit sequence}}
32   float b = 1'0e1;
33   float c = 1.'0e1; // expected-error {{digit separator cannot appear at start of digit sequence}}
34   float d = 1.0'e1; // expected-error {{digit separator cannot appear at end of digit sequence}}
35   float e = 1e'1; // expected-error {{digit separator cannot appear at start of digit sequence}}
36   float f = 1e1'ms; // expected-error {{digit separator cannot appear at end of digit sequence}}
37   float g = 0.'0; // expected-error {{digit separator cannot appear at start of digit sequence}}
38   float h = .'0; // '; // expected-error {{expected expression}}, lexed as . followed by character literal
39   float i = 0x.'0p0; // expected-error {{digit separator cannot appear at start of digit sequence}}
40   float j = 0x'0.0p0; // expected-error {{invalid suffix 'x'0.0p0'}}
41   float k = 0x0'.0p0; // '; // expected-error {{expected ';'}}
42   float l = 0x0.'0p0; // expected-error {{digit separator cannot appear at start of digit sequence}}
43   float m = 0x0.0'p0; // expected-error {{digit separator cannot appear at end of digit sequence}}
44   float n = 0x0.0p'0; // expected-error {{digit separator cannot appear at start of digit sequence}}
45   float o = 0x0.0p0'ms; // expected-error {{digit separator cannot appear at end of digit sequence}}
46   float p = 0'e1; // expected-error {{digit separator cannot appear at end of digit sequence}}
47   float q = 0'0e1;
48   float r = 0.'0e1; // expected-error {{digit separator cannot appear at start of digit sequence}}
49   float s = 0.0'e1; // expected-error {{digit separator cannot appear at end of digit sequence}}
50   float t = 0.0e'1; // expected-error {{digit separator cannot appear at start of digit sequence}}
51 }
52 
53 #line 123'456
54 static_assert(__LINE__ == 123456, "");
55 
56 // x has value 0 in C++11 and 34 in C++1y.
57 #define M(x, ...) __VA_ARGS__
58 constexpr int x = { M(1'2,3'4) };
59 static_assert(x == 34, "");
60 
61 namespace UCNs {
62   // UCNs can appear before digit separators but not after.
63   int a = 0\u1234'5; // expected-error {{invalid suffix '\u1234'5' on integer constant}}
64   int b = 0'\u12345; // '; // expected-error {{expected ';'}}
65   constexpr int c {M(0\u1234'0,0'1)};
66   constexpr int d {M(00'\u1234,0'1)};
67   static_assert(c == 1, "");
68   static_assert(d == 0, "");
69 }
70 
71 namespace UTF8 {
72   // extended characters can appear before digit separators but not after.
73   int a = 0'5; // expected-error {{invalid suffix ''5' on integer constant}}
74   int b = 0'ሴ5; // '; // expected-error {{expected ';'}}
75   constexpr int c {M(0'0,0'1)};
76   constexpr int d {M(00'ሴ,0'1)};
77   static_assert(c == 1, "");
78   static_assert(d == 0, "");
79 }
80