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 | |
| 20 | #include <cassert> |
Louis Dionne | cc69d21 | 2020-10-13 15:47:31 -0400 | [diff] [blame^] | 21 | #include <ios> |
| 22 | #include <istream> |
Louis Dionne | 2d3b8cc | 2020-07-13 11:53:48 -0400 | [diff] [blame] | 23 | #include <map> |
Louis Dionne | cc69d21 | 2020-10-13 15:47:31 -0400 | [diff] [blame^] | 24 | #include <ostream> |
Louis Dionne | 2d3b8cc | 2020-07-13 11:53:48 -0400 | [diff] [blame] | 25 | #include <string> |
| 26 | #include <utility> |
| 27 | |
| 28 | |
| 29 | typedef std::ios_base& (FormatFlagFunction)(std::ios_base&); |
| 30 | typedef std::basic_ostream<char>& (OstreamManipFunction)(std::basic_ostream<char>&); |
| 31 | typedef std::basic_ostream<wchar_t>& (WOstreamManipFunction)(std::basic_ostream<wchar_t>&); |
| 32 | typedef std::basic_istream<char>& (IstreamManipFunction)(std::basic_istream<char>&); |
| 33 | typedef std::basic_istream<wchar_t>& (WIstreamManipFunction)(std::basic_istream<wchar_t>&); |
| 34 | |
| 35 | extern FormatFlagFunction* get_formatflag_tu1(std::string); |
| 36 | extern FormatFlagFunction* get_formatflag_tu2(std::string); |
| 37 | |
| 38 | extern OstreamManipFunction* get_ostreammanip_tu1(std::string); |
| 39 | extern OstreamManipFunction* get_ostreammanip_tu2(std::string); |
| 40 | extern WOstreamManipFunction* get_wostreammanip_tu1(std::string); |
| 41 | extern WOstreamManipFunction* get_wostreammanip_tu2(std::string); |
| 42 | |
| 43 | extern IstreamManipFunction* get_istreammanip_tu1(std::string); |
| 44 | extern IstreamManipFunction* get_istreammanip_tu2(std::string); |
| 45 | extern WIstreamManipFunction* get_wistreammanip_tu1(std::string); |
| 46 | extern WIstreamManipFunction* get_wistreammanip_tu2(std::string); |
| 47 | |
| 48 | #ifdef TU1 |
| 49 | FormatFlagFunction* get_formatflag_tu1(std::string func) |
| 50 | #else |
| 51 | FormatFlagFunction* get_formatflag_tu2(std::string func) |
| 52 | #endif |
| 53 | { |
| 54 | std::map<std::string, FormatFlagFunction*> all_funcs; |
| 55 | |
| 56 | // [fmtflags.manip] |
| 57 | all_funcs.insert(std::make_pair("boolalpha", &std::boolalpha)); |
| 58 | all_funcs.insert(std::make_pair("noboolalpha", &std::noboolalpha)); |
| 59 | all_funcs.insert(std::make_pair("showbase", &std::showbase)); |
| 60 | all_funcs.insert(std::make_pair("noshowbase", &std::noshowbase)); |
| 61 | all_funcs.insert(std::make_pair("showpoint", &std::showpoint)); |
| 62 | all_funcs.insert(std::make_pair("noshowpoint", &std::noshowpoint)); |
| 63 | all_funcs.insert(std::make_pair("showpos", &std::showpos)); |
| 64 | all_funcs.insert(std::make_pair("noshowpos", &std::noshowpos)); |
| 65 | all_funcs.insert(std::make_pair("skipws", &std::skipws)); |
| 66 | all_funcs.insert(std::make_pair("noskipws", &std::noskipws)); |
| 67 | all_funcs.insert(std::make_pair("uppercase", &std::uppercase)); |
| 68 | all_funcs.insert(std::make_pair("nouppercase", &std::nouppercase)); |
| 69 | all_funcs.insert(std::make_pair("unitbuf", &std::unitbuf)); |
| 70 | all_funcs.insert(std::make_pair("nounitbuf", &std::nounitbuf)); |
| 71 | |
| 72 | // [adjustfield.manip] |
| 73 | all_funcs.insert(std::make_pair("internal", &std::internal)); |
| 74 | all_funcs.insert(std::make_pair("left", &std::left)); |
| 75 | all_funcs.insert(std::make_pair("right", &std::right)); |
| 76 | |
| 77 | // [basefield.manip] |
| 78 | all_funcs.insert(std::make_pair("dec", &std::dec)); |
| 79 | all_funcs.insert(std::make_pair("hex", &std::hex)); |
| 80 | all_funcs.insert(std::make_pair("oct", &std::oct)); |
| 81 | |
| 82 | // [floatfield.manip] |
| 83 | all_funcs.insert(std::make_pair("fixed", &std::fixed)); |
| 84 | all_funcs.insert(std::make_pair("scientific", &std::scientific)); |
| 85 | all_funcs.insert(std::make_pair("hexfloat", &std::hexfloat)); |
| 86 | all_funcs.insert(std::make_pair("defaultfloat", &std::defaultfloat)); |
| 87 | |
| 88 | return all_funcs.at(func); |
| 89 | } |
| 90 | |
| 91 | // [ostream.manip] (char) |
| 92 | #ifdef TU1 |
| 93 | OstreamManipFunction* get_ostreammanip_tu1(std::string func) |
| 94 | #else |
| 95 | OstreamManipFunction* get_ostreammanip_tu2(std::string func) |
| 96 | #endif |
| 97 | { |
| 98 | std::map<std::string, OstreamManipFunction*> all_funcs; |
| 99 | typedef std::char_traits<char> Traits; |
| 100 | all_funcs.insert(std::make_pair("endl", &std::endl<char, Traits>)); |
| 101 | all_funcs.insert(std::make_pair("ends", &std::ends<char, Traits>)); |
| 102 | all_funcs.insert(std::make_pair("flush", &std::flush<char, Traits>)); |
| 103 | return all_funcs.at(func); |
| 104 | } |
| 105 | |
| 106 | // [ostream.manip] (wchar_t) |
| 107 | #ifdef TU1 |
| 108 | WOstreamManipFunction* get_wostreammanip_tu1(std::string func) |
| 109 | #else |
| 110 | WOstreamManipFunction* get_wostreammanip_tu2(std::string func) |
| 111 | #endif |
| 112 | { |
| 113 | std::map<std::string, WOstreamManipFunction*> all_funcs; |
| 114 | typedef std::char_traits<wchar_t> Traits; |
| 115 | all_funcs.insert(std::make_pair("endl", &std::endl<wchar_t, Traits>)); |
| 116 | all_funcs.insert(std::make_pair("ends", &std::ends<wchar_t, Traits>)); |
| 117 | all_funcs.insert(std::make_pair("flush", &std::flush<wchar_t, Traits>)); |
| 118 | return all_funcs.at(func); |
| 119 | } |
| 120 | |
| 121 | // [istream.manip] (char) |
| 122 | #ifdef TU1 |
| 123 | IstreamManipFunction* get_istreammanip_tu1(std::string func) |
| 124 | #else |
| 125 | IstreamManipFunction* get_istreammanip_tu2(std::string func) |
| 126 | #endif |
| 127 | { |
| 128 | std::map<std::string, IstreamManipFunction*> all_funcs; |
| 129 | typedef std::char_traits<char> Traits; |
| 130 | all_funcs.insert(std::make_pair("ws", &std::ws<char, Traits>)); |
| 131 | return all_funcs.at(func); |
| 132 | } |
| 133 | |
| 134 | // [istream.manip] (wchar_t) |
| 135 | #ifdef TU1 |
| 136 | WIstreamManipFunction* get_wistreammanip_tu1(std::string func) |
| 137 | #else |
| 138 | WIstreamManipFunction* get_wistreammanip_tu2(std::string func) |
| 139 | #endif |
| 140 | { |
| 141 | std::map<std::string, WIstreamManipFunction*> all_funcs; |
| 142 | typedef std::char_traits<wchar_t> Traits; |
| 143 | all_funcs.insert(std::make_pair("ws", &std::ws<wchar_t, Traits>)); |
| 144 | return all_funcs.at(func); |
| 145 | } |
| 146 | |
| 147 | |
| 148 | #ifdef TU2 |
Louis Dionne | 504bc07 | 2020-10-08 13:36:33 -0400 | [diff] [blame] | 149 | int main(int, char**) { |
Louis Dionne | 2d3b8cc | 2020-07-13 11:53:48 -0400 | [diff] [blame] | 150 | assert(get_formatflag_tu1("boolalpha") == get_formatflag_tu2("boolalpha")); |
| 151 | assert(get_formatflag_tu1("noboolalpha") == get_formatflag_tu2("noboolalpha")); |
| 152 | assert(get_formatflag_tu1("showbase") == get_formatflag_tu2("showbase")); |
| 153 | assert(get_formatflag_tu1("noshowbase") == get_formatflag_tu2("noshowbase")); |
| 154 | assert(get_formatflag_tu1("showpoint") == get_formatflag_tu2("showpoint")); |
| 155 | assert(get_formatflag_tu1("noshowpoint") == get_formatflag_tu2("noshowpoint")); |
| 156 | assert(get_formatflag_tu1("showpos") == get_formatflag_tu2("showpos")); |
| 157 | assert(get_formatflag_tu1("noshowpos") == get_formatflag_tu2("noshowpos")); |
| 158 | assert(get_formatflag_tu1("skipws") == get_formatflag_tu2("skipws")); |
| 159 | assert(get_formatflag_tu1("noskipws") == get_formatflag_tu2("noskipws")); |
| 160 | assert(get_formatflag_tu1("uppercase") == get_formatflag_tu2("uppercase")); |
| 161 | assert(get_formatflag_tu1("nouppercase") == get_formatflag_tu2("nouppercase")); |
| 162 | assert(get_formatflag_tu1("unitbuf") == get_formatflag_tu2("unitbuf")); |
| 163 | assert(get_formatflag_tu1("nounitbuf") == get_formatflag_tu2("nounitbuf")); |
| 164 | assert(get_formatflag_tu1("internal") == get_formatflag_tu2("internal")); |
| 165 | assert(get_formatflag_tu1("left") == get_formatflag_tu2("left")); |
| 166 | assert(get_formatflag_tu1("right") == get_formatflag_tu2("right")); |
| 167 | assert(get_formatflag_tu1("dec") == get_formatflag_tu2("dec")); |
| 168 | assert(get_formatflag_tu1("hex") == get_formatflag_tu2("hex")); |
| 169 | assert(get_formatflag_tu1("oct") == get_formatflag_tu2("oct")); |
| 170 | assert(get_formatflag_tu1("fixed") == get_formatflag_tu2("fixed")); |
| 171 | assert(get_formatflag_tu1("scientific") == get_formatflag_tu2("scientific")); |
| 172 | assert(get_formatflag_tu1("hexfloat") == get_formatflag_tu2("hexfloat")); |
| 173 | assert(get_formatflag_tu1("defaultfloat") == get_formatflag_tu2("defaultfloat")); |
| 174 | |
| 175 | assert(get_ostreammanip_tu1("endl") == get_ostreammanip_tu2("endl")); |
| 176 | assert(get_ostreammanip_tu1("ends") == get_ostreammanip_tu2("ends")); |
| 177 | assert(get_ostreammanip_tu1("flush") == get_ostreammanip_tu2("flush")); |
| 178 | |
| 179 | assert(get_wostreammanip_tu1("endl") == get_wostreammanip_tu2("endl")); |
| 180 | assert(get_wostreammanip_tu1("ends") == get_wostreammanip_tu2("ends")); |
| 181 | assert(get_wostreammanip_tu1("flush") == get_wostreammanip_tu2("flush")); |
| 182 | |
| 183 | assert(get_istreammanip_tu1("ws") == get_istreammanip_tu2("ws")); |
| 184 | |
| 185 | assert(get_wistreammanip_tu1("ws") == get_wistreammanip_tu2("ws")); |
Louis Dionne | 504bc07 | 2020-10-08 13:36:33 -0400 | [diff] [blame] | 186 | |
| 187 | return 0; |
Louis Dionne | 2d3b8cc | 2020-07-13 11:53:48 -0400 | [diff] [blame] | 188 | } |
| 189 | #endif |