1 // Copyright (C) 2017-2024 Free Software Foundation, Inc.
3 // This file is part of the GNU ISO C++ Library. This library is free
4 // software; you can redistribute it and/or modify it under the
5 // terms of the GNU General Public License as published by the
6 // Free Software Foundation; either version 3, or (at your option)
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License along
15 // with this library; see the file COPYING3. If not see
16 // <http://www.gnu.org/licenses/>.
18 // { dg-do run { target c++14 } }
19 // { dg-require-cstdint "" }
20 // { dg-options "-Wno-address" }
22 #include <experimental/source_location>
23 #include <experimental/string_view>
24 #include <testsuite_hooks.h>
26 using std::experimental::source_location
;
27 using std::experimental::string_view
;
32 constexpr source_location loc
= source_location::current();
33 static_assert( loc
.line() == 32 );
34 // static_assert( loc.column() == 35 );
35 VERIFY( loc
.file_name() == __FILE__
);
36 VERIFY( loc
.function_name() == string_view(__FUNCTION__
) );
41 source_location loc
= source_location::current();
43 S(source_location loc
= source_location::current())
44 : func(__FUNCTION__
), loc(loc
) // values of loc will be from call-site
48 : func(__FUNCTION__
) // values of loc should be hereabouts
55 VERIFY( s0
.loc
.line() == 54 );
56 // static_assert( s0.loc.column() == 7 );
57 VERIFY( s0
.loc
.file_name() == __FILE__
);
58 VERIFY( s0
.loc
.function_name() == string_view(__FUNCTION__
) );
61 VERIFY( s1
.loc
.line() == 48 );
62 VERIFY( s1
.loc
.file_name() == __FILE__
);
63 VERIFY( s1
.loc
.function_name() == s1
.func
);
66 source_location
f(source_location a
= source_location::current()) {
70 source_location
g(string_view
& func
) {
71 source_location a
= source_location::current();
78 auto loc
= f(); // f's first argument corresponds to this line of code
79 VERIFY( loc
.line() == 78 );
80 // static_assert( loc.column() == 16 );
81 VERIFY( loc
.file_name() == __FILE__
);
82 VERIFY( loc
.function_name() == string_view(__FUNCTION__
) );
84 source_location c
= source_location::current();
85 loc
= f(c
); // f's first argument gets the same values as c, above
86 VERIFY( loc
.line() == 84 );
87 // static_assert( loc.column() == 23 );
88 VERIFY( loc
.file_name() == __FILE__
);
89 VERIFY( loc
.function_name() == string_view(__FUNCTION__
) );
93 VERIFY( loc
.line() == 71 );
94 // static_assert( loc.column() == 23 );
95 VERIFY( loc
.file_name() == __FILE__
);
96 VERIFY( loc
.function_name() == func
);
103 using std::uint_least32_t;
104 auto loc
= source_location::current();
105 static_assert(is_same
<decltype(loc
), source_location
>::value
, "");
106 static_assert(is_same
<decltype(loc
.line()), uint_least32_t>::value
, "");
107 static_assert(is_same
<decltype(loc
.column()), uint_least32_t>::value
, "");
108 static_assert(is_same
<decltype(loc
.file_name()), const char*>::value
, "");
109 static_assert(is_same
<decltype(loc
.function_name()), const char*>::value
, "");