Louis Dionne | 2d3b8cc | 2020-07-13 11:53:48 -0400 | [diff] [blame] | 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
| 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 |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 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. |
| 14 | |
| 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 |
Louis Dionne | 3e5f9da | 2020-09-29 10:49:52 -0400 | [diff] [blame] | 17 | // RUN: %{cxx} %t.tu1.o %t.tu2.o %{flags} %{link_flags} -o %t.exe |
Louis Dionne | 2d3b8cc | 2020-07-13 11:53:48 -0400 | [diff] [blame] | 18 | // RUN: %{exec} %t.exe |
| 19 | |
Louis Dionne | 88ffc72 | 2020-10-09 15:31:05 -0400 | [diff] [blame] | 20 | // The functions checked below come from <iostream> & friends |
| 21 | // UNSUPPORTED: libcpp-has-no-localization |
| 22 | |
Louis Dionne | 2d3b8cc | 2020-07-13 11:53:48 -0400 | [diff] [blame] | 23 | #include <cassert> |
Louis Dionne | cc69d21 | 2020-10-13 15:47:31 -0400 | [diff] [blame] | 24 | #include <ios> |
| 25 | #include <istream> |
Louis Dionne | 2d3b8cc | 2020-07-13 11:53:48 -0400 | [diff] [blame] | 26 | #include <map> |
Louis Dionne | cc69d21 | 2020-10-13 15:47:31 -0400 | [diff] [blame] | 27 | #include <ostream> |
Louis Dionne | 2d3b8cc | 2020-07-13 11:53:48 -0400 | [diff] [blame] | 28 | #include <string> |
| 29 | #include <utility> |
| 30 | |
Louis Dionne | f4c1258 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 31 | #include "test_macros.h" |
Louis Dionne | 2d3b8cc | 2020-07-13 11:53:48 -0400 | [diff] [blame] | 32 | |
| 33 | typedef std::ios_base& (FormatFlagFunction)(std::ios_base&); |
| 34 | typedef std::basic_ostream<char>& (OstreamManipFunction)(std::basic_ostream<char>&); |
Louis Dionne | 2d3b8cc | 2020-07-13 11:53:48 -0400 | [diff] [blame] | 35 | typedef std::basic_istream<char>& (IstreamManipFunction)(std::basic_istream<char>&); |
Louis Dionne | f4c1258 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 36 | #ifndef TEST_HAS_NO_WIDE_CHARACTERS |
| 37 | typedef std::basic_ostream<wchar_t>& (WOstreamManipFunction)(std::basic_ostream<wchar_t>&); |
Louis Dionne | 2d3b8cc | 2020-07-13 11:53:48 -0400 | [diff] [blame] | 38 | typedef std::basic_istream<wchar_t>& (WIstreamManipFunction)(std::basic_istream<wchar_t>&); |
Louis Dionne | f4c1258 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 39 | #endif |
Louis Dionne | 2d3b8cc | 2020-07-13 11:53:48 -0400 | [diff] [blame] | 40 | |
| 41 | extern FormatFlagFunction* get_formatflag_tu1(std::string); |
| 42 | extern FormatFlagFunction* get_formatflag_tu2(std::string); |
| 43 | |
| 44 | extern OstreamManipFunction* get_ostreammanip_tu1(std::string); |
| 45 | extern OstreamManipFunction* get_ostreammanip_tu2(std::string); |
Louis Dionne | f4c1258 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 46 | #ifndef TEST_HAS_NO_WIDE_CHARACTERS |
Louis Dionne | 2d3b8cc | 2020-07-13 11:53:48 -0400 | [diff] [blame] | 47 | extern WOstreamManipFunction* get_wostreammanip_tu1(std::string); |
| 48 | extern WOstreamManipFunction* get_wostreammanip_tu2(std::string); |
Louis Dionne | f4c1258 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 49 | #endif |
Louis Dionne | 2d3b8cc | 2020-07-13 11:53:48 -0400 | [diff] [blame] | 50 | |
| 51 | extern IstreamManipFunction* get_istreammanip_tu1(std::string); |
| 52 | extern IstreamManipFunction* get_istreammanip_tu2(std::string); |
Louis Dionne | f4c1258 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 53 | #ifndef TEST_HAS_NO_WIDE_CHARACTERS |
Louis Dionne | 2d3b8cc | 2020-07-13 11:53:48 -0400 | [diff] [blame] | 54 | extern WIstreamManipFunction* get_wistreammanip_tu1(std::string); |
| 55 | extern WIstreamManipFunction* get_wistreammanip_tu2(std::string); |
Louis Dionne | f4c1258 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 56 | #endif |
Louis Dionne | 2d3b8cc | 2020-07-13 11:53:48 -0400 | [diff] [blame] | 57 | |
| 58 | #ifdef TU1 |
| 59 | FormatFlagFunction* get_formatflag_tu1(std::string func) |
| 60 | #else |
| 61 | FormatFlagFunction* get_formatflag_tu2(std::string func) |
| 62 | #endif |
| 63 | { |
| 64 | std::map<std::string, FormatFlagFunction*> all_funcs; |
| 65 | |
| 66 | // [fmtflags.manip] |
| 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)); |
| 81 | |
| 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)); |
| 86 | |
| 87 | // [basefield.manip] |
| 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)); |
| 91 | |
| 92 | // [floatfield.manip] |
| 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)); |
| 97 | |
| 98 | return all_funcs.at(func); |
| 99 | } |
| 100 | |
| 101 | // [ostream.manip] (char) |
| 102 | #ifdef TU1 |
| 103 | OstreamManipFunction* get_ostreammanip_tu1(std::string func) |
| 104 | #else |
| 105 | OstreamManipFunction* get_ostreammanip_tu2(std::string func) |
| 106 | #endif |
| 107 | { |
| 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); |
| 114 | } |
| 115 | |
| 116 | // [ostream.manip] (wchar_t) |
Louis Dionne | f4c1258 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 117 | #ifndef TEST_HAS_NO_WIDE_CHARACTERS |
| 118 | # ifdef TU1 |
Louis Dionne | 2d3b8cc | 2020-07-13 11:53:48 -0400 | [diff] [blame] | 119 | WOstreamManipFunction* get_wostreammanip_tu1(std::string func) |
Louis Dionne | f4c1258 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 120 | # else |
Louis Dionne | 2d3b8cc | 2020-07-13 11:53:48 -0400 | [diff] [blame] | 121 | WOstreamManipFunction* get_wostreammanip_tu2(std::string func) |
Louis Dionne | f4c1258 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 122 | # endif |
Louis Dionne | 2d3b8cc | 2020-07-13 11:53:48 -0400 | [diff] [blame] | 123 | { |
| 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); |
| 130 | } |
Louis Dionne | f4c1258 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 131 | #endif // TEST_HAS_NO_WIDE_CHARACTERS |
Louis Dionne | 2d3b8cc | 2020-07-13 11:53:48 -0400 | [diff] [blame] | 132 | |
| 133 | // [istream.manip] (char) |
| 134 | #ifdef TU1 |
| 135 | IstreamManipFunction* get_istreammanip_tu1(std::string func) |
| 136 | #else |
| 137 | IstreamManipFunction* get_istreammanip_tu2(std::string func) |
| 138 | #endif |
| 139 | { |
| 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); |
| 144 | } |
| 145 | |
| 146 | // [istream.manip] (wchar_t) |
Louis Dionne | f4c1258 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 147 | #ifndef TEST_HAS_NO_WIDE_CHARACTERS |
| 148 | # ifdef TU1 |
Louis Dionne | 2d3b8cc | 2020-07-13 11:53:48 -0400 | [diff] [blame] | 149 | WIstreamManipFunction* get_wistreammanip_tu1(std::string func) |
Louis Dionne | f4c1258 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 150 | # else |
Louis Dionne | 2d3b8cc | 2020-07-13 11:53:48 -0400 | [diff] [blame] | 151 | WIstreamManipFunction* get_wistreammanip_tu2(std::string func) |
Louis Dionne | f4c1258 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 152 | # endif |
Louis Dionne | 2d3b8cc | 2020-07-13 11:53:48 -0400 | [diff] [blame] | 153 | { |
| 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); |
| 158 | } |
Louis Dionne | f4c1258 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 159 | #endif // TEST_HAS_NO_WIDE_CHARACTERS |
Louis Dionne | 2d3b8cc | 2020-07-13 11:53:48 -0400 | [diff] [blame] | 160 | |
| 161 | #ifdef TU2 |
Louis Dionne | 504bc07 | 2020-10-08 13:36:33 -0400 | [diff] [blame] | 162 | int main(int, char**) { |
Louis Dionne | 2d3b8cc | 2020-07-13 11:53:48 -0400 | [diff] [blame] | 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")); |
| 187 | |
| 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")); |
| 191 | |
Louis Dionne | f4c1258 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 192 | #ifndef TEST_HAS_NO_WIDE_CHARACTERS |
Louis Dionne | 2d3b8cc | 2020-07-13 11:53:48 -0400 | [diff] [blame] | 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")); |
Louis Dionne | f4c1258 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 196 | #endif |
Louis Dionne | 2d3b8cc | 2020-07-13 11:53:48 -0400 | [diff] [blame] | 197 | |
| 198 | assert(get_istreammanip_tu1("ws") == get_istreammanip_tu2("ws")); |
| 199 | |
Louis Dionne | f4c1258 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 200 | #ifndef TEST_HAS_NO_WIDE_CHARACTERS |
Louis Dionne | 2d3b8cc | 2020-07-13 11:53:48 -0400 | [diff] [blame] | 201 | assert(get_wistreammanip_tu1("ws") == get_wistreammanip_tu2("ws")); |
Louis Dionne | f4c1258 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 202 | #endif |
Louis Dionne | 504bc07 | 2020-10-08 13:36:33 -0400 | [diff] [blame] | 203 | |
| 204 | return 0; |
Louis Dionne | 2d3b8cc | 2020-07-13 11:53:48 -0400 | [diff] [blame] | 205 | } |
| 206 | #endif |