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}} |
| 37 | } |
Richard Smith | 7f2707a | 2013-09-26 18:13:20 +0000 | [diff] [blame] | 38 | |
| 39 | #line 123'456 |
| 40 | static_assert(__LINE__ == 123456, ""); |
Richard Smith | 52d0211 | 2013-09-26 18:15:22 +0000 | [diff] [blame] | 41 | |
| 42 | // x has value 0 in C++11 and 34 in C++1y. |
| 43 | #define M(x, ...) __VA_ARGS__ |
| 44 | constexpr int x = { M(1'2,3'4) }; |
| 45 | static_assert(x == 34, ""); |
Richard Smith | 86b8697 | 2014-02-28 20:13:19 +0000 | [diff] [blame] | 46 | |
| 47 | namespace UCNs { |
| 48 | // UCNs can appear before digit separators but not after. |
| 49 | int a = 0\u1234'5; // expected-error {{invalid suffix '\u1234'5' on integer constant}} |
| 50 | int b = 0'\u12345; // '; // expected-error {{expected ';'}} |
| 51 | constexpr int c {M(0\u1234'0,0'1)}; |
| 52 | constexpr int d {M(00'\u1234,0'1)}; |
| 53 | static_assert(c == 1, ""); |
| 54 | static_assert(d == 0, ""); |
| 55 | } |
| 56 | |
| 57 | namespace UTF8 { |
| 58 | // extended characters can appear before digit separators but not after. |
| 59 | int a = 0ሴ'5; // expected-error {{invalid suffix 'ሴ'5' on integer constant}} |
| 60 | int b = 0'ሴ5; // '; // expected-error {{expected ';'}} |
| 61 | constexpr int c {M(0ሴ'0,0'1)}; |
| 62 | constexpr int d {M(00'ሴ,0'1)}; |
| 63 | static_assert(c == 1, ""); |
| 64 | static_assert(d == 0, ""); |
| 65 | } |