| 1 |
// { dg-do compile { target c++20 } } |
| 2 |
|
| 3 |
namespace std { |
| 4 |
inline namespace _8 { } |
| 5 |
namespace _8 { |
| 6 |
struct source_location { |
| 7 |
struct __impl { |
| 8 |
const char *_M_file_name; |
| 9 |
const char *_M_function_name; |
| 10 |
unsigned int _M_line, _M_column; |
| 11 |
}; |
| 12 |
const __impl *__ptr; |
| 13 |
constexpr source_location () : __ptr (nullptr) {} |
| 14 |
static consteval source_location |
| 15 |
current (const void *__p = __builtin_source_location ()) { |
| 16 |
source_location __ret; |
| 17 |
__ret.__ptr = static_cast <const __impl *> (__p); |
| 18 |
return __ret; |
| 19 |
} |
| 20 |
constexpr const char *file_name () const { |
| 21 |
return __ptr ? __ptr->_M_file_name : ""; |
| 22 |
} |
| 23 |
constexpr const char *function_name () const { |
| 24 |
return __ptr ? __ptr->_M_function_name : ""; |
| 25 |
} |
| 26 |
constexpr unsigned line () const { |
| 27 |
return __ptr ? __ptr->_M_line : 0; |
| 28 |
} |
| 29 |
constexpr unsigned column () const { |
| 30 |
return __ptr ? __ptr->_M_column : 0; |
| 31 |
} |
| 32 |
}; |
| 33 |
} |
| 34 |
} |
| 35 |
|
| 36 |
using namespace std; |
| 37 |
|
| 38 |
consteval source_location |
| 39 |
bar (const source_location x = source_location::current ()) |
| 40 |
{ |
| 41 |
return x; |
| 42 |
} |
| 43 |
|
| 44 |
void |
| 45 |
foo (const char **p, unsigned *q) |
| 46 |
{ |
| 47 |
constexpr source_location s = source_location::current (); |
| 48 |
constexpr source_location t = bar (); |
| 49 |
p[0] = s.file_name (); |
| 50 |
p[1] = s.function_name (); |
| 51 |
q[0] = s.line (); |
| 52 |
q[1] = s.column (); |
| 53 |
p[2] = t.file_name (); |
| 54 |
p[3] = t.function_name (); |
| 55 |
q[2] = t.line (); |
| 56 |
q[3] = t.column (); |
| 57 |
constexpr const char *r = s.file_name (); |
| 58 |
} |
| 59 |
|
| 60 |
source_location s3 = source_location::current (); |
| 61 |
|
| 62 |
template <int N> |
| 63 |
constexpr source_location |
| 64 |
baz () |
| 65 |
{ |
| 66 |
return source_location::current (); |
| 67 |
} |
| 68 |
|
| 69 |
#define A \ |
| 70 |
source_location s[3] = { source_location::current (), \ |
| 71 |
source_location::current (), \ |
| 72 |
source_location::current () } |
| 73 |
|
| 74 |
source_location * |
| 75 |
boo () |
| 76 |
{ |
| 77 |
static A; |
| 78 |
return &s[0]; |
| 79 |
} |
| 80 |
|
| 81 |
constexpr source_location s1 = baz <0> (); |
| 82 |
constexpr source_location s2 = baz <1> (); |
| 83 |
const source_location *p1 = &s1; |
| 84 |
const source_location *p2 = &s2; |
| 85 |
|
| 86 |
static_assert (source_location::current ().line () == __LINE__); |
| 87 |
static_assert (source_location::current ().column () == 41); |
| 88 |
|
| 89 |
constexpr bool |
| 90 |
quux () |
| 91 |
{ |
| 92 |
const char *file1 = source_location::current ().file_name (); |
| 93 |
const char *file2 = __FILE__; |
| 94 |
const char *function1 = source_location::current ().function_name (); |
| 95 |
const char *function2 = __PRETTY_FUNCTION__; |
| 96 |
int line1 = source_location::current ().line (); |
| 97 |
int line2 = __LINE__ - 1; |
| 98 |
int column |
| 99 |
= source_location::current ().column (); |
| 100 |
int i = 0; |
| 101 |
for (; file1[i]; i++) |
| 102 |
if (file1[i] != file2[i]) |
| 103 |
return false; |
| 104 |
if (file2[i]) |
| 105 |
return false; |
| 106 |
for (i = 0; function1[i]; i++) |
| 107 |
if (function1[i] != function2[i]) |
| 108 |
return false; |
| 109 |
if (function2[i]) |
| 110 |
return false; |
| 111 |
if (line1 != line2) |
| 112 |
return false; |
| 113 |
if (column != 32) |
| 114 |
return false; |
| 115 |
return true; |
| 116 |
} |
| 117 |
|
| 118 |
static_assert (quux ()); |