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: libcpp-has-no-localization
32 typedef std::ios_base
& (FormatFlagFunction
)(std::ios_base
&);
33 typedef std::basic_ostream
<char>& (OstreamManipFunction
)(std::basic_ostream
<char>&);
34 typedef std::basic_ostream
<wchar_t>& (WOstreamManipFunction
)(std::basic_ostream
<wchar_t>&);
35 typedef std::basic_istream
<char>& (IstreamManipFunction
)(std::basic_istream
<char>&);
36 typedef std::basic_istream
<wchar_t>& (WIstreamManipFunction
)(std::basic_istream
<wchar_t>&);
38 extern FormatFlagFunction
* get_formatflag_tu1(std::string
);
39 extern FormatFlagFunction
* get_formatflag_tu2(std::string
);
41 extern OstreamManipFunction
* get_ostreammanip_tu1(std::string
);
42 extern OstreamManipFunction
* get_ostreammanip_tu2(std::string
);
43 extern WOstreamManipFunction
* get_wostreammanip_tu1(std::string
);
44 extern WOstreamManipFunction
* get_wostreammanip_tu2(std::string
);
46 extern IstreamManipFunction
* get_istreammanip_tu1(std::string
);
47 extern IstreamManipFunction
* get_istreammanip_tu2(std::string
);
48 extern WIstreamManipFunction
* get_wistreammanip_tu1(std::string
);
49 extern WIstreamManipFunction
* get_wistreammanip_tu2(std::string
);
52 FormatFlagFunction
* get_formatflag_tu1(std::string func
)
54 FormatFlagFunction
* get_formatflag_tu2(std::string func
)
57 std::map
<std::string
, FormatFlagFunction
*> all_funcs
;
60 all_funcs
.insert(std::make_pair("boolalpha", &std::boolalpha
));
61 all_funcs
.insert(std::make_pair("noboolalpha", &std::noboolalpha
));
62 all_funcs
.insert(std::make_pair("showbase", &std::showbase
));
63 all_funcs
.insert(std::make_pair("noshowbase", &std::noshowbase
));
64 all_funcs
.insert(std::make_pair("showpoint", &std::showpoint
));
65 all_funcs
.insert(std::make_pair("noshowpoint", &std::noshowpoint
));
66 all_funcs
.insert(std::make_pair("showpos", &std::showpos
));
67 all_funcs
.insert(std::make_pair("noshowpos", &std::noshowpos
));
68 all_funcs
.insert(std::make_pair("skipws", &std::skipws
));
69 all_funcs
.insert(std::make_pair("noskipws", &std::noskipws
));
70 all_funcs
.insert(std::make_pair("uppercase", &std::uppercase
));
71 all_funcs
.insert(std::make_pair("nouppercase", &std::nouppercase
));
72 all_funcs
.insert(std::make_pair("unitbuf", &std::unitbuf
));
73 all_funcs
.insert(std::make_pair("nounitbuf", &std::nounitbuf
));
75 // [adjustfield.manip]
76 all_funcs
.insert(std::make_pair("internal", &std::internal
));
77 all_funcs
.insert(std::make_pair("left", &std::left
));
78 all_funcs
.insert(std::make_pair("right", &std::right
));
81 all_funcs
.insert(std::make_pair("dec", &std::dec
));
82 all_funcs
.insert(std::make_pair("hex", &std::hex
));
83 all_funcs
.insert(std::make_pair("oct", &std::oct
));
86 all_funcs
.insert(std::make_pair("fixed", &std::fixed
));
87 all_funcs
.insert(std::make_pair("scientific", &std::scientific
));
88 all_funcs
.insert(std::make_pair("hexfloat", &std::hexfloat
));
89 all_funcs
.insert(std::make_pair("defaultfloat", &std::defaultfloat
));
91 return all_funcs
.at(func
);
94 // [ostream.manip] (char)
96 OstreamManipFunction
* get_ostreammanip_tu1(std::string func
)
98 OstreamManipFunction
* get_ostreammanip_tu2(std::string func
)
101 std::map
<std::string
, OstreamManipFunction
*> all_funcs
;
102 typedef std::char_traits
<char> Traits
;
103 all_funcs
.insert(std::make_pair("endl", &std::endl
<char, Traits
>));
104 all_funcs
.insert(std::make_pair("ends", &std::ends
<char, Traits
>));
105 all_funcs
.insert(std::make_pair("flush", &std::flush
<char, Traits
>));
106 return all_funcs
.at(func
);
109 // [ostream.manip] (wchar_t)
111 WOstreamManipFunction
* get_wostreammanip_tu1(std::string func
)
113 WOstreamManipFunction
* get_wostreammanip_tu2(std::string func
)
116 std::map
<std::string
, WOstreamManipFunction
*> all_funcs
;
117 typedef std::char_traits
<wchar_t> Traits
;
118 all_funcs
.insert(std::make_pair("endl", &std::endl
<wchar_t, Traits
>));
119 all_funcs
.insert(std::make_pair("ends", &std::ends
<wchar_t, Traits
>));
120 all_funcs
.insert(std::make_pair("flush", &std::flush
<wchar_t, Traits
>));
121 return all_funcs
.at(func
);
124 // [istream.manip] (char)
126 IstreamManipFunction
* get_istreammanip_tu1(std::string func
)
128 IstreamManipFunction
* get_istreammanip_tu2(std::string func
)
131 std::map
<std::string
, IstreamManipFunction
*> all_funcs
;
132 typedef std::char_traits
<char> Traits
;
133 all_funcs
.insert(std::make_pair("ws", &std::ws
<char, Traits
>));
134 return all_funcs
.at(func
);
137 // [istream.manip] (wchar_t)
139 WIstreamManipFunction
* get_wistreammanip_tu1(std::string func
)
141 WIstreamManipFunction
* get_wistreammanip_tu2(std::string func
)
144 std::map
<std::string
, WIstreamManipFunction
*> all_funcs
;
145 typedef std::char_traits
<wchar_t> Traits
;
146 all_funcs
.insert(std::make_pair("ws", &std::ws
<wchar_t, Traits
>));
147 return all_funcs
.at(func
);
152 int main(int, char**) {
153 assert(get_formatflag_tu1("boolalpha") == get_formatflag_tu2("boolalpha"));
154 assert(get_formatflag_tu1("noboolalpha") == get_formatflag_tu2("noboolalpha"));
155 assert(get_formatflag_tu1("showbase") == get_formatflag_tu2("showbase"));
156 assert(get_formatflag_tu1("noshowbase") == get_formatflag_tu2("noshowbase"));
157 assert(get_formatflag_tu1("showpoint") == get_formatflag_tu2("showpoint"));
158 assert(get_formatflag_tu1("noshowpoint") == get_formatflag_tu2("noshowpoint"));
159 assert(get_formatflag_tu1("showpos") == get_formatflag_tu2("showpos"));
160 assert(get_formatflag_tu1("noshowpos") == get_formatflag_tu2("noshowpos"));
161 assert(get_formatflag_tu1("skipws") == get_formatflag_tu2("skipws"));
162 assert(get_formatflag_tu1("noskipws") == get_formatflag_tu2("noskipws"));
163 assert(get_formatflag_tu1("uppercase") == get_formatflag_tu2("uppercase"));
164 assert(get_formatflag_tu1("nouppercase") == get_formatflag_tu2("nouppercase"));
165 assert(get_formatflag_tu1("unitbuf") == get_formatflag_tu2("unitbuf"));
166 assert(get_formatflag_tu1("nounitbuf") == get_formatflag_tu2("nounitbuf"));
167 assert(get_formatflag_tu1("internal") == get_formatflag_tu2("internal"));
168 assert(get_formatflag_tu1("left") == get_formatflag_tu2("left"));
169 assert(get_formatflag_tu1("right") == get_formatflag_tu2("right"));
170 assert(get_formatflag_tu1("dec") == get_formatflag_tu2("dec"));
171 assert(get_formatflag_tu1("hex") == get_formatflag_tu2("hex"));
172 assert(get_formatflag_tu1("oct") == get_formatflag_tu2("oct"));
173 assert(get_formatflag_tu1("fixed") == get_formatflag_tu2("fixed"));
174 assert(get_formatflag_tu1("scientific") == get_formatflag_tu2("scientific"));
175 assert(get_formatflag_tu1("hexfloat") == get_formatflag_tu2("hexfloat"));
176 assert(get_formatflag_tu1("defaultfloat") == get_formatflag_tu2("defaultfloat"));
178 assert(get_ostreammanip_tu1("endl") == get_ostreammanip_tu2("endl"));
179 assert(get_ostreammanip_tu1("ends") == get_ostreammanip_tu2("ends"));
180 assert(get_ostreammanip_tu1("flush") == get_ostreammanip_tu2("flush"));
182 assert(get_wostreammanip_tu1("endl") == get_wostreammanip_tu2("endl"));
183 assert(get_wostreammanip_tu1("ends") == get_wostreammanip_tu2("ends"));
184 assert(get_wostreammanip_tu1("flush") == get_wostreammanip_tu2("flush"));
186 assert(get_istreammanip_tu1("ws") == get_istreammanip_tu2("ws"));
188 assert(get_wistreammanip_tu1("ws") == get_wistreammanip_tu2("ws"));