Add missing dg-require-cstdint directives to tests
[official-gcc.git] / libstdc++-v3 / testsuite / experimental / source_location / 1.cc
blob8bc62ddc6b25b6e68d4a92a82ddcccac106741d2
1 // Copyright (C) 2017-2018 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 "" }
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;
28 void
29 test01()
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__) );
38 struct S {
39 string_view func;
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
46 S(int)
47 : func(__FUNCTION__) // values of loc should be hereabouts
51 void test02()
53 S s0;
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__) );
59 S s1(1);
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()) {
66 return a;
69 source_location g(string_view& func) {
70 source_location a = source_location::current();
71 func = __FUNCTION__;
72 return a;
75 void test03()
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__) );
90 string_view func;
91 loc = g(func);
92 VERIFY( loc.line() == 70 );
93 // static_assert( loc.column() == 23 );
94 VERIFY( loc.file_name() == __FILE__ );
95 VERIFY( loc.function_name() == func );
98 void
99 test04()
101 using std::is_same;
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, "");
112 main()
114 test01();
115 test02();
116 test03();
117 test04();