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