Index: test/std/concepts/concepts.lang/concept.commonref/common_reference.pass.cpp =================================================================== --- /dev/null +++ test/std/concepts/concepts.lang/concept.commonref/common_reference.pass.cpp @@ -0,0 +1,173 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// 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, c++17 + +#include +#include +#include + +using std::CommonReference; +using std::void_t; + +template +constexpr bool is_trait = false; +template +constexpr bool is_trait> = true; + +struct X {}; +struct Y { explicit Y(X){} }; + +namespace std +{ + template <> struct common_type { using type = Y; }; + template <> struct common_type { using type = Y; }; +} + +static_assert(std::is_same, int const volatile&>()); +static_assert(std::is_same, float>()); +static_assert(!is_trait>); + +static_assert(std::is_same, int>::value); +static_assert(std::is_same, int>::value); +static_assert(std::is_same, int>::value); +static_assert(std::is_same, int>::value); + +// tricky volatile reference case +static_assert(std::is_same, int>::value); +static_assert(std::is_same, int>::value); +static_assert(std::is_same, int const volatile&&>::value); +static_assert(std::is_same, int const volatile&>()); + +// Array types?? Yup! +static_assert(std::is_same, int const(&)[10]>::value); +static_assert(std::is_same, int const volatile(&)[10]>::value); +static_assert(std::is_same, int *>::value); + +struct X2 {}; +struct Y2 {}; +struct Z2 {}; + +namespace std +{ + template <> + struct common_type + { + using type = Z2; + }; + template <> + struct common_type + { + using type = Z2; + }; +} // namespace std + +template +void test_common_ref() { + static_assert(CommonReference); + static_assert(CommonReference); +} + +template +void test_not_common_ref() { + static_assert(!CommonReference); + static_assert(!CommonReference); +} + +int main() { + test_common_ref(); + test_common_ref(); + test_common_ref(); + test_common_ref(); + test_not_common_ref(); + test_not_common_ref(); + test_common_ref(); + test_common_ref(); + test_common_ref(); + + test_not_common_ref(); + + { + struct AA { + AA() = default; + AA(AA&&) = delete; + AA(AA const&) = delete; + }; + struct BB : AA { }; + + test_common_ref(); + test_common_ref(); + test_not_common_ref(); + } + + { + struct B {}; + struct D : B {}; + + test_common_ref(); + test_common_ref(); + test_common_ref(); + test_common_ref(); + + test_common_ref(); + test_common_ref(); + test_common_ref(); + test_common_ref(); + + test_common_ref(); + test_common_ref(); + test_common_ref(); + test_common_ref(); + + test_common_ref(); + test_common_ref(); + test_common_ref(); + test_common_ref(); + + test_common_ref(); + test_common_ref(); + test_common_ref(); + test_common_ref(); + } + + { + // https://github.com/ericniebler/stl2/issues/338 + struct MyIntRef { MyIntRef(int&); }; + test_common_ref(); + } + + { + struct noncopyable { + noncopyable() = default; + noncopyable(noncopyable&&) = default; + noncopyable& operator=(noncopyable&&) = default; + }; + struct noncopyable2 : noncopyable {}; + + test_not_common_ref(); + test_common_ref(); + test_not_common_ref(); + test_common_ref(); + test_not_common_ref(); + test_common_ref(); + } + + { + static_assert(std::is_same_v>); + test_not_common_ref(); + } + + { + struct B {}; + struct C { C() = default; C(B); C(int); }; + test_common_ref(); + } +} Index: test/std/concepts/concepts.lang/concept.convertibleto/convertible_to.pass.cpp =================================================================== --- /dev/null +++ test/std/concepts/concepts.lang/concept.convertibleto/convertible_to.pass.cpp @@ -0,0 +1,298 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// 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, c++17 + +#include +#include + +template +void test_convertible_to() { + static_assert(std::ConvertibleTo); + static_assert(std::ConvertibleTo); + static_assert(std::ConvertibleTo); + static_assert(std::ConvertibleTo); +} + +template +void test_not_convertible_to() { + static_assert(!std::ConvertibleTo); + static_assert(!std::ConvertibleTo); + static_assert(!std::ConvertibleTo); + static_assert(!std::ConvertibleTo); +} + +using Function = void(); +using ConstFunction = void() const; +using Array = char[1]; + +struct StringType { + StringType(const char*) {} +}; + +class NonCopyable { + NonCopyable(NonCopyable&); +}; + +template +class CannotInstantiate { + enum { X = T::ThisExpressionWillBlowUp }; +}; + +namespace X { + struct A { A() = default; A(int) {} }; + + enum class result { + exact, convertible, unrelated + }; + + result f(A) { + return result::exact; + } + + template T> + result f(T&&) { + return result::convertible; + } + + template + result f(T) { + return result::unrelated; + } +} // unnamed namespace + +int main() { + // void + test_convertible_to(); + test_not_convertible_to(); + test_not_convertible_to(); + test_not_convertible_to(); + test_not_convertible_to(); + test_not_convertible_to(); + test_not_convertible_to(); + test_not_convertible_to(); + test_not_convertible_to(); + test_not_convertible_to(); + + // Function + test_not_convertible_to(); + test_not_convertible_to(); + test_convertible_to(); + test_convertible_to(); + test_convertible_to(); + + static_assert(std::ConvertibleTo); + + test_not_convertible_to(); + test_not_convertible_to(); + test_not_convertible_to(); + test_not_convertible_to(); + test_not_convertible_to(); + + // Function& + test_not_convertible_to(); + test_not_convertible_to(); + test_convertible_to(); + + test_convertible_to(); + test_not_convertible_to(); + test_not_convertible_to(); + test_not_convertible_to(); + test_not_convertible_to(); + test_not_convertible_to(); + + // Function* + test_not_convertible_to(); + test_not_convertible_to(); + test_not_convertible_to(); + test_convertible_to(); + + test_not_convertible_to(); + test_not_convertible_to(); + test_not_convertible_to(); + test_not_convertible_to(); + test_not_convertible_to(); + + // Non-referencable function type + static_assert(!std::ConvertibleTo); + static_assert(!std::ConvertibleTo); + static_assert(!std::ConvertibleTo); + static_assert(!std::ConvertibleTo); + static_assert(!std::ConvertibleTo); + static_assert(!std::ConvertibleTo); + static_assert(!std::ConvertibleTo); + static_assert(!std::ConvertibleTo); + + // Array + test_not_convertible_to(); + test_not_convertible_to(); + test_not_convertible_to(); + test_not_convertible_to(); + test_not_convertible_to(); + + static_assert(!std::ConvertibleTo); + static_assert( std::ConvertibleTo); + static_assert(!std::ConvertibleTo); + + static_assert(!std::ConvertibleTo); + static_assert( std::ConvertibleTo); + static_assert(!std::ConvertibleTo); + static_assert(!std::ConvertibleTo); + + static_assert( std::ConvertibleTo); + static_assert( std::ConvertibleTo); + static_assert( std::ConvertibleTo); + static_assert( std::ConvertibleTo); + static_assert( std::ConvertibleTo); + static_assert(!std::ConvertibleTo); + static_assert(!std::ConvertibleTo); + + test_not_convertible_to(); + test_not_convertible_to(); + + static_assert(std::ConvertibleTo); + static_assert(std::ConvertibleTo); + static_assert(std::ConvertibleTo); + static_assert(std::ConvertibleTo); + + static_assert(!std::ConvertibleTo); + static_assert( std::ConvertibleTo); + + static_assert(!std::ConvertibleTo); + static_assert(!std::ConvertibleTo); + + // Array& + test_not_convertible_to(); + test_not_convertible_to(); + test_not_convertible_to(); + test_not_convertible_to(); + test_not_convertible_to(); + + static_assert( std::ConvertibleTo); + static_assert( std::ConvertibleTo); + static_assert(!std::ConvertibleTo); + static_assert( std::ConvertibleTo); + + test_not_convertible_to(); + test_not_convertible_to(); + + static_assert( std::ConvertibleTo); + static_assert( std::ConvertibleTo); + static_assert(!std::ConvertibleTo); + static_assert( std::ConvertibleTo); + + static_assert(std::ConvertibleTo); + static_assert(std::ConvertibleTo); + + // char + test_not_convertible_to(); + test_not_convertible_to(); + test_not_convertible_to(); + test_not_convertible_to(); + test_not_convertible_to(); + test_not_convertible_to(); + + test_convertible_to(); + + static_assert(!std::ConvertibleTo); + static_assert( std::ConvertibleTo); + static_assert(!std::ConvertibleTo); + static_assert( std::ConvertibleTo); + + test_not_convertible_to(); + + // char& + test_not_convertible_to(); + test_not_convertible_to(); + test_not_convertible_to(); + test_not_convertible_to(); + test_not_convertible_to(); + test_not_convertible_to(); + + test_convertible_to(); + + static_assert( std::ConvertibleTo); + static_assert( std::ConvertibleTo); + static_assert(!std::ConvertibleTo); + static_assert( std::ConvertibleTo); + + test_not_convertible_to(); + + // char* + test_not_convertible_to(); + test_not_convertible_to(); + test_not_convertible_to(); + test_not_convertible_to(); + test_not_convertible_to(); + test_not_convertible_to(); + + test_not_convertible_to(); + test_not_convertible_to(); + + static_assert( std::ConvertibleTo); + static_assert( std::ConvertibleTo); + static_assert(!std::ConvertibleTo); + static_assert( std::ConvertibleTo); + + // NonCopyable + static_assert( std::ConvertibleTo); + static_assert( std::ConvertibleTo); + static_assert( std::ConvertibleTo); + static_assert( std::ConvertibleTo); + static_assert( std::ConvertibleTo); + static_assert( std::ConvertibleTo); + static_assert( std::ConvertibleTo); + static_assert( std::ConvertibleTo); + static_assert(!std::ConvertibleTo); + + test_not_convertible_to(); + + // Ensure that CannotInstantiate is not instantiated by is_convertible when it is not needed. + // For example CannotInstantiate is instatiated as a part of ADL lookup for arguments of type CannotInstantiate*. + static_assert(std::ConvertibleTo*, CannotInstantiate*>); + + { + using namespace X; + assert(f(A{}) == result::exact); + { const A a{}; assert(f(a) == result::exact); } + assert(f(42) == result::convertible); + assert(f("foo") == result::unrelated); + } + + { + struct B {}; + struct D : B {}; + + test_convertible_to(); + test_convertible_to(); + test_convertible_to(); + test_not_convertible_to(); + } + + { + struct Z; + struct X { + X() = default; + explicit X(Z) = delete; + }; + struct Y1 { + operator X() const; + }; + struct Y2 { + explicit operator X() const; + }; + struct Z { + operator X() const; + }; + test_convertible_to(); // Both implicitly and explicitly convertible + test_not_convertible_to(); // Only explicitly convertible + test_not_convertible_to(); // Only implicitly convertible + } +} Index: test/std/concepts/concepts.lang/concept.derivedfrom/derived_from.pass.cpp =================================================================== --- /dev/null +++ test/std/concepts/concepts.lang/concept.derivedfrom/derived_from.pass.cpp @@ -0,0 +1,48 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// 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, c++17 + +#include +#include + +#include "test_macros.h" + +template +void test_derived_from() { + static_assert(std::DerivedFrom); + static_assert(std::DerivedFrom); + static_assert(std::DerivedFrom); + static_assert(std::DerivedFrom); +} + +template +void test_not_derived_from() { + static_assert(!std::DerivedFrom); +} + +struct B {}; +struct B1 : B {}; +struct B2 : B {}; +struct D : private B1, private B2 {}; + +int main() { + test_derived_from(); + test_derived_from(); + test_derived_from(); + + test_not_derived_from(); + test_not_derived_from(); + test_not_derived_from(); + test_not_derived_from(); + test_not_derived_from(); + test_not_derived_from(); + test_not_derived_from(); +} Index: test/std/concepts/concepts.lang/concept.same/same.pass.cpp =================================================================== --- /dev/null +++ test/std/concepts/concepts.lang/concept.same/same.pass.cpp @@ -0,0 +1,75 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// 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, c++17 + +#include +#include + +static_assert(std::Same); +static_assert(std::Same); +static_assert(!std::Same); +static_assert(!std::Same); + +// Test that `Same` subsumes `Same` (with reversed args). +template + requires std::Same +constexpr bool foo() { + return false; +} + +template + requires std::Same && std::is_integral_v +constexpr bool foo() { + return true; +} + +static_assert(!foo()); +static_assert(foo()); + +template +void test_same() { + static_assert( std::Same); + static_assert(!std::Same); + static_assert(!std::Same); + static_assert( std::Same); +} + +template +void test_same_ref() { + static_assert(std::Same); + static_assert(std::Same); + static_assert(std::Same); + static_assert(std::Same); +} + +template +void test_not_same() { + static_assert(!std::Same); +} + +struct Class +{ + ~Class(); +}; + +int main() { + test_same(); + test_same(); + test_same(); + test_same(); + test_same_ref(); + + test_not_same(); + test_not_same(); + test_not_same(); + test_not_same(); + test_not_same(); +} Index: test/std/concepts/lit.local.cfg =================================================================== --- /dev/null +++ test/std/concepts/lit.local.cfg @@ -0,0 +1,9 @@ +# If the compiler doesn't support concepts, mark all of the tests under +# this directory as unsupported. +if 'concepts' not in config.available_features: + config.unsupported = True +elif 'fconcepts' in config.available_features: + # The compiler supports concepts only with the flag - require it. + import copy + config.test_format.cxx = copy.deepcopy(config.test_format.cxx) + config.test_format.cxx.compile_flags += ['-fconcepts']