| 1 |
// { dg-do run { target c++20 } } |
| 2 |
|
| 3 |
namespace std { |
| 4 |
struct source_location { |
| 5 |
struct __impl { |
| 6 |
const char *_M_file_name; |
| 7 |
const char *_M_function_name; |
| 8 |
unsigned int _M_line, _M_column; |
| 9 |
}; |
| 10 |
const __impl *__ptr; |
| 11 |
constexpr source_location () : __ptr (nullptr) {} |
| 12 |
static consteval source_location |
| 13 |
current (const void *__p = __builtin_source_location ()) { |
| 14 |
source_location __ret; |
| 15 |
__ret.__ptr = static_cast <const __impl *> (__p); |
| 16 |
return __ret; |
| 17 |
} |
| 18 |
constexpr const char *file_name () const { |
| 19 |
return __ptr ? __ptr->_M_file_name : ""; |
| 20 |
} |
| 21 |
constexpr const char *function_name () const { |
| 22 |
return __ptr ? __ptr->_M_function_name : ""; |
| 23 |
} |
| 24 |
constexpr unsigned line () const { |
| 25 |
return __ptr ? __ptr->_M_line : 0; |
| 26 |
} |
| 27 |
constexpr unsigned column () const { |
| 28 |
return __ptr ? __ptr->_M_column : 0; |
| 29 |
} |
| 30 |
}; |
| 31 |
} |
| 32 |
|
| 33 |
using namespace std; |
| 34 |
|
| 35 |
template <int N> |
| 36 |
struct S |
| 37 |
{ |
| 38 |
source_location a = source_location::current (); |
| 39 |
source_location b = source_location::current (); |
| 40 |
source_location c = source_location (); |
| 41 |
constexpr S () { c = source_location::current (); } |
| 42 |
}; |
| 43 |
|
| 44 |
template <int N> |
| 45 |
struct T |
| 46 |
{ |
| 47 |
int t; |
| 48 |
source_location u = source_location::current (); |
| 49 |
int v = __builtin_LINE (); |
| 50 |
}; |
| 51 |
|
| 52 |
constexpr S<0> s; |
| 53 |
constexpr T<0> t = { 1 }; |
| 54 |
|
| 55 |
constexpr bool |
| 56 |
cmp (const char *p, const char *q) |
| 57 |
{ |
| 58 |
for (; *p && *q; p++, q++) |
| 59 |
if (*p != *q) |
| 60 |
return true; |
| 61 |
return *p || *q; |
| 62 |
} |
| 63 |
|
| 64 |
template <int N> |
| 65 |
constexpr bool |
| 66 |
foo () |
| 67 |
{ |
| 68 |
T<N> u = { 2 }; |
| 69 |
source_location v = source_location::current (); |
| 70 |
if (cmp (s.a.file_name (), s.c.file_name ()) |
| 71 |
|| cmp (s.b.file_name (), s.c.file_name ()) |
| 72 |
|| cmp (t.u.file_name (), s.c.file_name ()) |
| 73 |
|| cmp (u.u.file_name (), s.c.file_name ()) |
| 74 |
|| cmp (v.file_name (), s.c.file_name ()) |
| 75 |
|| cmp (s.a.function_name (), s.c.function_name ()) |
| 76 |
|| cmp (s.b.function_name (), s.c.function_name ()) |
| 77 |
|| cmp (t.u.function_name (), "") |
| 78 |
|| cmp (u.u.function_name (), v.function_name ()) |
| 79 |
|| s.a.line () != s.c.line () |
| 80 |
|| s.b.line () != s.c.line () |
| 81 |
|| t.u.line () != t.v |
| 82 |
|| u.u.line () + 1 != v.line () |
| 83 |
|| s.a.column () != 18 |
| 84 |
|| s.b.column () != 18 |
| 85 |
|| s.c.column () != 49 |
| 86 |
|| t.u.column () != 24 |
| 87 |
|| u.u.column () != 8 |
| 88 |
|| v.column () != 48) |
| 89 |
return false; |
| 90 |
return true; |
| 91 |
} |
| 92 |
|
| 93 |
static_assert (foo<1> ()); |
| 94 |
|
| 95 |
int |
| 96 |
main () |
| 97 |
{ |
| 98 |
if (!foo<1> ()) |
| 99 |
__builtin_abort (); |
| 100 |
} |