Richard Smith | fde9485 | 2013-09-26 03:33:06 +0000 | [diff] [blame] | 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 | |
Richard Smith | 7f2707a | 2013-09-26 18:13:20 +0000 | [diff] [blame] | 6 | int operator""_foo(unsigned long long); |
| 7 | |
Richard Smith | fde9485 | 2013-09-26 03:33:06 +0000 | [diff] [blame] | 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}} |
Richard Smith | 35ddad0 | 2014-02-28 20:06:02 +0000 | [diff] [blame] | 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 |
Richard Smith | fde9485 | 2013-09-26 03:33:06 +0000 | [diff] [blame] | 23 | |
Richard Smith | 7f2707a | 2013-09-26 18:13:20 +0000 | [diff] [blame] | 24 | int z = 0'123'_foo; //'; // expected-error {{cannot appear at end of digit seq}} |
Richard Smith | fde9485 | 2013-09-26 03:33:06 +0000 | [diff] [blame] | 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}} |
Richard Smith | 70ee92f | 2014-04-22 23:50:25 +0000 | [diff] [blame] | 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}} |
Richard Smith | 560a357 | 2016-03-04 22:32:06 +0000 | [diff] [blame] | 51 | float u = 0x.'p1f; // expected-error {{hexadecimal floating literal requires a significand}} |
Richard Smith | b1cba3e | 2016-02-09 22:34:35 +0000 | [diff] [blame] | 52 | float v = 0e'f; // expected-error {{exponent has no digits}} |
| 53 | float w = 0x0p'f; // expected-error {{exponent has no digits}} |
Volodymyr Sapsai | 579f0b3 | 2018-02-06 22:39:25 +0000 | [diff] [blame] | 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}} |
Richard Smith | fde9485 | 2013-09-26 03:33:06 +0000 | [diff] [blame] | 56 | } |
Richard Smith | 7f2707a | 2013-09-26 18:13:20 +0000 | [diff] [blame] | 57 | |
| 58 | #line 123'456 |
| 59 | static_assert(__LINE__ == 123456, ""); |
Richard Smith | 52d0211 | 2013-09-26 18:15:22 +0000 | [diff] [blame] | 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, ""); |
Richard Smith | 86b8697 | 2014-02-28 20:13:19 +0000 | [diff] [blame] | 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 | } |