Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expand old test coverage #4443

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion benchmarks/inc/utility.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
template <class Contained>
std::vector<Contained> random_vector(size_t n) {
std::random_device rd;
std::uniform_int_distribution<uint64_t> id64;
std::uniform_int_distribution<std::uint64_t> id64;
xoshiro256ss prng{id64(rd), id64(rd), id64(rd), id64(rd)};

std::vector<Contained> res(n);
Expand Down
17 changes: 9 additions & 8 deletions benchmarks/inc/xoshiro.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,17 @@ SPDX-License-Identifier: CC0-1.0 */
#pragma once

#include <bit>
#include <stdint.h>
#include <cstdint>

struct xoshiro256ss {
xoshiro256ss() = delete;
xoshiro256ss(uint64_t s0, uint64_t s1, uint64_t s2, uint64_t s3) : s0_(s0), s1_(s1), s2_(s2), s3_(s3) {}
xoshiro256ss(std::uint64_t s0, std::uint64_t s1, std::uint64_t s2, std::uint64_t s3)
: s0_(s0), s1_(s1), s2_(s2), s3_(s3) {}

uint64_t next() {
std::uint64_t next() {
auto result = std::rotl(s1_ * 5, 7) * 9;

const uint64_t t = s1_ << 17;
const std::uint64_t t = s1_ << 17;

s2_ ^= s0_;
s3_ ^= s1_;
Expand All @@ -34,8 +35,8 @@ struct xoshiro256ss {
}

private:
uint64_t s0_;
uint64_t s1_;
uint64_t s2_;
uint64_t s3_;
std::uint64_t s0_;
std::uint64_t s1_;
std::uint64_t s2_;
std::uint64_t s3_;
};
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,32 @@ struct Cat {
double purr_cv(int) const volatile {
return 22.2;
}

long double hiss(int, int) {
return 33.3l;
}
long double hiss_c(int, int) const {
return 33.3l;
}
long double hiss_v(int, int) volatile {
return 33.3l;
}
long double hiss_cv(int, int) const volatile {
return 33.3l;
}
};

// FDIS 20.8.10 [func.memfn]/2: "The simple call wrapper shall define two nested types named
// argument_type and result_type as synonyms for cv T* and Ret, respectively, when pm is a pointer to
// N4659 [depr.func.adaptor.typedefs]/10: "The simple call wrapper returned from a call to mem_fn(pm) shall define two
// nested types named argument_type and result_type as synonyms for cv T* and Ret, respectively, when pm is a pointer to
// member function with cv-qualifier cv and taking no arguments, where Ret is pm's return type."
template <typename Ptr, typename F>
void test_unary(F) {
STATIC_ASSERT(is_same_v<typename F::argument_type, Ptr>);
STATIC_ASSERT(is_same_v<typename F::result_type, float>);
}

// FDIS 20.8.10 [func.memfn]/3: "The simple call wrapper shall define three nested types named
// first_argument_type, second_argument_type, and result_type as synonyms for cv T*, T1, and Ret,
// N4659 [depr.func.adaptor.typedefs]/11: "The simple call wrapper returned from a call to mem_fn(pm) shall define three
// nested types named first_argument_type, second_argument_type, and result_type as synonyms for cv T*, T1, and Ret,
// respectively, when pm is a pointer to member function with cv-qualifier cv and taking one argument
// of type T1, where Ret is pm's return type."
template <typename Ptr, typename F>
Expand All @@ -59,6 +72,13 @@ void test_binary(F) {
STATIC_ASSERT(is_same_v<typename F::result_type, double>);
}

// N4659 [depr.func.adaptor.typedefs]/9: "The simple call wrapper returned from a call to mem_fn(pm) shall have a
// nested type result_type that is a synonym for the return type of pm when pm is a pointer to member function."
template <typename F>
void test_ternary(F) {
STATIC_ASSERT(is_same_v<typename F::result_type, long double>);
}

int main() {
test_unary<Cat*>(mem_fn(&Cat::meow));
test_unary<const Cat*>(mem_fn(&Cat::meow_c));
Expand All @@ -69,4 +89,9 @@ int main() {
test_binary<const Cat*>(mem_fn(&Cat::purr_c));
test_binary<volatile Cat*>(mem_fn(&Cat::purr_v));
test_binary<const volatile Cat*>(mem_fn(&Cat::purr_cv));

test_ternary(mem_fn(&Cat::hiss));
test_ternary(mem_fn(&Cat::hiss_c));
test_ternary(mem_fn(&Cat::hiss_v));
test_ternary(mem_fn(&Cat::hiss_cv));
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,34 +30,8 @@ void test_orig() {

// DevDiv-294051 "<functional>: std::function has lost the ability to invoke PMFs/PMDs on various things"

// FDIS 20.8.11.2 [func.wrap.func] specifies:
// template<class R, class... ArgTypes> class function<R(ArgTypes...)>
// /7 says:
// template<class F> function(F f);
// Requires: F shall be CopyConstructible. f shall be Callable (20.8.11.2) for
// argument types ArgTypes and return type R. The copy constructor and
// destructor of A shall not throw exceptions.
// /2 says:
// A callable object f of type F is Callable for argument types ArgTypes and
// return type R if the expression INVOKE(f, declval<ArgTypes>()..., R),
// considered as an unevaluated operand (Clause 5), is well formed (20.8.2).
// 20.8.2 [func.require]/1-2 says:
// Define INVOKE(f, t1, t2, ..., tN) as follows:
// - (t1.*f)(t2, ..., tN) when f is a pointer to a member function of a class T
// and t1 is an object of type T or a reference to an object of type T or
// a reference to an object of a type derived from T;
// - ((*t1).*f)(t2, ..., tN) when f is a pointer to a member function of a class T
// and t1 is not one of the types described in the previous item;
// - t1.*f when N == 1 and f is a pointer to member data of a class T
// and t1 is an object of type T or a reference to an object of type T
// or a reference to an object of a type derived from T;
// - (*t1).*f when N == 1 and f is a pointer to member data of a class T
// and t1 is not one of the types described in the previous item;
// - f(t1, t2, ..., tN) in all other cases.
// Define INVOKE(f, t1, t2, ..., tN, R) as INVOKE(f, t1, t2, ..., tN) implicitly converted to R.

// Therefore, std::function must be able to invoke PMFs/PMDs
// on values, references, derived references, raw pointers, and smart pointers.
// N4971 [func.require] says that std::function must be able to invoke PMFs/PMDs
// on values, references, raw pointers, smart pointers, and reference_wrappers - all handling base/derived cases.

struct B {
int func(int i) {
Expand All @@ -76,17 +50,21 @@ void test_DevDiv_294051() {
b->data = 220;
x->data = 330;

function<int(B, int)> f1 = &B::func;
function<int(B&, int)> f2 = &B::func;
function<int(X&, int)> f3 = &B::func;
function<int(B*, int)> f4 = &B::func;
function<int(X*, int)> f5 = &B::func;
function<int(shared_ptr<B>, int)> f6 = &B::func;
function<int(shared_ptr<X>, int)> f7 = &B::func;
function<int(const shared_ptr<B>&, int)> f8 = &B::func;
function<int(const shared_ptr<X>&, int)> f9 = &B::func;
function<int(B, int)> f1 = &B::func;
function<int(X, int)> f1x = &B::func;
function<int(B&, int)> f2 = &B::func;
function<int(X&, int)> f3 = &B::func;
function<int(B*, int)> f4 = &B::func;
function<int(X*, int)> f5 = &B::func;
function<int(shared_ptr<B>, int)> f6 = &B::func;
function<int(shared_ptr<X>, int)> f7 = &B::func;
function<int(const shared_ptr<B>&, int)> f8 = &B::func;
function<int(const shared_ptr<X>&, int)> f9 = &B::func;
function<int(reference_wrapper<B>, int)> f10 = &B::func;
function<int(reference_wrapper<X>, int)> f11 = &B::func;

assert(f1(*b, 1000) == 1225);
assert(f1x(*x, 1000) == 1335);
assert(f2(*b, 2000) == 2225);
assert(f3(*x, 3000) == 3335);
assert(f4(b.get(), 4000) == 4225);
Expand All @@ -95,18 +73,24 @@ void test_DevDiv_294051() {
assert(f7(x, 7000) == 7335);
assert(f8(b, 8000) == 8225);
assert(f9(x, 9000) == 9335);

function<int(B)> g1 = &B::data;
function<int(B&)> g2 = &B::data;
function<int(X&)> g3 = &B::data;
function<int(B*)> g4 = &B::data;
function<int(X*)> g5 = &B::data;
function<int(shared_ptr<B>)> g6 = &B::data;
function<int(shared_ptr<X>)> g7 = &B::data;
function<int(const shared_ptr<B>&)> g8 = &B::data;
function<int(const shared_ptr<X>&)> g9 = &B::data;
assert(f10(ref(*b), 10000) == 10225);
assert(f11(ref(*x), 11000) == 11335);

function<int(B)> g1 = &B::data;
function<int(X)> g1x = &B::data;
function<int(B&)> g2 = &B::data;
function<int(X&)> g3 = &B::data;
function<int(B*)> g4 = &B::data;
function<int(X*)> g5 = &B::data;
function<int(shared_ptr<B>)> g6 = &B::data;
function<int(shared_ptr<X>)> g7 = &B::data;
function<int(const shared_ptr<B>&)> g8 = &B::data;
function<int(const shared_ptr<X>&)> g9 = &B::data;
function<int(reference_wrapper<B>)> g10 = &B::data;
function<int(reference_wrapper<X>)> g11 = &B::data;

assert(g1(*b) == 220);
assert(g1x(*x) == 330);
assert(g2(*b) == 220);
assert(g3(*x) == 330);
assert(g4(b.get()) == 220);
Expand All @@ -115,6 +99,8 @@ void test_DevDiv_294051() {
assert(g7(x) == 330);
assert(g8(b) == 220);
assert(g9(x) == 330);
assert(g10(ref(*b)) == 220);
assert(g11(ref(*x)) == 330);
}


Expand Down
4 changes: 2 additions & 2 deletions tests/std/tests/P0088R3_variant/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6114,7 +6114,7 @@ int run_test()
#include "variant_test_helpers.h"

namespace visit {
#if _HAS_CXX20 && !defined(__EDG__) && !defined(TEST_PERMISSIVE)
#if _HAS_CXX20 && !defined(TEST_PERMISSIVE)
void test_call_operator_forwarding() {
using Fn = ForwardingCallObject;
Fn obj{};
Expand Down Expand Up @@ -6563,7 +6563,7 @@ int run_test() {
#include "variant_test_helpers.h"

namespace visit::return_type {
#if _HAS_CXX20 && !defined(__EDG__) && !defined(TEST_PERMISSIVE)
#if _HAS_CXX20 && !defined(TEST_PERMISSIVE)
template <typename ReturnType>
void test_call_operator_forwarding() {
using Fn = ForwardingCallObject;
Expand Down