1 //===----------------------------------------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // Make sure functions specified as being 'addressable' (their address can be
10 // taken in a well-defined manner) are indeed addressable. This notion was
11 // added by http://wg21.link/p0551. While it was technically only introduced
12 // in C++20, we test it in all standard modes because it's basic QOI to provide
13 // a consistent behavior for that across standard modes.
15 // RUN: %{cxx} %{flags} %{compile_flags} -c %s -o %t.tu1.o -DTU1
16 // RUN: %{cxx} %{flags} %{compile_flags} -c %s -o %t.tu2.o -DTU2
17 // RUN: %{cxx} %t.tu1.o %t.tu2.o %{flags} %{link_flags} -o %t.exe
18 // RUN: %{exec} %t.exe
20 // The functions checked below come from <iostream> & friends
21 // UNSUPPORTED: no-localization
31 #include "test_macros.h"
33 typedef std::ios_base
& (FormatFlagFunction
)(std::ios_base
&);
34 typedef std::basic_ostream
<char>& (OstreamManipFunction
)(std::basic_ostream
<char>&);
35 typedef std::basic_istream
<char>& (IstreamManipFunction
)(std::basic_istream
<char>&);
36 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
37 typedef std::basic_ostream
<wchar_t>& (WOstreamManipFunction
)(std::basic_ostream
<wchar_t>&);
38 typedef std::basic_istream
<wchar_t>& (WIstreamManipFunction
)(std::basic_istream
<wchar_t>&);
41 extern FormatFlagFunction
* get_formatflag_tu1(std::string
);
42 extern FormatFlagFunction
* get_formatflag_tu2(std::string
);
44 extern OstreamManipFunction
* get_ostreammanip_tu1(std::string
);
45 extern OstreamManipFunction
* get_ostreammanip_tu2(std::string
);
46 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
47 extern WOstreamManipFunction
* get_wostreammanip_tu1(std::string
);
48 extern WOstreamManipFunction
* get_wostreammanip_tu2(std::string
);
51 extern IstreamManipFunction
* get_istreammanip_tu1(std::string
);
52 extern IstreamManipFunction
* get_istreammanip_tu2(std::string
);
53 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
54 extern WIstreamManipFunction
* get_wistreammanip_tu1(std::string
);
55 extern WIstreamManipFunction
* get_wistreammanip_tu2(std::string
);
59 FormatFlagFunction
* get_formatflag_tu1(std::string func
)
61 FormatFlagFunction
* get_formatflag_tu2(std::string func
)
64 std::map
<std::string
, FormatFlagFunction
*> all_funcs
;
67 all_funcs
.insert(std::make_pair("boolalpha", &std::boolalpha
));
68 all_funcs
.insert(std::make_pair("noboolalpha", &std::noboolalpha
));
69 all_funcs
.insert(std::make_pair("showbase", &std::showbase
));
70 all_funcs
.insert(std::make_pair("noshowbase", &std::noshowbase
));
71 all_funcs
.insert(std::make_pair("showpoint", &std::showpoint
));
72 all_funcs
.insert(std::make_pair("noshowpoint", &std::noshowpoint
));
73 all_funcs
.insert(std::make_pair("showpos", &std::showpos
));
74 all_funcs
.insert(std::make_pair("noshowpos", &std::noshowpos
));
75 all_funcs
.insert(std::make_pair("skipws", &std::skipws
));
76 all_funcs
.insert(std::make_pair("noskipws", &std::noskipws
));
77 all_funcs
.insert(std::make_pair("uppercase", &std::uppercase
));
78 all_funcs
.insert(std::make_pair("nouppercase", &std::nouppercase
));
79 all_funcs
.insert(std::make_pair("unitbuf", &std::unitbuf
));
80 all_funcs
.insert(std::make_pair("nounitbuf", &std::nounitbuf
));
82 // [adjustfield.manip]
83 all_funcs
.insert(std::make_pair("internal", &std::internal
));
84 all_funcs
.insert(std::make_pair("left", &std::left
));
85 all_funcs
.insert(std::make_pair("right", &std::right
));
88 all_funcs
.insert(std::make_pair("dec", &std::dec
));
89 all_funcs
.insert(std::make_pair("hex", &std::hex
));
90 all_funcs
.insert(std::make_pair("oct", &std::oct
));
93 all_funcs
.insert(std::make_pair("fixed", &std::fixed
));
94 all_funcs
.insert(std::make_pair("scientific", &std::scientific
));
95 all_funcs
.insert(std::make_pair("hexfloat", &std::hexfloat
));
96 all_funcs
.insert(std::make_pair("defaultfloat", &std::defaultfloat
));
98 return all_funcs
.at(func
);
101 // [ostream.manip] (char)
103 OstreamManipFunction
* get_ostreammanip_tu1(std::string func
)
105 OstreamManipFunction
* get_ostreammanip_tu2(std::string func
)
108 std::map
<std::string
, OstreamManipFunction
*> all_funcs
;
109 typedef std::char_traits
<char> Traits
;
110 all_funcs
.insert(std::make_pair("endl", &std::endl
<char, Traits
>));
111 all_funcs
.insert(std::make_pair("ends", &std::ends
<char, Traits
>));
112 all_funcs
.insert(std::make_pair("flush", &std::flush
<char, Traits
>));
113 return all_funcs
.at(func
);
116 // [ostream.manip] (wchar_t)
117 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
119 WOstreamManipFunction
* get_wostreammanip_tu1(std::string func
)
121 WOstreamManipFunction
* get_wostreammanip_tu2(std::string func
)
124 std::map
<std::string
, WOstreamManipFunction
*> all_funcs
;
125 typedef std::char_traits
<wchar_t> Traits
;
126 all_funcs
.insert(std::make_pair("endl", &std::endl
<wchar_t, Traits
>));
127 all_funcs
.insert(std::make_pair("ends", &std::ends
<wchar_t, Traits
>));
128 all_funcs
.insert(std::make_pair("flush", &std::flush
<wchar_t, Traits
>));
129 return all_funcs
.at(func
);
131 #endif // TEST_HAS_NO_WIDE_CHARACTERS
133 // [istream.manip] (char)
135 IstreamManipFunction
* get_istreammanip_tu1(std::string func
)
137 IstreamManipFunction
* get_istreammanip_tu2(std::string func
)
140 std::map
<std::string
, IstreamManipFunction
*> all_funcs
;
141 typedef std::char_traits
<char> Traits
;
142 all_funcs
.insert(std::make_pair("ws", &std::ws
<char, Traits
>));
143 return all_funcs
.at(func
);
146 // [istream.manip] (wchar_t)
147 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
149 WIstreamManipFunction
* get_wistreammanip_tu1(std::string func
)
151 WIstreamManipFunction
* get_wistreammanip_tu2(std::string func
)
154 std::map
<std::string
, WIstreamManipFunction
*> all_funcs
;
155 typedef std::char_traits
<wchar_t> Traits
;
156 all_funcs
.insert(std::make_pair("ws", &std::ws
<wchar_t, Traits
>));
157 return all_funcs
.at(func
);
159 #endif // TEST_HAS_NO_WIDE_CHARACTERS
162 int main(int, char**) {
163 assert(get_formatflag_tu1("boolalpha") == get_formatflag_tu2("boolalpha"));
164 assert(get_formatflag_tu1("noboolalpha") == get_formatflag_tu2("noboolalpha"));
165 assert(get_formatflag_tu1("showbase") == get_formatflag_tu2("showbase"));
166 assert(get_formatflag_tu1("noshowbase") == get_formatflag_tu2("noshowbase"));
167 assert(get_formatflag_tu1("showpoint") == get_formatflag_tu2("showpoint"));
168 assert(get_formatflag_tu1("noshowpoint") == get_formatflag_tu2("noshowpoint"));
169 assert(get_formatflag_tu1("showpos") == get_formatflag_tu2("showpos"));
170 assert(get_formatflag_tu1("noshowpos") == get_formatflag_tu2("noshowpos"));
171 assert(get_formatflag_tu1("skipws") == get_formatflag_tu2("skipws"));
172 assert(get_formatflag_tu1("noskipws") == get_formatflag_tu2("noskipws"));
173 assert(get_formatflag_tu1("uppercase") == get_formatflag_tu2("uppercase"));
174 assert(get_formatflag_tu1("nouppercase") == get_formatflag_tu2("nouppercase"));
175 assert(get_formatflag_tu1("unitbuf") == get_formatflag_tu2("unitbuf"));
176 assert(get_formatflag_tu1("nounitbuf") == get_formatflag_tu2("nounitbuf"));
177 assert(get_formatflag_tu1("internal") == get_formatflag_tu2("internal"));
178 assert(get_formatflag_tu1("left") == get_formatflag_tu2("left"));
179 assert(get_formatflag_tu1("right") == get_formatflag_tu2("right"));
180 assert(get_formatflag_tu1("dec") == get_formatflag_tu2("dec"));
181 assert(get_formatflag_tu1("hex") == get_formatflag_tu2("hex"));
182 assert(get_formatflag_tu1("oct") == get_formatflag_tu2("oct"));
183 assert(get_formatflag_tu1("fixed") == get_formatflag_tu2("fixed"));
184 assert(get_formatflag_tu1("scientific") == get_formatflag_tu2("scientific"));
185 assert(get_formatflag_tu1("hexfloat") == get_formatflag_tu2("hexfloat"));
186 assert(get_formatflag_tu1("defaultfloat") == get_formatflag_tu2("defaultfloat"));
188 assert(get_ostreammanip_tu1("endl") == get_ostreammanip_tu2("endl"));
189 assert(get_ostreammanip_tu1("ends") == get_ostreammanip_tu2("ends"));
190 assert(get_ostreammanip_tu1("flush") == get_ostreammanip_tu2("flush"));
192 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
193 assert(get_wostreammanip_tu1("endl") == get_wostreammanip_tu2("endl"));
194 assert(get_wostreammanip_tu1("ends") == get_wostreammanip_tu2("ends"));
195 assert(get_wostreammanip_tu1("flush") == get_wostreammanip_tu2("flush"));
198 assert(get_istreammanip_tu1("ws") == get_istreammanip_tu2("ws"));
200 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
201 assert(get_wistreammanip_tu1("ws") == get_wistreammanip_tu2("ws"));