xref: /llvm-project/clang/test/Lexer/cxx1y_digit_separators.cpp (revision 579f0b307c19efd778d221703ea7743234113535)
1fde94852SRichard Smith // RUN: %clang_cc1 -std=c++1y -verify %s
2fde94852SRichard Smith 
3fde94852SRichard Smith int operator""ms(unsigned long long); // expected-warning {{reserved}}
4fde94852SRichard Smith float operator""ms(long double); // expected-warning {{reserved}}
5fde94852SRichard Smith 
67f2707a7SRichard Smith int operator""_foo(unsigned long long);
77f2707a7SRichard Smith 
8fde94852SRichard Smith namespace integral {
9fde94852SRichard Smith   static_assert(1'2'3 == 12'3, "");
10fde94852SRichard Smith   static_assert(1'000'000 == 0xf'4240, "");
11fde94852SRichard Smith   static_assert(0'004'000'000 == 0x10'0000, "");
12fde94852SRichard Smith   static_assert(0b0101'0100 == 0x54, "");
13fde94852SRichard Smith 
14fde94852SRichard Smith   int a = 123'; //'; // expected-error {{expected ';'}}
15fde94852SRichard Smith   int b = 0'xff; // expected-error {{digit separator cannot appear at end of digit sequence}} expected-error {{suffix 'xff' on integer}}
16fde94852SRichard Smith   int c = 0x'ff; // expected-error {{suffix 'x'ff' on integer}}
17fde94852SRichard Smith   int d = 0'1234; // ok, octal
18fde94852SRichard Smith   int e = 0'b1010; // expected-error {{digit 'b' in octal constant}}
19fde94852SRichard Smith   int f = 0b'1010; // expected-error {{invalid digit 'b' in octal}}
20fde94852SRichard Smith   int g = 123'ms; // expected-error {{digit separator cannot appear at end of digit sequence}}
2135ddad07SRichard Smith   int h = 0x1e+1; // expected-error {{invalid suffix '+1' on integer constant}}
2235ddad07SRichard Smith   int i = 0x1'e+1; // ok, 'e+' is not recognized after a digit separator
23fde94852SRichard Smith 
247f2707a7SRichard Smith   int z = 0'123'_foo; //'; // expected-error {{cannot appear at end of digit seq}}
25fde94852SRichard Smith }
26fde94852SRichard Smith 
27fde94852SRichard Smith namespace floating {
28fde94852SRichard Smith   static_assert(0'123.456'7 == 123.4567, "");
29fde94852SRichard Smith   static_assert(1e1'0 == 10'000'000'000, "");
30fde94852SRichard Smith 
31fde94852SRichard Smith   float a = 1'e1; // expected-error {{digit separator cannot appear at end of digit sequence}}
32fde94852SRichard Smith   float b = 1'0e1;
33fde94852SRichard Smith   float c = 1.'0e1; // expected-error {{digit separator cannot appear at start of digit sequence}}
34fde94852SRichard Smith   float d = 1.0'e1; // expected-error {{digit separator cannot appear at end of digit sequence}}
35fde94852SRichard Smith   float e = 1e'1; // expected-error {{digit separator cannot appear at start of digit sequence}}
36fde94852SRichard Smith   float f = 1e1'ms; // expected-error {{digit separator cannot appear at end of digit sequence}}
3770ee92faSRichard Smith   float g = 0.'0; // expected-error {{digit separator cannot appear at start of digit sequence}}
3870ee92faSRichard Smith   float h = .'0; // '; // expected-error {{expected expression}}, lexed as . followed by character literal
3970ee92faSRichard Smith   float i = 0x.'0p0; // expected-error {{digit separator cannot appear at start of digit sequence}}
4070ee92faSRichard Smith   float j = 0x'0.0p0; // expected-error {{invalid suffix 'x'0.0p0'}}
4170ee92faSRichard Smith   float k = 0x0'.0p0; // '; // expected-error {{expected ';'}}
4270ee92faSRichard Smith   float l = 0x0.'0p0; // expected-error {{digit separator cannot appear at start of digit sequence}}
4370ee92faSRichard Smith   float m = 0x0.0'p0; // expected-error {{digit separator cannot appear at end of digit sequence}}
4470ee92faSRichard Smith   float n = 0x0.0p'0; // expected-error {{digit separator cannot appear at start of digit sequence}}
4570ee92faSRichard Smith   float o = 0x0.0p0'ms; // expected-error {{digit separator cannot appear at end of digit sequence}}
4670ee92faSRichard Smith   float p = 0'e1; // expected-error {{digit separator cannot appear at end of digit sequence}}
4770ee92faSRichard Smith   float q = 0'0e1;
4870ee92faSRichard Smith   float r = 0.'0e1; // expected-error {{digit separator cannot appear at start of digit sequence}}
4970ee92faSRichard Smith   float s = 0.0'e1; // expected-error {{digit separator cannot appear at end of digit sequence}}
5070ee92faSRichard Smith   float t = 0.0e'1; // expected-error {{digit separator cannot appear at start of digit sequence}}
51560a3579SRichard Smith   float u = 0x.'p1f; // expected-error {{hexadecimal floating literal requires a significand}}
52b1cba3e7SRichard Smith   float v = 0e'f; // expected-error {{exponent has no digits}}
53b1cba3e7SRichard Smith   float w = 0x0p'f; // expected-error {{exponent has no digits}}
54*579f0b30SVolodymyr Sapsai   float x = 0'e+1; // expected-error {{digit separator cannot appear at end of digit sequence}}
55*579f0b30SVolodymyr Sapsai   float y = 0x0'p+1; // expected-error {{digit separator cannot appear at end of digit sequence}}
56fde94852SRichard Smith }
577f2707a7SRichard Smith 
587f2707a7SRichard Smith #line 123'456
597f2707a7SRichard Smith static_assert(__LINE__ == 123456, "");
6052d0211cSRichard Smith 
6152d0211cSRichard Smith // x has value 0 in C++11 and 34 in C++1y.
6252d0211cSRichard Smith #define M(x, ...) __VA_ARGS__
6352d0211cSRichard Smith constexpr int x = { M(1'2,3'4) };
6452d0211cSRichard Smith static_assert(x == 34, "");
6586b86973SRichard Smith 
6686b86973SRichard Smith namespace UCNs {
6786b86973SRichard Smith   // UCNs can appear before digit separators but not after.
6886b86973SRichard Smith   int a = 0\u1234'5; // expected-error {{invalid suffix '\u1234'5' on integer constant}}
6986b86973SRichard Smith   int b = 0'\u12345; // '; // expected-error {{expected ';'}}
7086b86973SRichard Smith   constexpr int c {M(0\u1234'0,0'1)};
7186b86973SRichard Smith   constexpr int d {M(00'\u1234,0'1)};
7286b86973SRichard Smith   static_assert(c == 1, "");
7386b86973SRichard Smith   static_assert(d == 0, "");
7486b86973SRichard Smith }
7586b86973SRichard Smith 
7686b86973SRichard Smith namespace UTF8 {
7786b86973SRichard Smith   // extended characters can appear before digit separators but not after.
7886b86973SRichard Smith   int a = 0'5; // expected-error {{invalid suffix ''5' on integer constant}}
7986b86973SRichard Smith   int b = 0'ሴ5; // '; // expected-error {{expected ';'}}
8086b86973SRichard Smith   constexpr int c {M(0'0,0'1)};
8186b86973SRichard Smith   constexpr int d {M(00'ሴ,0'1)};
8286b86973SRichard Smith   static_assert(c == 1, "");
8386b86973SRichard Smith   static_assert(d == 0, "");
8486b86973SRichard Smith }
85