aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.dg/cpp2a/srcloc20.C
blob: e99f1dcf7c45ea2f09aee5e34f34fdc630949d5b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// { dg-do compile { target c++20 } }

namespace std {
  struct source_location {
    struct __impl {
      const char *_M_file_name;
      const char *_M_function_name;
      unsigned int _M_line, _M_column;
    };
    const __impl *__ptr;
    constexpr source_location () : __ptr (nullptr) {}
    static consteval source_location
    current (const void *__p = __builtin_source_location ()) {
      source_location __ret;
      __ret.__ptr = static_cast <const __impl *> (__p);
      return __ret;
    }
    constexpr const char *file_name () const {
      return __ptr ? __ptr->_M_file_name : "";
    }
    constexpr const char *function_name () const {
      return __ptr ? __ptr->_M_function_name : "";
    }
    constexpr unsigned line () const {
      return __ptr ? __ptr->_M_line : 0;
    }
    constexpr unsigned column () const {
      return __ptr ? __ptr->_M_column : 0;
    }
  };
}

using namespace std;

auto a = source_location::current;		// { dg-error "taking address of an immediate function" }
constexpr auto b = &source_location::current;	// { dg-error "constant evaluation returns address of immediate function" }

void
foo ()
{
  auto c = &source_location::current;		// { dg-error "taking address of an immediate function" }
  constexpr auto d = source_location::current;	// { dg-error "constant evaluation returns address of immediate function" }
  static auto e = source_location::current;	// { dg-error "taking address of an immediate function" }
}