Fix 22_locale/locale/cons/12658_thread-2.cc on hppa.
[official-gcc.git] / libstdc++-v3 / testsuite / experimental / source_location / 1.cc
blob94988a3ea17267a922c69c21d856ca74cf928e6e
1 // Copyright (C) 2017-2023 Free Software Foundation, Inc.
2 //
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)
7 // any later version.
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;
29 void
30 test01()
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__) );
39 struct S {
40 string_view func;
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
47 S(int)
48 : func(__FUNCTION__) // values of loc should be hereabouts
52 void test02()
54 S s0;
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__) );
60 S s1(1);
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()) {
67 return a;
70 source_location g(string_view& func) {
71 source_location a = source_location::current();
72 func = __FUNCTION__;
73 return a;
76 void test03()
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__) );
91 string_view func;
92 loc = g(func);
93 VERIFY( loc.line() == 71 );
94 // static_assert( loc.column() == 23 );
95 VERIFY( loc.file_name() == __FILE__ );
96 VERIFY( loc.function_name() == func );
99 void
100 test04()
102 using std::is_same;
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, "");
113 main()
115 test01();
116 test02();
117 test03();
118 test04();