1 // { dg-do run { target c++20 } }
4 struct source_location {
6 const char *_M_file_name;
7 const char *_M_function_name;
8 unsigned int _M_line, _M_column;
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);
18 constexpr const char *file_name () const {
19 return __ptr ? __ptr->_M_file_name : "";
21 constexpr const char *function_name () const {
22 return __ptr ? __ptr->_M_function_name : "";
24 constexpr unsigned line () const {
25 return __ptr ? __ptr->_M_line : 0;
27 constexpr unsigned column () const {
28 return __ptr ? __ptr->_M_column : 0;
35 constexpr source_location
36 foo (const source_location x = source_location::current ())
44 source_location loc = source_location::current ();
46 constexpr S (int l, source_location loc = source_location::current ())
47 : func(__FUNCTION__), line(l), loc(loc)
51 : func(__FUNCTION__), line(__LINE__)
57 cmp (const char *p, const char *q)
59 for (; *p && *q; p++, q++)
69 source_location a = foo ();
70 source_location b = source_location::current ();
71 source_location c = foo ();
74 const source_location *d[3] = { &a, &b, &c };
75 const char *file1 = __FILE__;
76 const char *function1 = __FUNCTION__;
77 for (int j = 0; j < 3; j++)
80 if (cmp (d[j]->file_name (), file1))
82 if (cmp (d[j]->function_name (), function1))
84 if (d[j]->line () != line + j + 1)
86 if (d[j]->column () != (j == 1 ? 49 : 28))
93 if (cmp (e.loc.file_name (), file1))
95 if (cmp (f.loc.file_name (), file1))
97 if (cmp (e.loc.function_name (), function1))
99 if (cmp (f.loc.function_name (), f.func))
101 if (e.loc.line () != e.line)
103 if (f.loc.line () != f.line)
105 if (e.loc.column () != 9)
107 if (f.loc.column () != 38)
112 static_assert (bar ());