| 1 |
// { dg-do run { target c++11 } } |
| 2 |
// { dg-skip-if "requires hosted libstdc++ for cstring" { ! hostedlib } } |
| 3 |
|
| 4 |
// Test user-defined literals. |
| 5 |
// Test simple operator declaration and definition. |
| 6 |
|
| 7 |
#include <cstring> |
| 8 |
#include <string> |
| 9 |
#include <complex> |
| 10 |
#include <cassert> |
| 11 |
|
| 12 |
long double operator ""_v(long double); |
| 13 |
std::string operator ""_w(const char16_t*, size_t); |
| 14 |
unsigned operator ""_w(const char*); |
| 15 |
|
| 16 |
std::complex<double> |
| 17 |
operator ""_i(long double y) |
| 18 |
{ return std::complex<double>(0.0L, y); } |
| 19 |
|
| 20 |
void |
| 21 |
test1() |
| 22 |
{ |
| 23 |
long double x = operator ""_v(1.2L); |
| 24 |
assert(x == 2.2L); |
| 25 |
|
| 26 |
std::string s = operator ""_w(u"one", 3); |
| 27 |
assert(s == "boo"); |
| 28 |
|
| 29 |
unsigned u = operator ""_w("Hello, World!"); |
| 30 |
assert(u == 13U); |
| 31 |
|
| 32 |
std::complex<double> i = operator ""_i(2.0); |
| 33 |
assert(i == std::complex<double>(0.0, 2.0)); |
| 34 |
} |
| 35 |
|
| 36 |
int |
| 37 |
main() |
| 38 |
{ |
| 39 |
test1(); |
| 40 |
} |
| 41 |
|
| 42 |
long double |
| 43 |
operator ""_v(long double x) |
| 44 |
{ return x + 1.0L; } |
| 45 |
|
| 46 |
std::string |
| 47 |
operator ""_w(const char16_t*, size_t) |
| 48 |
{ return std::string("boo"); } |
| 49 |
|
| 50 |
unsigned |
| 51 |
operator ""_w(const char* str) |
| 52 |
{ return strlen(str); } |