1 // { dg-do compile { 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 auto a = source_location::current; // { dg-error "taking address of an immediate function" }
36 constexpr auto b = &source_location::current; // { dg-error "constant evaluation returns address of immediate function" }
41 auto c = &source_location::current; // { dg-error "taking address of an immediate function" }
42 constexpr auto d = source_location::current; // { dg-error "constant evaluation returns address of immediate function" }
43 static auto e = source_location::current; // { dg-error "taking address of an immediate function" }