1 // Copyright (C) 2017-2018 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 "" }
21 #include <experimental/source_location>
22 #include <experimental/string_view>
23 #include <testsuite_hooks.h>
25 using std::experimental::source_location
;
26 using std::experimental::string_view
;
31 constexpr source_location loc
= source_location::current();
32 static_assert( loc
.line() == 31 );
33 // static_assert( loc.column() == 35 );
34 VERIFY( loc
.file_name() == __FILE__
);
35 VERIFY( loc
.function_name() == string_view(__FUNCTION__
) );
40 source_location loc
= source_location::current();
42 S(source_location loc
= source_location::current())
43 : func(__FUNCTION__
), loc(loc
) // values of loc will be from call-site
47 : func(__FUNCTION__
) // values of loc should be hereabouts
54 VERIFY( s0
.loc
.line() == 53 );
55 // static_assert( s0.loc.column() == 7 );
56 VERIFY( s0
.loc
.file_name() == __FILE__
);
57 VERIFY( s0
.loc
.function_name() == string_view(__FUNCTION__
) );
60 VERIFY( s1
.loc
.line() == 47 );
61 VERIFY( s1
.loc
.file_name() == __FILE__
);
62 VERIFY( s1
.loc
.function_name() == s1
.func
);
65 source_location
f(source_location a
= source_location::current()) {
69 source_location
g(string_view
& func
) {
70 source_location a
= source_location::current();
77 auto loc
= f(); // f's first argument corresponds to this line of code
78 VERIFY( loc
.line() == 77 );
79 // static_assert( loc.column() == 16 );
80 VERIFY( loc
.file_name() == __FILE__
);
81 VERIFY( loc
.function_name() == string_view(__FUNCTION__
) );
83 source_location c
= source_location::current();
84 loc
= f(c
); // f's first argument gets the same values as c, above
85 VERIFY( loc
.line() == 83 );
86 // static_assert( loc.column() == 23 );
87 VERIFY( loc
.file_name() == __FILE__
);
88 VERIFY( loc
.function_name() == string_view(__FUNCTION__
) );
92 VERIFY( loc
.line() == 70 );
93 // static_assert( loc.column() == 23 );
94 VERIFY( loc
.file_name() == __FILE__
);
95 VERIFY( loc
.function_name() == func
);
102 using std::uint_least32_t;
103 auto loc
= source_location::current();
104 static_assert(is_same
<decltype(loc
), source_location
>::value
, "");
105 static_assert(is_same
<decltype(loc
.line()), uint_least32_t>::value
, "");
106 static_assert(is_same
<decltype(loc
.column()), uint_least32_t>::value
, "");
107 static_assert(is_same
<decltype(loc
.file_name()), const char*>::value
, "");
108 static_assert(is_same
<decltype(loc
.function_name()), const char*>::value
, "");