cxx1y_digit_separators.cpp revision 65ea687b8abbfc892e8d91bba477999b0379b07b
1// RUN: %clang_cc1 -std=c++1y -verify %s
2
3int operator""ms(unsigned long long); // expected-warning {{reserved}}
4float operator""ms(long double); // expected-warning {{reserved}}
5
6int operator""_foo(unsigned long long);
7
8namespace 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
22  int z = 0'123'_foo; //'; // expected-error {{cannot appear at end of digit seq}}
23}
24
25namespace floating {
26  static_assert(0'123.456'7 == 123.4567, "");
27  static_assert(1e1'0 == 10'000'000'000, "");
28
29  float a = 1'e1; // expected-error {{digit separator cannot appear at end of digit sequence}}
30  float b = 1'0e1;
31  float c = 1.'0e1; // expected-error {{digit separator cannot appear at start of digit sequence}}
32  float d = 1.0'e1; // expected-error {{digit separator cannot appear at end of digit sequence}}
33  float e = 1e'1; // expected-error {{digit separator cannot appear at start of digit sequence}}
34  float f = 1e1'ms; // expected-error {{digit separator cannot appear at end of digit sequence}}
35}
36
37#line 123'456
38static_assert(__LINE__ == 123456, "");
39
40// x has value 0 in C++11 and 34 in C++1y.
41#define M(x, ...) __VA_ARGS__
42constexpr int x = { M(1'2,3'4) };
43static_assert(x == 34, "");
44