diff --git a/libcxx/include/ios b/libcxx/include/ios index d6967edbccdb..7f0e2d65e640 100644 --- a/libcxx/include/ios +++ b/libcxx/include/ios @@ -843,7 +843,7 @@ basic_ios<_CharT, _Traits>::set_rdbuf(basic_streambuf* _ ios_base::set_rdbuf(__sb); } -inline _LIBCPP_INLINE_VISIBILITY +inline ios_base& boolalpha(ios_base& __str) { @@ -851,7 +851,7 @@ boolalpha(ios_base& __str) return __str; } -inline _LIBCPP_INLINE_VISIBILITY +inline ios_base& noboolalpha(ios_base& __str) { @@ -859,7 +859,7 @@ noboolalpha(ios_base& __str) return __str; } -inline _LIBCPP_INLINE_VISIBILITY +inline ios_base& showbase(ios_base& __str) { @@ -867,7 +867,7 @@ showbase(ios_base& __str) return __str; } -inline _LIBCPP_INLINE_VISIBILITY +inline ios_base& noshowbase(ios_base& __str) { @@ -875,7 +875,7 @@ noshowbase(ios_base& __str) return __str; } -inline _LIBCPP_INLINE_VISIBILITY +inline ios_base& showpoint(ios_base& __str) { @@ -883,7 +883,7 @@ showpoint(ios_base& __str) return __str; } -inline _LIBCPP_INLINE_VISIBILITY +inline ios_base& noshowpoint(ios_base& __str) { @@ -891,7 +891,7 @@ noshowpoint(ios_base& __str) return __str; } -inline _LIBCPP_INLINE_VISIBILITY +inline ios_base& showpos(ios_base& __str) { @@ -899,7 +899,7 @@ showpos(ios_base& __str) return __str; } -inline _LIBCPP_INLINE_VISIBILITY +inline ios_base& noshowpos(ios_base& __str) { @@ -907,7 +907,7 @@ noshowpos(ios_base& __str) return __str; } -inline _LIBCPP_INLINE_VISIBILITY +inline ios_base& skipws(ios_base& __str) { @@ -915,7 +915,7 @@ skipws(ios_base& __str) return __str; } -inline _LIBCPP_INLINE_VISIBILITY +inline ios_base& noskipws(ios_base& __str) { @@ -923,7 +923,7 @@ noskipws(ios_base& __str) return __str; } -inline _LIBCPP_INLINE_VISIBILITY +inline ios_base& uppercase(ios_base& __str) { @@ -931,7 +931,7 @@ uppercase(ios_base& __str) return __str; } -inline _LIBCPP_INLINE_VISIBILITY +inline ios_base& nouppercase(ios_base& __str) { @@ -939,7 +939,7 @@ nouppercase(ios_base& __str) return __str; } -inline _LIBCPP_INLINE_VISIBILITY +inline ios_base& unitbuf(ios_base& __str) { @@ -947,7 +947,7 @@ unitbuf(ios_base& __str) return __str; } -inline _LIBCPP_INLINE_VISIBILITY +inline ios_base& nounitbuf(ios_base& __str) { @@ -955,7 +955,7 @@ nounitbuf(ios_base& __str) return __str; } -inline _LIBCPP_INLINE_VISIBILITY +inline ios_base& internal(ios_base& __str) { @@ -963,7 +963,7 @@ internal(ios_base& __str) return __str; } -inline _LIBCPP_INLINE_VISIBILITY +inline ios_base& left(ios_base& __str) { @@ -971,7 +971,7 @@ left(ios_base& __str) return __str; } -inline _LIBCPP_INLINE_VISIBILITY +inline ios_base& right(ios_base& __str) { @@ -979,7 +979,7 @@ right(ios_base& __str) return __str; } -inline _LIBCPP_INLINE_VISIBILITY +inline ios_base& dec(ios_base& __str) { @@ -987,7 +987,7 @@ dec(ios_base& __str) return __str; } -inline _LIBCPP_INLINE_VISIBILITY +inline ios_base& hex(ios_base& __str) { @@ -995,7 +995,7 @@ hex(ios_base& __str) return __str; } -inline _LIBCPP_INLINE_VISIBILITY +inline ios_base& oct(ios_base& __str) { @@ -1003,7 +1003,7 @@ oct(ios_base& __str) return __str; } -inline _LIBCPP_INLINE_VISIBILITY +inline ios_base& fixed(ios_base& __str) { @@ -1011,7 +1011,7 @@ fixed(ios_base& __str) return __str; } -inline _LIBCPP_INLINE_VISIBILITY +inline ios_base& scientific(ios_base& __str) { @@ -1019,7 +1019,7 @@ scientific(ios_base& __str) return __str; } -inline _LIBCPP_INLINE_VISIBILITY +inline ios_base& hexfloat(ios_base& __str) { @@ -1027,7 +1027,7 @@ hexfloat(ios_base& __str) return __str; } -inline _LIBCPP_INLINE_VISIBILITY +inline ios_base& defaultfloat(ios_base& __str) { diff --git a/libcxx/include/ostream b/libcxx/include/ostream index ea3870532f32..697732d54e6d 100644 --- a/libcxx/include/ostream +++ b/libcxx/include/ostream @@ -999,7 +999,7 @@ basic_ostream<_CharT, _Traits>::seekp(off_type __off, ios_base::seekdir __dir) } template -inline _LIBCPP_INLINE_VISIBILITY +inline basic_ostream<_CharT, _Traits>& endl(basic_ostream<_CharT, _Traits>& __os) { @@ -1009,7 +1009,7 @@ endl(basic_ostream<_CharT, _Traits>& __os) } template -inline _LIBCPP_INLINE_VISIBILITY +inline basic_ostream<_CharT, _Traits>& ends(basic_ostream<_CharT, _Traits>& __os) { @@ -1018,7 +1018,7 @@ ends(basic_ostream<_CharT, _Traits>& __os) } template -inline _LIBCPP_INLINE_VISIBILITY +inline basic_ostream<_CharT, _Traits>& flush(basic_ostream<_CharT, _Traits>& __os) { diff --git a/libcxx/test/std/namespace/addressable_functions.sh.cpp b/libcxx/test/std/namespace/addressable_functions.sh.cpp new file mode 100644 index 000000000000..fb731abf306c --- /dev/null +++ b/libcxx/test/std/namespace/addressable_functions.sh.cpp @@ -0,0 +1,185 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +// Make sure functions specified as being 'addressable' (their address can be +// taken in a well-defined manner) are indeed addressable. This notion was +// added by http://wg21.link/p0551. While it was technically only introduced +// in C++20, we test it in all standard modes because it's basic QOI to provide +// a consistent behavior for that across standard modes. + +// RUN: %{cxx} %{flags} %{compile_flags} -c %s -o %t.tu1.o -DTU1 +// RUN: %{cxx} %{flags} %{compile_flags} -c %s -o %t.tu2.o -DTU2 +// RUN: %{cxx} %{flags} %{link_flags} %t.tu1.o %t.tu2.o -o %t.exe +// RUN: %{exec} %t.exe + +#include +#include +#include +#include +#include + + +typedef std::ios_base& (FormatFlagFunction)(std::ios_base&); +typedef std::basic_ostream& (OstreamManipFunction)(std::basic_ostream&); +typedef std::basic_ostream& (WOstreamManipFunction)(std::basic_ostream&); +typedef std::basic_istream& (IstreamManipFunction)(std::basic_istream&); +typedef std::basic_istream& (WIstreamManipFunction)(std::basic_istream&); + +extern FormatFlagFunction* get_formatflag_tu1(std::string); +extern FormatFlagFunction* get_formatflag_tu2(std::string); + +extern OstreamManipFunction* get_ostreammanip_tu1(std::string); +extern OstreamManipFunction* get_ostreammanip_tu2(std::string); +extern WOstreamManipFunction* get_wostreammanip_tu1(std::string); +extern WOstreamManipFunction* get_wostreammanip_tu2(std::string); + +extern IstreamManipFunction* get_istreammanip_tu1(std::string); +extern IstreamManipFunction* get_istreammanip_tu2(std::string); +extern WIstreamManipFunction* get_wistreammanip_tu1(std::string); +extern WIstreamManipFunction* get_wistreammanip_tu2(std::string); + +#ifdef TU1 +FormatFlagFunction* get_formatflag_tu1(std::string func) +#else +FormatFlagFunction* get_formatflag_tu2(std::string func) +#endif +{ + std::map all_funcs; + + // [fmtflags.manip] + all_funcs.insert(std::make_pair("boolalpha", &std::boolalpha)); + all_funcs.insert(std::make_pair("noboolalpha", &std::noboolalpha)); + all_funcs.insert(std::make_pair("showbase", &std::showbase)); + all_funcs.insert(std::make_pair("noshowbase", &std::noshowbase)); + all_funcs.insert(std::make_pair("showpoint", &std::showpoint)); + all_funcs.insert(std::make_pair("noshowpoint", &std::noshowpoint)); + all_funcs.insert(std::make_pair("showpos", &std::showpos)); + all_funcs.insert(std::make_pair("noshowpos", &std::noshowpos)); + all_funcs.insert(std::make_pair("skipws", &std::skipws)); + all_funcs.insert(std::make_pair("noskipws", &std::noskipws)); + all_funcs.insert(std::make_pair("uppercase", &std::uppercase)); + all_funcs.insert(std::make_pair("nouppercase", &std::nouppercase)); + all_funcs.insert(std::make_pair("unitbuf", &std::unitbuf)); + all_funcs.insert(std::make_pair("nounitbuf", &std::nounitbuf)); + + // [adjustfield.manip] + all_funcs.insert(std::make_pair("internal", &std::internal)); + all_funcs.insert(std::make_pair("left", &std::left)); + all_funcs.insert(std::make_pair("right", &std::right)); + + // [basefield.manip] + all_funcs.insert(std::make_pair("dec", &std::dec)); + all_funcs.insert(std::make_pair("hex", &std::hex)); + all_funcs.insert(std::make_pair("oct", &std::oct)); + + // [floatfield.manip] + all_funcs.insert(std::make_pair("fixed", &std::fixed)); + all_funcs.insert(std::make_pair("scientific", &std::scientific)); + all_funcs.insert(std::make_pair("hexfloat", &std::hexfloat)); + all_funcs.insert(std::make_pair("defaultfloat", &std::defaultfloat)); + + return all_funcs.at(func); +} + +// [ostream.manip] (char) +#ifdef TU1 +OstreamManipFunction* get_ostreammanip_tu1(std::string func) +#else +OstreamManipFunction* get_ostreammanip_tu2(std::string func) +#endif +{ + std::map all_funcs; + typedef std::char_traits Traits; + all_funcs.insert(std::make_pair("endl", &std::endl)); + all_funcs.insert(std::make_pair("ends", &std::ends)); + all_funcs.insert(std::make_pair("flush", &std::flush)); + return all_funcs.at(func); +} + +// [ostream.manip] (wchar_t) +#ifdef TU1 +WOstreamManipFunction* get_wostreammanip_tu1(std::string func) +#else +WOstreamManipFunction* get_wostreammanip_tu2(std::string func) +#endif +{ + std::map all_funcs; + typedef std::char_traits Traits; + all_funcs.insert(std::make_pair("endl", &std::endl)); + all_funcs.insert(std::make_pair("ends", &std::ends)); + all_funcs.insert(std::make_pair("flush", &std::flush)); + return all_funcs.at(func); +} + +// [istream.manip] (char) +#ifdef TU1 +IstreamManipFunction* get_istreammanip_tu1(std::string func) +#else +IstreamManipFunction* get_istreammanip_tu2(std::string func) +#endif +{ + std::map all_funcs; + typedef std::char_traits Traits; + all_funcs.insert(std::make_pair("ws", &std::ws)); + return all_funcs.at(func); +} + +// [istream.manip] (wchar_t) +#ifdef TU1 +WIstreamManipFunction* get_wistreammanip_tu1(std::string func) +#else +WIstreamManipFunction* get_wistreammanip_tu2(std::string func) +#endif +{ + std::map all_funcs; + typedef std::char_traits Traits; + all_funcs.insert(std::make_pair("ws", &std::ws)); + return all_funcs.at(func); +} + + +#ifdef TU2 + int main() { + assert(get_formatflag_tu1("boolalpha") == get_formatflag_tu2("boolalpha")); + assert(get_formatflag_tu1("noboolalpha") == get_formatflag_tu2("noboolalpha")); + assert(get_formatflag_tu1("showbase") == get_formatflag_tu2("showbase")); + assert(get_formatflag_tu1("noshowbase") == get_formatflag_tu2("noshowbase")); + assert(get_formatflag_tu1("showpoint") == get_formatflag_tu2("showpoint")); + assert(get_formatflag_tu1("noshowpoint") == get_formatflag_tu2("noshowpoint")); + assert(get_formatflag_tu1("showpos") == get_formatflag_tu2("showpos")); + assert(get_formatflag_tu1("noshowpos") == get_formatflag_tu2("noshowpos")); + assert(get_formatflag_tu1("skipws") == get_formatflag_tu2("skipws")); + assert(get_formatflag_tu1("noskipws") == get_formatflag_tu2("noskipws")); + assert(get_formatflag_tu1("uppercase") == get_formatflag_tu2("uppercase")); + assert(get_formatflag_tu1("nouppercase") == get_formatflag_tu2("nouppercase")); + assert(get_formatflag_tu1("unitbuf") == get_formatflag_tu2("unitbuf")); + assert(get_formatflag_tu1("nounitbuf") == get_formatflag_tu2("nounitbuf")); + assert(get_formatflag_tu1("internal") == get_formatflag_tu2("internal")); + assert(get_formatflag_tu1("left") == get_formatflag_tu2("left")); + assert(get_formatflag_tu1("right") == get_formatflag_tu2("right")); + assert(get_formatflag_tu1("dec") == get_formatflag_tu2("dec")); + assert(get_formatflag_tu1("hex") == get_formatflag_tu2("hex")); + assert(get_formatflag_tu1("oct") == get_formatflag_tu2("oct")); + assert(get_formatflag_tu1("fixed") == get_formatflag_tu2("fixed")); + assert(get_formatflag_tu1("scientific") == get_formatflag_tu2("scientific")); + assert(get_formatflag_tu1("hexfloat") == get_formatflag_tu2("hexfloat")); + assert(get_formatflag_tu1("defaultfloat") == get_formatflag_tu2("defaultfloat")); + + assert(get_ostreammanip_tu1("endl") == get_ostreammanip_tu2("endl")); + assert(get_ostreammanip_tu1("ends") == get_ostreammanip_tu2("ends")); + assert(get_ostreammanip_tu1("flush") == get_ostreammanip_tu2("flush")); + + assert(get_wostreammanip_tu1("endl") == get_wostreammanip_tu2("endl")); + assert(get_wostreammanip_tu1("ends") == get_wostreammanip_tu2("ends")); + assert(get_wostreammanip_tu1("flush") == get_wostreammanip_tu2("flush")); + + assert(get_istreammanip_tu1("ws") == get_istreammanip_tu2("ws")); + + assert(get_wistreammanip_tu1("ws") == get_wistreammanip_tu2("ws")); + } +#endif diff --git a/libcxx/www/cxx2a_status.html b/libcxx/www/cxx2a_status.html index 6a2f2f44d145..ad9bb36859cb 100644 --- a/libcxx/www/cxx2a_status.html +++ b/libcxx/www/cxx2a_status.html @@ -73,7 +73,7 @@ P0777R1LWGTreating Unnecessary decayAlbuquerqueComplete7.0 P0122R7LWG<span>JacksonvilleComplete7.0 P0355R7LWGExtending chrono to Calendars and Time ZonesJacksonvilleIn progress - P0551R3LWGThou Shalt Not Specialize std Function Templates!Jacksonville + P0551R3LWGThou Shalt Not Specialize std Function Templates!JacksonvilleComplete11.0 P0753R2LWGManipulators for C++ Synchronized Buffered OstreamJacksonville P0754R2LWG<version>JacksonvilleComplete7.0 P0809R0LWGComparing Unordered ContainersJacksonville