[PATCH] D33776: [libcxx] LWG2221: No formatted output operator for nullptr
K-ballo added inline comments. Comment at: include/ostream:225 +basic_ostream& operator<<(nullptr_t) +{ return *this << (const void*)0; } + Quuxplusone wrote: > mclow.lists wrote: > > lichray wrote: > > > Oh, common, I persuaded the committee to allow you to print a `(null)` > > > and you don't do it... > > I think that `(null)` is a better thing to output here than `0x0`. > Are you two implying that > > *this << (const void *)0; > > does *not* print `(null)`? It certainly should, IMO. (I mean, it'll call > `num_put` for `void*` in the current locale, but I would naturally expect > that to print `(null)`.) > Anyway, whether the current locale prints null as `(null)` or not, there is > great potential utility in using the same format for all pointers, as K-ballo > is doing here. I'd really like to be able to > > std::ostringstream oss; > oss << nullptr; // equivalently: oss << (void*)0; > void *p; > std::istringstream(oss.str()) >> p; // should read in a null pointer, > not derp out > > FWIW, it looks like libc++ currently *does* print null pointers as `(nil)`, > which is not quite the same thing as `(null)`. libstdc++ prints them as `0`. > https://wandbox.org/permlink/yAM6tjMzvEX9HhhE It's been a while now, but I seem to recall that the reason we settled on `(*this) << (const void*)0` was precisely so that it would go through `num_put`, as the rest of the pointers do. As I read back on the specification, however, I am no longer sure that such an implementation is conforming. Maybe if we were to call the facet directly... I am no longer interested in this issue. If anyone wants to take over control I would be happy to yield it; otherwise, I'll implement whatever I'm instructed to. https://reviews.llvm.org/D33776 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D38831: [libcxx] P0604, invoke_result and is_invocable
K-ballo added a comment. Thanks @lichray Repository: rL LLVM https://reviews.llvm.org/D38831 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D38831: [libcxx] P0604, invoke_result and is_invocable
K-ballo updated this revision to Diff 126545. K-ballo added a comment. Fixed incorrect test case. https://reviews.llvm.org/D38831 Files: include/type_traits include/variant test/std/utilities/function.objects/func.not_fn/not_fn.pass.cpp test/std/utilities/function.objects/unord.hash/non_enum.pass.cpp test/std/utilities/meta/meta.rel/is_callable.pass.cpp test/std/utilities/meta/meta.rel/is_invocable.pass.cpp test/std/utilities/meta/meta.rel/is_nothrow_callable.pass.cpp test/std/utilities/meta/meta.rel/is_nothrow_invocable.pass.cpp test/std/utilities/meta/meta.trans/meta.trans.other/result_of.pass.cpp test/std/utilities/meta/meta.trans/meta.trans.other/result_of11.pass.cpp Index: test/std/utilities/meta/meta.trans/meta.trans.other/result_of11.pass.cpp === --- test/std/utilities/meta/meta.trans/meta.trans.other/result_of11.pass.cpp +++ test/std/utilities/meta/meta.trans/meta.trans.other/result_of11.pass.cpp @@ -27,16 +27,32 @@ struct F {}; struct FD : public F {}; +#if TEST_STD_VER > 14 +template +struct test_invoke_result; + +template +struct test_invoke_result +{ +static void call() +{ +static_assert(std::is_invocable::value, ""); +static_assert(std::is_invocable_r::value, ""); +static_assert((std::is_same::type, Ret>::value), ""); +static_assert((std::is_same, Ret>::value), ""); +} +}; +#endif + template void test_result_of_imp() { static_assert((std::is_same::type, U>::value), ""); #if TEST_STD_VER > 11 static_assert((std::is_same, U>::value), ""); #endif #if TEST_STD_VER > 14 -static_assert(std::is_callable::value, ""); -static_assert(std::is_callable::value, ""); +test_invoke_result::call(); #endif } Index: test/std/utilities/meta/meta.trans/meta.trans.other/result_of.pass.cpp === --- test/std/utilities/meta/meta.trans/meta.trans.other/result_of.pass.cpp +++ test/std/utilities/meta/meta.trans/meta.trans.other/result_of.pass.cpp @@ -42,24 +42,54 @@ template struct HasType::type> : std::true_type {}; +#if TEST_STD_VER > 14 +template +struct test_invoke_result; + +template +struct test_invoke_result +{ +static void call() +{ +static_assert(std::is_invocable::value, ""); +static_assert(std::is_invocable_r::value, ""); +static_assert((std::is_same::type, Ret>::value), ""); +} +}; +#endif + template void test_result_of() { +static_assert((std::is_same::type, U>::value), ""); #if TEST_STD_VER > 14 -static_assert(std::is_callable::value, ""); -static_assert(std::is_callable::value, ""); +test_invoke_result::call(); #endif -static_assert((std::is_same::type, U>::value), ""); } +#if TEST_STD_VER > 14 +template +struct test_invoke_no_result; + +template +struct test_invoke_no_result +{ +static void call() +{ +static_assert(std::is_invocable::value == false, ""); +static_assert((!HasType >::value), ""); +} +}; +#endif + template void test_no_result() { #if TEST_STD_VER >= 11 static_assert((!HasType >::value), ""); #endif #if TEST_STD_VER > 14 -static_assert(std::is_callable::value == false, ""); +test_invoke_no_result::call(); #endif } Index: test/std/utilities/meta/meta.rel/is_nothrow_invocable.pass.cpp === --- /dev/null +++ test/std/utilities/meta/meta.rel/is_nothrow_invocable.pass.cpp @@ -0,0 +1,121 @@ +//===--===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===--===// + +// UNSUPPORTED: c++98, c++03, c++11, c++14 + +// type_traits + +// is_nothrow_invocable + +#include +#include + +#include "test_macros.h" + +struct Tag {}; + +struct Implicit { + Implicit(int) noexcept {} +}; + +struct ThrowsImplicit { + ThrowsImplicit(int) {} +}; + +struct Explicit { + explicit Explicit(int) noexcept {} +}; + +template +struct CallObject { + Ret operator()(Args&&...) const noexcept(IsNoexcept); +}; + +template +constexpr bool throws_invocable() { +return std::is_invocable::value && +!std::is_nothrow_invocable::value; +} + +template +constexpr bool throws_invocable_r() { +return std::is_invocable_r::value && +!std::is_nothrow_invocable_r::value; +} + +// FIXME(EricWF) Don't test the where noexcept is *not* part of the type system +// once implementations have caught up. +void test_noexcept_function_pointers() +{ +struct Dummy { void foo() noexcept {} static void bar() noexcept {} }; +#if !defined(__cpp_noexcept_function_type) +{ +// Check that PMF's and function pointers
[PATCH] D38831: [libcxx] P0604, invoke_result and is_invocable
K-ballo added a comment. In https://reviews.llvm.org/D38831#952228, @lichray wrote: > [...]test/std/utilities/meta/meta.rel/is_nothrow_invocable.pass.cpp:118:9: > error: static_assert failed due to requirement > '!std::is_nothrow_invocable_r_v' "" > static_assert(!std::is_nothrow_invocable_r_v, ""); > ^ ~~~ > 1 error generated. > -- > > > with Clang-5.0 and trunk. Can you reproduce? I can reproduce. It seems the intention was to match the tests from the previous section, so an extra `int` argument would be missing. I'll take care of it. https://reviews.llvm.org/D38831 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D40259: [libcxx] LWG2993: reference_wrapper
K-ballo updated this revision to Diff 124201. K-ballo edited the summary of this revision. K-ballo added a comment. Turn fail test into SFINAE based pass test, mark XFAIL for clang. https://reviews.llvm.org/D40259 Files: include/__functional_base include/functional test/std/utilities/function.objects/refwrap/refwrap.assign/copy_assign.pass.cpp test/std/utilities/function.objects/refwrap/refwrap.const/type_conv_ctor.pass.cpp test/std/utilities/function.objects/refwrap/refwrap.const/type_conv_ctor2.pass.cpp test/std/utilities/function.objects/refwrap/refwrap.const/type_ctor.pass.cpp Index: test/std/utilities/function.objects/refwrap/refwrap.const/type_ctor.pass.cpp === --- test/std/utilities/function.objects/refwrap/refwrap.const/type_ctor.pass.cpp +++ test/std/utilities/function.objects/refwrap/refwrap.const/type_ctor.pass.cpp @@ -15,6 +15,7 @@ #include #include +#include class functor1 { @@ -41,4 +42,19 @@ test(i); const int j = 0; test(j); + +{ +using Ref = std::reference_wrapper; +static_assert((std::is_constructible::value), ""); +static_assert((!std::is_constructible::value), ""); +static_assert((!std::is_constructible::value), ""); +} + +#if TEST_STD_VER >= 11 +{ +using Ref = std::reference_wrapper; +static_assert((std::is_nothrow_constructible::value), ""); +static_assert((!std::is_nothrow_constructible::value), ""); +} +#endif } Index: test/std/utilities/function.objects/refwrap/refwrap.const/type_conv_ctor2.pass.cpp === --- /dev/null +++ test/std/utilities/function.objects/refwrap/refwrap.const/type_conv_ctor2.pass.cpp @@ -0,0 +1,34 @@ +//===--===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===--===// + +// + +// reference_wrapper + +// template +// reference_wrapper(U&&) noexcept(see below); + +// UNSUPPORTED: c++98, c++03 +// XFAIL: clang-3.7, clang-3.8, clang-3.9, clang-4.0, clang-5.0, clang-6.0 + +#include +#include + +struct convertible_to_float_ref { +float val = 0; +operator float const&() { return val; } +operator float const&() const { return val; } +}; + +int main() +{ +using Ref = std::reference_wrapper; +static_assert((!std::is_constructible::value), ""); +static_assert((!std::is_constructible::value), ""); +} Index: test/std/utilities/function.objects/refwrap/refwrap.const/type_conv_ctor.pass.cpp === --- /dev/null +++ test/std/utilities/function.objects/refwrap/refwrap.const/type_conv_ctor.pass.cpp @@ -0,0 +1,82 @@ +//===--===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===--===// + +// + +// reference_wrapper + +// template +// reference_wrapper(U&&) noexcept(see below); + +// UNSUPPORTED: c++98, c++03 + +#include +#include + +struct convertible_to_int_ref { +int val = 0; +operator int&() { return val; } +operator int const&() const { return val; } +}; + +template +struct nothrow_convertible { +int val = 0; +operator int&() noexcept(IsNothrow) { return val; } +}; + +struct convertible_from_int { +convertible_from_int(int) {} +}; + +void meow(std::reference_wrapper) {} +void meow(convertible_from_int) {} + +int gi; +std::reference_wrapper purr() { return gi; }; + +template +void +test(T& t) +{ +std::reference_wrapper r(t); +assert(&r.get() == &t); +} + +void f() {} + +int main() +{ +convertible_to_int_ref convi; +test(convi); +convertible_to_int_ref const convic; +test(convic); + +{ +using Ref = std::reference_wrapper; +static_assert((std::is_nothrow_constructible>::value), ""); +static_assert((!std::is_nothrow_constructible>::value), ""); +} + +{ +meow(0); +(true) ? purr() : 0; +} + +#ifdef __cpp_deduction_guides +{ +int i = 0; +std::reference_wrapper ri(i); +static_assert((std::is_same>::value), "" ); +const int j = 0; +std::reference_wrapper rj(j); +static_assert((std::is_same>::value), "" ); +} +#endif +} Index: test/std/utilities/function.objects/refwrap/refwrap.assign/copy_assign.pass.cpp === --- test/std/utilities/function.objects/refwrap/refwrap.assign/copy_assign.pass.cpp +++ test/std/utilities/function
[PATCH] D40259: [libcxx] LWG2993: reference_wrapper
K-ballo updated this revision to Diff 124005. K-ballo added a comment. Back to `decltype`-based SFINAE. https://reviews.llvm.org/D40259 Files: include/__functional_base include/functional test/std/utilities/function.objects/refwrap/refwrap.assign/copy_assign.pass.cpp test/std/utilities/function.objects/refwrap/refwrap.const/type_conv_ctor.fail.cpp test/std/utilities/function.objects/refwrap/refwrap.const/type_conv_ctor.pass.cpp test/std/utilities/function.objects/refwrap/refwrap.const/type_ctor.pass.cpp Index: test/std/utilities/function.objects/refwrap/refwrap.const/type_ctor.pass.cpp === --- test/std/utilities/function.objects/refwrap/refwrap.const/type_ctor.pass.cpp +++ test/std/utilities/function.objects/refwrap/refwrap.const/type_ctor.pass.cpp @@ -15,6 +15,7 @@ #include #include +#include class functor1 { @@ -41,4 +42,19 @@ test(i); const int j = 0; test(j); + +{ +using Ref = std::reference_wrapper; +static_assert((std::is_constructible::value), ""); +static_assert((!std::is_constructible::value), ""); +static_assert((!std::is_constructible::value), ""); +} + +#if TEST_STD_VER >= 11 +{ +using Ref = std::reference_wrapper; +static_assert((std::is_nothrow_constructible::value), ""); +static_assert((!std::is_nothrow_constructible::value), ""); +} +#endif } Index: test/std/utilities/function.objects/refwrap/refwrap.const/type_conv_ctor.pass.cpp === --- /dev/null +++ test/std/utilities/function.objects/refwrap/refwrap.const/type_conv_ctor.pass.cpp @@ -0,0 +1,82 @@ +//===--===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===--===// + +// + +// reference_wrapper + +// template +// reference_wrapper(U&&) noexcept(see below); + +// UNSUPPORTED: c++98, c++03 + +#include +#include + +struct convertible_to_int_ref { +int val = 0; +operator int&() { return val; } +operator int const&() const { return val; } +}; + +template +struct nothrow_convertible { +int val = 0; +operator int&() noexcept(IsNothrow) { return val; } +}; + +struct convertible_from_int { +convertible_from_int(int) {} +}; + +void meow(std::reference_wrapper) {} +void meow(convertible_from_int) {} + +int gi; +std::reference_wrapper purr() { return gi; }; + +template +void +test(T& t) +{ +std::reference_wrapper r(t); +assert(&r.get() == &t); +} + +void f() {} + +int main() +{ +convertible_to_int_ref convi; +test(convi); +convertible_to_int_ref const convic; +test(convic); + +{ +using Ref = std::reference_wrapper; +static_assert((std::is_nothrow_constructible>::value), ""); +static_assert((!std::is_nothrow_constructible>::value), ""); +} + +{ +meow(0); +(true) ? purr() : 0; +} + +#ifdef __cpp_deduction_guides +{ +int i = 0; +std::reference_wrapper ri(i); +static_assert((std::is_same>::value), "" ); +const int j = 0; +std::reference_wrapper rj(j); +static_assert((std::is_same>::value), "" ); +} +#endif +} Index: test/std/utilities/function.objects/refwrap/refwrap.const/type_conv_ctor.fail.cpp === --- /dev/null +++ test/std/utilities/function.objects/refwrap/refwrap.const/type_conv_ctor.fail.cpp @@ -0,0 +1,31 @@ +//===--===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===--===// + +// + +// reference_wrapper + +// template +// reference_wrapper(U&&) noexcept(see below); + +// UNSUPPORTED: c++98, c++03 + +#include +#include + +struct convertible_to_float_ref { +float val = 0; +operator float const&() const { return val; } +}; + +int main() +{ +convertible_to_float_ref convf; +std::reference_wrapper r(convf); +} Index: test/std/utilities/function.objects/refwrap/refwrap.assign/copy_assign.pass.cpp === --- test/std/utilities/function.objects/refwrap/refwrap.assign/copy_assign.pass.cpp +++ test/std/utilities/function.objects/refwrap/refwrap.assign/copy_assign.pass.cpp @@ -15,11 +15,18 @@ #include #include +#include class functor1 { }; +struct convertible_to_int_ref { +int val = 0; +operator int&() { return val; } +operator int const&() const { return val; } +}; + tem
[PATCH] D40259: [libcxx] LWG2993: reference_wrapper
K-ballo updated this revision to Diff 123813. K-ballo added a comment. Full context diff. https://reviews.llvm.org/D40259 Files: include/__functional_base include/functional test/std/utilities/function.objects/refwrap/refwrap.assign/copy_assign.pass.cpp test/std/utilities/function.objects/refwrap/refwrap.const/type_conv_ctor.fail.cpp test/std/utilities/function.objects/refwrap/refwrap.const/type_conv_ctor.pass.cpp test/std/utilities/function.objects/refwrap/refwrap.const/type_ctor.pass.cpp Index: test/std/utilities/function.objects/refwrap/refwrap.const/type_ctor.pass.cpp === --- test/std/utilities/function.objects/refwrap/refwrap.const/type_ctor.pass.cpp +++ test/std/utilities/function.objects/refwrap/refwrap.const/type_ctor.pass.cpp @@ -15,6 +15,7 @@ #include #include +#include class functor1 { @@ -41,4 +42,19 @@ test(i); const int j = 0; test(j); + +{ +using Ref = std::reference_wrapper; +static_assert((std::is_constructible::value), ""); +static_assert((!std::is_constructible::value), ""); +static_assert((!std::is_constructible::value), ""); +} + +#if TEST_STD_VER >= 11 +{ +using Ref = std::reference_wrapper; +static_assert((std::is_nothrow_constructible::value), ""); +static_assert((!std::is_nothrow_constructible::value), ""); +} +#endif } Index: test/std/utilities/function.objects/refwrap/refwrap.const/type_conv_ctor.pass.cpp === --- /dev/null +++ test/std/utilities/function.objects/refwrap/refwrap.const/type_conv_ctor.pass.cpp @@ -0,0 +1,82 @@ +//===--===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===--===// + +// + +// reference_wrapper + +// template +// reference_wrapper(U&&) noexcept(see below); + +// XFAIL: c++98, c++03 + +#include +#include + +struct convertible_to_int_ref { +int val = 0; +operator int&() { return val; } +operator int const&() const { return val; } +}; + +template +struct nothrow_convertible { +int val = 0; +operator int&() noexcept(IsNothrow) { return val; } +}; + +struct convertible_from_int { +convertible_from_int(int) {} +}; + +void meow(std::reference_wrapper) {} +void meow(convertible_from_int) {} + +int gi; +std::reference_wrapper purr() { return gi; }; + +template +void +test(T& t) +{ +std::reference_wrapper r(t); +assert(&r.get() == &t); +} + +void f() {} + +int main() +{ +convertible_to_int_ref convi; +test(convi); +convertible_to_int_ref const convic; +test(convic); + +{ +using Ref = std::reference_wrapper; +static_assert((std::is_nothrow_constructible>::value), ""); +static_assert((!std::is_nothrow_constructible>::value), ""); +} + +{ +meow(0); +(true) ? purr() : 0; +} + +#ifdef __cpp_deduction_guides +{ +int i = 0; +std::reference_wrapper ri(i); +static_assert((std::is_same>::value), "" ); +const int j = 0; +std::reference_wrapper rj(j); +static_assert((std::is_same>::value), "" ); +} +#endif +} Index: test/std/utilities/function.objects/refwrap/refwrap.const/type_conv_ctor.fail.cpp === --- /dev/null +++ test/std/utilities/function.objects/refwrap/refwrap.const/type_conv_ctor.fail.cpp @@ -0,0 +1,31 @@ +//===--===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===--===// + +// + +// reference_wrapper + +// template +// reference_wrapper(U&&) noexcept(see below); + +// XFAIL: c++98, c++03 + +#include +#include + +struct convertible_to_float_ref { +float val = 0; +operator float const&() const { return val; } +}; + +int main() +{ +convertible_to_float_ref convf; +std::reference_wrapper r(convf); +} Index: test/std/utilities/function.objects/refwrap/refwrap.assign/copy_assign.pass.cpp === --- test/std/utilities/function.objects/refwrap/refwrap.assign/copy_assign.pass.cpp +++ test/std/utilities/function.objects/refwrap/refwrap.assign/copy_assign.pass.cpp @@ -15,11 +15,18 @@ #include #include +#include class functor1 { }; +struct convertible_to_int_ref { +int val = 0; +operator int&() { return val; } +operator int const&() const { return val; } +}; + template void test(T& t) @
[PATCH] D40259: [libcxx] LWG2993: reference_wrapper
K-ballo updated this revision to Diff 123679. K-ballo added a comment. Addressed review comments. Added tests for SFINAE, noexcept, deduction guide. https://reviews.llvm.org/D40259 Files: include/__functional_base include/functional test/std/utilities/function.objects/refwrap/refwrap.assign/copy_assign.pass.cpp test/std/utilities/function.objects/refwrap/refwrap.const/type_conv_ctor.fail.cpp test/std/utilities/function.objects/refwrap/refwrap.const/type_conv_ctor.pass.cpp test/std/utilities/function.objects/refwrap/refwrap.const/type_ctor.pass.cpp Index: test/std/utilities/function.objects/refwrap/refwrap.const/type_ctor.pass.cpp === --- test/std/utilities/function.objects/refwrap/refwrap.const/type_ctor.pass.cpp +++ test/std/utilities/function.objects/refwrap/refwrap.const/type_ctor.pass.cpp @@ -15,6 +15,7 @@ #include #include +#include class functor1 { @@ -41,4 +42,19 @@ test(i); const int j = 0; test(j); + +{ +using Ref = std::reference_wrapper; +static_assert((std::is_constructible::value), ""); +static_assert((!std::is_constructible::value), ""); +static_assert((!std::is_constructible::value), ""); +} + +#if TEST_STD_VER >= 11 +{ +using Ref = std::reference_wrapper; +static_assert((std::is_nothrow_constructible::value), ""); +static_assert((!std::is_nothrow_constructible::value), ""); +} +#endif } Index: test/std/utilities/function.objects/refwrap/refwrap.const/type_conv_ctor.pass.cpp === --- /dev/null +++ test/std/utilities/function.objects/refwrap/refwrap.const/type_conv_ctor.pass.cpp @@ -0,0 +1,82 @@ +//===--===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===--===// + +// + +// reference_wrapper + +// template +// reference_wrapper(U&&) noexcept(see below); + +// XFAIL: c++98, c++03 + +#include +#include + +struct convertible_to_int_ref { +int val = 0; +operator int&() { return val; } +operator int const&() const { return val; } +}; + +template +struct nothrow_convertible { +int val = 0; +operator int&() noexcept(IsNothrow) { return val; } +}; + +struct convertible_from_int { +convertible_from_int(int) {} +}; + +void meow(std::reference_wrapper) {} +void meow(convertible_from_int) {} + +int gi; +std::reference_wrapper purr() { return gi; }; + +template +void +test(T& t) +{ +std::reference_wrapper r(t); +assert(&r.get() == &t); +} + +void f() {} + +int main() +{ +convertible_to_int_ref convi; +test(convi); +convertible_to_int_ref const convic; +test(convic); + +{ +using Ref = std::reference_wrapper; +static_assert((std::is_nothrow_constructible>::value), ""); +static_assert((!std::is_nothrow_constructible>::value), ""); +} + +{ +meow(0); +(true) ? purr() : 0; +} + +#ifdef __cpp_deduction_guides +{ +int i = 0; +std::reference_wrapper ri(i); +static_assert((std::is_same>::value), "" ); +const int j = 0; +std::reference_wrapper rj(j); +static_assert((std::is_same>::value), "" ); +} +#endif +} Index: test/std/utilities/function.objects/refwrap/refwrap.const/type_conv_ctor.fail.cpp === --- /dev/null +++ test/std/utilities/function.objects/refwrap/refwrap.const/type_conv_ctor.fail.cpp @@ -0,0 +1,31 @@ +//===--===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===--===// + +// + +// reference_wrapper + +// template +// reference_wrapper(U&&) noexcept(see below); + +// XFAIL: c++98, c++03 + +#include +#include + +struct convertible_to_float_ref { +float val = 0; +operator float const&() const { return val; } +}; + +int main() +{ +convertible_to_float_ref convf; +std::reference_wrapper r(convf); +} Index: test/std/utilities/function.objects/refwrap/refwrap.assign/copy_assign.pass.cpp === --- test/std/utilities/function.objects/refwrap/refwrap.assign/copy_assign.pass.cpp +++ test/std/utilities/function.objects/refwrap/refwrap.assign/copy_assign.pass.cpp @@ -15,11 +15,18 @@ #include #include +#include class functor1 { }; +struct convertible_to_int_ref { +int val = 0; +operator int&() { return val; } +operator int const&()
[PATCH] D40259: [libcxx] LWG2993: reference_wrapper
K-ballo created this revision. Implement LWG2993, `reference_wrapper` conversion from `T&&`. The conversion fail test currently fails to fail (passes), due to https://bugs.llvm.org/show_bug.cgi?id=35332. Flagging it `XFAIL` does not seem to have any effect. https://reviews.llvm.org/D40259 Files: include/__functional_base test/std/utilities/function.objects/refwrap/refwrap.assign/copy_assign.pass.cpp test/std/utilities/function.objects/refwrap/refwrap.const/type_conv_ctor.fail.cpp test/std/utilities/function.objects/refwrap/refwrap.const/type_conv_ctor.pass.cpp Index: test/std/utilities/function.objects/refwrap/refwrap.const/type_conv_ctor.pass.cpp === --- /dev/null +++ test/std/utilities/function.objects/refwrap/refwrap.const/type_conv_ctor.pass.cpp @@ -0,0 +1,58 @@ +//===--===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===--===// + +// + +// reference_wrapper + +// template reference_wrapper(U&&); + +// XFAIL: c++98, c++03, c++11, c++14, c++17 + +#include +#include + +struct convertible_to_int_ref { +int val = 0; +operator int&() { return val; } +operator int const&() const { return val; } +}; + +struct convertible_from_int { +convertible_from_int(int) {} +}; + +void meow(std::reference_wrapper) {} +void meow(convertible_from_int) {} + +int gi; +std::reference_wrapper purr() { return gi; }; + +template +void +test(T& t) +{ +std::reference_wrapper r(t); +assert(&r.get() == &t); +} + +void f() {} + +int main() +{ +convertible_to_int_ref convi; +test(convi); +convertible_to_int_ref const convic; +test(convic); + +{ +meow(0); +(true) ? purr() : 0; +} +} Index: test/std/utilities/function.objects/refwrap/refwrap.const/type_conv_ctor.fail.cpp === --- /dev/null +++ test/std/utilities/function.objects/refwrap/refwrap.const/type_conv_ctor.fail.cpp @@ -0,0 +1,30 @@ +//===--===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===--===// + +// + +// reference_wrapper + +// template reference_wrapper(U&&); + +// XFAIL: c++98, c++03, c++11, c++14, c++17 + +#include +#include + +struct convertible_to_float_ref { +float val = 0; +operator float const&() const { return val; } +}; + +int main() +{ +convertible_to_float_ref convf; +std::reference_wrapper r(convf); +} Index: test/std/utilities/function.objects/refwrap/refwrap.assign/copy_assign.pass.cpp === --- test/std/utilities/function.objects/refwrap/refwrap.assign/copy_assign.pass.cpp +++ test/std/utilities/function.objects/refwrap/refwrap.assign/copy_assign.pass.cpp @@ -20,6 +20,12 @@ { }; +struct convertible_to_int_ref { +int val = 0; +operator int&() { return val; } +operator int const&() const { return val; } +}; + template void test(T& t) @@ -54,4 +60,11 @@ test(i); const int j = 0; test(j); + +#if TEST_STD_VER > 17 +convertible_to_int_ref convi; +test(convi); +convertible_to_int_ref const convic; +test(convic); +#endif } Index: include/__functional_base === --- include/__functional_base +++ include/__functional_base @@ -371,6 +371,15 @@ #endif }; +#if _LIBCPP_STD_VER > 17 +template +inline _LIBCPP_INLINE_VISIBILITY +_Tp& __lvref_bind(_Tp& r) _NOEXCEPT { return r; } + +template +_Tp& __lvref_bind(_Tp&& r) = delete; +#endif + template class _LIBCPP_TEMPLATE_VIS reference_wrapper : public __weak_result_type<_Tp> @@ -383,11 +392,22 @@ public: // construct/copy/destroy +#if _LIBCPP_STD_VER > 17 +template , reference_wrapper>::value +>, class = typename __void_t< +decltype(_VSTD::__lvref_bind<_Tp>(_VSTD::declval<_Up>())) +>::type> +_LIBCPP_INLINE_VISIBILITY reference_wrapper(_Up&& __u) +_NOEXCEPT_(noexcept(_VSTD::__lvref_bind<_Tp>(_VSTD::forward<_Up>(__u +: __f_(_VSTD::addressof(_VSTD::__lvref_bind<_Tp>(_VSTD::forward<_Up>(__u {} +#else _LIBCPP_INLINE_VISIBILITY reference_wrapper(type& __f) _NOEXCEPT : __f_(_VSTD::addressof(__f)) {} #ifndef _LIBCPP_CXX03_LANG private: reference_wrapper(type&&); public: // = delete; // do not bind to temps #endif +#endif // access _LIBCPP_INLINE_VISIBILITY opera
[PATCH] D38831: [libcxx] P0604, invoke_result and is_invocable
K-ballo added a comment. In https://reviews.llvm.org/D38831#917439, @EricWF wrote: > @K-ballo I always forget. Do you have commit access? I do not. It's all yours. https://reviews.llvm.org/D38831 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D38831: [libcxx] P0604, invoke_result and is_invocable
K-ballo updated this revision to Diff 119764. K-ballo added a comment. Fix synopsis https://reviews.llvm.org/D38831 Files: include/type_traits include/variant test/std/utilities/function.objects/func.not_fn/not_fn.pass.cpp test/std/utilities/function.objects/unord.hash/non_enum.pass.cpp test/std/utilities/meta/meta.rel/is_callable.pass.cpp test/std/utilities/meta/meta.rel/is_invocable.pass.cpp test/std/utilities/meta/meta.rel/is_nothrow_callable.pass.cpp test/std/utilities/meta/meta.rel/is_nothrow_invocable.pass.cpp test/std/utilities/meta/meta.trans/meta.trans.other/result_of.pass.cpp test/std/utilities/meta/meta.trans/meta.trans.other/result_of11.pass.cpp Index: test/std/utilities/meta/meta.trans/meta.trans.other/result_of11.pass.cpp === --- test/std/utilities/meta/meta.trans/meta.trans.other/result_of11.pass.cpp +++ test/std/utilities/meta/meta.trans/meta.trans.other/result_of11.pass.cpp @@ -27,6 +27,23 @@ struct F {}; struct FD : public F {}; +#if TEST_STD_VER > 14 +template +struct test_invoke_result; + +template +struct test_invoke_result +{ +static void call() +{ +static_assert(std::is_invocable::value, ""); +static_assert(std::is_invocable_r::value, ""); +static_assert((std::is_same::type, Ret>::value), ""); +static_assert((std::is_same, Ret>::value), ""); +} +}; +#endif + template void test_result_of_imp() { @@ -35,8 +52,7 @@ static_assert((std::is_same, U>::value), ""); #endif #if TEST_STD_VER > 14 -static_assert(std::is_callable::value, ""); -static_assert(std::is_callable::value, ""); +test_invoke_result::call(); #endif } Index: test/std/utilities/meta/meta.trans/meta.trans.other/result_of.pass.cpp === --- test/std/utilities/meta/meta.trans/meta.trans.other/result_of.pass.cpp +++ test/std/utilities/meta/meta.trans/meta.trans.other/result_of.pass.cpp @@ -42,16 +42,46 @@ template struct HasType::type> : std::true_type {}; +#if TEST_STD_VER > 14 +template +struct test_invoke_result; + +template +struct test_invoke_result +{ +static void call() +{ +static_assert(std::is_invocable::value, ""); +static_assert(std::is_invocable_r::value, ""); +static_assert((std::is_same::type, Ret>::value), ""); +} +}; +#endif + template void test_result_of() { +static_assert((std::is_same::type, U>::value), ""); #if TEST_STD_VER > 14 -static_assert(std::is_callable::value, ""); -static_assert(std::is_callable::value, ""); +test_invoke_result::call(); #endif -static_assert((std::is_same::type, U>::value), ""); } +#if TEST_STD_VER > 14 +template +struct test_invoke_no_result; + +template +struct test_invoke_no_result +{ +static void call() +{ +static_assert(std::is_invocable::value == false, ""); +static_assert((!HasType >::value), ""); +} +}; +#endif + template void test_no_result() { @@ -59,7 +89,7 @@ static_assert((!HasType >::value), ""); #endif #if TEST_STD_VER > 14 -static_assert(std::is_callable::value == false, ""); +test_invoke_no_result::call(); #endif } Index: test/std/utilities/meta/meta.rel/is_nothrow_invocable.pass.cpp === --- /dev/null +++ test/std/utilities/meta/meta.rel/is_nothrow_invocable.pass.cpp @@ -0,0 +1,121 @@ +//===--===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===--===// + +// UNSUPPORTED: c++98, c++03, c++11, c++14 + +// type_traits + +// is_nothrow_invocable + +#include +#include + +#include "test_macros.h" + +struct Tag {}; + +struct Implicit { + Implicit(int) noexcept {} +}; + +struct ThrowsImplicit { + ThrowsImplicit(int) {} +}; + +struct Explicit { + explicit Explicit(int) noexcept {} +}; + +template +struct CallObject { + Ret operator()(Args&&...) const noexcept(IsNoexcept); +}; + +template +constexpr bool throws_invocable() { +return std::is_invocable::value && +!std::is_nothrow_invocable::value; +} + +template +constexpr bool throws_invocable_r() { +return std::is_invocable_r::value && +!std::is_nothrow_invocable_r::value; +} + +// FIXME(EricWF) Don't test the where noexcept is *not* part of the type system +// once implementations have caught up. +void test_noexcept_function_pointers() +{ +struct Dummy { void foo() noexcept {} static void bar() noexcept {} }; +#if !defined(__cpp_noexcept_function_type) +{ +// Check that PMF's and function pointers *work*. is_nothrow_invocable will always +// return false because 'noexcept
[PATCH] D38831: [libcxx] P0604, invoke_result and is_invocable
K-ballo created this revision. Introduce a new form of `result_of` without function type encoding. Rename and split `is_callable/is_nothrow_callable` into `is_invocable/is_nothrow_invocable/is_invocable_r/is_nothrow_invocable_r` (and associated types accordingly) Change function type encoding of previous `is_callable/is_nothrow_callable` traits to conventional template type parameter lists. https://reviews.llvm.org/D38831 Files: include/type_traits include/variant test/std/utilities/function.objects/func.not_fn/not_fn.pass.cpp test/std/utilities/function.objects/unord.hash/non_enum.pass.cpp test/std/utilities/meta/meta.rel/is_callable.pass.cpp test/std/utilities/meta/meta.rel/is_invocable.pass.cpp test/std/utilities/meta/meta.rel/is_nothrow_callable.pass.cpp test/std/utilities/meta/meta.rel/is_nothrow_invocable.pass.cpp test/std/utilities/meta/meta.trans/meta.trans.other/result_of.pass.cpp test/std/utilities/meta/meta.trans/meta.trans.other/result_of11.pass.cpp Index: test/std/utilities/meta/meta.trans/meta.trans.other/result_of11.pass.cpp === --- test/std/utilities/meta/meta.trans/meta.trans.other/result_of11.pass.cpp +++ test/std/utilities/meta/meta.trans/meta.trans.other/result_of11.pass.cpp @@ -27,6 +27,23 @@ struct F {}; struct FD : public F {}; +#if TEST_STD_VER > 14 +template +struct test_invoke_result; + +template +struct test_invoke_result +{ +static void call() +{ +static_assert(std::is_invocable::value, ""); +static_assert(std::is_invocable_r::value, ""); +static_assert((std::is_same::type, Ret>::value), ""); +static_assert((std::is_same, Ret>::value), ""); +} +}; +#endif + template void test_result_of_imp() { @@ -35,8 +52,7 @@ static_assert((std::is_same, U>::value), ""); #endif #if TEST_STD_VER > 14 -static_assert(std::is_callable::value, ""); -static_assert(std::is_callable::value, ""); +test_invoke_result::call(); #endif } Index: test/std/utilities/meta/meta.trans/meta.trans.other/result_of.pass.cpp === --- test/std/utilities/meta/meta.trans/meta.trans.other/result_of.pass.cpp +++ test/std/utilities/meta/meta.trans/meta.trans.other/result_of.pass.cpp @@ -42,16 +42,46 @@ template struct HasType::type> : std::true_type {}; +#if TEST_STD_VER > 14 +template +struct test_invoke_result; + +template +struct test_invoke_result +{ +static void call() +{ +static_assert(std::is_invocable::value, ""); +static_assert(std::is_invocable_r::value, ""); +static_assert((std::is_same::type, Ret>::value), ""); +} +}; +#endif + template void test_result_of() { +static_assert((std::is_same::type, U>::value), ""); #if TEST_STD_VER > 14 -static_assert(std::is_callable::value, ""); -static_assert(std::is_callable::value, ""); +test_invoke_result::call(); #endif -static_assert((std::is_same::type, U>::value), ""); } +#if TEST_STD_VER > 14 +template +struct test_invoke_no_result; + +template +struct test_invoke_no_result +{ +static void call() +{ +static_assert(std::is_invocable::value == false, ""); +static_assert((!HasType >::value), ""); +} +}; +#endif + template void test_no_result() { @@ -59,7 +89,7 @@ static_assert((!HasType >::value), ""); #endif #if TEST_STD_VER > 14 -static_assert(std::is_callable::value == false, ""); +test_invoke_no_result::call(); #endif } Index: test/std/utilities/meta/meta.rel/is_nothrow_invocable.pass.cpp === --- /dev/null +++ test/std/utilities/meta/meta.rel/is_nothrow_invocable.pass.cpp @@ -0,0 +1,121 @@ +//===--===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===--===// + +// UNSUPPORTED: c++98, c++03, c++11, c++14 + +// type_traits + +// is_nothrow_invocable + +#include +#include + +#include "test_macros.h" + +struct Tag {}; + +struct Implicit { + Implicit(int) noexcept {} +}; + +struct ThrowsImplicit { + ThrowsImplicit(int) {} +}; + +struct Explicit { + explicit Explicit(int) noexcept {} +}; + +template +struct CallObject { + Ret operator()(Args&&...) const noexcept(IsNoexcept); +}; + +template +constexpr bool throws_invocable() { +return std::is_invocable::value && +!std::is_nothrow_invocable::value; +} + +template +constexpr bool throws_invocable_r() { +return std::is_invocable_r::value && +!std::is_nothrow_invocable_r::value; +} + +// FIXME(EricWF) Don't test the where noexcept is *not* part of the type system +// once implementations have
[PATCH] D33776: [libcxx] LWG2221: No formatted output operator for nullptr
K-ballo created this revision. With effects equivalent to `os << (const void*)nullptr`. https://reviews.llvm.org/D33776 Files: include/ostream test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.arithmetic/nullptr_t.pass.cpp www/cxx1z_status.html Index: www/cxx1z_status.html === --- www/cxx1z_status.html +++ www/cxx1z_status.html @@ -356,7 +356,7 @@ http://wg21.link/LWG2062";>2062Effect contradictions w/o no-throw guarantee of std::function swapsIssaquahComplete http://wg21.link/LWG2166";>2166Heap property underspecified?Issaquah - http://wg21.link/LWG2221";>2221No formatted output operator for nullptrIssaquah + http://wg21.link/LWG2221";>2221No formatted output operator for nullptrIssaquahComplete http://wg21.link/LWG2223";>2223shrink_to_fit effect on iterator validityIssaquahComplete http://wg21.link/LWG2261";>2261Are containers required to use their 'pointer' type internally?Issaquah http://wg21.link/LWG2394";>2394locale::name specification unclear - what is implementation-defined?IssaquahComplete Index: test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.arithmetic/nullptr_t.pass.cpp === --- /dev/null +++ test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.arithmetic/nullptr_t.pass.cpp @@ -0,0 +1,81 @@ +//===--===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===--===// + +// + +// template > +// class basic_ostream; + +// operator<<(nullptr_t); + +#include +#include +#include + +template +class testbuf +: public std::basic_streambuf +{ +typedef std::basic_streambuf base; +std::basic_string str_; +public: +testbuf() +{ +} + +std::basic_string str() const +{return std::basic_string(base::pbase(), base::pptr());} + +protected: + +virtual typename base::int_type +overflow(typename base::int_type __c = base::traits_type::eof()) +{ +if (__c != base::traits_type::eof()) +{ +int n = static_cast(str_.size()); +str_.push_back(static_cast(__c)); +str_.resize(str_.capacity()); +base::setp(const_cast(str_.data()), + const_cast(str_.data() + str_.size())); +base::pbump(n+1); +} +return __c; +} +}; + +int main() +{ +{ +std::ostream os((std::streambuf*)0); +std::nullptr_t n = nullptr; +os << n; +assert(os.bad()); +assert(os.fail()); +} +{ +testbuf sb; +std::ostream os(&sb); +std::nullptr_t n = nullptr; +os << n; +assert(os.good()); +std::string s(sb.str()); + +// Implementation defined. Instead of validating the output, +// at least ensure that it does not generate an empty string. +assert(!s.empty()); +} +{ +testbuf sb; +std::ostream os(&sb); +std::nullptr_t const n = nullptr; +os << n; +assert(os.good()); +} +} Index: include/ostream === --- include/ostream +++ include/ostream @@ -56,6 +56,7 @@ basic_ostream& operator<<(double f); basic_ostream& operator<<(long double f); basic_ostream& operator<<(const void* p); +basic_ostream& operator<<(nullptr_t); basic_ostream& operator<<(basic_streambuf* sb); // 27.7.2.7 Unformatted output: @@ -140,6 +141,7 @@ #include #include #include +#include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) #pragma GCC system_header @@ -218,6 +220,10 @@ basic_ostream& operator<<(const void* __p); basic_ostream& operator<<(basic_streambuf* __sb); +inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY +basic_ostream& operator<<(nullptr_t) +{ return *this << (const void*)0; } + // 27.7.2.7 Unformatted output: basic_ostream& put(char_type __c); basic_ostream& write(const char_type* __s, streamsize __n); ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D27565: [libcxx] Fix __compressed_pair so it doesn't copy the argument multiple times, and add constexpr.
K-ballo accepted this revision. K-ballo added a comment. This revision is now accepted and ready to land. LGTM https://reviews.llvm.org/D27565 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D27565: [libcxx] Fix __compressed_pair so it doesn't copy the argument multiple times, and add constexpr.
K-ballo added a comment. I don't see any potential layout change, other than the case in which both `T1` and `T2` are empty (which I understand doesn't happen within libc++). As far as I know, the rest of the cases should result in the same layout regardless of whether EBO actually applies or not. Some notes inline. Comment at: include/memory:2058 -template ::type, - typename remove_cv<_T2>::type>::value, -bool = is_empty<_T1>::value - && !__libcpp_is_final<_T1>::value, -bool = is_empty<_T2>::value - && !__libcpp_is_final<_T2>::value - > -struct __libcpp_compressed_pair_switch; - -template -struct __libcpp_compressed_pair_switch<_T1, _T2, IsSame, false, false> {enum {value = 0};}; - -template -struct __libcpp_compressed_pair_switch<_T1, _T2, IsSame, true, false> {enum {value = 1};}; - -template -struct __libcpp_compressed_pair_switch<_T1, _T2, IsSame, false, true> {enum {value = 2};}; - -template -struct __libcpp_compressed_pair_switch<_T1, _T2, false, true, true>{enum {value = 3};}; - -template -struct __libcpp_compressed_pair_switch<_T1, _T2, true, true, true> {enum {value = 1};}; - -template ::value> -class __libcpp_compressed_pair_imp; +template ::value + && !__libcpp_is_final<_Tp>::value> Should be `_IsEmpty` Comment at: include/memory:2063 + typedef typename remove_reference<_Tp>::type& reference; + typedef const typename remove_reference<_Tp>::type& const_reference; If `_Tp` can actually be a reference type, turning it into reference to const here doesn't seem right Comment at: include/memory:2110 + _LIBCPP_CONSTEXPR explicit __compressed_pair_elem(_Up&& __u) + : __value_(_VSTD::forward<_Up>(__u)) {}; This use of `__value_` as a type is overly smart, consider just using `_Tp` for clarity https://reviews.llvm.org/D27565 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits