145
|
1 // { dg-do compile { target c++2a } }
|
|
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 consteval source_location
|
|
36 bar (const source_location x = source_location::current ())
|
|
37 {
|
|
38 return x;
|
|
39 }
|
|
40
|
|
41 void
|
|
42 foo (const char **p, unsigned *q)
|
|
43 {
|
|
44 constexpr source_location s = source_location::current ();
|
|
45 constexpr source_location t = bar ();
|
|
46 p[0] = s.file_name ();
|
|
47 p[1] = s.function_name ();
|
|
48 q[0] = s.line ();
|
|
49 q[1] = s.column ();
|
|
50 p[2] = t.file_name ();
|
|
51 p[3] = t.function_name ();
|
|
52 q[2] = t.line ();
|
|
53 q[3] = t.column ();
|
|
54 constexpr const char *r = s.file_name ();
|
|
55 }
|
|
56
|
|
57 source_location s3 = source_location::current ();
|
|
58
|
|
59 template <int N>
|
|
60 constexpr source_location
|
|
61 baz ()
|
|
62 {
|
|
63 return source_location::current ();
|
|
64 }
|
|
65
|
|
66 #define A \
|
|
67 source_location s[3] = { source_location::current (), \
|
|
68 source_location::current (), \
|
|
69 source_location::current () }
|
|
70
|
|
71 source_location *
|
|
72 boo ()
|
|
73 {
|
|
74 static A;
|
|
75 return &s[0];
|
|
76 }
|
|
77
|
|
78 constexpr source_location s1 = baz <0> ();
|
|
79 constexpr source_location s2 = baz <1> ();
|
|
80 const source_location *p1 = &s1;
|
|
81 const source_location *p2 = &s2;
|
|
82 static_assert (source_location::current ().line () == __LINE__);
|
|
83 static_assert (source_location::current ().column () == 42);
|
|
84
|
|
85 constexpr bool
|
|
86 quux ()
|
|
87 {
|
|
88 const char *file1 = source_location::current ().file_name ();
|
|
89 const char *file2 = __FILE__;
|
|
90 const char *function1 = source_location::current ().function_name ();
|
|
91 const char *function2 = __FUNCTION__;
|
|
92 int line1 = source_location::current ().line ();
|
|
93 int line2 = __LINE__ - 1;
|
|
94 int column
|
|
95 = source_location::current ().column ();
|
|
96 int i = 0;
|
|
97 for (; file1[i]; i++)
|
|
98 if (file1[i] != file2[i])
|
|
99 return false;
|
|
100 if (file2[i])
|
|
101 return false;
|
|
102 for (i = 0; function1[i]; i++)
|
|
103 if (function1[i] != function2[i])
|
|
104 return false;
|
|
105 if (function2[i])
|
|
106 return false;
|
|
107 if (line1 != line2)
|
|
108 return false;
|
|
109 if (column != 33)
|
|
110 return false;
|
|
111 return true;
|
|
112 }
|
|
113
|
|
114 static_assert (quux ());
|