• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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   float u = 0x.'p1f; // expected-error {{hexadecimal floating literal requires a significand}}
52   float v = 0e'f; // expected-error {{exponent has no digits}}
53   float w = 0x0p'f; // expected-error {{exponent has no digits}}
54   float x = 0'e+1; // expected-error {{digit separator cannot appear at end of digit sequence}}
55   float y = 0x0'p+1; // expected-error {{digit separator cannot appear at end of digit sequence}}
56 }
57 
58 #line 123'456
59 static_assert(__LINE__ == 123456, "");
60 
61 // x has value 0 in C++11 and 34 in C++1y.
62 #define M(x, ...) __VA_ARGS__
63 constexpr int x = { M(1'2,3'4) };
64 static_assert(x == 34, "");
65 
66 namespace UCNs {
67   // UCNs can appear before digit separators but not after.
68   int a = 0\u1234'5; // expected-error {{invalid suffix '\u1234'5' on integer constant}}
69   int b = 0'\u12345; // '; // expected-error {{expected ';'}}
70   constexpr int c {M(0\u1234'0,0'1)};
71   constexpr int d {M(00'\u1234,0'1)};
72   static_assert(c == 1, "");
73   static_assert(d == 0, "");
74 }
75 
76 namespace UTF8 {
77   // extended characters can appear before digit separators but not after.
78   int a = 0'5; // expected-error {{invalid suffix ''5' on integer constant}}
79   int b = 0'ሴ5; // '; // expected-error {{expected ';'}}
80   constexpr int c {M(0'0,0'1)};
81   constexpr int d {M(00'ሴ,0'1)};
82   static_assert(c == 1, "");
83   static_assert(d == 0, "");
84 }
85