File: cxx1y_digit_separators.cpp

package info (click to toggle)
llvm-toolchain-3.4 1%3A3.4.2-13
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 253,236 kB
  • ctags: 276,203
  • sloc: cpp: 1,665,580; ansic: 298,647; asm: 206,157; objc: 84,350; python: 73,119; sh: 23,466; perl: 5,679; makefile: 5,542; ml: 5,250; pascal: 2,467; lisp: 1,420; xml: 679; cs: 236; csh: 117
file content (43 lines) | stat: -rw-r--r-- 1,831 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// RUN: %clang_cc1 -std=c++1y -verify %s

int operator""ms(unsigned long long); // expected-warning {{reserved}}
float operator""ms(long double); // expected-warning {{reserved}}

int operator""_foo(unsigned long long);

namespace integral {
  static_assert(1'2'3 == 12'3, "");
  static_assert(1'000'000 == 0xf'4240, "");
  static_assert(0'004'000'000 == 0x10'0000, "");
  static_assert(0b0101'0100 == 0x54, "");

  int a = 123'; //'; // expected-error {{expected ';'}}
  int b = 0'xff; // expected-error {{digit separator cannot appear at end of digit sequence}} expected-error {{suffix 'xff' on integer}}
  int c = 0x'ff; // expected-error {{suffix 'x'ff' on integer}}
  int d = 0'1234; // ok, octal
  int e = 0'b1010; // expected-error {{digit 'b' in octal constant}}
  int f = 0b'1010; // expected-error {{invalid digit 'b' in octal}}
  int g = 123'ms; // expected-error {{digit separator cannot appear at end of digit sequence}}

  int z = 0'123'_foo; //'; // expected-error {{cannot appear at end of digit seq}}
}

namespace floating {
  static_assert(0'123.456'7 == 123.4567, "");
  static_assert(1e1'0 == 10'000'000'000, "");

  float a = 1'e1; // expected-error {{digit separator cannot appear at end of digit sequence}}
  float b = 1'0e1;
  float c = 1.'0e1; // expected-error {{digit separator cannot appear at start of digit sequence}}
  float d = 1.0'e1; // expected-error {{digit separator cannot appear at end of digit sequence}}
  float e = 1e'1; // expected-error {{digit separator cannot appear at start of digit sequence}}
  float f = 1e1'ms; // expected-error {{digit separator cannot appear at end of digit sequence}}
}

#line 123'456
static_assert(__LINE__ == 123456, "");

// x has value 0 in C++11 and 34 in C++1y.
#define M(x, ...) __VA_ARGS__
constexpr int x = { M(1'2,3'4) };
static_assert(x == 34, "");