diff options
author | Howard Hinnant <hhinnant@apple.com> | 2010-08-22 00:59:46 +0000 |
---|---|---|
committer | Howard Hinnant <hhinnant@apple.com> | 2010-08-22 00:59:46 +0000 |
commit | 94b2dd0998230c758abd92c99d3700c971f7a31a (patch) | |
tree | 1b9f66ba0b4f8fd99fc02a112d4b7a30c4afe0f6 /libcxx/test | |
parent | d9c6c0b583ac1f1efeec3db571a1028a3c9b7a99 (diff) | |
download | bcm5719-llvm-94b2dd0998230c758abd92c99d3700c971f7a31a.tar.gz bcm5719-llvm-94b2dd0998230c758abd92c99d3700c971f7a31a.zip |
Fixing whitespace problems
llvm-svn: 111767
Diffstat (limited to 'libcxx/test')
652 files changed, 29155 insertions, 716 deletions
diff --git a/libcxx/test/utilities/date.time/tested_elsewhere.pass.cpp b/libcxx/test/utilities/date.time/tested_elsewhere.pass.cpp index bdb4d3403ce..0e8e2b8f1f9 100644 --- a/libcxx/test/utilities/date.time/tested_elsewhere.pass.cpp +++ b/libcxx/test/utilities/date.time/tested_elsewhere.pass.cpp @@ -1 +1,37 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include <ctime>
#include <type_traits>
#ifndef NULL
#error NULL not defined
#endif
#ifndef CLOCKS_PER_SEC
#error CLOCKS_PER_SEC not defined
#endif
int main()
{
std::clock_t c = 0;
std::size_t s = 0;
std::time_t t = 0;
std::tm tm = {0};
char str[3];
static_assert((std::is_same<decltype(std::clock()), std::clock_t>::value), "");
static_assert((std::is_same<decltype(std::difftime(t,t)), double>::value), "");
static_assert((std::is_same<decltype(std::mktime(&tm)), std::time_t>::value), "");
static_assert((std::is_same<decltype(std::time(&t)), std::time_t>::value), "");
static_assert((std::is_same<decltype(std::asctime(&tm)), char*>::value), "");
static_assert((std::is_same<decltype(std::ctime(&t)), char*>::value), "");
static_assert((std::is_same<decltype(std::gmtime(&t)), std::tm*>::value), "");
static_assert((std::is_same<decltype(std::localtime(&t)), std::tm*>::value), "");
static_assert((std::is_same<decltype(std::strftime(str,s,"",&tm)), std::size_t>::value), "");
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include <ctime> +#include <type_traits> + +#ifndef NULL +#error NULL not defined +#endif + +#ifndef CLOCKS_PER_SEC +#error CLOCKS_PER_SEC not defined +#endif + +int main() +{ + std::clock_t c = 0; + std::size_t s = 0; + std::time_t t = 0; + std::tm tm = {0}; + char str[3]; + static_assert((std::is_same<decltype(std::clock()), std::clock_t>::value), ""); + static_assert((std::is_same<decltype(std::difftime(t,t)), double>::value), ""); + static_assert((std::is_same<decltype(std::mktime(&tm)), std::time_t>::value), ""); + static_assert((std::is_same<decltype(std::time(&t)), std::time_t>::value), ""); + static_assert((std::is_same<decltype(std::asctime(&tm)), char*>::value), ""); + static_assert((std::is_same<decltype(std::ctime(&t)), char*>::value), ""); + static_assert((std::is_same<decltype(std::gmtime(&t)), std::tm*>::value), ""); + static_assert((std::is_same<decltype(std::localtime(&t)), std::tm*>::value), ""); + static_assert((std::is_same<decltype(std::strftime(str,s,"",&tm)), std::size_t>::value), ""); +} diff --git a/libcxx/test/utilities/function.objects/arithmetic.operations/divides.pass.cpp b/libcxx/test/utilities/function.objects/arithmetic.operations/divides.pass.cpp index c8528c2303f..3c19624e754 100644 --- a/libcxx/test/utilities/function.objects/arithmetic.operations/divides.pass.cpp +++ b/libcxx/test/utilities/function.objects/arithmetic.operations/divides.pass.cpp @@ -1 +1,24 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <functional>
// divides
#include <functional>
#include <type_traits>
#include <cassert>
int main()
{
typedef std::divides<int> F;
const F f = F();
static_assert((std::is_base_of<std::binary_function<int, int, int>, F>::value), "");
assert(f(36, 4) == 9);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// divides + +#include <functional> +#include <type_traits> +#include <cassert> + +int main() +{ + typedef std::divides<int> F; + const F f = F(); + static_assert((std::is_base_of<std::binary_function<int, int, int>, F>::value), ""); + assert(f(36, 4) == 9); +} diff --git a/libcxx/test/utilities/function.objects/arithmetic.operations/minus.pass.cpp b/libcxx/test/utilities/function.objects/arithmetic.operations/minus.pass.cpp index e21d03f43ba..11336d113eb 100644 --- a/libcxx/test/utilities/function.objects/arithmetic.operations/minus.pass.cpp +++ b/libcxx/test/utilities/function.objects/arithmetic.operations/minus.pass.cpp @@ -1 +1,24 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <functional>
// minus
#include <functional>
#include <type_traits>
#include <cassert>
int main()
{
typedef std::minus<int> F;
const F f = F();
static_assert((std::is_base_of<std::binary_function<int, int, int>, F>::value), "");
assert(f(3, 2) == 1);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// minus + +#include <functional> +#include <type_traits> +#include <cassert> + +int main() +{ + typedef std::minus<int> F; + const F f = F(); + static_assert((std::is_base_of<std::binary_function<int, int, int>, F>::value), ""); + assert(f(3, 2) == 1); +} diff --git a/libcxx/test/utilities/function.objects/arithmetic.operations/modulus.pass.cpp b/libcxx/test/utilities/function.objects/arithmetic.operations/modulus.pass.cpp index 39315696625..ade0f91c1d7 100644 --- a/libcxx/test/utilities/function.objects/arithmetic.operations/modulus.pass.cpp +++ b/libcxx/test/utilities/function.objects/arithmetic.operations/modulus.pass.cpp @@ -1 +1,24 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <functional>
// modulus
#include <functional>
#include <type_traits>
#include <cassert>
int main()
{
typedef std::modulus<int> F;
const F f = F();
static_assert((std::is_base_of<std::binary_function<int, int, int>, F>::value), "");
assert(f(36, 8) == 4);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// modulus + +#include <functional> +#include <type_traits> +#include <cassert> + +int main() +{ + typedef std::modulus<int> F; + const F f = F(); + static_assert((std::is_base_of<std::binary_function<int, int, int>, F>::value), ""); + assert(f(36, 8) == 4); +} diff --git a/libcxx/test/utilities/function.objects/arithmetic.operations/multiplies.pass.cpp b/libcxx/test/utilities/function.objects/arithmetic.operations/multiplies.pass.cpp index f020cd56194..93dbf4137bc 100644 --- a/libcxx/test/utilities/function.objects/arithmetic.operations/multiplies.pass.cpp +++ b/libcxx/test/utilities/function.objects/arithmetic.operations/multiplies.pass.cpp @@ -1 +1,24 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <functional>
// multiplies
#include <functional>
#include <type_traits>
#include <cassert>
int main()
{
typedef std::multiplies<int> F;
const F f = F();
static_assert((std::is_base_of<std::binary_function<int, int, int>, F>::value), "");
assert(f(3, 2) == 6);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// multiplies + +#include <functional> +#include <type_traits> +#include <cassert> + +int main() +{ + typedef std::multiplies<int> F; + const F f = F(); + static_assert((std::is_base_of<std::binary_function<int, int, int>, F>::value), ""); + assert(f(3, 2) == 6); +} diff --git a/libcxx/test/utilities/function.objects/arithmetic.operations/negate.pass.cpp b/libcxx/test/utilities/function.objects/arithmetic.operations/negate.pass.cpp index 59b56a3c62d..72a90b903f1 100644 --- a/libcxx/test/utilities/function.objects/arithmetic.operations/negate.pass.cpp +++ b/libcxx/test/utilities/function.objects/arithmetic.operations/negate.pass.cpp @@ -1 +1,24 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <functional>
// negate
#include <functional>
#include <type_traits>
#include <cassert>
int main()
{
typedef std::negate<int> F;
const F f = F();
static_assert((std::is_base_of<std::unary_function<int, int>, F>::value), "");
assert(f(36) == -36);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// negate + +#include <functional> +#include <type_traits> +#include <cassert> + +int main() +{ + typedef std::negate<int> F; + const F f = F(); + static_assert((std::is_base_of<std::unary_function<int, int>, F>::value), ""); + assert(f(36) == -36); +} diff --git a/libcxx/test/utilities/function.objects/arithmetic.operations/plus.pass.cpp b/libcxx/test/utilities/function.objects/arithmetic.operations/plus.pass.cpp index 2e922d2d010..40077fe36db 100644 --- a/libcxx/test/utilities/function.objects/arithmetic.operations/plus.pass.cpp +++ b/libcxx/test/utilities/function.objects/arithmetic.operations/plus.pass.cpp @@ -1 +1,24 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <functional>
// plus
#include <functional>
#include <type_traits>
#include <cassert>
int main()
{
typedef std::plus<int> F;
const F f = F();
static_assert((std::is_base_of<std::binary_function<int, int, int>, F>::value), "");
assert(f(3, 2) == 5);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// plus + +#include <functional> +#include <type_traits> +#include <cassert> + +int main() +{ + typedef std::plus<int> F; + const F f = F(); + static_assert((std::is_base_of<std::binary_function<int, int, int>, F>::value), ""); + assert(f(3, 2) == 5); +} diff --git a/libcxx/test/utilities/function.objects/base/nothing_to_do.pass.cpp b/libcxx/test/utilities/function.objects/base/nothing_to_do.pass.cpp index e8db90cbee0..b89f168e9c4 100644 --- a/libcxx/test/utilities/function.objects/base/nothing_to_do.pass.cpp +++ b/libcxx/test/utilities/function.objects/base/nothing_to_do.pass.cpp @@ -1 +1,12 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
int main()
{
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/libcxx/test/utilities/function.objects/bind/func.bind/func.bind.bind/invoke_int_0.pass.cpp b/libcxx/test/utilities/function.objects/bind/func.bind/func.bind.bind/invoke_int_0.pass.cpp index 28ec9d4b123..61211308bba 100644 --- a/libcxx/test/utilities/function.objects/bind/func.bind/func.bind.bind/invoke_int_0.pass.cpp +++ b/libcxx/test/utilities/function.objects/bind/func.bind/func.bind.bind/invoke_int_0.pass.cpp @@ -1 +1,53 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <functional>
// template<CopyConstructible Fn, CopyConstructible... Types>
// unspecified bind(Fn, Types...);
// template<Returnable R, CopyConstructible Fn, CopyConstructible... Types>
// unspecified bind(Fn, Types...);
#include <functional>
#include <cassert>
template <class R, class F>
void
test(F f, R expected)
{
assert(f() == expected);
}
template <class R, class F>
void
test_const(const F& f, R expected)
{
assert(f() == expected);
}
int f() {return 1;}
struct A_int_0
{
int operator()() {return 4;}
int operator()() const {return 5;}
};
int main()
{
test(std::bind(f), 1);
test(std::bind(&f), 1);
test(std::bind(A_int_0()), 4);
test_const(std::bind(A_int_0()), 5);
test(std::bind<int>(f), 1);
test(std::bind<int>(&f), 1);
test(std::bind<int>(A_int_0()), 4);
test_const(std::bind<int>(A_int_0()), 5);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// template<CopyConstructible Fn, CopyConstructible... Types> +// unspecified bind(Fn, Types...); +// template<Returnable R, CopyConstructible Fn, CopyConstructible... Types> +// unspecified bind(Fn, Types...); + +#include <functional> +#include <cassert> + +template <class R, class F> +void +test(F f, R expected) +{ + assert(f() == expected); +} + +template <class R, class F> +void +test_const(const F& f, R expected) +{ + assert(f() == expected); +} + +int f() {return 1;} + +struct A_int_0 +{ + int operator()() {return 4;} + int operator()() const {return 5;} +}; + +int main() +{ + test(std::bind(f), 1); + test(std::bind(&f), 1); + test(std::bind(A_int_0()), 4); + test_const(std::bind(A_int_0()), 5); + + test(std::bind<int>(f), 1); + test(std::bind<int>(&f), 1); + test(std::bind<int>(A_int_0()), 4); + test_const(std::bind<int>(A_int_0()), 5); +} diff --git a/libcxx/test/utilities/function.objects/bind/func.bind/func.bind.bind/invoke_lvalue.pass.cpp b/libcxx/test/utilities/function.objects/bind/func.bind/func.bind.bind/invoke_lvalue.pass.cpp index 84afdea2b8c..3b6f5d44050 100644 --- a/libcxx/test/utilities/function.objects/bind/func.bind/func.bind.bind/invoke_lvalue.pass.cpp +++ b/libcxx/test/utilities/function.objects/bind/func.bind/func.bind.bind/invoke_lvalue.pass.cpp @@ -1 +1,267 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <functional>
// template<CopyConstructible Fn, CopyConstructible... Types>
// unspecified bind(Fn, Types...);
// template<Returnable R, CopyConstructible Fn, CopyConstructible... Types>
// unspecified bind(Fn, Types...);
#include <stdio.h>
#include <functional>
#include <cassert>
int count = 0;
// 1 arg, return void
void f_void_1(int i)
{
count += i;
}
struct A_void_1
{
void operator()(int i)
{
count += i;
}
void mem1() {++count;}
void mem2() const {count += 2;}
};
void
test_void_1()
{
using namespace std::placeholders;
int save_count = count;
// function
{
int i = 2;
std::bind(f_void_1, _1)(i);
assert(count == save_count + 2);
save_count = count;
}
{
int i = 2;
std::bind(f_void_1, i)();
assert(count == save_count + 2);
save_count = count;
}
// function pointer
{
void (*fp)(int) = f_void_1;
int i = 3;
std::bind(fp, _1)(i);
assert(count == save_count+3);
save_count = count;
}
{
void (*fp)(int) = f_void_1;
int i = 3;
std::bind(fp, i)();
assert(count == save_count+3);
save_count = count;
}
// functor
{
A_void_1 a0;
int i = 4;
std::bind(a0, _1)(i);
assert(count == save_count+4);
save_count = count;
}
{
A_void_1 a0;
int i = 4;
std::bind(a0, i)();
assert(count == save_count+4);
save_count = count;
}
// member function pointer
{
void (A_void_1::*fp)() = &A_void_1::mem1;
A_void_1 a;
std::bind(fp, _1)(a);
assert(count == save_count+1);
save_count = count;
A_void_1* ap = &a;
std::bind(fp, _1)(ap);
assert(count == save_count+1);
save_count = count;
}
{
void (A_void_1::*fp)() = &A_void_1::mem1;
A_void_1 a;
std::bind(fp, a)();
assert(count == save_count+1);
save_count = count;
A_void_1* ap = &a;
std::bind(fp, ap)();
assert(count == save_count+1);
save_count = count;
}
// const member function pointer
{
void (A_void_1::*fp)() const = &A_void_1::mem2;
A_void_1 a;
std::bind(fp, _1)(a);
assert(count == save_count+2);
save_count = count;
A_void_1* ap = &a;
std::bind(fp, _1)(ap);
assert(count == save_count+2);
save_count = count;
}
{
void (A_void_1::*fp)() const = &A_void_1::mem2;
A_void_1 a;
std::bind(fp, a)();
assert(count == save_count+2);
save_count = count;
A_void_1* ap = &a;
std::bind(fp, ap)();
assert(count == save_count+2);
save_count = count;
}
}
// 1 arg, return int
int f_int_1(int i)
{
return i + 1;
}
struct A_int_1
{
A_int_1() : data_(5) {}
int operator()(int i)
{
return i - 1;
}
int mem1() {return 3;}
int mem2() const {return 4;}
int data_;
};
void
test_int_1()
{
using namespace std::placeholders;
// function
{
int i = 2;
assert(std::bind(f_int_1, _1)(i) == 3);
assert(std::bind(f_int_1, i)() == 3);
}
// function pointer
{
int (*fp)(int) = f_int_1;
int i = 3;
assert(std::bind(fp, _1)(i) == 4);
assert(std::bind(fp, i)() == 4);
}
// functor
{
int i = 4;
assert(std::bind(A_int_1(), _1)(i) == 3);
assert(std::bind(A_int_1(), i)() == 3);
}
// member function pointer
{
A_int_1 a;
assert(std::bind(&A_int_1::mem1, _1)(a) == 3);
assert(std::bind(&A_int_1::mem1, a)() == 3);
A_int_1* ap = &a;
assert(std::bind(&A_int_1::mem1, _1)(ap) == 3);
assert(std::bind(&A_int_1::mem1, ap)() == 3);
}
// const member function pointer
{
A_int_1 a;
assert(std::bind(&A_int_1::mem2, _1)(A_int_1()) == 4);
assert(std::bind(&A_int_1::mem2, A_int_1())() == 4);
A_int_1* ap = &a;
assert(std::bind(&A_int_1::mem2, _1)(ap) == 4);
assert(std::bind(&A_int_1::mem2, ap)() == 4);
}
// member data pointer
{
A_int_1 a;
assert(std::bind(&A_int_1::data_, _1)(a) == 5);
assert(std::bind(&A_int_1::data_, a)() == 5);
A_int_1* ap = &a;
assert(std::bind(&A_int_1::data_, _1)(a) == 5);
std::bind(&A_int_1::data_, _1)(a) = 6;
assert(std::bind(&A_int_1::data_, _1)(a) == 6);
assert(std::bind(&A_int_1::data_, _1)(ap) == 6);
std::bind(&A_int_1::data_, _1)(ap) = 7;
assert(std::bind(&A_int_1::data_, _1)(ap) == 7);
}
}
// 2 arg, return void
void f_void_2(int i, int j)
{
count += i+j;
}
struct A_void_2
{
void operator()(int i, int j)
{
count += i+j;
}
void mem1(int i) {count += i;}
void mem2(int i) const {count += i;}
};
void
test_void_2()
{
using namespace std::placeholders;
int save_count = count;
// function
{
int i = 2;
int j = 3;
std::bind(f_void_2, _1, _2)(i, j);
assert(count == save_count+5);
save_count = count;
std::bind(f_void_2, i, _1)(j);
assert(count == save_count+5);
save_count = count;
std::bind(f_void_2, i, j)();
assert(count == save_count+5);
save_count = count;
}
// member function pointer
{
int j = 3;
std::bind(&A_void_2::mem1, _1, _2)(A_void_2(), j);
assert(count == save_count+3);
save_count = count;
std::bind(&A_void_2::mem1, _2, _1)(j, A_void_2());
assert(count == save_count+3);
save_count = count;
}
}
int main()
{
test_void_1();
test_int_1();
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// template<CopyConstructible Fn, CopyConstructible... Types> +// unspecified bind(Fn, Types...); +// template<Returnable R, CopyConstructible Fn, CopyConstructible... Types> +// unspecified bind(Fn, Types...); + +#include <stdio.h> + +#include <functional> +#include <cassert> + +int count = 0; + +// 1 arg, return void + +void f_void_1(int i) +{ + count += i; +} + +struct A_void_1 +{ + void operator()(int i) + { + count += i; + } + + void mem1() {++count;} + void mem2() const {count += 2;} +}; + +void +test_void_1() +{ + using namespace std::placeholders; + int save_count = count; + // function + { + int i = 2; + std::bind(f_void_1, _1)(i); + assert(count == save_count + 2); + save_count = count; + } + { + int i = 2; + std::bind(f_void_1, i)(); + assert(count == save_count + 2); + save_count = count; + } + // function pointer + { + void (*fp)(int) = f_void_1; + int i = 3; + std::bind(fp, _1)(i); + assert(count == save_count+3); + save_count = count; + } + { + void (*fp)(int) = f_void_1; + int i = 3; + std::bind(fp, i)(); + assert(count == save_count+3); + save_count = count; + } + // functor + { + A_void_1 a0; + int i = 4; + std::bind(a0, _1)(i); + assert(count == save_count+4); + save_count = count; + } + { + A_void_1 a0; + int i = 4; + std::bind(a0, i)(); + assert(count == save_count+4); + save_count = count; + } + // member function pointer + { + void (A_void_1::*fp)() = &A_void_1::mem1; + A_void_1 a; + std::bind(fp, _1)(a); + assert(count == save_count+1); + save_count = count; + A_void_1* ap = &a; + std::bind(fp, _1)(ap); + assert(count == save_count+1); + save_count = count; + } + { + void (A_void_1::*fp)() = &A_void_1::mem1; + A_void_1 a; + std::bind(fp, a)(); + assert(count == save_count+1); + save_count = count; + A_void_1* ap = &a; + std::bind(fp, ap)(); + assert(count == save_count+1); + save_count = count; + } + // const member function pointer + { + void (A_void_1::*fp)() const = &A_void_1::mem2; + A_void_1 a; + std::bind(fp, _1)(a); + assert(count == save_count+2); + save_count = count; + A_void_1* ap = &a; + std::bind(fp, _1)(ap); + assert(count == save_count+2); + save_count = count; + } + { + void (A_void_1::*fp)() const = &A_void_1::mem2; + A_void_1 a; + std::bind(fp, a)(); + assert(count == save_count+2); + save_count = count; + A_void_1* ap = &a; + std::bind(fp, ap)(); + assert(count == save_count+2); + save_count = count; + } +} + +// 1 arg, return int + +int f_int_1(int i) +{ + return i + 1; +} + +struct A_int_1 +{ + A_int_1() : data_(5) {} + int operator()(int i) + { + return i - 1; + } + + int mem1() {return 3;} + int mem2() const {return 4;} + int data_; +}; + +void +test_int_1() +{ + using namespace std::placeholders; + // function + { + int i = 2; + assert(std::bind(f_int_1, _1)(i) == 3); + assert(std::bind(f_int_1, i)() == 3); + } + // function pointer + { + int (*fp)(int) = f_int_1; + int i = 3; + assert(std::bind(fp, _1)(i) == 4); + assert(std::bind(fp, i)() == 4); + } + // functor + { + int i = 4; + assert(std::bind(A_int_1(), _1)(i) == 3); + assert(std::bind(A_int_1(), i)() == 3); + } + // member function pointer + { + A_int_1 a; + assert(std::bind(&A_int_1::mem1, _1)(a) == 3); + assert(std::bind(&A_int_1::mem1, a)() == 3); + A_int_1* ap = &a; + assert(std::bind(&A_int_1::mem1, _1)(ap) == 3); + assert(std::bind(&A_int_1::mem1, ap)() == 3); + } + // const member function pointer + { + A_int_1 a; + assert(std::bind(&A_int_1::mem2, _1)(A_int_1()) == 4); + assert(std::bind(&A_int_1::mem2, A_int_1())() == 4); + A_int_1* ap = &a; + assert(std::bind(&A_int_1::mem2, _1)(ap) == 4); + assert(std::bind(&A_int_1::mem2, ap)() == 4); + } + // member data pointer + { + A_int_1 a; + assert(std::bind(&A_int_1::data_, _1)(a) == 5); + assert(std::bind(&A_int_1::data_, a)() == 5); + A_int_1* ap = &a; + assert(std::bind(&A_int_1::data_, _1)(a) == 5); + std::bind(&A_int_1::data_, _1)(a) = 6; + assert(std::bind(&A_int_1::data_, _1)(a) == 6); + assert(std::bind(&A_int_1::data_, _1)(ap) == 6); + std::bind(&A_int_1::data_, _1)(ap) = 7; + assert(std::bind(&A_int_1::data_, _1)(ap) == 7); + } +} + +// 2 arg, return void + +void f_void_2(int i, int j) +{ + count += i+j; +} + +struct A_void_2 +{ + void operator()(int i, int j) + { + count += i+j; + } + + void mem1(int i) {count += i;} + void mem2(int i) const {count += i;} +}; + +void +test_void_2() +{ + using namespace std::placeholders; + int save_count = count; + // function + { + int i = 2; + int j = 3; + std::bind(f_void_2, _1, _2)(i, j); + assert(count == save_count+5); + save_count = count; + std::bind(f_void_2, i, _1)(j); + assert(count == save_count+5); + save_count = count; + std::bind(f_void_2, i, j)(); + assert(count == save_count+5); + save_count = count; + } + // member function pointer + { + int j = 3; + std::bind(&A_void_2::mem1, _1, _2)(A_void_2(), j); + assert(count == save_count+3); + save_count = count; + std::bind(&A_void_2::mem1, _2, _1)(j, A_void_2()); + assert(count == save_count+3); + save_count = count; + } +} + +int main() +{ + test_void_1(); + test_int_1(); +} diff --git a/libcxx/test/utilities/function.objects/bind/func.bind/func.bind.bind/invoke_rvalue.pass.cpp b/libcxx/test/utilities/function.objects/bind/func.bind/func.bind.bind/invoke_rvalue.pass.cpp index 508caee69c6..365b38e87ec 100644 --- a/libcxx/test/utilities/function.objects/bind/func.bind/func.bind.bind/invoke_rvalue.pass.cpp +++ b/libcxx/test/utilities/function.objects/bind/func.bind/func.bind.bind/invoke_rvalue.pass.cpp @@ -1 +1,248 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <functional>
// template<CopyConstructible Fn, CopyConstructible... Types>
// unspecified bind(Fn, Types...);
// template<Returnable R, CopyConstructible Fn, CopyConstructible... Types>
// unspecified bind(Fn, Types...);
#include <stdio.h>
#include <functional>
#include <cassert>
int count = 0;
// 1 arg, return void
void f_void_1(int i)
{
count += i;
}
struct A_void_1
{
void operator()(int i)
{
count += i;
}
void mem1() {++count;}
void mem2() const {count += 2;}
};
void
test_void_1()
{
using namespace std::placeholders;
int save_count = count;
// function
{
std::bind(f_void_1, _1)(2);
assert(count == save_count + 2);
save_count = count;
}
{
std::bind(f_void_1, 2)();
assert(count == save_count + 2);
save_count = count;
}
// function pointer
{
void (*fp)(int) = f_void_1;
std::bind(fp, _1)(3);
assert(count == save_count+3);
save_count = count;
}
{
void (*fp)(int) = f_void_1;
std::bind(fp, 3)();
assert(count == save_count+3);
save_count = count;
}
// functor
{
A_void_1 a0;
std::bind(a0, _1)(4);
assert(count == save_count+4);
save_count = count;
}
{
A_void_1 a0;
std::bind(a0, 4)();
assert(count == save_count+4);
save_count = count;
}
// member function pointer
{
void (A_void_1::*fp)() = &A_void_1::mem1;
std::bind(fp, _1)(A_void_1());
assert(count == save_count+1);
save_count = count;
A_void_1 a;
std::bind(fp, _1)(&a);
assert(count == save_count+1);
save_count = count;
}
{
void (A_void_1::*fp)() = &A_void_1::mem1;
std::bind(fp, A_void_1())();
assert(count == save_count+1);
save_count = count;
A_void_1 a;
std::bind(fp, &a)();
assert(count == save_count+1);
save_count = count;
}
// const member function pointer
{
void (A_void_1::*fp)() const = &A_void_1::mem2;
std::bind(fp, _1)(A_void_1());
assert(count == save_count+2);
save_count = count;
A_void_1 a;
std::bind(fp, _1)(&a);
assert(count == save_count+2);
save_count = count;
}
{
void (A_void_1::*fp)() const = &A_void_1::mem2;
std::bind(fp, A_void_1())();
assert(count == save_count+2);
save_count = count;
A_void_1 a;
std::bind(fp, &a)();
assert(count == save_count+2);
save_count = count;
}
}
// 1 arg, return int
int f_int_1(int i)
{
return i + 1;
}
struct A_int_1
{
A_int_1() : data_(5) {}
int operator()(int i)
{
return i - 1;
}
int mem1() {return 3;}
int mem2() const {return 4;}
int data_;
};
void
test_int_1()
{
using namespace std::placeholders;
// function
{
assert(std::bind(f_int_1, _1)(2) == 3);
assert(std::bind(f_int_1, 2)() == 3);
}
// function pointer
{
int (*fp)(int) = f_int_1;
assert(std::bind(fp, _1)(3) == 4);
assert(std::bind(fp, 3)() == 4);
}
// functor
{
assert(std::bind(A_int_1(), _1)(4) == 3);
assert(std::bind(A_int_1(), 4)() == 3);
}
// member function pointer
{
assert(std::bind(&A_int_1::mem1, _1)(A_int_1()) == 3);
assert(std::bind(&A_int_1::mem1, A_int_1())() == 3);
A_int_1 a;
assert(std::bind(&A_int_1::mem1, _1)(&a) == 3);
assert(std::bind(&A_int_1::mem1, &a)() == 3);
}
// const member function pointer
{
assert(std::bind(&A_int_1::mem2, _1)(A_int_1()) == 4);
assert(std::bind(&A_int_1::mem2, A_int_1())() == 4);
A_int_1 a;
assert(std::bind(&A_int_1::mem2, _1)(&a) == 4);
assert(std::bind(&A_int_1::mem2, &a)() == 4);
}
// member data pointer
{
assert(std::bind(&A_int_1::data_, _1)(A_int_1()) == 5);
assert(std::bind(&A_int_1::data_, A_int_1())() == 5);
A_int_1 a;
assert(std::bind(&A_int_1::data_, _1)(a) == 5);
std::bind(&A_int_1::data_, _1)(a) = 6;
assert(std::bind(&A_int_1::data_, _1)(a) == 6);
assert(std::bind(&A_int_1::data_, _1)(&a) == 6);
std::bind(&A_int_1::data_, _1)(&a) = 7;
assert(std::bind(&A_int_1::data_, _1)(&a) == 7);
}
}
// 2 arg, return void
void f_void_2(int i, int j)
{
count += i+j;
}
struct A_void_2
{
void operator()(int i, int j)
{
count += i+j;
}
void mem1(int i) {count += i;}
void mem2(int i) const {count += i;}
};
void
test_void_2()
{
using namespace std::placeholders;
int save_count = count;
// function
{
std::bind(f_void_2, _1, _2)(2, 3);
assert(count == save_count+5);
save_count = count;
std::bind(f_void_2, 2, _1)(3);
assert(count == save_count+5);
save_count = count;
std::bind(f_void_2, 2, 3)();
assert(count == save_count+5);
save_count = count;
}
// member function pointer
{
std::bind(&A_void_2::mem1, _1, _2)(A_void_2(), 3);
assert(count == save_count+3);
save_count = count;
std::bind(&A_void_2::mem1, _2, _1)(3, A_void_2());
assert(count == save_count+3);
save_count = count;
}
}
int main()
{
test_void_1();
test_int_1();
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// template<CopyConstructible Fn, CopyConstructible... Types> +// unspecified bind(Fn, Types...); +// template<Returnable R, CopyConstructible Fn, CopyConstructible... Types> +// unspecified bind(Fn, Types...); + +#include <stdio.h> + +#include <functional> +#include <cassert> + +int count = 0; + +// 1 arg, return void + +void f_void_1(int i) +{ + count += i; +} + +struct A_void_1 +{ + void operator()(int i) + { + count += i; + } + + void mem1() {++count;} + void mem2() const {count += 2;} +}; + +void +test_void_1() +{ + using namespace std::placeholders; + int save_count = count; + // function + { + std::bind(f_void_1, _1)(2); + assert(count == save_count + 2); + save_count = count; + } + { + std::bind(f_void_1, 2)(); + assert(count == save_count + 2); + save_count = count; + } + // function pointer + { + void (*fp)(int) = f_void_1; + std::bind(fp, _1)(3); + assert(count == save_count+3); + save_count = count; + } + { + void (*fp)(int) = f_void_1; + std::bind(fp, 3)(); + assert(count == save_count+3); + save_count = count; + } + // functor + { + A_void_1 a0; + std::bind(a0, _1)(4); + assert(count == save_count+4); + save_count = count; + } + { + A_void_1 a0; + std::bind(a0, 4)(); + assert(count == save_count+4); + save_count = count; + } + // member function pointer + { + void (A_void_1::*fp)() = &A_void_1::mem1; + std::bind(fp, _1)(A_void_1()); + assert(count == save_count+1); + save_count = count; + A_void_1 a; + std::bind(fp, _1)(&a); + assert(count == save_count+1); + save_count = count; + } + { + void (A_void_1::*fp)() = &A_void_1::mem1; + std::bind(fp, A_void_1())(); + assert(count == save_count+1); + save_count = count; + A_void_1 a; + std::bind(fp, &a)(); + assert(count == save_count+1); + save_count = count; + } + // const member function pointer + { + void (A_void_1::*fp)() const = &A_void_1::mem2; + std::bind(fp, _1)(A_void_1()); + assert(count == save_count+2); + save_count = count; + A_void_1 a; + std::bind(fp, _1)(&a); + assert(count == save_count+2); + save_count = count; + } + { + void (A_void_1::*fp)() const = &A_void_1::mem2; + std::bind(fp, A_void_1())(); + assert(count == save_count+2); + save_count = count; + A_void_1 a; + std::bind(fp, &a)(); + assert(count == save_count+2); + save_count = count; + } +} + +// 1 arg, return int + +int f_int_1(int i) +{ + return i + 1; +} + +struct A_int_1 +{ + A_int_1() : data_(5) {} + int operator()(int i) + { + return i - 1; + } + + int mem1() {return 3;} + int mem2() const {return 4;} + int data_; +}; + +void +test_int_1() +{ + using namespace std::placeholders; + // function + { + assert(std::bind(f_int_1, _1)(2) == 3); + assert(std::bind(f_int_1, 2)() == 3); + } + // function pointer + { + int (*fp)(int) = f_int_1; + assert(std::bind(fp, _1)(3) == 4); + assert(std::bind(fp, 3)() == 4); + } + // functor + { + assert(std::bind(A_int_1(), _1)(4) == 3); + assert(std::bind(A_int_1(), 4)() == 3); + } + // member function pointer + { + assert(std::bind(&A_int_1::mem1, _1)(A_int_1()) == 3); + assert(std::bind(&A_int_1::mem1, A_int_1())() == 3); + A_int_1 a; + assert(std::bind(&A_int_1::mem1, _1)(&a) == 3); + assert(std::bind(&A_int_1::mem1, &a)() == 3); + } + // const member function pointer + { + assert(std::bind(&A_int_1::mem2, _1)(A_int_1()) == 4); + assert(std::bind(&A_int_1::mem2, A_int_1())() == 4); + A_int_1 a; + assert(std::bind(&A_int_1::mem2, _1)(&a) == 4); + assert(std::bind(&A_int_1::mem2, &a)() == 4); + } + // member data pointer + { + assert(std::bind(&A_int_1::data_, _1)(A_int_1()) == 5); + assert(std::bind(&A_int_1::data_, A_int_1())() == 5); + A_int_1 a; + assert(std::bind(&A_int_1::data_, _1)(a) == 5); + std::bind(&A_int_1::data_, _1)(a) = 6; + assert(std::bind(&A_int_1::data_, _1)(a) == 6); + assert(std::bind(&A_int_1::data_, _1)(&a) == 6); + std::bind(&A_int_1::data_, _1)(&a) = 7; + assert(std::bind(&A_int_1::data_, _1)(&a) == 7); + } +} + +// 2 arg, return void + +void f_void_2(int i, int j) +{ + count += i+j; +} + +struct A_void_2 +{ + void operator()(int i, int j) + { + count += i+j; + } + + void mem1(int i) {count += i;} + void mem2(int i) const {count += i;} +}; + +void +test_void_2() +{ + using namespace std::placeholders; + int save_count = count; + // function + { + std::bind(f_void_2, _1, _2)(2, 3); + assert(count == save_count+5); + save_count = count; + std::bind(f_void_2, 2, _1)(3); + assert(count == save_count+5); + save_count = count; + std::bind(f_void_2, 2, 3)(); + assert(count == save_count+5); + save_count = count; + } + // member function pointer + { + std::bind(&A_void_2::mem1, _1, _2)(A_void_2(), 3); + assert(count == save_count+3); + save_count = count; + std::bind(&A_void_2::mem1, _2, _1)(3, A_void_2()); + assert(count == save_count+3); + save_count = count; + } +} + +int main() +{ + test_void_1(); + test_int_1(); +} diff --git a/libcxx/test/utilities/function.objects/bind/func.bind/func.bind.bind/invoke_void_0.pass.cpp b/libcxx/test/utilities/function.objects/bind/func.bind/func.bind.bind/invoke_void_0.pass.cpp index d9d7e94df14..f84d1bf1825 100644 --- a/libcxx/test/utilities/function.objects/bind/func.bind/func.bind.bind/invoke_void_0.pass.cpp +++ b/libcxx/test/utilities/function.objects/bind/func.bind/func.bind.bind/invoke_void_0.pass.cpp @@ -1 +1,59 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <functional>
// template<CopyConstructible Fn, CopyConstructible... Types>
// unspecified bind(Fn, Types...);
// template<Returnable R, CopyConstructible Fn, CopyConstructible... Types>
// unspecified bind(Fn, Types...);
#include <functional>
#include <cassert>
int count = 0;
template <class F>
void
test(F f)
{
int save_count = count;
f();
assert(count == save_count + 1);
}
template <class F>
void
test_const(const F& f)
{
int save_count = count;
f();
assert(count == save_count + 2);
}
void f() {++count;}
struct A_int_0
{
void operator()() {++count;}
void operator()() const {count += 2;}
};
int main()
{
test(std::bind(f));
test(std::bind(&f));
test(std::bind(A_int_0()));
test_const(std::bind(A_int_0()));
test(std::bind<void>(f));
test(std::bind<void>(&f));
test(std::bind<void>(A_int_0()));
test_const(std::bind<void>(A_int_0()));
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// template<CopyConstructible Fn, CopyConstructible... Types> +// unspecified bind(Fn, Types...); +// template<Returnable R, CopyConstructible Fn, CopyConstructible... Types> +// unspecified bind(Fn, Types...); + +#include <functional> +#include <cassert> + +int count = 0; + +template <class F> +void +test(F f) +{ + int save_count = count; + f(); + assert(count == save_count + 1); +} + +template <class F> +void +test_const(const F& f) +{ + int save_count = count; + f(); + assert(count == save_count + 2); +} + +void f() {++count;} + +struct A_int_0 +{ + void operator()() {++count;} + void operator()() const {count += 2;} +}; + +int main() +{ + test(std::bind(f)); + test(std::bind(&f)); + test(std::bind(A_int_0())); + test_const(std::bind(A_int_0())); + + test(std::bind<void>(f)); + test(std::bind<void>(&f)); + test(std::bind<void>(A_int_0())); + test_const(std::bind<void>(A_int_0())); +} diff --git a/libcxx/test/utilities/function.objects/bind/func.bind/func.bind.isbind/is_bind_expression.pass.cpp b/libcxx/test/utilities/function.objects/bind/func.bind/func.bind.isbind/is_bind_expression.pass.cpp index 54c44a66654..a572a6f6164 100644 --- a/libcxx/test/utilities/function.objects/bind/func.bind/func.bind.isbind/is_bind_expression.pass.cpp +++ b/libcxx/test/utilities/function.objects/bind/func.bind/func.bind.isbind/is_bind_expression.pass.cpp @@ -1 +1,32 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <functional>
// template<class T> struct is_bind_expression
#include <functional>
template <bool Expected, class T>
void
test(const T&)
{
static_assert(std::is_bind_expression<T>::value == Expected, "");
}
struct C {};
int main()
{
test<true>(std::bind(C()));
test<true>(std::bind(C(), std::placeholders::_2));
test<true>(std::bind<int>(C()));
test<false>(1);
test<false>(std::placeholders::_2);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// template<class T> struct is_bind_expression + +#include <functional> + +template <bool Expected, class T> +void +test(const T&) +{ + static_assert(std::is_bind_expression<T>::value == Expected, ""); +} + +struct C {}; + +int main() +{ + test<true>(std::bind(C())); + test<true>(std::bind(C(), std::placeholders::_2)); + test<true>(std::bind<int>(C())); + test<false>(1); + test<false>(std::placeholders::_2); +} diff --git a/libcxx/test/utilities/function.objects/bind/func.bind/func.bind.isbind/is_placeholder.pass.cpp b/libcxx/test/utilities/function.objects/bind/func.bind/func.bind.isbind/is_placeholder.pass.cpp index 93fca7be258..a3f9ce5a349 100644 --- a/libcxx/test/utilities/function.objects/bind/func.bind/func.bind.isbind/is_placeholder.pass.cpp +++ b/libcxx/test/utilities/function.objects/bind/func.bind/func.bind.isbind/is_placeholder.pass.cpp @@ -1 +1,41 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <functional>
// struct is_placeholder
#include <functional>
template <int Expected, class T>
void
test(const T&)
{
static_assert(std::is_placeholder<T>::value == Expected, "");
}
struct C {};
int main()
{
test<1>(std::placeholders::_1);
test<2>(std::placeholders::_2);
test<3>(std::placeholders::_3);
test<4>(std::placeholders::_4);
test<5>(std::placeholders::_5);
test<6>(std::placeholders::_6);
test<7>(std::placeholders::_7);
test<8>(std::placeholders::_8);
test<9>(std::placeholders::_9);
test<10>(std::placeholders::_10);
test<0>(4);
test<0>(5.5);
test<0>('a');
test<0>(C());
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// struct is_placeholder + +#include <functional> + +template <int Expected, class T> +void +test(const T&) +{ + static_assert(std::is_placeholder<T>::value == Expected, ""); +} + +struct C {}; + +int main() +{ + test<1>(std::placeholders::_1); + test<2>(std::placeholders::_2); + test<3>(std::placeholders::_3); + test<4>(std::placeholders::_4); + test<5>(std::placeholders::_5); + test<6>(std::placeholders::_6); + test<7>(std::placeholders::_7); + test<8>(std::placeholders::_8); + test<9>(std::placeholders::_9); + test<10>(std::placeholders::_10); + test<0>(4); + test<0>(5.5); + test<0>('a'); + test<0>(C()); +} diff --git a/libcxx/test/utilities/function.objects/bind/func.bind/func.bind.place/placeholders.pass.cpp b/libcxx/test/utilities/function.objects/bind/func.bind/func.bind.place/placeholders.pass.cpp index 0414f62c88e..182d613f0fa 100644 --- a/libcxx/test/utilities/function.objects/bind/func.bind/func.bind.place/placeholders.pass.cpp +++ b/libcxx/test/utilities/function.objects/bind/func.bind/func.bind.place/placeholders.pass.cpp @@ -1 +1,36 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <functional>
// placeholders
#include <functional>
template <class T>
void
test(const T& t)
{
T t2;
T t3 = t;
}
int main()
{
test(std::placeholders::_1);
test(std::placeholders::_2);
test(std::placeholders::_3);
test(std::placeholders::_4);
test(std::placeholders::_5);
test(std::placeholders::_6);
test(std::placeholders::_7);
test(std::placeholders::_8);
test(std::placeholders::_9);
test(std::placeholders::_10);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// placeholders + +#include <functional> + +template <class T> +void +test(const T& t) +{ + T t2; + T t3 = t; +} + +int main() +{ + test(std::placeholders::_1); + test(std::placeholders::_2); + test(std::placeholders::_3); + test(std::placeholders::_4); + test(std::placeholders::_5); + test(std::placeholders::_6); + test(std::placeholders::_7); + test(std::placeholders::_8); + test(std::placeholders::_9); + test(std::placeholders::_10); +} diff --git a/libcxx/test/utilities/function.objects/bind/func.bind/nothing_to_do.pass.cpp b/libcxx/test/utilities/function.objects/bind/func.bind/nothing_to_do.pass.cpp index e8db90cbee0..b89f168e9c4 100644 --- a/libcxx/test/utilities/function.objects/bind/func.bind/nothing_to_do.pass.cpp +++ b/libcxx/test/utilities/function.objects/bind/func.bind/nothing_to_do.pass.cpp @@ -1 +1,12 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
int main()
{
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/libcxx/test/utilities/function.objects/bind/nothing_to_do.pass.cpp b/libcxx/test/utilities/function.objects/bind/nothing_to_do.pass.cpp index e8db90cbee0..b89f168e9c4 100644 --- a/libcxx/test/utilities/function.objects/bind/nothing_to_do.pass.cpp +++ b/libcxx/test/utilities/function.objects/bind/nothing_to_do.pass.cpp @@ -1 +1,12 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
int main()
{
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/libcxx/test/utilities/function.objects/bitwise.operations/bit_and.pass.cpp b/libcxx/test/utilities/function.objects/bitwise.operations/bit_and.pass.cpp index b334dac7f47..95b19b8ceb5 100644 --- a/libcxx/test/utilities/function.objects/bitwise.operations/bit_and.pass.cpp +++ b/libcxx/test/utilities/function.objects/bitwise.operations/bit_and.pass.cpp @@ -1 +1,28 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <functional>
// bit_and
#include <functional>
#include <type_traits>
#include <cassert>
int main()
{
typedef std::bit_and<int> F;
const F f = F();
static_assert((std::is_base_of<std::binary_function<int, int, int>, F>::value), "");
assert(f(0xEA95, 0xEA95) == 0xEA95);
assert(f(0xEA95, 0x58D3) == 0x4891);
assert(f(0x58D3, 0xEA95) == 0x4891);
assert(f(0x58D3, 0) == 0);
assert(f(0xFFFF, 0x58D3) == 0x58D3);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// bit_and + +#include <functional> +#include <type_traits> +#include <cassert> + +int main() +{ + typedef std::bit_and<int> F; + const F f = F(); + static_assert((std::is_base_of<std::binary_function<int, int, int>, F>::value), ""); + assert(f(0xEA95, 0xEA95) == 0xEA95); + assert(f(0xEA95, 0x58D3) == 0x4891); + assert(f(0x58D3, 0xEA95) == 0x4891); + assert(f(0x58D3, 0) == 0); + assert(f(0xFFFF, 0x58D3) == 0x58D3); +} diff --git a/libcxx/test/utilities/function.objects/bitwise.operations/bit_or.pass.cpp b/libcxx/test/utilities/function.objects/bitwise.operations/bit_or.pass.cpp index 227863b481e..70a2aa07042 100644 --- a/libcxx/test/utilities/function.objects/bitwise.operations/bit_or.pass.cpp +++ b/libcxx/test/utilities/function.objects/bitwise.operations/bit_or.pass.cpp @@ -1 +1,28 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <functional>
// bit_or
#include <functional>
#include <type_traits>
#include <cassert>
int main()
{
typedef std::bit_or<int> F;
const F f = F();
static_assert((std::is_base_of<std::binary_function<int, int, int>, F>::value), "");
assert(f(0xEA95, 0xEA95) == 0xEA95);
assert(f(0xEA95, 0x58D3) == 0xFAD7);
assert(f(0x58D3, 0xEA95) == 0xFAD7);
assert(f(0x58D3, 0) == 0x58D3);
assert(f(0xFFFF, 0x58D3) == 0xFFFF);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// bit_or + +#include <functional> +#include <type_traits> +#include <cassert> + +int main() +{ + typedef std::bit_or<int> F; + const F f = F(); + static_assert((std::is_base_of<std::binary_function<int, int, int>, F>::value), ""); + assert(f(0xEA95, 0xEA95) == 0xEA95); + assert(f(0xEA95, 0x58D3) == 0xFAD7); + assert(f(0x58D3, 0xEA95) == 0xFAD7); + assert(f(0x58D3, 0) == 0x58D3); + assert(f(0xFFFF, 0x58D3) == 0xFFFF); +} diff --git a/libcxx/test/utilities/function.objects/bitwise.operations/bit_xor.pass.cpp b/libcxx/test/utilities/function.objects/bitwise.operations/bit_xor.pass.cpp index 657498f69fb..205cca0eb73 100644 --- a/libcxx/test/utilities/function.objects/bitwise.operations/bit_xor.pass.cpp +++ b/libcxx/test/utilities/function.objects/bitwise.operations/bit_xor.pass.cpp @@ -1 +1,28 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <functional>
// bit_xor
#include <functional>
#include <type_traits>
#include <cassert>
int main()
{
typedef std::bit_xor<int> F;
const F f = F();
static_assert((std::is_base_of<std::binary_function<int, int, int>, F>::value), "");
assert(f(0xEA95, 0xEA95) == 0);
assert(f(0xEA95, 0x58D3) == 0xB246);
assert(f(0x58D3, 0xEA95) == 0xB246);
assert(f(0x58D3, 0) == 0x58D3);
assert(f(0xFFFF, 0x58D3) == 0xA72C);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// bit_xor + +#include <functional> +#include <type_traits> +#include <cassert> + +int main() +{ + typedef std::bit_xor<int> F; + const F f = F(); + static_assert((std::is_base_of<std::binary_function<int, int, int>, F>::value), ""); + assert(f(0xEA95, 0xEA95) == 0); + assert(f(0xEA95, 0x58D3) == 0xB246); + assert(f(0x58D3, 0xEA95) == 0xB246); + assert(f(0x58D3, 0) == 0x58D3); + assert(f(0xFFFF, 0x58D3) == 0xA72C); +} diff --git a/libcxx/test/utilities/function.objects/comparisons/equal_to.pass.cpp b/libcxx/test/utilities/function.objects/comparisons/equal_to.pass.cpp index 282d410219f..fb856863c6b 100644 --- a/libcxx/test/utilities/function.objects/comparisons/equal_to.pass.cpp +++ b/libcxx/test/utilities/function.objects/comparisons/equal_to.pass.cpp @@ -1 +1,25 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <functional>
// equal_to
#include <functional>
#include <type_traits>
#include <cassert>
int main()
{
typedef std::equal_to<int> F;
const F f = F();
static_assert((std::is_base_of<std::binary_function<int, int, bool>, F>::value), "");
assert(f(36, 36));
assert(!f(36, 6));
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// equal_to + +#include <functional> +#include <type_traits> +#include <cassert> + +int main() +{ + typedef std::equal_to<int> F; + const F f = F(); + static_assert((std::is_base_of<std::binary_function<int, int, bool>, F>::value), ""); + assert(f(36, 36)); + assert(!f(36, 6)); +} diff --git a/libcxx/test/utilities/function.objects/comparisons/greater.pass.cpp b/libcxx/test/utilities/function.objects/comparisons/greater.pass.cpp index 4595c9742fe..4642b27e846 100644 --- a/libcxx/test/utilities/function.objects/comparisons/greater.pass.cpp +++ b/libcxx/test/utilities/function.objects/comparisons/greater.pass.cpp @@ -1 +1,26 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <functional>
// greater
#include <functional>
#include <type_traits>
#include <cassert>
int main()
{
typedef std::greater<int> F;
const F f = F();
static_assert((std::is_base_of<std::binary_function<int, int, bool>, F>::value), "");
assert(!f(36, 36));
assert(f(36, 6));
assert(!f(6, 36));
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// greater + +#include <functional> +#include <type_traits> +#include <cassert> + +int main() +{ + typedef std::greater<int> F; + const F f = F(); + static_assert((std::is_base_of<std::binary_function<int, int, bool>, F>::value), ""); + assert(!f(36, 36)); + assert(f(36, 6)); + assert(!f(6, 36)); +} diff --git a/libcxx/test/utilities/function.objects/comparisons/greater_equal.pass.cpp b/libcxx/test/utilities/function.objects/comparisons/greater_equal.pass.cpp index 52089e07991..76d56bbc93c 100644 --- a/libcxx/test/utilities/function.objects/comparisons/greater_equal.pass.cpp +++ b/libcxx/test/utilities/function.objects/comparisons/greater_equal.pass.cpp @@ -1 +1,26 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <functional>
// greater_equal
#include <functional>
#include <type_traits>
#include <cassert>
int main()
{
typedef std::greater_equal<int> F;
const F f = F();
static_assert((std::is_base_of<std::binary_function<int, int, bool>, F>::value), "");
assert(f(36, 36));
assert(f(36, 6));
assert(!f(6, 36));
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// greater_equal + +#include <functional> +#include <type_traits> +#include <cassert> + +int main() +{ + typedef std::greater_equal<int> F; + const F f = F(); + static_assert((std::is_base_of<std::binary_function<int, int, bool>, F>::value), ""); + assert(f(36, 36)); + assert(f(36, 6)); + assert(!f(6, 36)); +} diff --git a/libcxx/test/utilities/function.objects/comparisons/less.pass.cpp b/libcxx/test/utilities/function.objects/comparisons/less.pass.cpp index 178378a4f39..b0ca9961946 100644 --- a/libcxx/test/utilities/function.objects/comparisons/less.pass.cpp +++ b/libcxx/test/utilities/function.objects/comparisons/less.pass.cpp @@ -1 +1,26 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <functional>
// less
#include <functional>
#include <type_traits>
#include <cassert>
int main()
{
typedef std::less<int> F;
const F f = F();
static_assert((std::is_base_of<std::binary_function<int, int, bool>, F>::value), "");
assert(!f(36, 36));
assert(!f(36, 6));
assert(f(6, 36));
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// less + +#include <functional> +#include <type_traits> +#include <cassert> + +int main() +{ + typedef std::less<int> F; + const F f = F(); + static_assert((std::is_base_of<std::binary_function<int, int, bool>, F>::value), ""); + assert(!f(36, 36)); + assert(!f(36, 6)); + assert(f(6, 36)); +} diff --git a/libcxx/test/utilities/function.objects/comparisons/less_equal.pass.cpp b/libcxx/test/utilities/function.objects/comparisons/less_equal.pass.cpp index 9df852816d2..d40839c5122 100644 --- a/libcxx/test/utilities/function.objects/comparisons/less_equal.pass.cpp +++ b/libcxx/test/utilities/function.objects/comparisons/less_equal.pass.cpp @@ -1 +1,26 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <functional>
// less_equal
#include <functional>
#include <type_traits>
#include <cassert>
int main()
{
typedef std::less_equal<int> F;
const F f = F();
static_assert((std::is_base_of<std::binary_function<int, int, bool>, F>::value), "");
assert(f(36, 36));
assert(!f(36, 6));
assert(f(6, 36));
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// less_equal + +#include <functional> +#include <type_traits> +#include <cassert> + +int main() +{ + typedef std::less_equal<int> F; + const F f = F(); + static_assert((std::is_base_of<std::binary_function<int, int, bool>, F>::value), ""); + assert(f(36, 36)); + assert(!f(36, 6)); + assert(f(6, 36)); +} diff --git a/libcxx/test/utilities/function.objects/comparisons/not_equal_to.pass.cpp b/libcxx/test/utilities/function.objects/comparisons/not_equal_to.pass.cpp index d3793340cba..3b1a0d50743 100644 --- a/libcxx/test/utilities/function.objects/comparisons/not_equal_to.pass.cpp +++ b/libcxx/test/utilities/function.objects/comparisons/not_equal_to.pass.cpp @@ -1 +1,25 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <functional>
// not_equal_to
#include <functional>
#include <type_traits>
#include <cassert>
int main()
{
typedef std::not_equal_to<int> F;
const F f = F();
static_assert((std::is_base_of<std::binary_function<int, int, bool>, F>::value), "");
assert(!f(36, 36));
assert(f(36, 6));
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// not_equal_to + +#include <functional> +#include <type_traits> +#include <cassert> + +int main() +{ + typedef std::not_equal_to<int> F; + const F f = F(); + static_assert((std::is_base_of<std::binary_function<int, int, bool>, F>::value), ""); + assert(!f(36, 36)); + assert(f(36, 6)); +} diff --git a/libcxx/test/utilities/function.objects/func.def/nothing_to_do.pass.cpp b/libcxx/test/utilities/function.objects/func.def/nothing_to_do.pass.cpp index e8db90cbee0..b89f168e9c4 100644 --- a/libcxx/test/utilities/function.objects/func.def/nothing_to_do.pass.cpp +++ b/libcxx/test/utilities/function.objects/func.def/nothing_to_do.pass.cpp @@ -1 +1,12 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
int main()
{
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/libcxx/test/utilities/function.objects/func.memfn/member_data.fail.cpp b/libcxx/test/utilities/function.objects/func.memfn/member_data.fail.cpp index 4a284d25167..2f893e6aa39 100644 --- a/libcxx/test/utilities/function.objects/func.memfn/member_data.fail.cpp +++ b/libcxx/test/utilities/function.objects/func.memfn/member_data.fail.cpp @@ -1 +1,42 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <functional>
// template<Returnable R, class T> unspecified mem_fn(R T::* pm);
#include <functional>
#include <cassert>
struct A
{
double data_;
};
template <class F>
void
test(F f)
{
{
A a;
f(a) = 5;
assert(a.data_ == 5);
A* ap = &a;
f(ap) = 6;
assert(a.data_ == 6);
const A* cap = ap;
assert(f(cap) == f(ap));
f(cap) = 7;
}
}
int main()
{
test(std::mem_fn(&A::data_));
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// template<Returnable R, class T> unspecified mem_fn(R T::* pm); + +#include <functional> +#include <cassert> + +struct A +{ + double data_; +}; + +template <class F> +void +test(F f) +{ + { + A a; + f(a) = 5; + assert(a.data_ == 5); + A* ap = &a; + f(ap) = 6; + assert(a.data_ == 6); + const A* cap = ap; + assert(f(cap) == f(ap)); + f(cap) = 7; + } +} + +int main() +{ + test(std::mem_fn(&A::data_)); +} diff --git a/libcxx/test/utilities/function.objects/func.memfn/member_data.pass.cpp b/libcxx/test/utilities/function.objects/func.memfn/member_data.pass.cpp index 54cf2d3dfb2..906088ce91a 100644 --- a/libcxx/test/utilities/function.objects/func.memfn/member_data.pass.cpp +++ b/libcxx/test/utilities/function.objects/func.memfn/member_data.pass.cpp @@ -1 +1,41 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <functional>
// template<Returnable R, class T> unspecified mem_fn(R T::* pm);
#include <functional>
#include <cassert>
struct A
{
double data_;
};
template <class F>
void
test(F f)
{
{
A a;
f(a) = 5;
assert(a.data_ == 5);
A* ap = &a;
f(ap) = 6;
assert(a.data_ == 6);
const A* cap = ap;
assert(f(cap) == f(ap));
}
}
int main()
{
test(std::mem_fn(&A::data_));
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// template<Returnable R, class T> unspecified mem_fn(R T::* pm); + +#include <functional> +#include <cassert> + +struct A +{ + double data_; +}; + +template <class F> +void +test(F f) +{ + { + A a; + f(a) = 5; + assert(a.data_ == 5); + A* ap = &a; + f(ap) = 6; + assert(a.data_ == 6); + const A* cap = ap; + assert(f(cap) == f(ap)); + } +} + +int main() +{ + test(std::mem_fn(&A::data_)); +} diff --git a/libcxx/test/utilities/function.objects/func.memfn/member_function.pass.cpp b/libcxx/test/utilities/function.objects/func.memfn/member_function.pass.cpp index 5995c618c74..89016a52346 100644 --- a/libcxx/test/utilities/function.objects/func.memfn/member_function.pass.cpp +++ b/libcxx/test/utilities/function.objects/func.memfn/member_function.pass.cpp @@ -1 +1,66 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <functional>
// template<Returnable R, class T, CopyConstructible... Args>
// unspecified mem_fn(R (T::* pm)(Args...));
#include <functional>
#include <cassert>
struct A
{
char test0() {return 'a';}
char test1(int) {return 'b';}
char test2(int, double) {return 'c';}
};
template <class F>
void
test0(F f)
{
{
A a;
assert(f(a) == 'a');
A* ap = &a;
assert(f(ap) == 'a');
}
}
template <class F>
void
test1(F f)
{
{
A a;
assert(f(a, 1) == 'b');
A* ap = &a;
assert(f(ap, 2) == 'b');
}
}
template <class F>
void
test2(F f)
{
{
A a;
assert(f(a, 1, 2) == 'c');
A* ap = &a;
assert(f(ap, 2, 3.5) == 'c');
}
}
int main()
{
test0(std::mem_fn(&A::test0));
test1(std::mem_fn(&A::test1));
test2(std::mem_fn(&A::test2));
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// template<Returnable R, class T, CopyConstructible... Args> +// unspecified mem_fn(R (T::* pm)(Args...)); + +#include <functional> +#include <cassert> + +struct A +{ + char test0() {return 'a';} + char test1(int) {return 'b';} + char test2(int, double) {return 'c';} +}; + +template <class F> +void +test0(F f) +{ + { + A a; + assert(f(a) == 'a'); + A* ap = &a; + assert(f(ap) == 'a'); + } +} + +template <class F> +void +test1(F f) +{ + { + A a; + assert(f(a, 1) == 'b'); + A* ap = &a; + assert(f(ap, 2) == 'b'); + } +} + +template <class F> +void +test2(F f) +{ + { + A a; + assert(f(a, 1, 2) == 'c'); + A* ap = &a; + assert(f(ap, 2, 3.5) == 'c'); + } +} + +int main() +{ + test0(std::mem_fn(&A::test0)); + test1(std::mem_fn(&A::test1)); + test2(std::mem_fn(&A::test2)); +} diff --git a/libcxx/test/utilities/function.objects/func.memfn/member_function_const.pass.cpp b/libcxx/test/utilities/function.objects/func.memfn/member_function_const.pass.cpp index f927474b4ca..38f92047497 100644 --- a/libcxx/test/utilities/function.objects/func.memfn/member_function_const.pass.cpp +++ b/libcxx/test/utilities/function.objects/func.memfn/member_function_const.pass.cpp @@ -1 +1,72 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <functional>
// template<Returnable R, class T, CopyConstructible... Args>
// unspecified mem_fn(R (T::* pm)(Args...) const);
#include <functional>
#include <cassert>
struct A
{
char test0() const {return 'a';}
char test1(int) const {return 'b';}
char test2(int, double) const {return 'c';}
};
template <class F>
void
test0(F f)
{
{
A a;
assert(f(a) == 'a');
A* ap = &a;
assert(f(ap) == 'a');
const A* cap = &a;
assert(f(cap) == 'a');
}
}
template <class F>
void
test1(F f)
{
{
A a;
assert(f(a, 1) == 'b');
A* ap = &a;
assert(f(ap, 2) == 'b');
const A* cap = &a;
assert(f(cap, 2) == 'b');
}
}
template <class F>
void
test2(F f)
{
{
A a;
assert(f(a, 1, 2) == 'c');
A* ap = &a;
assert(f(ap, 2, 3.5) == 'c');
const A* cap = &a;
assert(f(cap, 2, 3.5) == 'c');
}
}
int main()
{
test0(std::mem_fn(&A::test0));
test1(std::mem_fn(&A::test1));
test2(std::mem_fn(&A::test2));
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// template<Returnable R, class T, CopyConstructible... Args> +// unspecified mem_fn(R (T::* pm)(Args...) const); + +#include <functional> +#include <cassert> + +struct A +{ + char test0() const {return 'a';} + char test1(int) const {return 'b';} + char test2(int, double) const {return 'c';} +}; + +template <class F> +void +test0(F f) +{ + { + A a; + assert(f(a) == 'a'); + A* ap = &a; + assert(f(ap) == 'a'); + const A* cap = &a; + assert(f(cap) == 'a'); + } +} + +template <class F> +void +test1(F f) +{ + { + A a; + assert(f(a, 1) == 'b'); + A* ap = &a; + assert(f(ap, 2) == 'b'); + const A* cap = &a; + assert(f(cap, 2) == 'b'); + } +} + +template <class F> +void +test2(F f) +{ + { + A a; + assert(f(a, 1, 2) == 'c'); + A* ap = &a; + assert(f(ap, 2, 3.5) == 'c'); + const A* cap = &a; + assert(f(cap, 2, 3.5) == 'c'); + } +} + +int main() +{ + test0(std::mem_fn(&A::test0)); + test1(std::mem_fn(&A::test1)); + test2(std::mem_fn(&A::test2)); +} diff --git a/libcxx/test/utilities/function.objects/func.memfn/member_function_const_volatile.pass.cpp b/libcxx/test/utilities/function.objects/func.memfn/member_function_const_volatile.pass.cpp index a33c13c5679..beec02d9ba0 100644 --- a/libcxx/test/utilities/function.objects/func.memfn/member_function_const_volatile.pass.cpp +++ b/libcxx/test/utilities/function.objects/func.memfn/member_function_const_volatile.pass.cpp @@ -1 +1,72 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <functional>
// template<Returnable R, class T, CopyConstructible... Args>
// unspecified mem_fn(R (T::* pm)(Args...) const volatile);
#include <functional>
#include <cassert>
struct A
{
char test0() const volatile {return 'a';}
char test1(int) const volatile {return 'b';}
char test2(int, double) const volatile {return 'c';}
};
template <class F>
void
test0(F f)
{
{
A a;
assert(f(a) == 'a');
A* ap = &a;
assert(f(ap) == 'a');
const volatile A* cap = &a;
assert(f(cap) == 'a');
}
}
template <class F>
void
test1(F f)
{
{
A a;
assert(f(a, 1) == 'b');
A* ap = &a;
assert(f(ap, 2) == 'b');
const volatile A* cap = &a;
assert(f(cap, 2) == 'b');
}
}
template <class F>
void
test2(F f)
{
{
A a;
assert(f(a, 1, 2) == 'c');
A* ap = &a;
assert(f(ap, 2, 3.5) == 'c');
const volatile A* cap = &a;
assert(f(cap, 2, 3.5) == 'c');
}
}
int main()
{
test0(std::mem_fn(&A::test0));
test1(std::mem_fn(&A::test1));
test2(std::mem_fn(&A::test2));
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// template<Returnable R, class T, CopyConstructible... Args> +// unspecified mem_fn(R (T::* pm)(Args...) const volatile); + +#include <functional> +#include <cassert> + +struct A +{ + char test0() const volatile {return 'a';} + char test1(int) const volatile {return 'b';} + char test2(int, double) const volatile {return 'c';} +}; + +template <class F> +void +test0(F f) +{ + { + A a; + assert(f(a) == 'a'); + A* ap = &a; + assert(f(ap) == 'a'); + const volatile A* cap = &a; + assert(f(cap) == 'a'); + } +} + +template <class F> +void +test1(F f) +{ + { + A a; + assert(f(a, 1) == 'b'); + A* ap = &a; + assert(f(ap, 2) == 'b'); + const volatile A* cap = &a; + assert(f(cap, 2) == 'b'); + } +} + +template <class F> +void +test2(F f) +{ + { + A a; + assert(f(a, 1, 2) == 'c'); + A* ap = &a; + assert(f(ap, 2, 3.5) == 'c'); + const volatile A* cap = &a; + assert(f(cap, 2, 3.5) == 'c'); + } +} + +int main() +{ + test0(std::mem_fn(&A::test0)); + test1(std::mem_fn(&A::test1)); + test2(std::mem_fn(&A::test2)); +} diff --git a/libcxx/test/utilities/function.objects/func.memfn/member_function_volatile.pass.cpp b/libcxx/test/utilities/function.objects/func.memfn/member_function_volatile.pass.cpp index 3f445f5fb3d..80959716bb3 100644 --- a/libcxx/test/utilities/function.objects/func.memfn/member_function_volatile.pass.cpp +++ b/libcxx/test/utilities/function.objects/func.memfn/member_function_volatile.pass.cpp @@ -1 +1,72 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <functional>
// template<Returnable R, class T, CopyConstructible... Args>
// unspecified mem_fn(R (T::* pm)(Args...) volatile);
#include <functional>
#include <cassert>
struct A
{
char test0() volatile {return 'a';}
char test1(int) volatile {return 'b';}
char test2(int, double) volatile {return 'c';}
};
template <class F>
void
test0(F f)
{
{
A a;
assert(f(a) == 'a');
A* ap = &a;
assert(f(ap) == 'a');
volatile A* cap = &a;
assert(f(cap) == 'a');
}
}
template <class F>
void
test1(F f)
{
{
A a;
assert(f(a, 1) == 'b');
A* ap = &a;
assert(f(ap, 2) == 'b');
volatile A* cap = &a;
assert(f(cap, 2) == 'b');
}
}
template <class F>
void
test2(F f)
{
{
A a;
assert(f(a, 1, 2) == 'c');
A* ap = &a;
assert(f(ap, 2, 3.5) == 'c');
volatile A* cap = &a;
assert(f(cap, 2, 3.5) == 'c');
}
}
int main()
{
test0(std::mem_fn(&A::test0));
test1(std::mem_fn(&A::test1));
test2(std::mem_fn(&A::test2));
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// template<Returnable R, class T, CopyConstructible... Args> +// unspecified mem_fn(R (T::* pm)(Args...) volatile); + +#include <functional> +#include <cassert> + +struct A +{ + char test0() volatile {return 'a';} + char test1(int) volatile {return 'b';} + char test2(int, double) volatile {return 'c';} +}; + +template <class F> +void +test0(F f) +{ + { + A a; + assert(f(a) == 'a'); + A* ap = &a; + assert(f(ap) == 'a'); + volatile A* cap = &a; + assert(f(cap) == 'a'); + } +} + +template <class F> +void +test1(F f) +{ + { + A a; + assert(f(a, 1) == 'b'); + A* ap = &a; + assert(f(ap, 2) == 'b'); + volatile A* cap = &a; + assert(f(cap, 2) == 'b'); + } +} + +template <class F> +void +test2(F f) +{ + { + A a; + assert(f(a, 1, 2) == 'c'); + A* ap = &a; + assert(f(ap, 2, 3.5) == 'c'); + volatile A* cap = &a; + assert(f(cap, 2, 3.5) == 'c'); + } +} + +int main() +{ + test0(std::mem_fn(&A::test0)); + test1(std::mem_fn(&A::test1)); + test2(std::mem_fn(&A::test2)); +} diff --git a/libcxx/test/utilities/function.objects/func.require/binary_function.pass.cpp b/libcxx/test/utilities/function.objects/func.require/binary_function.pass.cpp index 53ac5c57f39..4bf9c833655 100644 --- a/libcxx/test/utilities/function.objects/func.require/binary_function.pass.cpp +++ b/libcxx/test/utilities/function.objects/func.require/binary_function.pass.cpp @@ -1 +1,23 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <functional>
// binary_function
#include <functional>
#include <type_traits>
int main()
{
typedef std::binary_function<int, short, bool> bf;
static_assert((std::is_same<bf::first_argument_type, int>::value), "");
static_assert((std::is_same<bf::second_argument_type, short>::value), "");
static_assert((std::is_same<bf::result_type, bool>::value), "");
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// binary_function + +#include <functional> +#include <type_traits> + +int main() +{ + typedef std::binary_function<int, short, bool> bf; + static_assert((std::is_same<bf::first_argument_type, int>::value), ""); + static_assert((std::is_same<bf::second_argument_type, short>::value), ""); + static_assert((std::is_same<bf::result_type, bool>::value), ""); +} diff --git a/libcxx/test/utilities/function.objects/func.require/unary_function.pass.cpp b/libcxx/test/utilities/function.objects/func.require/unary_function.pass.cpp index 5f251260e0b..6af07ef9a7d 100644 --- a/libcxx/test/utilities/function.objects/func.require/unary_function.pass.cpp +++ b/libcxx/test/utilities/function.objects/func.require/unary_function.pass.cpp @@ -1 +1,22 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <functional>
// unary_function
#include <functional>
#include <type_traits>
int main()
{
typedef std::unary_function<int, bool> uf;
static_assert((std::is_same<uf::argument_type, int>::value), "");
static_assert((std::is_same<uf::result_type, bool>::value), "");
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// unary_function + +#include <functional> +#include <type_traits> + +int main() +{ + typedef std::unary_function<int, bool> uf; + static_assert((std::is_same<uf::argument_type, int>::value), ""); + static_assert((std::is_same<uf::result_type, bool>::value), ""); +} diff --git a/libcxx/test/utilities/function.objects/func.wrap/func.wrap.badcall/bad_function_call.pass.cpp b/libcxx/test/utilities/function.objects/func.wrap/func.wrap.badcall/bad_function_call.pass.cpp index b39198f8d73..121235fcffe 100644 --- a/libcxx/test/utilities/function.objects/func.wrap/func.wrap.badcall/bad_function_call.pass.cpp +++ b/libcxx/test/utilities/function.objects/func.wrap/func.wrap.badcall/bad_function_call.pass.cpp @@ -1 +1,26 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// Class bad_function_call
// class bad_function_call
// : public exception
// {
// public:
// // 20.7.16.1.1, constructor:
// bad_function_call();
// };
#include <functional>
#include <type_traits>
int main()
{
static_assert((std::is_base_of<std::exception, std::bad_function_call>::value), "");
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// Class bad_function_call + +// class bad_function_call +// : public exception +// { +// public: +// // 20.7.16.1.1, constructor: +// bad_function_call(); +// }; + +#include <functional> +#include <type_traits> + +int main() +{ + static_assert((std::is_base_of<std::exception, std::bad_function_call>::value), ""); +} diff --git a/libcxx/test/utilities/function.objects/func.wrap/func.wrap.badcall/func.wrap.badcall.const/bad_function_call_ctor.pass.cpp b/libcxx/test/utilities/function.objects/func.wrap/func.wrap.badcall/func.wrap.badcall.const/bad_function_call_ctor.pass.cpp index d9fb5fd1d60..31ccdba096b 100644 --- a/libcxx/test/utilities/function.objects/func.wrap/func.wrap.badcall/func.wrap.badcall.const/bad_function_call_ctor.pass.cpp +++ b/libcxx/test/utilities/function.objects/func.wrap/func.wrap.badcall/func.wrap.badcall.const/bad_function_call_ctor.pass.cpp @@ -1 +1,20 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// Class bad_function_call
// bad_function_call();
#include <functional>
#include <type_traits>
int main()
{
std::bad_function_call ex;
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// Class bad_function_call + +// bad_function_call(); + +#include <functional> +#include <type_traits> + +int main() +{ + std::bad_function_call ex; +} diff --git a/libcxx/test/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.alg/swap.pass.cpp b/libcxx/test/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.alg/swap.pass.cpp index 12f95a7201b..d3e50f2d13e 100644 --- a/libcxx/test/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.alg/swap.pass.cpp +++ b/libcxx/test/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.alg/swap.pass.cpp @@ -1 +1,135 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <functional>
// class function<R(ArgTypes...)>
// template <MoveConstructible R, MoveConstructible ... ArgTypes>
// void swap(function<R(ArgTypes...)>&, function<R(ArgTypes...)>&);
#include <functional>
#include <new>
#include <cstdlib>
#include <cassert>
int new_called = 0;
void* operator new(std::size_t s) throw(std::bad_alloc)
{
++new_called;
return std::malloc(s);
}
void operator delete(void* p) throw()
{
--new_called;
std::free(p);
}
class A
{
int data_[10];
public:
static int count;
explicit A(int j)
{
++count;
data_[0] = j;
}
A(const A& a)
{
++count;
for (int i = 0; i < 10; ++i)
data_[i] = a.data_[i];
}
~A() {--count;}
int operator()(int i) const
{
for (int j = 0; j < 10; ++j)
i += data_[j];
return i;
}
int id() const {return data_[0];}
};
int A::count = 0;
int g(int) {return 0;}
int h(int) {return 1;}
int main()
{
assert(new_called == 0);
{
std::function<int(int)> f1 = A(1);
std::function<int(int)> f2 = A(2);
assert(A::count == 2);
assert(new_called == 2);
assert(f1.target<A>()->id() == 1);
assert(f2.target<A>()->id() == 2);
swap(f1, f2);
assert(A::count == 2);
assert(new_called == 2);
assert(f1.target<A>()->id() == 2);
assert(f2.target<A>()->id() == 1);
}
assert(A::count == 0);
assert(new_called == 0);
{
std::function<int(int)> f1 = A(1);
std::function<int(int)> f2 = g;
assert(A::count == 1);
assert(new_called == 1);
assert(f1.target<A>()->id() == 1);
assert(*f2.target<int(*)(int)>() == g);
swap(f1, f2);
assert(A::count == 1);
assert(new_called == 1);
assert(*f1.target<int(*)(int)>() == g);
assert(f2.target<A>()->id() == 1);
}
assert(A::count == 0);
assert(new_called == 0);
{
std::function<int(int)> f1 = g;
std::function<int(int)> f2 = A(1);
assert(A::count == 1);
assert(new_called == 1);
assert(*f1.target<int(*)(int)>() == g);
assert(f2.target<A>()->id() == 1);
swap(f1, f2);
assert(A::count == 1);
assert(new_called == 1);
assert(f1.target<A>()->id() == 1);
assert(*f2.target<int(*)(int)>() == g);
}
assert(A::count == 0);
assert(new_called == 0);
{
std::function<int(int)> f1 = g;
std::function<int(int)> f2 = h;
assert(A::count == 0);
assert(new_called == 0);
assert(*f1.target<int(*)(int)>() == g);
assert(*f2.target<int(*)(int)>() == h);
swap(f1, f2);
assert(A::count == 0);
assert(new_called == 0);
assert(*f1.target<int(*)(int)>() == h);
assert(*f2.target<int(*)(int)>() == g);
}
assert(A::count == 0);
assert(new_called == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// class function<R(ArgTypes...)> + +// template <MoveConstructible R, MoveConstructible ... ArgTypes> +// void swap(function<R(ArgTypes...)>&, function<R(ArgTypes...)>&); + +#include <functional> +#include <new> +#include <cstdlib> +#include <cassert> + +int new_called = 0; + +void* operator new(std::size_t s) throw(std::bad_alloc) +{ + ++new_called; + return std::malloc(s); +} + +void operator delete(void* p) throw() +{ + --new_called; + std::free(p); +} + +class A +{ + int data_[10]; +public: + static int count; + + explicit A(int j) + { + ++count; + data_[0] = j; + } + + A(const A& a) + { + ++count; + for (int i = 0; i < 10; ++i) + data_[i] = a.data_[i]; + } + + ~A() {--count;} + + int operator()(int i) const + { + for (int j = 0; j < 10; ++j) + i += data_[j]; + return i; + } + + int id() const {return data_[0];} +}; + +int A::count = 0; + +int g(int) {return 0;} +int h(int) {return 1;} + +int main() +{ + assert(new_called == 0); + { + std::function<int(int)> f1 = A(1); + std::function<int(int)> f2 = A(2); + assert(A::count == 2); + assert(new_called == 2); + assert(f1.target<A>()->id() == 1); + assert(f2.target<A>()->id() == 2); + swap(f1, f2); + assert(A::count == 2); + assert(new_called == 2); + assert(f1.target<A>()->id() == 2); + assert(f2.target<A>()->id() == 1); + } + assert(A::count == 0); + assert(new_called == 0); + { + std::function<int(int)> f1 = A(1); + std::function<int(int)> f2 = g; + assert(A::count == 1); + assert(new_called == 1); + assert(f1.target<A>()->id() == 1); + assert(*f2.target<int(*)(int)>() == g); + swap(f1, f2); + assert(A::count == 1); + assert(new_called == 1); + assert(*f1.target<int(*)(int)>() == g); + assert(f2.target<A>()->id() == 1); + } + assert(A::count == 0); + assert(new_called == 0); + { + std::function<int(int)> f1 = g; + std::function<int(int)> f2 = A(1); + assert(A::count == 1); + assert(new_called == 1); + assert(*f1.target<int(*)(int)>() == g); + assert(f2.target<A>()->id() == 1); + swap(f1, f2); + assert(A::count == 1); + assert(new_called == 1); + assert(f1.target<A>()->id() == 1); + assert(*f2.target<int(*)(int)>() == g); + } + assert(A::count == 0); + assert(new_called == 0); + { + std::function<int(int)> f1 = g; + std::function<int(int)> f2 = h; + assert(A::count == 0); + assert(new_called == 0); + assert(*f1.target<int(*)(int)>() == g); + assert(*f2.target<int(*)(int)>() == h); + swap(f1, f2); + assert(A::count == 0); + assert(new_called == 0); + assert(*f1.target<int(*)(int)>() == h); + assert(*f2.target<int(*)(int)>() == g); + } + assert(A::count == 0); + assert(new_called == 0); +} diff --git a/libcxx/test/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.cap/operator_bool.pass.cpp b/libcxx/test/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.cap/operator_bool.pass.cpp index 44327baed3b..63683c958b2 100644 --- a/libcxx/test/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.cap/operator_bool.pass.cpp +++ b/libcxx/test/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.cap/operator_bool.pass.cpp @@ -1 +1,29 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <functional>
// class function<R(ArgTypes...)>
// explicit operator bool() const
#include <functional>
#include <cassert>
int g(int) {return 0;}
int main()
{
{
std::function<int(int)> f;
assert(!f);
f = g;
assert(f);
}
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// class function<R(ArgTypes...)> + +// explicit operator bool() const + +#include <functional> +#include <cassert> + +int g(int) {return 0;} + +int main() +{ + { + std::function<int(int)> f; + assert(!f); + f = g; + assert(f); + } +} diff --git a/libcxx/test/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/F.pass.cpp b/libcxx/test/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/F.pass.cpp index 06368fe3e89..22706dc2c88 100644 --- a/libcxx/test/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/F.pass.cpp +++ b/libcxx/test/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/F.pass.cpp @@ -1 +1,98 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <functional>
// class function<R(ArgTypes...)>
// function(nullptr_t);
#include <functional>
#include <new>
#include <cstdlib>
#include <cassert>
int new_called = 0;
void* operator new(std::size_t s) throw(std::bad_alloc)
{
++new_called;
return std::malloc(s);
}
void operator delete(void* p) throw()
{
--new_called;
std::free(p);
}
class A
{
int data_[10];
public:
static int count;
A()
{
++count;
for (int i = 0; i < 10; ++i)
data_[i] = i;
}
A(const A&) {++count;}
~A() {--count;}
int operator()(int i) const
{
for (int j = 0; j < 10; ++j)
i += data_[j];
return i;
}
int foo(int) const {return 1;}
};
int A::count = 0;
int g(int) {return 0;}
int main()
{
assert(new_called == 0);
{
std::function<int(int)> f = A();
assert(A::count == 1);
assert(new_called == 1);
assert(f.target<A>());
assert(f.target<int(*)(int)>() == 0);
}
assert(A::count == 0);
assert(new_called == 0);
{
std::function<int(int)> f = g;
assert(new_called == 0);
assert(f.target<int(*)(int)>());
assert(f.target<A>() == 0);
}
assert(new_called == 0);
{
std::function<int(int)> f = (int (*)(int))0;
assert(!f);
assert(new_called == 0);
assert(f.target<int(*)(int)>() == 0);
assert(f.target<A>() == 0);
}
{
std::function<int(const A*, int)> f = &A::foo;
assert(f);
assert(new_called == 0);
assert(f.target<int (A::*)(int) const>() != 0);
}
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// class function<R(ArgTypes...)> + +// function(nullptr_t); + +#include <functional> +#include <new> +#include <cstdlib> +#include <cassert> + +int new_called = 0; + +void* operator new(std::size_t s) throw(std::bad_alloc) +{ + ++new_called; + return std::malloc(s); +} + +void operator delete(void* p) throw() +{ + --new_called; + std::free(p); +} + +class A +{ + int data_[10]; +public: + static int count; + + A() + { + ++count; + for (int i = 0; i < 10; ++i) + data_[i] = i; + } + + A(const A&) {++count;} + + ~A() {--count;} + + int operator()(int i) const + { + for (int j = 0; j < 10; ++j) + i += data_[j]; + return i; + } + + int foo(int) const {return 1;} +}; + +int A::count = 0; + +int g(int) {return 0;} + +int main() +{ + assert(new_called == 0); + { + std::function<int(int)> f = A(); + assert(A::count == 1); + assert(new_called == 1); + assert(f.target<A>()); + assert(f.target<int(*)(int)>() == 0); + } + assert(A::count == 0); + assert(new_called == 0); + { + std::function<int(int)> f = g; + assert(new_called == 0); + assert(f.target<int(*)(int)>()); + assert(f.target<A>() == 0); + } + assert(new_called == 0); + { + std::function<int(int)> f = (int (*)(int))0; + assert(!f); + assert(new_called == 0); + assert(f.target<int(*)(int)>() == 0); + assert(f.target<A>() == 0); + } + { + std::function<int(const A*, int)> f = &A::foo; + assert(f); + assert(new_called == 0); + assert(f.target<int (A::*)(int) const>() != 0); + } +} diff --git a/libcxx/test/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/F_assign.pass.cpp b/libcxx/test/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/F_assign.pass.cpp index 2d6ab4b94cf..2d48079c973 100644 --- a/libcxx/test/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/F_assign.pass.cpp +++ b/libcxx/test/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/F_assign.pass.cpp @@ -1 +1,105 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <functional>
// class function<R(ArgTypes...)>
// template<class F>
// requires CopyConstructible<F> && Callable<F, ArgTypes..>
// && Convertible<Callable<F, ArgTypes...>::result_type
// operator=(F f);
#include <functional>
#include <new>
#include <cstdlib>
#include <cassert>
int new_called = 0;
void* operator new(std::size_t s) throw(std::bad_alloc)
{
++new_called;
return std::malloc(s);
}
void operator delete(void* p) throw()
{
--new_called;
std::free(p);
}
class A
{
int data_[10];
public:
static int count;
A()
{
++count;
for (int i = 0; i < 10; ++i)
data_[i] = i;
}
A(const A&) {++count;}
~A() {--count;}
int operator()(int i) const
{
for (int j = 0; j < 10; ++j)
i += data_[j];
return i;
}
int foo(int) const {return 1;}
};
int A::count = 0;
int g(int) {return 0;}
int main()
{
assert(new_called == 0);
{
std::function<int(int)> f;
f = A();
assert(A::count == 1);
assert(new_called == 1);
assert(f.target<A>());
assert(f.target<int(*)(int)>() == 0);
}
assert(A::count == 0);
assert(new_called == 0);
{
std::function<int(int)> f;
f = g;
assert(new_called == 0);
assert(f.target<int(*)(int)>());
assert(f.target<A>() == 0);
}
assert(new_called == 0);
{
std::function<int(int)> f;
f = (int (*)(int))0;
assert(!f);
assert(new_called == 0);
assert(f.target<int(*)(int)>() == 0);
assert(f.target<A>() == 0);
}
{
std::function<int(const A*, int)> f;
f = &A::foo;
assert(f);
assert(new_called == 0);
assert(f.target<int (A::*)(int) const>() != 0);
}
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// class function<R(ArgTypes...)> + +// template<class F> +// requires CopyConstructible<F> && Callable<F, ArgTypes..> +// && Convertible<Callable<F, ArgTypes...>::result_type +// operator=(F f); + +#include <functional> +#include <new> +#include <cstdlib> +#include <cassert> + +int new_called = 0; + +void* operator new(std::size_t s) throw(std::bad_alloc) +{ + ++new_called; + return std::malloc(s); +} + +void operator delete(void* p) throw() +{ + --new_called; + std::free(p); +} + +class A +{ + int data_[10]; +public: + static int count; + + A() + { + ++count; + for (int i = 0; i < 10; ++i) + data_[i] = i; + } + + A(const A&) {++count;} + + ~A() {--count;} + + int operator()(int i) const + { + for (int j = 0; j < 10; ++j) + i += data_[j]; + return i; + } + + int foo(int) const {return 1;} +}; + +int A::count = 0; + +int g(int) {return 0;} + +int main() +{ + assert(new_called == 0); + { + std::function<int(int)> f; + f = A(); + assert(A::count == 1); + assert(new_called == 1); + assert(f.target<A>()); + assert(f.target<int(*)(int)>() == 0); + } + assert(A::count == 0); + assert(new_called == 0); + { + std::function<int(int)> f; + f = g; + assert(new_called == 0); + assert(f.target<int(*)(int)>()); + assert(f.target<A>() == 0); + } + assert(new_called == 0); + { + std::function<int(int)> f; + f = (int (*)(int))0; + assert(!f); + assert(new_called == 0); + assert(f.target<int(*)(int)>() == 0); + assert(f.target<A>() == 0); + } + { + std::function<int(const A*, int)> f; + f = &A::foo; + assert(f); + assert(new_called == 0); + assert(f.target<int (A::*)(int) const>() != 0); + } +} diff --git a/libcxx/test/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_rfunction.pass.cpp b/libcxx/test/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_rfunction.pass.cpp index 263cd81aee1..000faa7f259 100644 --- a/libcxx/test/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_rfunction.pass.cpp +++ b/libcxx/test/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_rfunction.pass.cpp @@ -77,5 +77,5 @@ int main() assert(f.target<A>() == 0); assert(f.target<int(*)(int)>() == 0); } -#endif +#endif // _LIBCPP_MOVE } diff --git a/libcxx/test/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/copy.pass.cpp b/libcxx/test/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/copy.pass.cpp index d41975262fd..dc4b092d804 100644 --- a/libcxx/test/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/copy.pass.cpp +++ b/libcxx/test/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/copy.pass.cpp @@ -1 +1,119 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <functional>
// class function<R(ArgTypes...)>
// function(const function& f);
#include <functional>
#include <new>
#include <cstdlib>
#include <cassert>
int new_called = 0;
void* operator new(std::size_t s) throw(std::bad_alloc)
{
++new_called;
return std::malloc(s);
}
void operator delete(void* p) throw()
{
--new_called;
std::free(p);
}
class A
{
int data_[10];
public:
static int count;
A()
{
++count;
for (int i = 0; i < 10; ++i)
data_[i] = i;
}
A(const A&) {++count;}
~A() {--count;}
int operator()(int i) const
{
for (int j = 0; j < 10; ++j)
i += data_[j];
return i;
}
};
int A::count = 0;
int g(int) {return 0;}
int main()
{
assert(new_called == 0);
{
std::function<int(int)> f = A();
assert(A::count == 1);
assert(new_called == 1);
assert(f.target<A>());
assert(f.target<int(*)(int)>() == 0);
std::function<int(int)> f2 = f;
assert(A::count == 2);
assert(new_called == 2);
assert(f2.target<A>());
assert(f2.target<int(*)(int)>() == 0);
}
assert(A::count == 0);
assert(new_called == 0);
{
std::function<int(int)> f = g;
assert(new_called == 0);
assert(f.target<int(*)(int)>());
assert(f.target<A>() == 0);
std::function<int(int)> f2 = f;
assert(new_called == 0);
assert(f2.target<int(*)(int)>());
assert(f2.target<A>() == 0);
}
assert(new_called == 0);
{
std::function<int(int)> f;
assert(new_called == 0);
assert(f.target<int(*)(int)>() == 0);
assert(f.target<A>() == 0);
std::function<int(int)> f2 = f;
assert(new_called == 0);
assert(f2.target<int(*)(int)>() == 0);
assert(f2.target<A>() == 0);
}
#ifdef _LIBCPP_MOVE
assert(new_called == 0);
{
std::function<int(int)> f = A();
assert(A::count == 1);
assert(new_called == 1);
assert(f.target<A>());
assert(f.target<int(*)(int)>() == 0);
std::function<int(int)> f2 = _STD::move(f);
assert(A::count == 1);
assert(new_called == 1);
assert(f2.target<A>());
assert(f2.target<int(*)(int)>() == 0);
assert(f.target<A>() == 0);
assert(f.target<int(*)(int)>() == 0);
}
#endif
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// class function<R(ArgTypes...)> + +// function(const function& f); + +#include <functional> +#include <new> +#include <cstdlib> +#include <cassert> + +int new_called = 0; + +void* operator new(std::size_t s) throw(std::bad_alloc) +{ + ++new_called; + return std::malloc(s); +} + +void operator delete(void* p) throw() +{ + --new_called; + std::free(p); +} + +class A +{ + int data_[10]; +public: + static int count; + + A() + { + ++count; + for (int i = 0; i < 10; ++i) + data_[i] = i; + } + + A(const A&) {++count;} + + ~A() {--count;} + + int operator()(int i) const + { + for (int j = 0; j < 10; ++j) + i += data_[j]; + return i; + } +}; + +int A::count = 0; + +int g(int) {return 0;} + +int main() +{ + assert(new_called == 0); + { + std::function<int(int)> f = A(); + assert(A::count == 1); + assert(new_called == 1); + assert(f.target<A>()); + assert(f.target<int(*)(int)>() == 0); + std::function<int(int)> f2 = f; + assert(A::count == 2); + assert(new_called == 2); + assert(f2.target<A>()); + assert(f2.target<int(*)(int)>() == 0); + } + assert(A::count == 0); + assert(new_called == 0); + { + std::function<int(int)> f = g; + assert(new_called == 0); + assert(f.target<int(*)(int)>()); + assert(f.target<A>() == 0); + std::function<int(int)> f2 = f; + assert(new_called == 0); + assert(f2.target<int(*)(int)>()); + assert(f2.target<A>() == 0); + } + assert(new_called == 0); + { + std::function<int(int)> f; + assert(new_called == 0); + assert(f.target<int(*)(int)>() == 0); + assert(f.target<A>() == 0); + std::function<int(int)> f2 = f; + assert(new_called == 0); + assert(f2.target<int(*)(int)>() == 0); + assert(f2.target<A>() == 0); + } +#ifdef _LIBCPP_MOVE + assert(new_called == 0); + { + std::function<int(int)> f = A(); + assert(A::count == 1); + assert(new_called == 1); + assert(f.target<A>()); + assert(f.target<int(*)(int)>() == 0); + std::function<int(int)> f2 = _STD::move(f); + assert(A::count == 1); + assert(new_called == 1); + assert(f2.target<A>()); + assert(f2.target<int(*)(int)>() == 0); + assert(f.target<A>() == 0); + assert(f.target<int(*)(int)>() == 0); + } +#endif // _LIBCPP_MOVE +} diff --git a/libcxx/test/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/copy_assign.pass.cpp b/libcxx/test/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/copy_assign.pass.cpp index 2dc88a93c84..1202914c3bb 100644 --- a/libcxx/test/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/copy_assign.pass.cpp +++ b/libcxx/test/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/copy_assign.pass.cpp @@ -1 +1,123 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <functional>
// class function<R(ArgTypes...)>
// function& operator=(const function& f);
#include <functional>
#include <new>
#include <cstdlib>
#include <cassert>
int new_called = 0;
void* operator new(std::size_t s) throw(std::bad_alloc)
{
++new_called;
return std::malloc(s);
}
void operator delete(void* p) throw()
{
--new_called;
std::free(p);
}
class A
{
int data_[10];
public:
static int count;
A()
{
++count;
for (int i = 0; i < 10; ++i)
data_[i] = i;
}
A(const A&) {++count;}
~A() {--count;}
int operator()(int i) const
{
for (int j = 0; j < 10; ++j)
i += data_[j];
return i;
}
};
int A::count = 0;
int g(int) {return 0;}
int main()
{
assert(new_called == 0);
{
std::function<int(int)> f = A();
assert(A::count == 1);
assert(new_called == 1);
assert(f.target<A>());
assert(f.target<int(*)(int)>() == 0);
std::function<int(int)> f2;
f2 = f;
assert(A::count == 2);
assert(new_called == 2);
assert(f2.target<A>());
assert(f2.target<int(*)(int)>() == 0);
}
assert(A::count == 0);
assert(new_called == 0);
{
std::function<int(int)> f = g;
assert(new_called == 0);
assert(f.target<int(*)(int)>());
assert(f.target<A>() == 0);
std::function<int(int)> f2;
f2 = f;
assert(new_called == 0);
assert(f2.target<int(*)(int)>());
assert(f2.target<A>() == 0);
}
assert(new_called == 0);
{
std::function<int(int)> f;
assert(new_called == 0);
assert(f.target<int(*)(int)>() == 0);
assert(f.target<A>() == 0);
std::function<int(int)> f2;
f2 = f;
assert(new_called == 0);
assert(f2.target<int(*)(int)>() == 0);
assert(f2.target<A>() == 0);
}
#ifdef _LIBCPP_MOVE
assert(new_called == 0);
{
std::function<int(int)> f = A();
assert(A::count == 1);
assert(new_called == 1);
assert(f.target<A>());
assert(f.target<int(*)(int)>() == 0);
std::function<int(int)> f2;
f2 = _STD::move(f);
assert(A::count == 1);
assert(new_called == 1);
assert(f2.target<A>());
assert(f2.target<int(*)(int)>() == 0);
assert(f.target<A>() == 0);
assert(f.target<int(*)(int)>() == 0);
}
#endif
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// class function<R(ArgTypes...)> + +// function& operator=(const function& f); + +#include <functional> +#include <new> +#include <cstdlib> +#include <cassert> + +int new_called = 0; + +void* operator new(std::size_t s) throw(std::bad_alloc) +{ + ++new_called; + return std::malloc(s); +} + +void operator delete(void* p) throw() +{ + --new_called; + std::free(p); +} + +class A +{ + int data_[10]; +public: + static int count; + + A() + { + ++count; + for (int i = 0; i < 10; ++i) + data_[i] = i; + } + + A(const A&) {++count;} + + ~A() {--count;} + + int operator()(int i) const + { + for (int j = 0; j < 10; ++j) + i += data_[j]; + return i; + } +}; + +int A::count = 0; + +int g(int) {return 0;} + +int main() +{ + assert(new_called == 0); + { + std::function<int(int)> f = A(); + assert(A::count == 1); + assert(new_called == 1); + assert(f.target<A>()); + assert(f.target<int(*)(int)>() == 0); + std::function<int(int)> f2; + f2 = f; + assert(A::count == 2); + assert(new_called == 2); + assert(f2.target<A>()); + assert(f2.target<int(*)(int)>() == 0); + } + assert(A::count == 0); + assert(new_called == 0); + { + std::function<int(int)> f = g; + assert(new_called == 0); + assert(f.target<int(*)(int)>()); + assert(f.target<A>() == 0); + std::function<int(int)> f2; + f2 = f; + assert(new_called == 0); + assert(f2.target<int(*)(int)>()); + assert(f2.target<A>() == 0); + } + assert(new_called == 0); + { + std::function<int(int)> f; + assert(new_called == 0); + assert(f.target<int(*)(int)>() == 0); + assert(f.target<A>() == 0); + std::function<int(int)> f2; + f2 = f; + assert(new_called == 0); + assert(f2.target<int(*)(int)>() == 0); + assert(f2.target<A>() == 0); + } +#ifdef _LIBCPP_MOVE + assert(new_called == 0); + { + std::function<int(int)> f = A(); + assert(A::count == 1); + assert(new_called == 1); + assert(f.target<A>()); + assert(f.target<int(*)(int)>() == 0); + std::function<int(int)> f2; + f2 = _STD::move(f); + assert(A::count == 1); + assert(new_called == 1); + assert(f2.target<A>()); + assert(f2.target<int(*)(int)>() == 0); + assert(f.target<A>() == 0); + assert(f.target<int(*)(int)>() == 0); + } +#endif // _LIBCPP_MOVE +} diff --git a/libcxx/test/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/default.pass.cpp b/libcxx/test/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/default.pass.cpp index 98e11620cfb..3a1cd667522 100644 --- a/libcxx/test/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/default.pass.cpp +++ b/libcxx/test/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/default.pass.cpp @@ -1 +1,23 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <functional>
// class function<R(ArgTypes...)>
// explicit function();
#include <functional>
#include <cassert>
int main()
{
std::function<int(int)> f;
assert(!f);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// class function<R(ArgTypes...)> + +// explicit function(); + +#include <functional> +#include <cassert> + +int main() +{ + std::function<int(int)> f; + assert(!f); +} diff --git a/libcxx/test/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/nullptr_t.pass.cpp b/libcxx/test/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/nullptr_t.pass.cpp index e812070ff0f..824e62c2e44 100644 --- a/libcxx/test/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/nullptr_t.pass.cpp +++ b/libcxx/test/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/nullptr_t.pass.cpp @@ -1 +1,23 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <functional>
// class function<R(ArgTypes...)>
// function(nullptr_t);
#include <functional>
#include <cassert>
int main()
{
std::function<int(int)> f(nullptr);
assert(!f);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// class function<R(ArgTypes...)> + +// function(nullptr_t); + +#include <functional> +#include <cassert> + +int main() +{ + std::function<int(int)> f(nullptr); + assert(!f); +} diff --git a/libcxx/test/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/nullptr_t_assign.pass.cpp b/libcxx/test/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/nullptr_t_assign.pass.cpp index aa00a04f16e..5d64fa4fc72 100644 --- a/libcxx/test/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/nullptr_t_assign.pass.cpp +++ b/libcxx/test/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/nullptr_t_assign.pass.cpp @@ -1 +1,86 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <functional>
// class function<R(ArgTypes...)>
// function& operator=(nullptr_t);
#include <functional>
#include <new>
#include <cstdlib>
#include <cassert>
int new_called = 0;
void* operator new(std::size_t s) throw(std::bad_alloc)
{
++new_called;
return std::malloc(s);
}
void operator delete(void* p) throw()
{
--new_called;
std::free(p);
}
class A
{
int data_[10];
public:
static int count;
A()
{
++count;
for (int i = 0; i < 10; ++i)
data_[i] = i;
}
A(const A&) {++count;}
~A() {--count;}
int operator()(int i) const
{
for (int j = 0; j < 10; ++j)
i += data_[j];
return i;
}
};
int A::count = 0;
int g(int) {return 0;}
int main()
{
assert(new_called == 0);
{
std::function<int(int)> f = A();
assert(A::count == 1);
assert(new_called == 1);
assert(f.target<A>());
f = nullptr;
assert(A::count == 0);
assert(new_called == 0);
assert(f.target<A>() == 0);
}
{
std::function<int(int)> f = g;
assert(new_called == 0);
assert(f.target<int(*)(int)>());
assert(f.target<A>() == 0);
f = nullptr;
assert(new_called == 0);
assert(f.target<int(*)(int)>() == 0);
}
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// class function<R(ArgTypes...)> + +// function& operator=(nullptr_t); + +#include <functional> +#include <new> +#include <cstdlib> +#include <cassert> + +int new_called = 0; + +void* operator new(std::size_t s) throw(std::bad_alloc) +{ + ++new_called; + return std::malloc(s); +} + +void operator delete(void* p) throw() +{ + --new_called; + std::free(p); +} + +class A +{ + int data_[10]; +public: + static int count; + + A() + { + ++count; + for (int i = 0; i < 10; ++i) + data_[i] = i; + } + + A(const A&) {++count;} + + ~A() {--count;} + + int operator()(int i) const + { + for (int j = 0; j < 10; ++j) + i += data_[j]; + return i; + } +}; + +int A::count = 0; + +int g(int) {return 0;} + +int main() +{ + assert(new_called == 0); + { + std::function<int(int)> f = A(); + assert(A::count == 1); + assert(new_called == 1); + assert(f.target<A>()); + f = nullptr; + assert(A::count == 0); + assert(new_called == 0); + assert(f.target<A>() == 0); + } + { + std::function<int(int)> f = g; + assert(new_called == 0); + assert(f.target<int(*)(int)>()); + assert(f.target<A>() == 0); + f = nullptr; + assert(new_called == 0); + assert(f.target<int(*)(int)>() == 0); + } +} diff --git a/libcxx/test/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.inv/invoke.fail.cpp b/libcxx/test/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.inv/invoke.fail.cpp index 9df88e8c110..a7d16e9387f 100644 --- a/libcxx/test/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.inv/invoke.fail.cpp +++ b/libcxx/test/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.inv/invoke.fail.cpp @@ -1 +1,46 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <functional>
// class function<R(ArgTypes...)>
// R operator()(ArgTypes... args) const
#include <functional>
#include <cassert>
// member data pointer: cv qualifiers should transfer from argument to return type
struct A_int_1
{
A_int_1() : data_(5) {}
int data_;
};
void
test_int_1()
{
// member data pointer
{
int A_int_1::*fp = &A_int_1::data_;
A_int_1 a;
std::function<int& (const A_int_1*)> r2(fp);
const A_int_1* ap = &a;
assert(r2(ap) == 6);
r2(ap) = 7;
assert(r2(ap) == 7);
}
}
int main()
{
test_int_1();
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// class function<R(ArgTypes...)> + +// R operator()(ArgTypes... args) const + +#include <functional> +#include <cassert> + +// member data pointer: cv qualifiers should transfer from argument to return type + +struct A_int_1 +{ + A_int_1() : data_(5) {} + + int data_; +}; + +void +test_int_1() +{ + // member data pointer + { + int A_int_1::*fp = &A_int_1::data_; + A_int_1 a; + std::function<int& (const A_int_1*)> r2(fp); + const A_int_1* ap = &a; + assert(r2(ap) == 6); + r2(ap) = 7; + assert(r2(ap) == 7); + } +} + +int main() +{ + test_int_1(); +} diff --git a/libcxx/test/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.inv/invoke.pass.cpp b/libcxx/test/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.inv/invoke.pass.cpp index f95f082cf64..ab3d600b5b4 100644 --- a/libcxx/test/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.inv/invoke.pass.cpp +++ b/libcxx/test/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.inv/invoke.pass.cpp @@ -1 +1,335 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <functional>
// class function<R(ArgTypes...)>
// R operator()(ArgTypes... args) const
#include <functional>
#include <cassert>
int count = 0;
// 1 arg, return void
void f_void_1(int i)
{
count += i;
}
struct A_void_1
{
void operator()(int i)
{
count += i;
}
void mem1() {++count;}
void mem2() const {++count;}
};
void
test_void_1()
{
int save_count = count;
// function
{
std::function<void (int)> r1(f_void_1);
int i = 2;
r1(i);
assert(count == save_count+2);
save_count = count;
}
// function pointer
{
void (*fp)(int) = f_void_1;
std::function<void (int)> r1(fp);
int i = 3;
r1(i);
assert(count == save_count+3);
save_count = count;
}
// functor
{
A_void_1 a0;
std::function<void (int)> r1(a0);
int i = 4;
r1(i);
assert(count == save_count+4);
save_count = count;
}
// member function pointer
{
void (A_void_1::*fp)() = &A_void_1::mem1;
std::function<void (A_void_1)> r1(fp);
A_void_1 a;
r1(a);
assert(count == save_count+1);
save_count = count;
A_void_1* ap = &a;
std::function<void (A_void_1*)> r2 = fp;
r2(ap);
assert(count == save_count+1);
save_count = count;
}
// const member function pointer
{
void (A_void_1::*fp)() const = &A_void_1::mem2;
std::function<void (A_void_1)> r1(fp);
A_void_1 a;
r1(a);
assert(count == save_count+1);
save_count = count;
std::function<void (A_void_1*)> r2(fp);
A_void_1* ap = &a;
r2(ap);
assert(count == save_count+1);
save_count = count;
}
}
// 1 arg, return int
int f_int_1(int i)
{
return i + 1;
}
struct A_int_1
{
A_int_1() : data_(5) {}
int operator()(int i)
{
return i - 1;
}
int mem1() {return 3;}
int mem2() const {return 4;}
int data_;
};
void
test_int_1()
{
// function
{
std::function<int (int)> r1(f_int_1);
int i = 2;
assert(r1(i) == 3);
}
// function pointer
{
int (*fp)(int) = f_int_1;
std::function<int (int)> r1(fp);
int i = 3;
assert(r1(i) == 4);
}
// functor
{
A_int_1 a0;
std::function<int (int)> r1(a0);
int i = 4;
assert(r1(i) == 3);
}
// member function pointer
{
int (A_int_1::*fp)() = &A_int_1::mem1;
std::function<int (A_int_1)> r1(fp);
A_int_1 a;
assert(r1(a) == 3);
std::function<int (A_int_1*)> r2(fp);
A_int_1* ap = &a;
assert(r2(ap) == 3);
}
// const member function pointer
{
int (A_int_1::*fp)() const = &A_int_1::mem2;
std::function<int (A_int_1)> r1(fp);
A_int_1 a;
assert(r1(a) == 4);
std::function<int (A_int_1*)> r2(fp);
A_int_1* ap = &a;
assert(r2(ap) == 4);
}
// member data pointer
{
int A_int_1::*fp = &A_int_1::data_;
std::function<int& (A_int_1&)> r1(fp);
A_int_1 a;
assert(r1(a) == 5);
r1(a) = 6;
assert(r1(a) == 6);
std::function<int& (A_int_1*)> r2(fp);
A_int_1* ap = &a;
assert(r2(ap) == 6);
r2(ap) = 7;
assert(r2(ap) == 7);
}
}
// 2 arg, return void
void f_void_2(int i, int j)
{
count += i+j;
}
struct A_void_2
{
void operator()(int i, int j)
{
count += i+j;
}
void mem1(int i) {count += i;}
void mem2(int i) const {count += i;}
};
void
test_void_2()
{
int save_count = count;
// function
{
std::function<void (int, int)> r1(f_void_2);
int i = 2;
int j = 3;
r1(i, j);
assert(count == save_count+5);
save_count = count;
}
// function pointer
{
void (*fp)(int, int) = f_void_2;
std::function<void (int, int)> r1(fp);
int i = 3;
int j = 4;
r1(i, j);
assert(count == save_count+7);
save_count = count;
}
// functor
{
A_void_2 a0;
std::function<void (int, int)> r1(a0);
int i = 4;
int j = 5;
r1(i, j);
assert(count == save_count+9);
save_count = count;
}
// member function pointer
{
void (A_void_2::*fp)(int) = &A_void_2::mem1;
std::function<void (A_void_2, int)> r1(fp);
A_void_2 a;
int i = 3;
r1(a, i);
assert(count == save_count+3);
save_count = count;
std::function<void (A_void_2*, int)> r2(fp);
A_void_2* ap = &a;
r2(ap, i);
assert(count == save_count+3);
save_count = count;
}
// const member function pointer
{
void (A_void_2::*fp)(int) const = &A_void_2::mem2;
std::function<void (A_void_2, int)> r1(fp);
A_void_2 a;
int i = 4;
r1(a, i);
assert(count == save_count+4);
save_count = count;
std::function<void (A_void_2*, int)> r2(fp);
A_void_2* ap = &a;
r2(ap, i);
assert(count == save_count+4);
save_count = count;
}
}
// 2 arg, return int
int f_int_2(int i, int j)
{
return i+j;
}
struct A_int_2
{
int operator()(int i, int j)
{
return i+j;
}
int mem1(int i) {return i+1;}
int mem2(int i) const {return i+2;}
};
void
testint_2()
{
// function
{
std::function<int (int, int)> r1(f_int_2);
int i = 2;
int j = 3;
assert(r1(i, j) == i+j);
}
// function pointer
{
int (*fp)(int, int) = f_int_2;
std::function<int (int, int)> r1(fp);
int i = 3;
int j = 4;
assert(r1(i, j) == i+j);
}
// functor
{
A_int_2 a0;
std::function<int (int, int)> r1(a0);
int i = 4;
int j = 5;
assert(r1(i, j) == i+j);
}
// member function pointer
{
int(A_int_2::*fp)(int) = &A_int_2::mem1;
std::function<int (A_int_2, int)> r1(fp);
A_int_2 a;
int i = 3;
assert(r1(a, i) == i+1);
std::function<int (A_int_2*, int)> r2(fp);
A_int_2* ap = &a;
assert(r2(ap, i) == i+1);
}
// const member function pointer
{
int (A_int_2::*fp)(int) const = &A_int_2::mem2;
std::function<int (A_int_2, int)> r1(fp);
A_int_2 a;
int i = 4;
assert(r1(a, i) == i+2);
std::function<int (A_int_2*, int)> r2(fp);
A_int_2* ap = &a;
assert(r2(ap, i) == i+2);
}
}
int main()
{
test_void_1();
test_int_1();
test_void_2();
testint_2();
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// class function<R(ArgTypes...)> + +// R operator()(ArgTypes... args) const + +#include <functional> +#include <cassert> + +int count = 0; + +// 1 arg, return void + +void f_void_1(int i) +{ + count += i; +} + +struct A_void_1 +{ + void operator()(int i) + { + count += i; + } + + void mem1() {++count;} + void mem2() const {++count;} +}; + +void +test_void_1() +{ + int save_count = count; + // function + { + std::function<void (int)> r1(f_void_1); + int i = 2; + r1(i); + assert(count == save_count+2); + save_count = count; + } + // function pointer + { + void (*fp)(int) = f_void_1; + std::function<void (int)> r1(fp); + int i = 3; + r1(i); + assert(count == save_count+3); + save_count = count; + } + // functor + { + A_void_1 a0; + std::function<void (int)> r1(a0); + int i = 4; + r1(i); + assert(count == save_count+4); + save_count = count; + } + // member function pointer + { + void (A_void_1::*fp)() = &A_void_1::mem1; + std::function<void (A_void_1)> r1(fp); + A_void_1 a; + r1(a); + assert(count == save_count+1); + save_count = count; + A_void_1* ap = &a; + std::function<void (A_void_1*)> r2 = fp; + r2(ap); + assert(count == save_count+1); + save_count = count; + } + // const member function pointer + { + void (A_void_1::*fp)() const = &A_void_1::mem2; + std::function<void (A_void_1)> r1(fp); + A_void_1 a; + r1(a); + assert(count == save_count+1); + save_count = count; + std::function<void (A_void_1*)> r2(fp); + A_void_1* ap = &a; + r2(ap); + assert(count == save_count+1); + save_count = count; + } +} + +// 1 arg, return int + +int f_int_1(int i) +{ + return i + 1; +} + +struct A_int_1 +{ + A_int_1() : data_(5) {} + int operator()(int i) + { + return i - 1; + } + + int mem1() {return 3;} + int mem2() const {return 4;} + int data_; +}; + +void +test_int_1() +{ + // function + { + std::function<int (int)> r1(f_int_1); + int i = 2; + assert(r1(i) == 3); + } + // function pointer + { + int (*fp)(int) = f_int_1; + std::function<int (int)> r1(fp); + int i = 3; + assert(r1(i) == 4); + } + // functor + { + A_int_1 a0; + std::function<int (int)> r1(a0); + int i = 4; + assert(r1(i) == 3); + } + // member function pointer + { + int (A_int_1::*fp)() = &A_int_1::mem1; + std::function<int (A_int_1)> r1(fp); + A_int_1 a; + assert(r1(a) == 3); + std::function<int (A_int_1*)> r2(fp); + A_int_1* ap = &a; + assert(r2(ap) == 3); + } + // const member function pointer + { + int (A_int_1::*fp)() const = &A_int_1::mem2; + std::function<int (A_int_1)> r1(fp); + A_int_1 a; + assert(r1(a) == 4); + std::function<int (A_int_1*)> r2(fp); + A_int_1* ap = &a; + assert(r2(ap) == 4); + } + // member data pointer + { + int A_int_1::*fp = &A_int_1::data_; + std::function<int& (A_int_1&)> r1(fp); + A_int_1 a; + assert(r1(a) == 5); + r1(a) = 6; + assert(r1(a) == 6); + std::function<int& (A_int_1*)> r2(fp); + A_int_1* ap = &a; + assert(r2(ap) == 6); + r2(ap) = 7; + assert(r2(ap) == 7); + } +} + +// 2 arg, return void + +void f_void_2(int i, int j) +{ + count += i+j; +} + +struct A_void_2 +{ + void operator()(int i, int j) + { + count += i+j; + } + + void mem1(int i) {count += i;} + void mem2(int i) const {count += i;} +}; + +void +test_void_2() +{ + int save_count = count; + // function + { + std::function<void (int, int)> r1(f_void_2); + int i = 2; + int j = 3; + r1(i, j); + assert(count == save_count+5); + save_count = count; + } + // function pointer + { + void (*fp)(int, int) = f_void_2; + std::function<void (int, int)> r1(fp); + int i = 3; + int j = 4; + r1(i, j); + assert(count == save_count+7); + save_count = count; + } + // functor + { + A_void_2 a0; + std::function<void (int, int)> r1(a0); + int i = 4; + int j = 5; + r1(i, j); + assert(count == save_count+9); + save_count = count; + } + // member function pointer + { + void (A_void_2::*fp)(int) = &A_void_2::mem1; + std::function<void (A_void_2, int)> r1(fp); + A_void_2 a; + int i = 3; + r1(a, i); + assert(count == save_count+3); + save_count = count; + std::function<void (A_void_2*, int)> r2(fp); + A_void_2* ap = &a; + r2(ap, i); + assert(count == save_count+3); + save_count = count; + } + // const member function pointer + { + void (A_void_2::*fp)(int) const = &A_void_2::mem2; + std::function<void (A_void_2, int)> r1(fp); + A_void_2 a; + int i = 4; + r1(a, i); + assert(count == save_count+4); + save_count = count; + std::function<void (A_void_2*, int)> r2(fp); + A_void_2* ap = &a; + r2(ap, i); + assert(count == save_count+4); + save_count = count; + } +} + +// 2 arg, return int + +int f_int_2(int i, int j) +{ + return i+j; +} + +struct A_int_2 +{ + int operator()(int i, int j) + { + return i+j; + } + + int mem1(int i) {return i+1;} + int mem2(int i) const {return i+2;} +}; + +void +testint_2() +{ + // function + { + std::function<int (int, int)> r1(f_int_2); + int i = 2; + int j = 3; + assert(r1(i, j) == i+j); + } + // function pointer + { + int (*fp)(int, int) = f_int_2; + std::function<int (int, int)> r1(fp); + int i = 3; + int j = 4; + assert(r1(i, j) == i+j); + } + // functor + { + A_int_2 a0; + std::function<int (int, int)> r1(a0); + int i = 4; + int j = 5; + assert(r1(i, j) == i+j); + } + // member function pointer + { + int(A_int_2::*fp)(int) = &A_int_2::mem1; + std::function<int (A_int_2, int)> r1(fp); + A_int_2 a; + int i = 3; + assert(r1(a, i) == i+1); + std::function<int (A_int_2*, int)> r2(fp); + A_int_2* ap = &a; + assert(r2(ap, i) == i+1); + } + // const member function pointer + { + int (A_int_2::*fp)(int) const = &A_int_2::mem2; + std::function<int (A_int_2, int)> r1(fp); + A_int_2 a; + int i = 4; + assert(r1(a, i) == i+2); + std::function<int (A_int_2*, int)> r2(fp); + A_int_2* ap = &a; + assert(r2(ap, i) == i+2); + } +} + +int main() +{ + test_void_1(); + test_int_1(); + test_void_2(); + testint_2(); +} diff --git a/libcxx/test/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.inv/invoke_int_0.pass.cpp b/libcxx/test/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.inv/invoke_int_0.pass.cpp index 1f84b3c7853..aed33e30971 100644 --- a/libcxx/test/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.inv/invoke_int_0.pass.cpp +++ b/libcxx/test/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.inv/invoke_int_0.pass.cpp @@ -1 +1,58 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <functional>
// class function<R(ArgTypes...)>
// R operator()(ArgTypes... args) const
#include <functional>
#include <cassert>
// 0 args, return int
int count = 0;
int f_int_0()
{
return 3;
}
struct A_int_0
{
int operator()() {return 4;}
};
void
test_int_0()
{
// function
{
std::function<int ()> r1(f_int_0);
assert(r1() == 3);
}
// function pointer
{
int (*fp)() = f_int_0;
std::function<int ()> r1(fp);
assert(r1() == 3);
}
// functor
{
A_int_0 a0;
std::function<int ()> r1(a0);
assert(r1() == 4);
}
}
int main()
{
test_int_0();
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// class function<R(ArgTypes...)> + +// R operator()(ArgTypes... args) const + +#include <functional> +#include <cassert> + +// 0 args, return int + +int count = 0; + +int f_int_0() +{ + return 3; +} + +struct A_int_0 +{ + int operator()() {return 4;} +}; + +void +test_int_0() +{ + // function + { + std::function<int ()> r1(f_int_0); + assert(r1() == 3); + } + // function pointer + { + int (*fp)() = f_int_0; + std::function<int ()> r1(fp); + assert(r1() == 3); + } + // functor + { + A_int_0 a0; + std::function<int ()> r1(a0); + assert(r1() == 4); + } +} + +int main() +{ + test_int_0(); +} diff --git a/libcxx/test/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.inv/invoke_void_0.pass.cpp b/libcxx/test/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.inv/invoke_void_0.pass.cpp index d9f92d39870..024b4b956d7 100644 --- a/libcxx/test/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.inv/invoke_void_0.pass.cpp +++ b/libcxx/test/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.inv/invoke_void_0.pass.cpp @@ -1 +1,67 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <functional>
// class function<R(ArgTypes...)>
// R operator()(ArgTypes... args) const
#include <functional>
#include <new>
#include <cstdlib>
#include <cassert>
// 0 args, return void
int count = 0;
void f_void_0()
{
++count;
}
struct A_void_0
{
void operator()() {++count;}
};
void
test_void_0()
{
int save_count = count;
// function
{
std::function<void ()> r1(f_void_0);
r1();
assert(count == save_count+1);
save_count = count;
}
// function pointer
{
void (*fp)() = f_void_0;
std::function<void ()> r1(fp);
r1();
assert(count == save_count+1);
save_count = count;
}
// functor
{
A_void_0 a0;
std::function<void ()> r1(a0);
r1();
assert(count == save_count+1);
save_count = count;
}
}
int main()
{
test_void_0();
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// class function<R(ArgTypes...)> + +// R operator()(ArgTypes... args) const + +#include <functional> +#include <new> +#include <cstdlib> +#include <cassert> + +// 0 args, return void + +int count = 0; + +void f_void_0() +{ + ++count; +} + +struct A_void_0 +{ + void operator()() {++count;} +}; + +void +test_void_0() +{ + int save_count = count; + // function + { + std::function<void ()> r1(f_void_0); + r1(); + assert(count == save_count+1); + save_count = count; + } + // function pointer + { + void (*fp)() = f_void_0; + std::function<void ()> r1(fp); + r1(); + assert(count == save_count+1); + save_count = count; + } + // functor + { + A_void_0 a0; + std::function<void ()> r1(a0); + r1(); + assert(count == save_count+1); + save_count = count; + } +} + +int main() +{ + test_void_0(); +} diff --git a/libcxx/test/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.mod/swap.pass.cpp b/libcxx/test/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.mod/swap.pass.cpp index 935bc839d5e..02e3e1f119d 100644 --- a/libcxx/test/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.mod/swap.pass.cpp +++ b/libcxx/test/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.mod/swap.pass.cpp @@ -1 +1,134 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <functional>
// class function<R(ArgTypes...)>
// void swap(function& other);
#include <functional>
#include <new>
#include <cstdlib>
#include <cassert>
int new_called = 0;
void* operator new(std::size_t s) throw(std::bad_alloc)
{
++new_called;
return std::malloc(s);
}
void operator delete(void* p) throw()
{
--new_called;
std::free(p);
}
class A
{
int data_[10];
public:
static int count;
explicit A(int j)
{
++count;
data_[0] = j;
}
A(const A& a)
{
++count;
for (int i = 0; i < 10; ++i)
data_[i] = a.data_[i];
}
~A() {--count;}
int operator()(int i) const
{
for (int j = 0; j < 10; ++j)
i += data_[j];
return i;
}
int id() const {return data_[0];}
};
int A::count = 0;
int g(int) {return 0;}
int h(int) {return 1;}
int main()
{
assert(new_called == 0);
{
std::function<int(int)> f1 = A(1);
std::function<int(int)> f2 = A(2);
assert(A::count == 2);
assert(new_called == 2);
assert(f1.target<A>()->id() == 1);
assert(f2.target<A>()->id() == 2);
f1.swap(f2);
assert(A::count == 2);
assert(new_called == 2);
assert(f1.target<A>()->id() == 2);
assert(f2.target<A>()->id() == 1);
}
assert(A::count == 0);
assert(new_called == 0);
{
std::function<int(int)> f1 = A(1);
std::function<int(int)> f2 = g;
assert(A::count == 1);
assert(new_called == 1);
assert(f1.target<A>()->id() == 1);
assert(*f2.target<int(*)(int)>() == g);
f1.swap(f2);
assert(A::count == 1);
assert(new_called == 1);
assert(*f1.target<int(*)(int)>() == g);
assert(f2.target<A>()->id() == 1);
}
assert(A::count == 0);
assert(new_called == 0);
{
std::function<int(int)> f1 = g;
std::function<int(int)> f2 = A(1);
assert(A::count == 1);
assert(new_called == 1);
assert(*f1.target<int(*)(int)>() == g);
assert(f2.target<A>()->id() == 1);
f1.swap(f2);
assert(A::count == 1);
assert(new_called == 1);
assert(f1.target<A>()->id() == 1);
assert(*f2.target<int(*)(int)>() == g);
}
assert(A::count == 0);
assert(new_called == 0);
{
std::function<int(int)> f1 = g;
std::function<int(int)> f2 = h;
assert(A::count == 0);
assert(new_called == 0);
assert(*f1.target<int(*)(int)>() == g);
assert(*f2.target<int(*)(int)>() == h);
f1.swap(f2);
assert(A::count == 0);
assert(new_called == 0);
assert(*f1.target<int(*)(int)>() == h);
assert(*f2.target<int(*)(int)>() == g);
}
assert(A::count == 0);
assert(new_called == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// class function<R(ArgTypes...)> + +// void swap(function& other); + +#include <functional> +#include <new> +#include <cstdlib> +#include <cassert> + +int new_called = 0; + +void* operator new(std::size_t s) throw(std::bad_alloc) +{ + ++new_called; + return std::malloc(s); +} + +void operator delete(void* p) throw() +{ + --new_called; + std::free(p); +} + +class A +{ + int data_[10]; +public: + static int count; + + explicit A(int j) + { + ++count; + data_[0] = j; + } + + A(const A& a) + { + ++count; + for (int i = 0; i < 10; ++i) + data_[i] = a.data_[i]; + } + + ~A() {--count;} + + int operator()(int i) const + { + for (int j = 0; j < 10; ++j) + i += data_[j]; + return i; + } + + int id() const {return data_[0];} +}; + +int A::count = 0; + +int g(int) {return 0;} +int h(int) {return 1;} + +int main() +{ + assert(new_called == 0); + { + std::function<int(int)> f1 = A(1); + std::function<int(int)> f2 = A(2); + assert(A::count == 2); + assert(new_called == 2); + assert(f1.target<A>()->id() == 1); + assert(f2.target<A>()->id() == 2); + f1.swap(f2); + assert(A::count == 2); + assert(new_called == 2); + assert(f1.target<A>()->id() == 2); + assert(f2.target<A>()->id() == 1); + } + assert(A::count == 0); + assert(new_called == 0); + { + std::function<int(int)> f1 = A(1); + std::function<int(int)> f2 = g; + assert(A::count == 1); + assert(new_called == 1); + assert(f1.target<A>()->id() == 1); + assert(*f2.target<int(*)(int)>() == g); + f1.swap(f2); + assert(A::count == 1); + assert(new_called == 1); + assert(*f1.target<int(*)(int)>() == g); + assert(f2.target<A>()->id() == 1); + } + assert(A::count == 0); + assert(new_called == 0); + { + std::function<int(int)> f1 = g; + std::function<int(int)> f2 = A(1); + assert(A::count == 1); + assert(new_called == 1); + assert(*f1.target<int(*)(int)>() == g); + assert(f2.target<A>()->id() == 1); + f1.swap(f2); + assert(A::count == 1); + assert(new_called == 1); + assert(f1.target<A>()->id() == 1); + assert(*f2.target<int(*)(int)>() == g); + } + assert(A::count == 0); + assert(new_called == 0); + { + std::function<int(int)> f1 = g; + std::function<int(int)> f2 = h; + assert(A::count == 0); + assert(new_called == 0); + assert(*f1.target<int(*)(int)>() == g); + assert(*f2.target<int(*)(int)>() == h); + f1.swap(f2); + assert(A::count == 0); + assert(new_called == 0); + assert(*f1.target<int(*)(int)>() == h); + assert(*f2.target<int(*)(int)>() == g); + } + assert(A::count == 0); + assert(new_called == 0); +} diff --git a/libcxx/test/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.nullptr/operator_==.pass.cpp b/libcxx/test/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.nullptr/operator_==.pass.cpp index 6ea89d4c125..91083bbe68c 100644 --- a/libcxx/test/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.nullptr/operator_==.pass.cpp +++ b/libcxx/test/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.nullptr/operator_==.pass.cpp @@ -1 +1,41 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <functional>
// class function<R(ArgTypes...)>
// template <MoveConstructible R, MoveConstructible ... ArgTypes>
// bool operator==(const function<R(ArgTypes...)>&, nullptr_t);
//
// template <MoveConstructible R, MoveConstructible ... ArgTypes>
// bool operator==(nullptr_t, const function<R(ArgTypes...)>&);
//
// template <MoveConstructible R, MoveConstructible ... ArgTypes>
// bool operator!=(const function<R(ArgTypes...)>&, nullptr_t);
//
// template <MoveConstructible R, MoveConstructible ... ArgTypes>
// bool operator!=(nullptr_t, const function<R(ArgTypes...)>&);
#include <functional>
#include <cassert>
int g(int) {return 0;}
int main()
{
{
std::function<int(int)> f;
assert(f == nullptr);
assert(nullptr == f);
f = g;
assert(f != nullptr);
assert(nullptr != f);
}
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// class function<R(ArgTypes...)> + +// template <MoveConstructible R, MoveConstructible ... ArgTypes> +// bool operator==(const function<R(ArgTypes...)>&, nullptr_t); +// +// template <MoveConstructible R, MoveConstructible ... ArgTypes> +// bool operator==(nullptr_t, const function<R(ArgTypes...)>&); +// +// template <MoveConstructible R, MoveConstructible ... ArgTypes> +// bool operator!=(const function<R(ArgTypes...)>&, nullptr_t); +// +// template <MoveConstructible R, MoveConstructible ... ArgTypes> +// bool operator!=(nullptr_t, const function<R(ArgTypes...)>&); + +#include <functional> +#include <cassert> + +int g(int) {return 0;} + +int main() +{ + { + std::function<int(int)> f; + assert(f == nullptr); + assert(nullptr == f); + f = g; + assert(f != nullptr); + assert(nullptr != f); + } +} diff --git a/libcxx/test/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.targ/target.pass.cpp b/libcxx/test/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.targ/target.pass.cpp index 718aedcb2b0..d58131c0b5f 100644 --- a/libcxx/test/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.targ/target.pass.cpp +++ b/libcxx/test/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.targ/target.pass.cpp @@ -1 +1,89 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <functional>
// class function<R(ArgTypes...)>
// template<typename T>
// requires Callable<T, ArgTypes...> && Convertible<Callable<T, ArgTypes...>::result_type, R>
// T*
// target();
// template<typename T>
// requires Callable<T, ArgTypes...> && Convertible<Callable<T, ArgTypes...>::result_type, R>
// const T*
// target() const;
#include <functional>
#include <new>
#include <cstdlib>
#include <cassert>
class A
{
int data_[10];
public:
static int count;
A()
{
++count;
for (int i = 0; i < 10; ++i)
data_[i] = i;
}
A(const A&) {++count;}
~A() {--count;}
int operator()(int i) const
{
for (int j = 0; j < 10; ++j)
i += data_[j];
return i;
}
int foo(int) const {return 1;}
};
int A::count = 0;
int g(int) {return 0;}
int main()
{
{
std::function<int(int)> f = A();
assert(A::count == 1);
assert(f.target<A>());
assert(f.target<int(*)(int)>() == 0);
}
assert(A::count == 0);
{
std::function<int(int)> f = g;
assert(A::count == 0);
assert(f.target<int(*)(int)>());
assert(f.target<A>() == 0);
}
assert(A::count == 0);
{
const std::function<int(int)> f = A();
assert(A::count == 1);
assert(f.target<A>());
assert(f.target<int(*)(int)>() == 0);
}
assert(A::count == 0);
{
const std::function<int(int)> f = g;
assert(A::count == 0);
assert(f.target<int(*)(int)>());
assert(f.target<A>() == 0);
}
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// class function<R(ArgTypes...)> + +// template<typename T> +// requires Callable<T, ArgTypes...> && Convertible<Callable<T, ArgTypes...>::result_type, R> +// T* +// target(); +// template<typename T> +// requires Callable<T, ArgTypes...> && Convertible<Callable<T, ArgTypes...>::result_type, R> +// const T* +// target() const; + +#include <functional> +#include <new> +#include <cstdlib> +#include <cassert> + +class A +{ + int data_[10]; +public: + static int count; + + A() + { + ++count; + for (int i = 0; i < 10; ++i) + data_[i] = i; + } + + A(const A&) {++count;} + + ~A() {--count;} + + int operator()(int i) const + { + for (int j = 0; j < 10; ++j) + i += data_[j]; + return i; + } + + int foo(int) const {return 1;} +}; + +int A::count = 0; + +int g(int) {return 0;} + +int main() +{ + { + std::function<int(int)> f = A(); + assert(A::count == 1); + assert(f.target<A>()); + assert(f.target<int(*)(int)>() == 0); + } + assert(A::count == 0); + { + std::function<int(int)> f = g; + assert(A::count == 0); + assert(f.target<int(*)(int)>()); + assert(f.target<A>() == 0); + } + assert(A::count == 0); + { + const std::function<int(int)> f = A(); + assert(A::count == 1); + assert(f.target<A>()); + assert(f.target<int(*)(int)>() == 0); + } + assert(A::count == 0); + { + const std::function<int(int)> f = g; + assert(A::count == 0); + assert(f.target<int(*)(int)>()); + assert(f.target<A>() == 0); + } + assert(A::count == 0); +} diff --git a/libcxx/test/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.targ/target_type.pass.cpp b/libcxx/test/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.targ/target_type.pass.cpp index 36bd29fcfb9..c675dfcd749 100644 --- a/libcxx/test/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.targ/target_type.pass.cpp +++ b/libcxx/test/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.targ/target_type.pass.cpp @@ -1 +1,61 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <functional>
// class function<R(ArgTypes...)>
// const std::type_info& target_type() const;
#include <functional>
#include <typeinfo>
#include <cassert>
class A
{
int data_[10];
public:
static int count;
A()
{
++count;
for (int i = 0; i < 10; ++i)
data_[i] = i;
}
A(const A&) {++count;}
~A() {--count;}
int operator()(int i) const
{
for (int j = 0; j < 10; ++j)
i += data_[j];
return i;
}
int foo(int) const {return 1;}
};
int A::count = 0;
int g(int) {return 0;}
int main()
{
{
std::function<int(int)> f = A();
assert(f.target_type() == typeid(A));
}
{
std::function<int(int)> f;
assert(f.target_type() == typeid(void));
}
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// class function<R(ArgTypes...)> + +// const std::type_info& target_type() const; + +#include <functional> +#include <typeinfo> +#include <cassert> + +class A +{ + int data_[10]; +public: + static int count; + + A() + { + ++count; + for (int i = 0; i < 10; ++i) + data_[i] = i; + } + + A(const A&) {++count;} + + ~A() {--count;} + + int operator()(int i) const + { + for (int j = 0; j < 10; ++j) + i += data_[j]; + return i; + } + + int foo(int) const {return 1;} +}; + +int A::count = 0; + +int g(int) {return 0;} + +int main() +{ + { + std::function<int(int)> f = A(); + assert(f.target_type() == typeid(A)); + } + { + std::function<int(int)> f; + assert(f.target_type() == typeid(void)); + } +} diff --git a/libcxx/test/utilities/function.objects/func.wrap/func.wrap.func/test_allocator.h b/libcxx/test/utilities/function.objects/func.wrap/func.wrap.func/test_allocator.h index 898c0900d4e..1c0f163d053 100644 --- a/libcxx/test/utilities/function.objects/func.wrap/func.wrap.func/test_allocator.h +++ b/libcxx/test/utilities/function.objects/func.wrap/func.wrap.func/test_allocator.h @@ -62,7 +62,7 @@ public: #ifdef _LIBCPP_MOVE void construct(pointer p, T&& val) {::new(p) T(std::move(val));} -#endif +#endif // _LIBCPP_MOVE void destroy(pointer p) {p->~T();} friend bool operator==(const test_allocator& x, const test_allocator& y) @@ -105,8 +105,8 @@ public: #ifdef _LIBCPP_HAS_NO_ADVANCED_SFINAE std::size_t max_size() const {return UINT_MAX / sizeof(T);} -#endif +#endif // _LIBCPP_HAS_NO_ADVANCED_SFINAE }; -#endif +#endif // TEST_ALLOCATOR_H diff --git a/libcxx/test/utilities/function.objects/func.wrap/func.wrap.func/types.pass.cpp b/libcxx/test/utilities/function.objects/func.wrap/func.wrap.func/types.pass.cpp index 819c8fd1ba2..94e07ecea18 100644 --- a/libcxx/test/utilities/function.objects/func.wrap/func.wrap.func/types.pass.cpp +++ b/libcxx/test/utilities/function.objects/func.wrap/func.wrap.func/types.pass.cpp @@ -1 +1,49 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <functional>
// template<Returnable R, CopyConstructible... ArgTypes>
// class function<R(ArgTypes...)>
// : public unary_function<T1, R> // iff sizeof...(ArgTypes) == 1 and
// // ArgTypes contains T1
// : public binary_function<T1, T2, R> // iff sizeof...(ArgTypes) == 2 and
// // ArgTypes contains T1 and T2
// {
// public:
// typedef R result_type;
// ...
// };
#include <functional>
#include <type_traits>
int main()
{
static_assert((!std::is_base_of<std::unary_function <int, int>,
std::function<int()> >::value), "");
static_assert((!std::is_base_of<std::binary_function<int, int, int>,
std::function<int()> >::value), "");
static_assert(( std::is_same< std::function<int()>::result_type,
int>::value), "");
static_assert(( std::is_base_of<std::unary_function <int, double>,
std::function<double(int)> >::value), "");
static_assert((!std::is_base_of<std::binary_function<int, int, double>,
std::function<double(int)> >::value), "");
static_assert(( std::is_same< std::function<double(int)>::result_type,
double>::value), "");
static_assert((!std::is_base_of<std::unary_function <int, double>,
std::function<double(int, char)> >::value), "");
static_assert(( std::is_base_of<std::binary_function<int, char, double>,
std::function<double(int, char)> >::value), "");
static_assert(( std::is_same< std::function<double(int, char)>::result_type,
double>::value), "");
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// template<Returnable R, CopyConstructible... ArgTypes> +// class function<R(ArgTypes...)> +// : public unary_function<T1, R> // iff sizeof...(ArgTypes) == 1 and +// // ArgTypes contains T1 +// : public binary_function<T1, T2, R> // iff sizeof...(ArgTypes) == 2 and +// // ArgTypes contains T1 and T2 +// { +// public: +// typedef R result_type; +// ... +// }; + +#include <functional> +#include <type_traits> + +int main() +{ + static_assert((!std::is_base_of<std::unary_function <int, int>, + std::function<int()> >::value), ""); + static_assert((!std::is_base_of<std::binary_function<int, int, int>, + std::function<int()> >::value), ""); + static_assert(( std::is_same< std::function<int()>::result_type, + int>::value), ""); + + static_assert(( std::is_base_of<std::unary_function <int, double>, + std::function<double(int)> >::value), ""); + static_assert((!std::is_base_of<std::binary_function<int, int, double>, + std::function<double(int)> >::value), ""); + static_assert(( std::is_same< std::function<double(int)>::result_type, + double>::value), ""); + + static_assert((!std::is_base_of<std::unary_function <int, double>, + std::function<double(int, char)> >::value), ""); + static_assert(( std::is_base_of<std::binary_function<int, char, double>, + std::function<double(int, char)> >::value), ""); + static_assert(( std::is_same< std::function<double(int, char)>::result_type, + double>::value), ""); +} diff --git a/libcxx/test/utilities/function.objects/func.wrap/nothing_to_do.pass.cpp b/libcxx/test/utilities/function.objects/func.wrap/nothing_to_do.pass.cpp index e8db90cbee0..b89f168e9c4 100644 --- a/libcxx/test/utilities/function.objects/func.wrap/nothing_to_do.pass.cpp +++ b/libcxx/test/utilities/function.objects/func.wrap/nothing_to_do.pass.cpp @@ -1 +1,12 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
int main()
{
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/libcxx/test/utilities/function.objects/function.pointer.adaptors/pointer_to_binary_function.pass.cpp b/libcxx/test/utilities/function.objects/function.pointer.adaptors/pointer_to_binary_function.pass.cpp index 0538c6ea3b8..d3587aa0e01 100644 --- a/libcxx/test/utilities/function.objects/function.pointer.adaptors/pointer_to_binary_function.pass.cpp +++ b/libcxx/test/utilities/function.objects/function.pointer.adaptors/pointer_to_binary_function.pass.cpp @@ -1 +1,26 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <functional>
// pointer_to_binary_function
#include <functional>
#include <type_traits>
#include <cassert>
double binary_f(int i, short j) {return i - j + .75;}
int main()
{
typedef std::pointer_to_binary_function<int, short, double> F;
static_assert((std::is_base_of<std::binary_function<int, short, double>, F>::value), "");
const F f(binary_f);
assert(f(36, 27) == 9.75);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// pointer_to_binary_function + +#include <functional> +#include <type_traits> +#include <cassert> + +double binary_f(int i, short j) {return i - j + .75;} + +int main() +{ + typedef std::pointer_to_binary_function<int, short, double> F; + static_assert((std::is_base_of<std::binary_function<int, short, double>, F>::value), ""); + const F f(binary_f); + assert(f(36, 27) == 9.75); +} diff --git a/libcxx/test/utilities/function.objects/function.pointer.adaptors/pointer_to_unary_function.pass.cpp b/libcxx/test/utilities/function.objects/function.pointer.adaptors/pointer_to_unary_function.pass.cpp index 9ff953e5550..30e13010261 100644 --- a/libcxx/test/utilities/function.objects/function.pointer.adaptors/pointer_to_unary_function.pass.cpp +++ b/libcxx/test/utilities/function.objects/function.pointer.adaptors/pointer_to_unary_function.pass.cpp @@ -1 +1,26 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <functional>
// pointer_to_unary_function
#include <functional>
#include <type_traits>
#include <cassert>
double unary_f(int i) {return 0.5 - i;}
int main()
{
typedef std::pointer_to_unary_function<int, double> F;
static_assert((std::is_base_of<std::unary_function<int, double>, F>::value), "");
const F f(unary_f);
assert(f(36) == -35.5);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// pointer_to_unary_function + +#include <functional> +#include <type_traits> +#include <cassert> + +double unary_f(int i) {return 0.5 - i;} + +int main() +{ + typedef std::pointer_to_unary_function<int, double> F; + static_assert((std::is_base_of<std::unary_function<int, double>, F>::value), ""); + const F f(unary_f); + assert(f(36) == -35.5); +} diff --git a/libcxx/test/utilities/function.objects/function.pointer.adaptors/ptr_fun1.pass.cpp b/libcxx/test/utilities/function.objects/function.pointer.adaptors/ptr_fun1.pass.cpp index a4f16d0a83c..25162c3b59d 100644 --- a/libcxx/test/utilities/function.objects/function.pointer.adaptors/ptr_fun1.pass.cpp +++ b/libcxx/test/utilities/function.objects/function.pointer.adaptors/ptr_fun1.pass.cpp @@ -1 +1,25 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <functional>
// template <CopyConstructible Arg, Returnable Result>
// pointer_to_unary_function<Arg, Result>
// ptr_fun(Result (*f)(Arg));
#include <functional>
#include <type_traits>
#include <cassert>
double unary_f(int i) {return 0.5 - i;}
int main()
{
assert(std::ptr_fun(unary_f)(36) == -35.5);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// template <CopyConstructible Arg, Returnable Result> +// pointer_to_unary_function<Arg, Result> +// ptr_fun(Result (*f)(Arg)); + +#include <functional> +#include <type_traits> +#include <cassert> + +double unary_f(int i) {return 0.5 - i;} + +int main() +{ + assert(std::ptr_fun(unary_f)(36) == -35.5); +} diff --git a/libcxx/test/utilities/function.objects/function.pointer.adaptors/ptr_fun2.pass.cpp b/libcxx/test/utilities/function.objects/function.pointer.adaptors/ptr_fun2.pass.cpp index 84622320965..61525dd4dd7 100644 --- a/libcxx/test/utilities/function.objects/function.pointer.adaptors/ptr_fun2.pass.cpp +++ b/libcxx/test/utilities/function.objects/function.pointer.adaptors/ptr_fun2.pass.cpp @@ -1 +1,25 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <functional>
// template <CopyConstructible Arg1, CopyConstructible Arg2, Returnable Result>
// pointer_to_binary_function<Arg1,Arg2,Result>
// ptr_fun(Result (*f)(Arg1, Arg2));
#include <functional>
#include <type_traits>
#include <cassert>
double binary_f(int i, short j) {return i - j + .75;}
int main()
{
assert(std::ptr_fun(binary_f)(36, 27) == 9.75);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// template <CopyConstructible Arg1, CopyConstructible Arg2, Returnable Result> +// pointer_to_binary_function<Arg1,Arg2,Result> +// ptr_fun(Result (*f)(Arg1, Arg2)); + +#include <functional> +#include <type_traits> +#include <cassert> + +double binary_f(int i, short j) {return i - j + .75;} + +int main() +{ + assert(std::ptr_fun(binary_f)(36, 27) == 9.75); +} diff --git a/libcxx/test/utilities/function.objects/logical.operations/logical_and.pass.cpp b/libcxx/test/utilities/function.objects/logical.operations/logical_and.pass.cpp index ae03d2c74ae..e9ae960a09c 100644 --- a/libcxx/test/utilities/function.objects/logical.operations/logical_and.pass.cpp +++ b/libcxx/test/utilities/function.objects/logical.operations/logical_and.pass.cpp @@ -1 +1,27 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <functional>
// logical_and
#include <functional>
#include <type_traits>
#include <cassert>
int main()
{
typedef std::logical_and<int> F;
const F f = F();
static_assert((std::is_base_of<std::binary_function<int, int, bool>, F>::value), "");
assert(f(36, 36));
assert(!f(36, 0));
assert(!f(0, 36));
assert(!f(0, 0));
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// logical_and + +#include <functional> +#include <type_traits> +#include <cassert> + +int main() +{ + typedef std::logical_and<int> F; + const F f = F(); + static_assert((std::is_base_of<std::binary_function<int, int, bool>, F>::value), ""); + assert(f(36, 36)); + assert(!f(36, 0)); + assert(!f(0, 36)); + assert(!f(0, 0)); +} diff --git a/libcxx/test/utilities/function.objects/logical.operations/logical_not.pass.cpp b/libcxx/test/utilities/function.objects/logical.operations/logical_not.pass.cpp index 471b145aa0f..c2bb2566e6b 100644 --- a/libcxx/test/utilities/function.objects/logical.operations/logical_not.pass.cpp +++ b/libcxx/test/utilities/function.objects/logical.operations/logical_not.pass.cpp @@ -1 +1,25 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <functional>
// logical_not
#include <functional>
#include <type_traits>
#include <cassert>
int main()
{
typedef std::logical_not<int> F;
const F f = F();
static_assert((std::is_base_of<std::unary_function<int, bool>, F>::value), "");
assert(!f(36));
assert(f(0));
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// logical_not + +#include <functional> +#include <type_traits> +#include <cassert> + +int main() +{ + typedef std::logical_not<int> F; + const F f = F(); + static_assert((std::is_base_of<std::unary_function<int, bool>, F>::value), ""); + assert(!f(36)); + assert(f(0)); +} diff --git a/libcxx/test/utilities/function.objects/logical.operations/logical_or.pass.cpp b/libcxx/test/utilities/function.objects/logical.operations/logical_or.pass.cpp index 35c1f815b31..17efd5cba3d 100644 --- a/libcxx/test/utilities/function.objects/logical.operations/logical_or.pass.cpp +++ b/libcxx/test/utilities/function.objects/logical.operations/logical_or.pass.cpp @@ -1 +1,27 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <functional>
// logical_or
#include <functional>
#include <type_traits>
#include <cassert>
int main()
{
typedef std::logical_or<int> F;
const F f = F();
static_assert((std::is_base_of<std::binary_function<int, int, bool>, F>::value), "");
assert(f(36, 36));
assert(f(36, 0));
assert(f(0, 36));
assert(!f(0, 0));
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// logical_or + +#include <functional> +#include <type_traits> +#include <cassert> + +int main() +{ + typedef std::logical_or<int> F; + const F f = F(); + static_assert((std::is_base_of<std::binary_function<int, int, bool>, F>::value), ""); + assert(f(36, 36)); + assert(f(36, 0)); + assert(f(0, 36)); + assert(!f(0, 0)); +} diff --git a/libcxx/test/utilities/function.objects/member.pointer.adaptors/const_mem_fun.pass.cpp b/libcxx/test/utilities/function.objects/member.pointer.adaptors/const_mem_fun.pass.cpp index 7c1fb7432bf..a06374f9768 100644 --- a/libcxx/test/utilities/function.objects/member.pointer.adaptors/const_mem_fun.pass.cpp +++ b/libcxx/test/utilities/function.objects/member.pointer.adaptors/const_mem_fun.pass.cpp @@ -1 +1,31 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <functional>
// template<cReturnable S, ClassType T>
// const_mem_fun_t<S,T>
// mem_fun(S (T::*f)() const);
#include <functional>
#include <cassert>
struct A
{
char a1() {return 5;}
short a2(int i) {return short(i+1);}
int a3() const {return 1;}
double a4(unsigned i) const {return i-1;}
};
int main()
{
const A a = A();
assert(std::mem_fun(&A::a3)(&a) == 1);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// template<cReturnable S, ClassType T> +// const_mem_fun_t<S,T> +// mem_fun(S (T::*f)() const); + +#include <functional> +#include <cassert> + +struct A +{ + char a1() {return 5;} + short a2(int i) {return short(i+1);} + int a3() const {return 1;} + double a4(unsigned i) const {return i-1;} +}; + +int main() +{ + const A a = A(); + assert(std::mem_fun(&A::a3)(&a) == 1); +} diff --git a/libcxx/test/utilities/function.objects/member.pointer.adaptors/const_mem_fun1.pass.cpp b/libcxx/test/utilities/function.objects/member.pointer.adaptors/const_mem_fun1.pass.cpp index b23389abb4e..ae899563410 100644 --- a/libcxx/test/utilities/function.objects/member.pointer.adaptors/const_mem_fun1.pass.cpp +++ b/libcxx/test/utilities/function.objects/member.pointer.adaptors/const_mem_fun1.pass.cpp @@ -1 +1,31 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <functional>
// template<Returnable S, ClassType T, CopyConstructible A>
// const_mem_fun1_t<S,T,A>
// mem_fun(S (T::*f)(A) const);
#include <functional>
#include <cassert>
struct A
{
char a1() {return 5;}
short a2(int i) {return short(i+1);}
int a3() const {return 1;}
double a4(unsigned i) const {return i-1;}
};
int main()
{
const A a = A();
assert(std::mem_fun(&A::a4)(&a, 6) == 5);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// template<Returnable S, ClassType T, CopyConstructible A> +// const_mem_fun1_t<S,T,A> +// mem_fun(S (T::*f)(A) const); + +#include <functional> +#include <cassert> + +struct A +{ + char a1() {return 5;} + short a2(int i) {return short(i+1);} + int a3() const {return 1;} + double a4(unsigned i) const {return i-1;} +}; + +int main() +{ + const A a = A(); + assert(std::mem_fun(&A::a4)(&a, 6) == 5); +} diff --git a/libcxx/test/utilities/function.objects/member.pointer.adaptors/const_mem_fun1_ref_t.pass.cpp b/libcxx/test/utilities/function.objects/member.pointer.adaptors/const_mem_fun1_ref_t.pass.cpp index a7b5d50c2fa..f918ff99066 100644 --- a/libcxx/test/utilities/function.objects/member.pointer.adaptors/const_mem_fun1_ref_t.pass.cpp +++ b/libcxx/test/utilities/function.objects/member.pointer.adaptors/const_mem_fun1_ref_t.pass.cpp @@ -1 +1,33 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <functional>
// const_mem_fun1_ref_t
#include <functional>
#include <type_traits>
#include <cassert>
struct A
{
char a1() {return 5;}
short a2(int i) {return short(i+1);}
int a3() const {return 1;}
double a4(unsigned i) const {return i-1;}
};
int main()
{
typedef std::const_mem_fun1_ref_t<double, A, unsigned> F;
static_assert((std::is_base_of<std::binary_function<A, unsigned, double>, F>::value), "");
const F f(&A::a4);
const A a = A();
assert(f(a, 6) == 5);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// const_mem_fun1_ref_t + +#include <functional> +#include <type_traits> +#include <cassert> + +struct A +{ + char a1() {return 5;} + short a2(int i) {return short(i+1);} + int a3() const {return 1;} + double a4(unsigned i) const {return i-1;} +}; + +int main() +{ + typedef std::const_mem_fun1_ref_t<double, A, unsigned> F; + static_assert((std::is_base_of<std::binary_function<A, unsigned, double>, F>::value), ""); + const F f(&A::a4); + const A a = A(); + assert(f(a, 6) == 5); +} diff --git a/libcxx/test/utilities/function.objects/member.pointer.adaptors/const_mem_fun1_t.pass.cpp b/libcxx/test/utilities/function.objects/member.pointer.adaptors/const_mem_fun1_t.pass.cpp index 8989ae778c8..c99674282f3 100644 --- a/libcxx/test/utilities/function.objects/member.pointer.adaptors/const_mem_fun1_t.pass.cpp +++ b/libcxx/test/utilities/function.objects/member.pointer.adaptors/const_mem_fun1_t.pass.cpp @@ -1 +1,33 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <functional>
// const_mem_fun1_t
#include <functional>
#include <type_traits>
#include <cassert>
struct A
{
char a1() {return 5;}
short a2(int i) {return short(i+1);}
int a3() const {return 1;}
double a4(unsigned i) const {return i-1;}
};
int main()
{
typedef std::const_mem_fun1_t<double, A, unsigned> F;
static_assert((std::is_base_of<std::binary_function<const A*, unsigned, double>, F>::value), "");
const F f(&A::a4);
const A a = A();
assert(f(&a, 6) == 5);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// const_mem_fun1_t + +#include <functional> +#include <type_traits> +#include <cassert> + +struct A +{ + char a1() {return 5;} + short a2(int i) {return short(i+1);} + int a3() const {return 1;} + double a4(unsigned i) const {return i-1;} +}; + +int main() +{ + typedef std::const_mem_fun1_t<double, A, unsigned> F; + static_assert((std::is_base_of<std::binary_function<const A*, unsigned, double>, F>::value), ""); + const F f(&A::a4); + const A a = A(); + assert(f(&a, 6) == 5); +} diff --git a/libcxx/test/utilities/function.objects/member.pointer.adaptors/const_mem_fun_ref.pass.cpp b/libcxx/test/utilities/function.objects/member.pointer.adaptors/const_mem_fun_ref.pass.cpp index 987b4c72ff7..93273aeeaa5 100644 --- a/libcxx/test/utilities/function.objects/member.pointer.adaptors/const_mem_fun_ref.pass.cpp +++ b/libcxx/test/utilities/function.objects/member.pointer.adaptors/const_mem_fun_ref.pass.cpp @@ -1 +1,31 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <functional>
// template<Returnable S, ClassType T>
// const_mem_fun_ref_t<S,T>
// mem_fun_ref(S (T::*f)() const);
#include <functional>
#include <cassert>
struct A
{
char a1() {return 5;}
short a2(int i) {return short(i+1);}
int a3() const {return 1;}
double a4(unsigned i) const {return i-1;}
};
int main()
{
const A a = A();
assert(std::mem_fun_ref(&A::a3)(a) == 1);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// template<Returnable S, ClassType T> +// const_mem_fun_ref_t<S,T> +// mem_fun_ref(S (T::*f)() const); + +#include <functional> +#include <cassert> + +struct A +{ + char a1() {return 5;} + short a2(int i) {return short(i+1);} + int a3() const {return 1;} + double a4(unsigned i) const {return i-1;} +}; + +int main() +{ + const A a = A(); + assert(std::mem_fun_ref(&A::a3)(a) == 1); +} diff --git a/libcxx/test/utilities/function.objects/member.pointer.adaptors/const_mem_fun_ref1.pass.cpp b/libcxx/test/utilities/function.objects/member.pointer.adaptors/const_mem_fun_ref1.pass.cpp index 60aadc79921..3eaee7f034e 100644 --- a/libcxx/test/utilities/function.objects/member.pointer.adaptors/const_mem_fun_ref1.pass.cpp +++ b/libcxx/test/utilities/function.objects/member.pointer.adaptors/const_mem_fun_ref1.pass.cpp @@ -1 +1,31 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <functional>
// template<Returnable S, ClassType T, CopyConstructible A>
// const_mem_fun1_ref_t<S,T,A>
// mem_fun_ref(S (T::*f)(A) const);
#include <functional>
#include <cassert>
struct A
{
char a1() {return 5;}
short a2(int i) {return short(i+1);}
int a3() const {return 1;}
double a4(unsigned i) const {return i-1;}
};
int main()
{
const A a = A();
assert(std::mem_fun_ref(&A::a4)(a, 6) == 5);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// template<Returnable S, ClassType T, CopyConstructible A> +// const_mem_fun1_ref_t<S,T,A> +// mem_fun_ref(S (T::*f)(A) const); + +#include <functional> +#include <cassert> + +struct A +{ + char a1() {return 5;} + short a2(int i) {return short(i+1);} + int a3() const {return 1;} + double a4(unsigned i) const {return i-1;} +}; + +int main() +{ + const A a = A(); + assert(std::mem_fun_ref(&A::a4)(a, 6) == 5); +} diff --git a/libcxx/test/utilities/function.objects/member.pointer.adaptors/const_mem_fun_ref_t.pass.cpp b/libcxx/test/utilities/function.objects/member.pointer.adaptors/const_mem_fun_ref_t.pass.cpp index 424622ed3aa..83d677ff343 100644 --- a/libcxx/test/utilities/function.objects/member.pointer.adaptors/const_mem_fun_ref_t.pass.cpp +++ b/libcxx/test/utilities/function.objects/member.pointer.adaptors/const_mem_fun_ref_t.pass.cpp @@ -1 +1,33 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <functional>
// const_mem_fun_ref_t
#include <functional>
#include <type_traits>
#include <cassert>
struct A
{
char a1() {return 5;}
short a2(int i) {return short(i+1);}
int a3() const {return 1;}
double a4(unsigned i) const {return i-1;}
};
int main()
{
typedef std::const_mem_fun_ref_t<int, A> F;
static_assert((std::is_base_of<std::unary_function<A, int>, F>::value), "");
const F f(&A::a3);
const A a = A();
assert(f(a) == 1);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// const_mem_fun_ref_t + +#include <functional> +#include <type_traits> +#include <cassert> + +struct A +{ + char a1() {return 5;} + short a2(int i) {return short(i+1);} + int a3() const {return 1;} + double a4(unsigned i) const {return i-1;} +}; + +int main() +{ + typedef std::const_mem_fun_ref_t<int, A> F; + static_assert((std::is_base_of<std::unary_function<A, int>, F>::value), ""); + const F f(&A::a3); + const A a = A(); + assert(f(a) == 1); +} diff --git a/libcxx/test/utilities/function.objects/member.pointer.adaptors/const_mem_fun_t.pass.cpp b/libcxx/test/utilities/function.objects/member.pointer.adaptors/const_mem_fun_t.pass.cpp index 6eebb0edbed..3f099face59 100644 --- a/libcxx/test/utilities/function.objects/member.pointer.adaptors/const_mem_fun_t.pass.cpp +++ b/libcxx/test/utilities/function.objects/member.pointer.adaptors/const_mem_fun_t.pass.cpp @@ -1 +1,33 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <functional>
// const_mem_fun_t
#include <functional>
#include <type_traits>
#include <cassert>
struct A
{
char a1() {return 5;}
short a2(int i) {return short(i+1);}
int a3() const {return 1;}
double a4(unsigned i) const {return i-1;}
};
int main()
{
typedef std::const_mem_fun_t<int, A> F;
static_assert((std::is_base_of<std::unary_function<const A*, int>, F>::value), "");
const F f(&A::a3);
const A a = A();
assert(f(&a) == 1);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// const_mem_fun_t + +#include <functional> +#include <type_traits> +#include <cassert> + +struct A +{ + char a1() {return 5;} + short a2(int i) {return short(i+1);} + int a3() const {return 1;} + double a4(unsigned i) const {return i-1;} +}; + +int main() +{ + typedef std::const_mem_fun_t<int, A> F; + static_assert((std::is_base_of<std::unary_function<const A*, int>, F>::value), ""); + const F f(&A::a3); + const A a = A(); + assert(f(&a) == 1); +} diff --git a/libcxx/test/utilities/function.objects/member.pointer.adaptors/mem_fun.pass.cpp b/libcxx/test/utilities/function.objects/member.pointer.adaptors/mem_fun.pass.cpp index 144691bf850..5a227fae776 100644 --- a/libcxx/test/utilities/function.objects/member.pointer.adaptors/mem_fun.pass.cpp +++ b/libcxx/test/utilities/function.objects/member.pointer.adaptors/mem_fun.pass.cpp @@ -1 +1,31 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <functional>
// template<Returnable S, ClassType T>
// mem_fun_t<S,T>
// mem_fun(S (T::*f)());
#include <functional>
#include <cassert>
struct A
{
char a1() {return 5;}
short a2(int i) {return short(i+1);}
int a3() const {return 1;}
double a4(unsigned i) const {return i-1;}
};
int main()
{
A a;
assert(std::mem_fun(&A::a1)(&a) == 5);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// template<Returnable S, ClassType T> +// mem_fun_t<S,T> +// mem_fun(S (T::*f)()); + +#include <functional> +#include <cassert> + +struct A +{ + char a1() {return 5;} + short a2(int i) {return short(i+1);} + int a3() const {return 1;} + double a4(unsigned i) const {return i-1;} +}; + +int main() +{ + A a; + assert(std::mem_fun(&A::a1)(&a) == 5); +} diff --git a/libcxx/test/utilities/function.objects/member.pointer.adaptors/mem_fun1.pass.cpp b/libcxx/test/utilities/function.objects/member.pointer.adaptors/mem_fun1.pass.cpp index 514fac9301e..a1f4c197156 100644 --- a/libcxx/test/utilities/function.objects/member.pointer.adaptors/mem_fun1.pass.cpp +++ b/libcxx/test/utilities/function.objects/member.pointer.adaptors/mem_fun1.pass.cpp @@ -1 +1,31 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <functional>
// template<Returnable S, ClassType T, CopyConstructible A>
// mem_fun1_t<S,T,A>
// mem_fun(S (T::*f)(A));
#include <functional>
#include <cassert>
struct A
{
char a1() {return 5;}
short a2(int i) {return short(i+1);}
int a3() const {return 1;}
double a4(unsigned i) const {return i-1;}
};
int main()
{
A a;
assert(std::mem_fun(&A::a2)(&a, 5) == 6);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// template<Returnable S, ClassType T, CopyConstructible A> +// mem_fun1_t<S,T,A> +// mem_fun(S (T::*f)(A)); + +#include <functional> +#include <cassert> + +struct A +{ + char a1() {return 5;} + short a2(int i) {return short(i+1);} + int a3() const {return 1;} + double a4(unsigned i) const {return i-1;} +}; + +int main() +{ + A a; + assert(std::mem_fun(&A::a2)(&a, 5) == 6); +} diff --git a/libcxx/test/utilities/function.objects/member.pointer.adaptors/mem_fun1_ref_t.pass.cpp b/libcxx/test/utilities/function.objects/member.pointer.adaptors/mem_fun1_ref_t.pass.cpp index b451d680bc0..3aab735a21f 100644 --- a/libcxx/test/utilities/function.objects/member.pointer.adaptors/mem_fun1_ref_t.pass.cpp +++ b/libcxx/test/utilities/function.objects/member.pointer.adaptors/mem_fun1_ref_t.pass.cpp @@ -1 +1,33 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <functional>
// mem_fun1_ref_t
#include <functional>
#include <type_traits>
#include <cassert>
struct A
{
char a1() {return 5;}
short a2(int i) {return short(i+1);}
int a3() const {return 1;}
double a4(unsigned i) const {return i-1;}
};
int main()
{
typedef std::mem_fun1_ref_t<short, A, int> F;
static_assert((std::is_base_of<std::binary_function<A, int, short>, F>::value), "");
const F f(&A::a2);
A a;
assert(f(a, 5) == 6);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// mem_fun1_ref_t + +#include <functional> +#include <type_traits> +#include <cassert> + +struct A +{ + char a1() {return 5;} + short a2(int i) {return short(i+1);} + int a3() const {return 1;} + double a4(unsigned i) const {return i-1;} +}; + +int main() +{ + typedef std::mem_fun1_ref_t<short, A, int> F; + static_assert((std::is_base_of<std::binary_function<A, int, short>, F>::value), ""); + const F f(&A::a2); + A a; + assert(f(a, 5) == 6); +} diff --git a/libcxx/test/utilities/function.objects/member.pointer.adaptors/mem_fun1_t.pass.cpp b/libcxx/test/utilities/function.objects/member.pointer.adaptors/mem_fun1_t.pass.cpp index a9a62e05033..7fb6ebdc16c 100644 --- a/libcxx/test/utilities/function.objects/member.pointer.adaptors/mem_fun1_t.pass.cpp +++ b/libcxx/test/utilities/function.objects/member.pointer.adaptors/mem_fun1_t.pass.cpp @@ -1 +1,33 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <functional>
// mem_fun1_t
#include <functional>
#include <type_traits>
#include <cassert>
struct A
{
char a1() {return 5;}
short a2(int i) {return short(i+1);}
int a3() const {return 1;}
double a4(unsigned i) const {return i-1;}
};
int main()
{
typedef std::mem_fun1_t<short, A, int> F;
static_assert((std::is_base_of<std::binary_function<A*, int, short>, F>::value), "");
const F f(&A::a2);
A a;
assert(f(&a, 5) == 6);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// mem_fun1_t + +#include <functional> +#include <type_traits> +#include <cassert> + +struct A +{ + char a1() {return 5;} + short a2(int i) {return short(i+1);} + int a3() const {return 1;} + double a4(unsigned i) const {return i-1;} +}; + +int main() +{ + typedef std::mem_fun1_t<short, A, int> F; + static_assert((std::is_base_of<std::binary_function<A*, int, short>, F>::value), ""); + const F f(&A::a2); + A a; + assert(f(&a, 5) == 6); +} diff --git a/libcxx/test/utilities/function.objects/member.pointer.adaptors/mem_fun_ref.pass.cpp b/libcxx/test/utilities/function.objects/member.pointer.adaptors/mem_fun_ref.pass.cpp index 785305eaa74..401b5745ddf 100644 --- a/libcxx/test/utilities/function.objects/member.pointer.adaptors/mem_fun_ref.pass.cpp +++ b/libcxx/test/utilities/function.objects/member.pointer.adaptors/mem_fun_ref.pass.cpp @@ -1 +1,31 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <functional>
// template<Returnable S, ClassType T>
// mem_fun_ref_t<S,T>
// mem_fun_ref(S (T::*f)());
#include <functional>
#include <cassert>
struct A
{
char a1() {return 5;}
short a2(int i) {return short(i+1);}
int a3() const {return 1;}
double a4(unsigned i) const {return i-1;}
};
int main()
{
A a;
assert(std::mem_fun_ref(&A::a1)(a) == 5);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// template<Returnable S, ClassType T> +// mem_fun_ref_t<S,T> +// mem_fun_ref(S (T::*f)()); + +#include <functional> +#include <cassert> + +struct A +{ + char a1() {return 5;} + short a2(int i) {return short(i+1);} + int a3() const {return 1;} + double a4(unsigned i) const {return i-1;} +}; + +int main() +{ + A a; + assert(std::mem_fun_ref(&A::a1)(a) == 5); +} diff --git a/libcxx/test/utilities/function.objects/member.pointer.adaptors/mem_fun_ref1.pass.cpp b/libcxx/test/utilities/function.objects/member.pointer.adaptors/mem_fun_ref1.pass.cpp index 733db16ee41..8a29d0a7ed7 100644 --- a/libcxx/test/utilities/function.objects/member.pointer.adaptors/mem_fun_ref1.pass.cpp +++ b/libcxx/test/utilities/function.objects/member.pointer.adaptors/mem_fun_ref1.pass.cpp @@ -1 +1,31 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <functional>
// template<Returnable S, ClassType T, CopyConstructible A>
// mem_fun1_ref_t<S,T,A>
// mem_fun_ref(S (T::*f)(A));
#include <functional>
#include <cassert>
struct A
{
char a1() {return 5;}
short a2(int i) {return short(i+1);}
int a3() const {return 1;}
double a4(unsigned i) const {return i-1;}
};
int main()
{
A a;
assert(std::mem_fun_ref(&A::a2)(a, 5) == 6);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// template<Returnable S, ClassType T, CopyConstructible A> +// mem_fun1_ref_t<S,T,A> +// mem_fun_ref(S (T::*f)(A)); + +#include <functional> +#include <cassert> + +struct A +{ + char a1() {return 5;} + short a2(int i) {return short(i+1);} + int a3() const {return 1;} + double a4(unsigned i) const {return i-1;} +}; + +int main() +{ + A a; + assert(std::mem_fun_ref(&A::a2)(a, 5) == 6); +} diff --git a/libcxx/test/utilities/function.objects/member.pointer.adaptors/mem_fun_ref_t.pass.cpp b/libcxx/test/utilities/function.objects/member.pointer.adaptors/mem_fun_ref_t.pass.cpp index d92f378f6b6..f407506bdaa 100644 --- a/libcxx/test/utilities/function.objects/member.pointer.adaptors/mem_fun_ref_t.pass.cpp +++ b/libcxx/test/utilities/function.objects/member.pointer.adaptors/mem_fun_ref_t.pass.cpp @@ -1 +1,33 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <functional>
// mem_fun_ref_t
#include <functional>
#include <type_traits>
#include <cassert>
struct A
{
char a1() {return 5;}
short a2(int i) {return short(i+1);}
int a3() const {return 1;}
double a4(unsigned i) const {return i-1;}
};
int main()
{
typedef std::mem_fun_ref_t<char, A> F;
static_assert((std::is_base_of<std::unary_function<A, char>, F>::value), "");
const F f(&A::a1);
A a;
assert(f(a) == 5);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// mem_fun_ref_t + +#include <functional> +#include <type_traits> +#include <cassert> + +struct A +{ + char a1() {return 5;} + short a2(int i) {return short(i+1);} + int a3() const {return 1;} + double a4(unsigned i) const {return i-1;} +}; + +int main() +{ + typedef std::mem_fun_ref_t<char, A> F; + static_assert((std::is_base_of<std::unary_function<A, char>, F>::value), ""); + const F f(&A::a1); + A a; + assert(f(a) == 5); +} diff --git a/libcxx/test/utilities/function.objects/member.pointer.adaptors/mem_fun_t.pass.cpp b/libcxx/test/utilities/function.objects/member.pointer.adaptors/mem_fun_t.pass.cpp index 721e9266d6f..b8a340ca474 100644 --- a/libcxx/test/utilities/function.objects/member.pointer.adaptors/mem_fun_t.pass.cpp +++ b/libcxx/test/utilities/function.objects/member.pointer.adaptors/mem_fun_t.pass.cpp @@ -1 +1,33 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <functional>
// mem_fun_t
#include <functional>
#include <type_traits>
#include <cassert>
struct A
{
char a1() {return 5;}
short a2(int i) {return short(i+1);}
int a3() const {return 1;}
double a4(unsigned i) const {return i-1;}
};
int main()
{
typedef std::mem_fun_t<char, A> F;
static_assert((std::is_base_of<std::unary_function<A*, char>, F>::value), "");
const F f(&A::a1);
A a;
assert(f(&a) == 5);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// mem_fun_t + +#include <functional> +#include <type_traits> +#include <cassert> + +struct A +{ + char a1() {return 5;} + short a2(int i) {return short(i+1);} + int a3() const {return 1;} + double a4(unsigned i) const {return i-1;} +}; + +int main() +{ + typedef std::mem_fun_t<char, A> F; + static_assert((std::is_base_of<std::unary_function<A*, char>, F>::value), ""); + const F f(&A::a1); + A a; + assert(f(&a) == 5); +} diff --git a/libcxx/test/utilities/function.objects/negators/binary_negate.pass.cpp b/libcxx/test/utilities/function.objects/negators/binary_negate.pass.cpp index da48bbd4f31..e846f6c51dd 100644 --- a/libcxx/test/utilities/function.objects/negators/binary_negate.pass.cpp +++ b/libcxx/test/utilities/function.objects/negators/binary_negate.pass.cpp @@ -1 +1,27 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <functional>
// binary_negate
#include <functional>
#include <type_traits>
#include <cassert>
int main()
{
typedef std::binary_negate<std::logical_and<int> > F;
const F f = F(std::logical_and<int>());
static_assert((std::is_base_of<std::binary_function<int, int, bool>, F>::value), "");
assert(!f(36, 36));
assert( f(36, 0));
assert( f(0, 36));
assert( f(0, 0));
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// binary_negate + +#include <functional> +#include <type_traits> +#include <cassert> + +int main() +{ + typedef std::binary_negate<std::logical_and<int> > F; + const F f = F(std::logical_and<int>()); + static_assert((std::is_base_of<std::binary_function<int, int, bool>, F>::value), ""); + assert(!f(36, 36)); + assert( f(36, 0)); + assert( f(0, 36)); + assert( f(0, 0)); +} diff --git a/libcxx/test/utilities/function.objects/negators/not1.pass.cpp b/libcxx/test/utilities/function.objects/negators/not1.pass.cpp index 6b399307e4f..c0ec87f5208 100644 --- a/libcxx/test/utilities/function.objects/negators/not1.pass.cpp +++ b/libcxx/test/utilities/function.objects/negators/not1.pass.cpp @@ -1 +1,22 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <functional>
// not1
#include <functional>
#include <cassert>
int main()
{
typedef std::logical_not<int> F;
assert(std::not1(F())(36));
assert(!std::not1(F())(0));
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// not1 + +#include <functional> +#include <cassert> + +int main() +{ + typedef std::logical_not<int> F; + assert(std::not1(F())(36)); + assert(!std::not1(F())(0)); +} diff --git a/libcxx/test/utilities/function.objects/negators/not2.pass.cpp b/libcxx/test/utilities/function.objects/negators/not2.pass.cpp index 9e65415cb2b..ff5db68ad74 100644 --- a/libcxx/test/utilities/function.objects/negators/not2.pass.cpp +++ b/libcxx/test/utilities/function.objects/negators/not2.pass.cpp @@ -1 +1,24 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <functional>
// not2
#include <functional>
#include <cassert>
int main()
{
typedef std::logical_and<int> F;
assert(!std::not2(F())(36, 36));
assert( std::not2(F())(36, 0));
assert( std::not2(F())(0, 36));
assert( std::not2(F())(0, 0));
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// not2 + +#include <functional> +#include <cassert> + +int main() +{ + typedef std::logical_and<int> F; + assert(!std::not2(F())(36, 36)); + assert( std::not2(F())(36, 0)); + assert( std::not2(F())(0, 36)); + assert( std::not2(F())(0, 0)); +} diff --git a/libcxx/test/utilities/function.objects/negators/unary_negate.pass.cpp b/libcxx/test/utilities/function.objects/negators/unary_negate.pass.cpp index 9c5c2592b19..1479e12b2ee 100644 --- a/libcxx/test/utilities/function.objects/negators/unary_negate.pass.cpp +++ b/libcxx/test/utilities/function.objects/negators/unary_negate.pass.cpp @@ -1 +1,25 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <functional>
// unary_negate
#include <functional>
#include <type_traits>
#include <cassert>
int main()
{
typedef std::unary_negate<std::logical_not<int> > F;
const F f = F(std::logical_not<int>());
static_assert((std::is_base_of<std::unary_function<int, bool>, F>::value), "");
assert(f(36));
assert(!f(0));
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// unary_negate + +#include <functional> +#include <type_traits> +#include <cassert> + +int main() +{ + typedef std::unary_negate<std::logical_not<int> > F; + const F f = F(std::logical_not<int>()); + static_assert((std::is_base_of<std::unary_function<int, bool>, F>::value), ""); + assert(f(36)); + assert(!f(0)); +} diff --git a/libcxx/test/utilities/function.objects/refwrap/binary.pass.cpp b/libcxx/test/utilities/function.objects/refwrap/binary.pass.cpp index e9d7dda00a3..5c4c730ac6a 100644 --- a/libcxx/test/utilities/function.objects/refwrap/binary.pass.cpp +++ b/libcxx/test/utilities/function.objects/refwrap/binary.pass.cpp @@ -1 +1,80 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <functional>
// reference_wrapper
// check for deriving from binary_function
#include <functional>
#include <type_traits>
class functor1
: public std::unary_function<int, char>
{
};
class functor2
: public std::binary_function<char, int, double>
{
};
class functor3
: public std::unary_function<int, int>,
public std::binary_function<char, int, double>
{
public:
typedef float result_type;
};
class functor4
: public std::unary_function<int, int>,
public std::binary_function<char, int, double>
{
public:
};
struct C
{
typedef int argument_type;
typedef int result_type;
};
int main()
{
static_assert((!std::is_base_of<std::binary_function<int, char, int>,
std::reference_wrapper<functor1> >::value), "");
static_assert((std::is_base_of<std::binary_function<char, int, double>,
std::reference_wrapper<functor2> >::value), "");
static_assert((std::is_base_of<std::binary_function<char, int, double>,
std::reference_wrapper<functor3> >::value), "");
static_assert((std::is_base_of<std::binary_function<char, int, double>,
std::reference_wrapper<functor4> >::value), "");
static_assert((!std::is_base_of<std::binary_function<int, int, int>,
std::reference_wrapper<C> >::value), "");
static_assert((!std::is_base_of<std::binary_function<int, int, float>,
std::reference_wrapper<float ()> >::value), "");
static_assert((!std::is_base_of<std::binary_function<int, int, float>,
std::reference_wrapper<float (int)> >::value), "");
static_assert((std::is_base_of<std::binary_function<int, int, float>,
std::reference_wrapper<float (int, int)> >::value), "");
static_assert((!std::is_base_of<std::binary_function<int, int, float>,
std::reference_wrapper<float(*)()> >::value), "");
static_assert((!std::is_base_of<std::binary_function<int, int, float>,
std::reference_wrapper<float(*)(int)> >::value), "");
static_assert((std::is_base_of<std::binary_function<int, int, float>,
std::reference_wrapper<float(*)(int, int)> >::value), "");
static_assert((!std::is_base_of<std::binary_function<C*, int, float>,
std::reference_wrapper<float(C::*)()> >::value), "");
static_assert((std::is_base_of<std::binary_function<C*, int, float>,
std::reference_wrapper<float(C::*)(int)> >::value), "");
static_assert((std::is_base_of<std::binary_function<const volatile C*, int, float>,
std::reference_wrapper<float(C::*)(int) const volatile> >::value), "");
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// reference_wrapper + +// check for deriving from binary_function + +#include <functional> +#include <type_traits> + +class functor1 + : public std::unary_function<int, char> +{ +}; + +class functor2 + : public std::binary_function<char, int, double> +{ +}; + +class functor3 + : public std::unary_function<int, int>, + public std::binary_function<char, int, double> +{ +public: + typedef float result_type; +}; + +class functor4 + : public std::unary_function<int, int>, + public std::binary_function<char, int, double> +{ +public: +}; + +struct C +{ + typedef int argument_type; + typedef int result_type; +}; + +int main() +{ + static_assert((!std::is_base_of<std::binary_function<int, char, int>, + std::reference_wrapper<functor1> >::value), ""); + static_assert((std::is_base_of<std::binary_function<char, int, double>, + std::reference_wrapper<functor2> >::value), ""); + static_assert((std::is_base_of<std::binary_function<char, int, double>, + std::reference_wrapper<functor3> >::value), ""); + static_assert((std::is_base_of<std::binary_function<char, int, double>, + std::reference_wrapper<functor4> >::value), ""); + static_assert((!std::is_base_of<std::binary_function<int, int, int>, + std::reference_wrapper<C> >::value), ""); + static_assert((!std::is_base_of<std::binary_function<int, int, float>, + std::reference_wrapper<float ()> >::value), ""); + static_assert((!std::is_base_of<std::binary_function<int, int, float>, + std::reference_wrapper<float (int)> >::value), ""); + static_assert((std::is_base_of<std::binary_function<int, int, float>, + std::reference_wrapper<float (int, int)> >::value), ""); + static_assert((!std::is_base_of<std::binary_function<int, int, float>, + std::reference_wrapper<float(*)()> >::value), ""); + static_assert((!std::is_base_of<std::binary_function<int, int, float>, + std::reference_wrapper<float(*)(int)> >::value), ""); + static_assert((std::is_base_of<std::binary_function<int, int, float>, + std::reference_wrapper<float(*)(int, int)> >::value), ""); + static_assert((!std::is_base_of<std::binary_function<C*, int, float>, + std::reference_wrapper<float(C::*)()> >::value), ""); + static_assert((std::is_base_of<std::binary_function<C*, int, float>, + std::reference_wrapper<float(C::*)(int)> >::value), ""); + static_assert((std::is_base_of<std::binary_function<const volatile C*, int, float>, + std::reference_wrapper<float(C::*)(int) const volatile> >::value), ""); +} diff --git a/libcxx/test/utilities/function.objects/refwrap/refwrap.access/conversion.pass.cpp b/libcxx/test/utilities/function.objects/refwrap/refwrap.access/conversion.pass.cpp index 76986162b49..7c33f7712e5 100644 --- a/libcxx/test/utilities/function.objects/refwrap/refwrap.access/conversion.pass.cpp +++ b/libcxx/test/utilities/function.objects/refwrap/refwrap.access/conversion.pass.cpp @@ -1 +1,46 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <functional>
// reference_wrapper
// operator T& () const;
#include <functional>
#include <cassert>
class functor1
: public std::unary_function<int, char>
{
};
template <class T>
void
test(T& t)
{
std::reference_wrapper<T> r(t);
T& r2 = r;
assert(&r2 == &t);
}
void f() {}
int main()
{
void (*fp)() = f;
test(fp);
test(f);
functor1 f1;
test(f1);
int i = 0;
test(i);
const int j = 0;
test(j);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// reference_wrapper + +// operator T& () const; + +#include <functional> +#include <cassert> + +class functor1 + : public std::unary_function<int, char> +{ +}; + +template <class T> +void +test(T& t) +{ + std::reference_wrapper<T> r(t); + T& r2 = r; + assert(&r2 == &t); +} + +void f() {} + +int main() +{ + void (*fp)() = f; + test(fp); + test(f); + functor1 f1; + test(f1); + int i = 0; + test(i); + const int j = 0; + test(j); +} diff --git a/libcxx/test/utilities/function.objects/refwrap/refwrap.assign/copy_assign.pass.cpp b/libcxx/test/utilities/function.objects/refwrap/refwrap.assign/copy_assign.pass.cpp index bccafd746e2..b08fb87b075 100644 --- a/libcxx/test/utilities/function.objects/refwrap/refwrap.assign/copy_assign.pass.cpp +++ b/libcxx/test/utilities/function.objects/refwrap/refwrap.assign/copy_assign.pass.cpp @@ -1 +1,58 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <functional>
// reference_wrapper
// reference_wrapper& operator=(const reference_wrapper<T>& x);
#include <functional>
#include <cassert>
class functor1
: public std::unary_function<int, char>
{
};
template <class T>
void
test(T& t)
{
std::reference_wrapper<T> r(t);
T t2 = t;
std::reference_wrapper<T> r2(t2);
r2 = r;
assert(&r2.get() == &t);
}
void f() {}
void g() {}
void
test_function()
{
std::reference_wrapper<void ()> r(f);
std::reference_wrapper<void ()> r2(g);
r2 = r;
assert(&r2.get() == &f);
}
int main()
{
void (*fp)() = f;
test(fp);
test_function();
functor1 f1;
test(f1);
int i = 0;
test(i);
const int j = 0;
test(j);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// reference_wrapper + +// reference_wrapper& operator=(const reference_wrapper<T>& x); + +#include <functional> +#include <cassert> + +class functor1 + : public std::unary_function<int, char> +{ +}; + +template <class T> +void +test(T& t) +{ + std::reference_wrapper<T> r(t); + T t2 = t; + std::reference_wrapper<T> r2(t2); + r2 = r; + assert(&r2.get() == &t); +} + +void f() {} +void g() {} + +void +test_function() +{ + std::reference_wrapper<void ()> r(f); + std::reference_wrapper<void ()> r2(g); + r2 = r; + assert(&r2.get() == &f); +} + +int main() +{ + void (*fp)() = f; + test(fp); + test_function(); + functor1 f1; + test(f1); + int i = 0; + test(i); + const int j = 0; + test(j); +} diff --git a/libcxx/test/utilities/function.objects/refwrap/refwrap.const/copy_ctor.pass.cpp b/libcxx/test/utilities/function.objects/refwrap/refwrap.const/copy_ctor.pass.cpp index 8bdbec5a75c..497e5fbc199 100644 --- a/libcxx/test/utilities/function.objects/refwrap/refwrap.const/copy_ctor.pass.cpp +++ b/libcxx/test/utilities/function.objects/refwrap/refwrap.const/copy_ctor.pass.cpp @@ -1 +1,46 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <functional>
// reference_wrapper
// reference_wrapper(const reference_wrapper<T>& x);
#include <functional>
#include <cassert>
class functor1
: public std::unary_function<int, char>
{
};
template <class T>
void
test(T& t)
{
std::reference_wrapper<T> r(t);
std::reference_wrapper<T> r2 = r;
assert(&r2.get() == &t);
}
void f() {}
int main()
{
void (*fp)() = f;
test(fp);
test(f);
functor1 f1;
test(f1);
int i = 0;
test(i);
const int j = 0;
test(j);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// reference_wrapper + +// reference_wrapper(const reference_wrapper<T>& x); + +#include <functional> +#include <cassert> + +class functor1 + : public std::unary_function<int, char> +{ +}; + +template <class T> +void +test(T& t) +{ + std::reference_wrapper<T> r(t); + std::reference_wrapper<T> r2 = r; + assert(&r2.get() == &t); +} + +void f() {} + +int main() +{ + void (*fp)() = f; + test(fp); + test(f); + functor1 f1; + test(f1); + int i = 0; + test(i); + const int j = 0; + test(j); +} diff --git a/libcxx/test/utilities/function.objects/refwrap/refwrap.const/type_ctor.fail.cpp b/libcxx/test/utilities/function.objects/refwrap/refwrap.const/type_ctor.fail.cpp index f07592db475..78153d6bd7d 100644 --- a/libcxx/test/utilities/function.objects/refwrap/refwrap.const/type_ctor.fail.cpp +++ b/libcxx/test/utilities/function.objects/refwrap/refwrap.const/type_ctor.fail.cpp @@ -1 +1,22 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <functional>
// reference_wrapper
// reference_wrapper(T&&) = delete;
#include <functional>
#include <cassert>
int main()
{
std::reference_wrapper<const int> r(3);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// reference_wrapper + +// reference_wrapper(T&&) = delete; + +#include <functional> +#include <cassert> + +int main() +{ + std::reference_wrapper<const int> r(3); +} diff --git a/libcxx/test/utilities/function.objects/refwrap/refwrap.const/type_ctor.pass.cpp b/libcxx/test/utilities/function.objects/refwrap/refwrap.const/type_ctor.pass.cpp index a4c2c8727b1..770ac52dde2 100644 --- a/libcxx/test/utilities/function.objects/refwrap/refwrap.const/type_ctor.pass.cpp +++ b/libcxx/test/utilities/function.objects/refwrap/refwrap.const/type_ctor.pass.cpp @@ -1 +1,45 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <functional>
// reference_wrapper
// reference_wrapper(T& t);
#include <functional>
#include <cassert>
class functor1
: public std::unary_function<int, char>
{
};
template <class T>
void
test(T& t)
{
std::reference_wrapper<T> r(t);
assert(&r.get() == &t);
}
void f() {}
int main()
{
void (*fp)() = f;
test(fp);
test(f);
functor1 f1;
test(f1);
int i = 0;
test(i);
const int j = 0;
test(j);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// reference_wrapper + +// reference_wrapper(T& t); + +#include <functional> +#include <cassert> + +class functor1 + : public std::unary_function<int, char> +{ +}; + +template <class T> +void +test(T& t) +{ + std::reference_wrapper<T> r(t); + assert(&r.get() == &t); +} + +void f() {} + +int main() +{ + void (*fp)() = f; + test(fp); + test(f); + functor1 f1; + test(f1); + int i = 0; + test(i); + const int j = 0; + test(j); +} diff --git a/libcxx/test/utilities/function.objects/refwrap/refwrap.helpers/cref_1.pass.cpp b/libcxx/test/utilities/function.objects/refwrap/refwrap.helpers/cref_1.pass.cpp index f60de648d96..22ad0b8a2e5 100644 --- a/libcxx/test/utilities/function.objects/refwrap/refwrap.helpers/cref_1.pass.cpp +++ b/libcxx/test/utilities/function.objects/refwrap/refwrap.helpers/cref_1.pass.cpp @@ -1 +1,24 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <functional>
// reference_wrapper
// template <ObjectType T> reference_wrapper<const T> cref(const T& t);
#include <functional>
#include <cassert>
int main()
{
int i = 0;
std::reference_wrapper<const int> r = std::cref(i);
assert(&r.get() == &i);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// reference_wrapper + +// template <ObjectType T> reference_wrapper<const T> cref(const T& t); + +#include <functional> +#include <cassert> + +int main() +{ + int i = 0; + std::reference_wrapper<const int> r = std::cref(i); + assert(&r.get() == &i); +} diff --git a/libcxx/test/utilities/function.objects/refwrap/refwrap.helpers/cref_2.pass.cpp b/libcxx/test/utilities/function.objects/refwrap/refwrap.helpers/cref_2.pass.cpp index 2f05d467eb3..a11e3dad9dd 100644 --- a/libcxx/test/utilities/function.objects/refwrap/refwrap.helpers/cref_2.pass.cpp +++ b/libcxx/test/utilities/function.objects/refwrap/refwrap.helpers/cref_2.pass.cpp @@ -1 +1,25 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <functional>
// reference_wrapper
// template <ObjectType T> reference_wrapper<const T> cref(reference_wrapper<T> t);
#include <functional>
#include <cassert>
int main()
{
const int i = 0;
std::reference_wrapper<const int> r1 = std::cref(i);
std::reference_wrapper<const int> r2 = std::cref(r1);
assert(&r2.get() == &i);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// reference_wrapper + +// template <ObjectType T> reference_wrapper<const T> cref(reference_wrapper<T> t); + +#include <functional> +#include <cassert> + +int main() +{ + const int i = 0; + std::reference_wrapper<const int> r1 = std::cref(i); + std::reference_wrapper<const int> r2 = std::cref(r1); + assert(&r2.get() == &i); +} diff --git a/libcxx/test/utilities/function.objects/refwrap/refwrap.helpers/ref_1.fail.cpp b/libcxx/test/utilities/function.objects/refwrap/refwrap.helpers/ref_1.fail.cpp index 7fe32d7b023..abdd9fa26b9 100644 --- a/libcxx/test/utilities/function.objects/refwrap/refwrap.helpers/ref_1.fail.cpp +++ b/libcxx/test/utilities/function.objects/refwrap/refwrap.helpers/ref_1.fail.cpp @@ -1 +1,27 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <functional>
// reference_wrapper
// template <ObjectType T> reference_wrapper<T> ref(T& t);
// Don't allow binding to a temp
#include <functional>
struct A {};
const A source() {return A();}
int main()
{
std::reference_wrapper<const A> r = std::ref(source());
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// reference_wrapper + +// template <ObjectType T> reference_wrapper<T> ref(T& t); + +// Don't allow binding to a temp + +#include <functional> + +struct A {}; + +const A source() {return A();} + +int main() +{ + std::reference_wrapper<const A> r = std::ref(source()); +} diff --git a/libcxx/test/utilities/function.objects/refwrap/refwrap.helpers/ref_1.pass.cpp b/libcxx/test/utilities/function.objects/refwrap/refwrap.helpers/ref_1.pass.cpp index d4e493e0906..c01286c17c0 100644 --- a/libcxx/test/utilities/function.objects/refwrap/refwrap.helpers/ref_1.pass.cpp +++ b/libcxx/test/utilities/function.objects/refwrap/refwrap.helpers/ref_1.pass.cpp @@ -1 +1,24 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <functional>
// reference_wrapper
// template <ObjectType T> reference_wrapper<T> ref(T& t);
#include <functional>
#include <cassert>
int main()
{
int i = 0;
std::reference_wrapper<int> r = std::ref(i);
assert(&r.get() == &i);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// reference_wrapper + +// template <ObjectType T> reference_wrapper<T> ref(T& t); + +#include <functional> +#include <cassert> + +int main() +{ + int i = 0; + std::reference_wrapper<int> r = std::ref(i); + assert(&r.get() == &i); +} diff --git a/libcxx/test/utilities/function.objects/refwrap/refwrap.helpers/ref_2.pass.cpp b/libcxx/test/utilities/function.objects/refwrap/refwrap.helpers/ref_2.pass.cpp index f486a00aed4..646cd10aa11 100644 --- a/libcxx/test/utilities/function.objects/refwrap/refwrap.helpers/ref_2.pass.cpp +++ b/libcxx/test/utilities/function.objects/refwrap/refwrap.helpers/ref_2.pass.cpp @@ -1 +1,25 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <functional>
// reference_wrapper
// template <ObjectType T> reference_wrapper<T> ref(reference_wrapper<T>t);
#include <functional>
#include <cassert>
int main()
{
int i = 0;
std::reference_wrapper<int> r1 = std::ref(i);
std::reference_wrapper<int> r2 = std::ref(r1);
assert(&r2.get() == &i);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// reference_wrapper + +// template <ObjectType T> reference_wrapper<T> ref(reference_wrapper<T>t); + +#include <functional> +#include <cassert> + +int main() +{ + int i = 0; + std::reference_wrapper<int> r1 = std::ref(i); + std::reference_wrapper<int> r2 = std::ref(r1); + assert(&r2.get() == &i); +} diff --git a/libcxx/test/utilities/function.objects/refwrap/refwrap.invoke/invoke.fail.cpp b/libcxx/test/utilities/function.objects/refwrap/refwrap.invoke/invoke.fail.cpp index d7b94ab6064..60c7bf06074 100644 --- a/libcxx/test/utilities/function.objects/refwrap/refwrap.invoke/invoke.fail.cpp +++ b/libcxx/test/utilities/function.objects/refwrap/refwrap.invoke/invoke.fail.cpp @@ -1 +1,52 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <functional>
// reference_wrapper
// template <class... ArgTypes>
// requires Callable<T, ArgTypes&&...>
// Callable<T, ArgTypes&&...>::result_type
// operator()(ArgTypes&&... args) const;
#include <functional>
#include <cassert>
// member data pointer: cv qualifiers should transfer from argument to return type
struct A_int_1
{
A_int_1() : data_(5) {}
int data_;
};
void
test_int_1()
{
// member data pointer
{
int A_int_1::*fp = &A_int_1::data_;
std::reference_wrapper<int A_int_1::*> r1(fp);
A_int_1 a;
assert(r1(a) == 5);
r1(a) = 6;
assert(r1(a) == 6);
const A_int_1* ap = &a;
assert(r1(ap) == 6);
r1(ap) = 7;
assert(r1(ap) == 7);
}
}
int main()
{
test_int_1();
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// reference_wrapper + +// template <class... ArgTypes> +// requires Callable<T, ArgTypes&&...> +// Callable<T, ArgTypes&&...>::result_type +// operator()(ArgTypes&&... args) const; + +#include <functional> +#include <cassert> + +// member data pointer: cv qualifiers should transfer from argument to return type + +struct A_int_1 +{ + A_int_1() : data_(5) {} + + int data_; +}; + +void +test_int_1() +{ + // member data pointer + { + int A_int_1::*fp = &A_int_1::data_; + std::reference_wrapper<int A_int_1::*> r1(fp); + A_int_1 a; + assert(r1(a) == 5); + r1(a) = 6; + assert(r1(a) == 6); + const A_int_1* ap = &a; + assert(r1(ap) == 6); + r1(ap) = 7; + assert(r1(ap) == 7); + } +} + +int main() +{ + test_int_1(); +} diff --git a/libcxx/test/utilities/function.objects/refwrap/refwrap.invoke/invoke.pass.cpp b/libcxx/test/utilities/function.objects/refwrap/refwrap.invoke/invoke.pass.cpp index ca7f226b682..b750564ff6d 100644 --- a/libcxx/test/utilities/function.objects/refwrap/refwrap.invoke/invoke.pass.cpp +++ b/libcxx/test/utilities/function.objects/refwrap/refwrap.invoke/invoke.pass.cpp @@ -1 +1,329 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <functional>
// reference_wrapper
// template <class... ArgTypes>
// requires Callable<T, ArgTypes&&...>
// Callable<T, ArgTypes&&...>::result_type
// operator()(ArgTypes&&... args) const;
#include <functional>
#include <cassert>
int count = 0;
// 1 arg, return void
void f_void_1(int i)
{
count += i;
}
struct A_void_1
{
void operator()(int i)
{
count += i;
}
void mem1() {++count;}
void mem2() const {++count;}
};
void
test_void_1()
{
int save_count = count;
// function
{
std::reference_wrapper<void (int)> r1(f_void_1);
int i = 2;
r1(i);
assert(count == save_count+2);
save_count = count;
}
// function pointer
{
void (*fp)(int) = f_void_1;
std::reference_wrapper<void (*)(int)> r1(fp);
int i = 3;
r1(i);
assert(count == save_count+3);
save_count = count;
}
// functor
{
A_void_1 a0;
std::reference_wrapper<A_void_1> r1(a0);
int i = 4;
r1(i);
assert(count == save_count+4);
save_count = count;
}
// member function pointer
{
void (A_void_1::*fp)() = &A_void_1::mem1;
std::reference_wrapper<void (A_void_1::*)()> r1(fp);
A_void_1 a;
r1(a);
assert(count == save_count+1);
save_count = count;
A_void_1* ap = &a;
r1(ap);
assert(count == save_count+1);
save_count = count;
}
// const member function pointer
{
void (A_void_1::*fp)() const = &A_void_1::mem2;
std::reference_wrapper<void (A_void_1::*)() const> r1(fp);
A_void_1 a;
r1(a);
assert(count == save_count+1);
save_count = count;
A_void_1* ap = &a;
r1(ap);
assert(count == save_count+1);
save_count = count;
}
}
// 1 arg, return int
int f_int_1(int i)
{
return i + 1;
}
struct A_int_1
{
A_int_1() : data_(5) {}
int operator()(int i)
{
return i - 1;
}
int mem1() {return 3;}
int mem2() const {return 4;}
int data_;
};
void
test_int_1()
{
// function
{
std::reference_wrapper<int (int)> r1(f_int_1);
int i = 2;
assert(r1(i) == 3);
}
// function pointer
{
int (*fp)(int) = f_int_1;
std::reference_wrapper<int (*)(int)> r1(fp);
int i = 3;
assert(r1(i) == 4);
}
// functor
{
A_int_1 a0;
std::reference_wrapper<A_int_1> r1(a0);
int i = 4;
assert(r1(i) == 3);
}
// member function pointer
{
int (A_int_1::*fp)() = &A_int_1::mem1;
std::reference_wrapper<int (A_int_1::*)()> r1(fp);
A_int_1 a;
assert(r1(a) == 3);
A_int_1* ap = &a;
assert(r1(ap) == 3);
}
// const member function pointer
{
int (A_int_1::*fp)() const = &A_int_1::mem2;
std::reference_wrapper<int (A_int_1::*)() const> r1(fp);
A_int_1 a;
assert(r1(a) == 4);
A_int_1* ap = &a;
assert(r1(ap) == 4);
}
// member data pointer
{
int A_int_1::*fp = &A_int_1::data_;
std::reference_wrapper<int A_int_1::*> r1(fp);
A_int_1 a;
assert(r1(a) == 5);
r1(a) = 6;
assert(r1(a) == 6);
A_int_1* ap = &a;
assert(r1(ap) == 6);
r1(ap) = 7;
assert(r1(ap) == 7);
}
}
// 2 arg, return void
void f_void_2(int i, int j)
{
count += i+j;
}
struct A_void_2
{
void operator()(int i, int j)
{
count += i+j;
}
void mem1(int i) {count += i;}
void mem2(int i) const {count += i;}
};
void
test_void_2()
{
int save_count = count;
// function
{
std::reference_wrapper<void (int, int)> r1(f_void_2);
int i = 2;
int j = 3;
r1(i, j);
assert(count == save_count+5);
save_count = count;
}
// function pointer
{
void (*fp)(int, int) = f_void_2;
std::reference_wrapper<void (*)(int, int)> r1(fp);
int i = 3;
int j = 4;
r1(i, j);
assert(count == save_count+7);
save_count = count;
}
// functor
{
A_void_2 a0;
std::reference_wrapper<A_void_2> r1(a0);
int i = 4;
int j = 5;
r1(i, j);
assert(count == save_count+9);
save_count = count;
}
// member function pointer
{
void (A_void_2::*fp)(int) = &A_void_2::mem1;
std::reference_wrapper<void (A_void_2::*)(int)> r1(fp);
A_void_2 a;
int i = 3;
r1(a, i);
assert(count == save_count+3);
save_count = count;
A_void_2* ap = &a;
r1(ap, i);
assert(count == save_count+3);
save_count = count;
}
// const member function pointer
{
void (A_void_2::*fp)(int) const = &A_void_2::mem2;
std::reference_wrapper<void (A_void_2::*)(int) const> r1(fp);
A_void_2 a;
int i = 4;
r1(a, i);
assert(count == save_count+4);
save_count = count;
A_void_2* ap = &a;
r1(ap, i);
assert(count == save_count+4);
save_count = count;
}
}
// 2 arg, return int
int f_int_2(int i, int j)
{
return i+j;
}
struct A_int_2
{
int operator()(int i, int j)
{
return i+j;
}
int mem1(int i) {return i+1;}
int mem2(int i) const {return i+2;}
};
void
testint_2()
{
// function
{
std::reference_wrapper<int (int, int)> r1(f_int_2);
int i = 2;
int j = 3;
assert(r1(i, j) == i+j);
}
// function pointer
{
int (*fp)(int, int) = f_int_2;
std::reference_wrapper<int (*)(int, int)> r1(fp);
int i = 3;
int j = 4;
assert(r1(i, j) == i+j);
}
// functor
{
A_int_2 a0;
std::reference_wrapper<A_int_2> r1(a0);
int i = 4;
int j = 5;
assert(r1(i, j) == i+j);
}
// member function pointer
{
int(A_int_2::*fp)(int) = &A_int_2::mem1;
std::reference_wrapper<int (A_int_2::*)(int)> r1(fp);
A_int_2 a;
int i = 3;
assert(r1(a, i) == i+1);
A_int_2* ap = &a;
assert(r1(ap, i) == i+1);
}
// const member function pointer
{
int (A_int_2::*fp)(int) const = &A_int_2::mem2;
std::reference_wrapper<int (A_int_2::*)(int) const> r1(fp);
A_int_2 a;
int i = 4;
assert(r1(a, i) == i+2);
A_int_2* ap = &a;
assert(r1(ap, i) == i+2);
}
}
int main()
{
test_void_1();
test_int_1();
test_void_2();
testint_2();
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// reference_wrapper + +// template <class... ArgTypes> +// requires Callable<T, ArgTypes&&...> +// Callable<T, ArgTypes&&...>::result_type +// operator()(ArgTypes&&... args) const; + +#include <functional> +#include <cassert> + +int count = 0; + +// 1 arg, return void + +void f_void_1(int i) +{ + count += i; +} + +struct A_void_1 +{ + void operator()(int i) + { + count += i; + } + + void mem1() {++count;} + void mem2() const {++count;} +}; + +void +test_void_1() +{ + int save_count = count; + // function + { + std::reference_wrapper<void (int)> r1(f_void_1); + int i = 2; + r1(i); + assert(count == save_count+2); + save_count = count; + } + // function pointer + { + void (*fp)(int) = f_void_1; + std::reference_wrapper<void (*)(int)> r1(fp); + int i = 3; + r1(i); + assert(count == save_count+3); + save_count = count; + } + // functor + { + A_void_1 a0; + std::reference_wrapper<A_void_1> r1(a0); + int i = 4; + r1(i); + assert(count == save_count+4); + save_count = count; + } + // member function pointer + { + void (A_void_1::*fp)() = &A_void_1::mem1; + std::reference_wrapper<void (A_void_1::*)()> r1(fp); + A_void_1 a; + r1(a); + assert(count == save_count+1); + save_count = count; + A_void_1* ap = &a; + r1(ap); + assert(count == save_count+1); + save_count = count; + } + // const member function pointer + { + void (A_void_1::*fp)() const = &A_void_1::mem2; + std::reference_wrapper<void (A_void_1::*)() const> r1(fp); + A_void_1 a; + r1(a); + assert(count == save_count+1); + save_count = count; + A_void_1* ap = &a; + r1(ap); + assert(count == save_count+1); + save_count = count; + } +} + +// 1 arg, return int + +int f_int_1(int i) +{ + return i + 1; +} + +struct A_int_1 +{ + A_int_1() : data_(5) {} + int operator()(int i) + { + return i - 1; + } + + int mem1() {return 3;} + int mem2() const {return 4;} + int data_; +}; + +void +test_int_1() +{ + // function + { + std::reference_wrapper<int (int)> r1(f_int_1); + int i = 2; + assert(r1(i) == 3); + } + // function pointer + { + int (*fp)(int) = f_int_1; + std::reference_wrapper<int (*)(int)> r1(fp); + int i = 3; + assert(r1(i) == 4); + } + // functor + { + A_int_1 a0; + std::reference_wrapper<A_int_1> r1(a0); + int i = 4; + assert(r1(i) == 3); + } + // member function pointer + { + int (A_int_1::*fp)() = &A_int_1::mem1; + std::reference_wrapper<int (A_int_1::*)()> r1(fp); + A_int_1 a; + assert(r1(a) == 3); + A_int_1* ap = &a; + assert(r1(ap) == 3); + } + // const member function pointer + { + int (A_int_1::*fp)() const = &A_int_1::mem2; + std::reference_wrapper<int (A_int_1::*)() const> r1(fp); + A_int_1 a; + assert(r1(a) == 4); + A_int_1* ap = &a; + assert(r1(ap) == 4); + } + // member data pointer + { + int A_int_1::*fp = &A_int_1::data_; + std::reference_wrapper<int A_int_1::*> r1(fp); + A_int_1 a; + assert(r1(a) == 5); + r1(a) = 6; + assert(r1(a) == 6); + A_int_1* ap = &a; + assert(r1(ap) == 6); + r1(ap) = 7; + assert(r1(ap) == 7); + } +} + +// 2 arg, return void + +void f_void_2(int i, int j) +{ + count += i+j; +} + +struct A_void_2 +{ + void operator()(int i, int j) + { + count += i+j; + } + + void mem1(int i) {count += i;} + void mem2(int i) const {count += i;} +}; + +void +test_void_2() +{ + int save_count = count; + // function + { + std::reference_wrapper<void (int, int)> r1(f_void_2); + int i = 2; + int j = 3; + r1(i, j); + assert(count == save_count+5); + save_count = count; + } + // function pointer + { + void (*fp)(int, int) = f_void_2; + std::reference_wrapper<void (*)(int, int)> r1(fp); + int i = 3; + int j = 4; + r1(i, j); + assert(count == save_count+7); + save_count = count; + } + // functor + { + A_void_2 a0; + std::reference_wrapper<A_void_2> r1(a0); + int i = 4; + int j = 5; + r1(i, j); + assert(count == save_count+9); + save_count = count; + } + // member function pointer + { + void (A_void_2::*fp)(int) = &A_void_2::mem1; + std::reference_wrapper<void (A_void_2::*)(int)> r1(fp); + A_void_2 a; + int i = 3; + r1(a, i); + assert(count == save_count+3); + save_count = count; + A_void_2* ap = &a; + r1(ap, i); + assert(count == save_count+3); + save_count = count; + } + // const member function pointer + { + void (A_void_2::*fp)(int) const = &A_void_2::mem2; + std::reference_wrapper<void (A_void_2::*)(int) const> r1(fp); + A_void_2 a; + int i = 4; + r1(a, i); + assert(count == save_count+4); + save_count = count; + A_void_2* ap = &a; + r1(ap, i); + assert(count == save_count+4); + save_count = count; + } +} + +// 2 arg, return int + +int f_int_2(int i, int j) +{ + return i+j; +} + +struct A_int_2 +{ + int operator()(int i, int j) + { + return i+j; + } + + int mem1(int i) {return i+1;} + int mem2(int i) const {return i+2;} +}; + +void +testint_2() +{ + // function + { + std::reference_wrapper<int (int, int)> r1(f_int_2); + int i = 2; + int j = 3; + assert(r1(i, j) == i+j); + } + // function pointer + { + int (*fp)(int, int) = f_int_2; + std::reference_wrapper<int (*)(int, int)> r1(fp); + int i = 3; + int j = 4; + assert(r1(i, j) == i+j); + } + // functor + { + A_int_2 a0; + std::reference_wrapper<A_int_2> r1(a0); + int i = 4; + int j = 5; + assert(r1(i, j) == i+j); + } + // member function pointer + { + int(A_int_2::*fp)(int) = &A_int_2::mem1; + std::reference_wrapper<int (A_int_2::*)(int)> r1(fp); + A_int_2 a; + int i = 3; + assert(r1(a, i) == i+1); + A_int_2* ap = &a; + assert(r1(ap, i) == i+1); + } + // const member function pointer + { + int (A_int_2::*fp)(int) const = &A_int_2::mem2; + std::reference_wrapper<int (A_int_2::*)(int) const> r1(fp); + A_int_2 a; + int i = 4; + assert(r1(a, i) == i+2); + A_int_2* ap = &a; + assert(r1(ap, i) == i+2); + } +} + +int main() +{ + test_void_1(); + test_int_1(); + test_void_2(); + testint_2(); +} diff --git a/libcxx/test/utilities/function.objects/refwrap/refwrap.invoke/invoke_int_0.pass.cpp b/libcxx/test/utilities/function.objects/refwrap/refwrap.invoke/invoke_int_0.pass.cpp index 2bef95e6d60..709836bd3cb 100644 --- a/libcxx/test/utilities/function.objects/refwrap/refwrap.invoke/invoke_int_0.pass.cpp +++ b/libcxx/test/utilities/function.objects/refwrap/refwrap.invoke/invoke_int_0.pass.cpp @@ -1 +1,76 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <functional>
// reference_wrapper
// template <class... ArgTypes>
// requires Callable<T, ArgTypes&&...>
// Callable<T, ArgTypes&&...>::result_type
// operator()(ArgTypes&&... args) const;
#include <functional>
#include <cassert>
// 0 args, return int
int count = 0;
int f_int_0()
{
return 3;
}
struct A_int_0
{
int operator()() {return 4;}
};
void
test_int_0()
{
// function
{
std::reference_wrapper<int ()> r1(f_int_0);
assert(r1() == 3);
}
// function pointer
{
int (*fp)() = f_int_0;
std::reference_wrapper<int (*)()> r1(fp);
assert(r1() == 3);
}
// functor
{
A_int_0 a0;
std::reference_wrapper<A_int_0> r1(a0);
assert(r1() == 4);
}
}
// 1 arg, return void
void f_void_1(int i)
{
count += i;
}
struct A_void_1
{
void operator()(int i)
{
count += i;
}
};
int main()
{
test_int_0();
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// reference_wrapper + +// template <class... ArgTypes> +// requires Callable<T, ArgTypes&&...> +// Callable<T, ArgTypes&&...>::result_type +// operator()(ArgTypes&&... args) const; + +#include <functional> +#include <cassert> + +// 0 args, return int + +int count = 0; + +int f_int_0() +{ + return 3; +} + +struct A_int_0 +{ + int operator()() {return 4;} +}; + +void +test_int_0() +{ + // function + { + std::reference_wrapper<int ()> r1(f_int_0); + assert(r1() == 3); + } + // function pointer + { + int (*fp)() = f_int_0; + std::reference_wrapper<int (*)()> r1(fp); + assert(r1() == 3); + } + // functor + { + A_int_0 a0; + std::reference_wrapper<A_int_0> r1(a0); + assert(r1() == 4); + } +} + +// 1 arg, return void + +void f_void_1(int i) +{ + count += i; +} + +struct A_void_1 +{ + void operator()(int i) + { + count += i; + } +}; + +int main() +{ + test_int_0(); +} diff --git a/libcxx/test/utilities/function.objects/refwrap/refwrap.invoke/invoke_void_0.pass.cpp b/libcxx/test/utilities/function.objects/refwrap/refwrap.invoke/invoke_void_0.pass.cpp index e7445217cc0..127a97c6711 100644 --- a/libcxx/test/utilities/function.objects/refwrap/refwrap.invoke/invoke_void_0.pass.cpp +++ b/libcxx/test/utilities/function.objects/refwrap/refwrap.invoke/invoke_void_0.pass.cpp @@ -1 +1,68 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <functional>
// reference_wrapper
// template <class... ArgTypes>
// requires Callable<T, ArgTypes&&...>
// Callable<T, ArgTypes&&...>::result_type
// operator()(ArgTypes&&... args) const;
#include <functional>
#include <cassert>
// 0 args, return void
int count = 0;
void f_void_0()
{
++count;
}
struct A_void_0
{
void operator()() {++count;}
};
void
test_void_0()
{
int save_count = count;
// function
{
std::reference_wrapper<void ()> r1(f_void_0);
r1();
assert(count == save_count+1);
save_count = count;
}
// function pointer
{
void (*fp)() = f_void_0;
std::reference_wrapper<void (*)()> r1(fp);
r1();
assert(count == save_count+1);
save_count = count;
}
// functor
{
A_void_0 a0;
std::reference_wrapper<A_void_0> r1(a0);
r1();
assert(count == save_count+1);
save_count = count;
}
}
int main()
{
test_void_0();
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// reference_wrapper + +// template <class... ArgTypes> +// requires Callable<T, ArgTypes&&...> +// Callable<T, ArgTypes&&...>::result_type +// operator()(ArgTypes&&... args) const; + +#include <functional> +#include <cassert> + +// 0 args, return void + +int count = 0; + +void f_void_0() +{ + ++count; +} + +struct A_void_0 +{ + void operator()() {++count;} +}; + +void +test_void_0() +{ + int save_count = count; + // function + { + std::reference_wrapper<void ()> r1(f_void_0); + r1(); + assert(count == save_count+1); + save_count = count; + } + // function pointer + { + void (*fp)() = f_void_0; + std::reference_wrapper<void (*)()> r1(fp); + r1(); + assert(count == save_count+1); + save_count = count; + } + // functor + { + A_void_0 a0; + std::reference_wrapper<A_void_0> r1(a0); + r1(); + assert(count == save_count+1); + save_count = count; + } +} + +int main() +{ + test_void_0(); +} diff --git a/libcxx/test/utilities/function.objects/refwrap/type.pass.cpp b/libcxx/test/utilities/function.objects/refwrap/type.pass.cpp index 0ff12536803..fb1523e7d46 100644 --- a/libcxx/test/utilities/function.objects/refwrap/type.pass.cpp +++ b/libcxx/test/utilities/function.objects/refwrap/type.pass.cpp @@ -1 +1,37 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <functional>
// reference_wrapper
// check for member typedef type
#include <functional>
#include <type_traits>
class C {};
int main()
{
static_assert((std::is_same<std::reference_wrapper<C>::type,
C>::value), "");
static_assert((std::is_same<std::reference_wrapper<void ()>::type,
void ()>::value), "");
static_assert((std::is_same<std::reference_wrapper<int* (double*)>::type,
int* (double*)>::value), "");
static_assert((std::is_same<std::reference_wrapper<void(*)()>::type,
void(*)()>::value), "");
static_assert((std::is_same<std::reference_wrapper<int*(*)(double*)>::type,
int*(*)(double*)>::value), "");
static_assert((std::is_same<std::reference_wrapper<int*(C::*)(double*)>::type,
int*(C::*)(double*)>::value), "");
static_assert((std::is_same<std::reference_wrapper<int (C::*)(double*) const volatile>::type,
int (C::*)(double*) const volatile>::value), "");
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// reference_wrapper + +// check for member typedef type + +#include <functional> +#include <type_traits> + +class C {}; + +int main() +{ + static_assert((std::is_same<std::reference_wrapper<C>::type, + C>::value), ""); + static_assert((std::is_same<std::reference_wrapper<void ()>::type, + void ()>::value), ""); + static_assert((std::is_same<std::reference_wrapper<int* (double*)>::type, + int* (double*)>::value), ""); + static_assert((std::is_same<std::reference_wrapper<void(*)()>::type, + void(*)()>::value), ""); + static_assert((std::is_same<std::reference_wrapper<int*(*)(double*)>::type, + int*(*)(double*)>::value), ""); + static_assert((std::is_same<std::reference_wrapper<int*(C::*)(double*)>::type, + int*(C::*)(double*)>::value), ""); + static_assert((std::is_same<std::reference_wrapper<int (C::*)(double*) const volatile>::type, + int (C::*)(double*) const volatile>::value), ""); +} diff --git a/libcxx/test/utilities/function.objects/refwrap/unary.pass.cpp b/libcxx/test/utilities/function.objects/refwrap/unary.pass.cpp index 411d34fa26f..5998deacead 100644 --- a/libcxx/test/utilities/function.objects/refwrap/unary.pass.cpp +++ b/libcxx/test/utilities/function.objects/refwrap/unary.pass.cpp @@ -1 +1,78 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <functional>
// reference_wrapper
// check for deriving from unary_function
#include <functional>
#include <type_traits>
class functor1
: public std::unary_function<int, char>
{
};
class functor2
: public std::binary_function<char, int, double>
{
};
class functor3
: public std::unary_function<int, int>,
public std::binary_function<char, int, double>
{
public:
typedef float result_type;
};
class functor4
: public std::unary_function<int, int>,
public std::binary_function<char, int, double>
{
public:
};
struct C
{
typedef int argument_type;
typedef int result_type;
};
int main()
{
static_assert((std::is_base_of<std::unary_function<int, char>,
std::reference_wrapper<functor1> >::value), "");
static_assert((!std::is_base_of<std::unary_function<char, int>,
std::reference_wrapper<functor2> >::value), "");
static_assert((std::is_base_of<std::unary_function<int, int>,
std::reference_wrapper<functor3> >::value), "");
static_assert((std::is_base_of<std::unary_function<int, int>,
std::reference_wrapper<functor4> >::value), "");
static_assert((!std::is_base_of<std::unary_function<int, int>,
std::reference_wrapper<C> >::value), "");
static_assert((!std::is_base_of<std::unary_function<int, float>,
std::reference_wrapper<float(*)()> >::value), "");
static_assert((std::is_base_of<std::unary_function<int, float>,
std::reference_wrapper<float (int)> >::value), "");
static_assert((!std::is_base_of<std::unary_function<int, float>,
std::reference_wrapper<float (int, int)> >::value), "");
static_assert((std::is_base_of<std::unary_function<int, float>,
std::reference_wrapper<float(*)(int)> >::value), "");
static_assert((!std::is_base_of<std::unary_function<int, float>,
std::reference_wrapper<float(*)(int, int)> >::value), "");
static_assert((std::is_base_of<std::unary_function<C*, float>,
std::reference_wrapper<float(C::*)()> >::value), "");
static_assert((std::is_base_of<std::unary_function<const volatile C*, float>,
std::reference_wrapper<float(C::*)() const volatile> >::value), "");
static_assert((!std::is_base_of<std::unary_function<C*, float>,
std::reference_wrapper<float(C::*)(int)> >::value), "");
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// reference_wrapper + +// check for deriving from unary_function + +#include <functional> +#include <type_traits> + +class functor1 + : public std::unary_function<int, char> +{ +}; + +class functor2 + : public std::binary_function<char, int, double> +{ +}; + +class functor3 + : public std::unary_function<int, int>, + public std::binary_function<char, int, double> +{ +public: + typedef float result_type; +}; + +class functor4 + : public std::unary_function<int, int>, + public std::binary_function<char, int, double> +{ +public: +}; + +struct C +{ + typedef int argument_type; + typedef int result_type; +}; + +int main() +{ + static_assert((std::is_base_of<std::unary_function<int, char>, + std::reference_wrapper<functor1> >::value), ""); + static_assert((!std::is_base_of<std::unary_function<char, int>, + std::reference_wrapper<functor2> >::value), ""); + static_assert((std::is_base_of<std::unary_function<int, int>, + std::reference_wrapper<functor3> >::value), ""); + static_assert((std::is_base_of<std::unary_function<int, int>, + std::reference_wrapper<functor4> >::value), ""); + static_assert((!std::is_base_of<std::unary_function<int, int>, + std::reference_wrapper<C> >::value), ""); + static_assert((!std::is_base_of<std::unary_function<int, float>, + std::reference_wrapper<float(*)()> >::value), ""); + static_assert((std::is_base_of<std::unary_function<int, float>, + std::reference_wrapper<float (int)> >::value), ""); + static_assert((!std::is_base_of<std::unary_function<int, float>, + std::reference_wrapper<float (int, int)> >::value), ""); + static_assert((std::is_base_of<std::unary_function<int, float>, + std::reference_wrapper<float(*)(int)> >::value), ""); + static_assert((!std::is_base_of<std::unary_function<int, float>, + std::reference_wrapper<float(*)(int, int)> >::value), ""); + static_assert((std::is_base_of<std::unary_function<C*, float>, + std::reference_wrapper<float(C::*)()> >::value), ""); + static_assert((std::is_base_of<std::unary_function<const volatile C*, float>, + std::reference_wrapper<float(C::*)() const volatile> >::value), ""); + static_assert((!std::is_base_of<std::unary_function<C*, float>, + std::reference_wrapper<float(C::*)(int)> >::value), ""); +} diff --git a/libcxx/test/utilities/function.objects/refwrap/weak_result.pass.cpp b/libcxx/test/utilities/function.objects/refwrap/weak_result.pass.cpp index 09cef664298..794651dbde7 100644 --- a/libcxx/test/utilities/function.objects/refwrap/weak_result.pass.cpp +++ b/libcxx/test/utilities/function.objects/refwrap/weak_result.pass.cpp @@ -1 +1,82 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <functional>
// reference_wrapper
// has weak result type
#include <functional>
#include <type_traits>
class functor1
: public std::unary_function<int, char>
{
};
class functor2
: public std::binary_function<char, int, double>
{
};
class functor3
: public std::unary_function<char, int>,
public std::binary_function<char, int, double>
{
public:
typedef float result_type;
};
class functor4
: public std::unary_function<char, int>,
public std::binary_function<char, int, double>
{
public:
};
class C {};
template <class T>
struct has_result_type
{
private:
struct two {char _; char __;};
template <class U> static two test(...);
template <class U> static char test(typename U::result_type* = 0);
public:
static const bool value = sizeof(test<T>(0)) == 1;
};
int main()
{
static_assert((std::is_same<std::reference_wrapper<functor1>::result_type,
char>::value), "");
static_assert((std::is_same<std::reference_wrapper<functor2>::result_type,
double>::value), "");
static_assert((std::is_same<std::reference_wrapper<functor3>::result_type,
float>::value), "");
static_assert((std::is_same<std::reference_wrapper<void()>::result_type,
void>::value), "");
static_assert((std::is_same<std::reference_wrapper<int*(double*)>::result_type,
int*>::value), "");
static_assert((std::is_same<std::reference_wrapper<void(*)()>::result_type,
void>::value), "");
static_assert((std::is_same<std::reference_wrapper<int*(*)(double*)>::result_type,
int*>::value), "");
static_assert((std::is_same<std::reference_wrapper<int*(C::*)(double*)>::result_type,
int*>::value), "");
static_assert((std::is_same<std::reference_wrapper<int (C::*)(double*) const volatile>::result_type,
int>::value), "");
static_assert((std::is_same<std::reference_wrapper<C()>::result_type,
C>::value), "");
static_assert(has_result_type<std::reference_wrapper<functor3> >::value, "");
static_assert(!has_result_type<std::reference_wrapper<functor4> >::value, "");
static_assert(!has_result_type<std::reference_wrapper<C> >::value, "");
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// reference_wrapper + +// has weak result type + +#include <functional> +#include <type_traits> + +class functor1 + : public std::unary_function<int, char> +{ +}; + +class functor2 + : public std::binary_function<char, int, double> +{ +}; + +class functor3 + : public std::unary_function<char, int>, + public std::binary_function<char, int, double> +{ +public: + typedef float result_type; +}; + +class functor4 + : public std::unary_function<char, int>, + public std::binary_function<char, int, double> +{ +public: +}; + +class C {}; + +template <class T> +struct has_result_type +{ +private: + struct two {char _; char __;}; + template <class U> static two test(...); + template <class U> static char test(typename U::result_type* = 0); +public: + static const bool value = sizeof(test<T>(0)) == 1; +}; + +int main() +{ + static_assert((std::is_same<std::reference_wrapper<functor1>::result_type, + char>::value), ""); + static_assert((std::is_same<std::reference_wrapper<functor2>::result_type, + double>::value), ""); + static_assert((std::is_same<std::reference_wrapper<functor3>::result_type, + float>::value), ""); + static_assert((std::is_same<std::reference_wrapper<void()>::result_type, + void>::value), ""); + static_assert((std::is_same<std::reference_wrapper<int*(double*)>::result_type, + int*>::value), ""); + static_assert((std::is_same<std::reference_wrapper<void(*)()>::result_type, + void>::value), ""); + static_assert((std::is_same<std::reference_wrapper<int*(*)(double*)>::result_type, + int*>::value), ""); + static_assert((std::is_same<std::reference_wrapper<int*(C::*)(double*)>::result_type, + int*>::value), ""); + static_assert((std::is_same<std::reference_wrapper<int (C::*)(double*) const volatile>::result_type, + int>::value), ""); + static_assert((std::is_same<std::reference_wrapper<C()>::result_type, + C>::value), ""); + static_assert(has_result_type<std::reference_wrapper<functor3> >::value, ""); + static_assert(!has_result_type<std::reference_wrapper<functor4> >::value, ""); + static_assert(!has_result_type<std::reference_wrapper<C> >::value, ""); +} diff --git a/libcxx/test/utilities/function.objects/version.pass.cpp b/libcxx/test/utilities/function.objects/version.pass.cpp index 293168ba490..03024d1f10f 100644 --- a/libcxx/test/utilities/function.objects/version.pass.cpp +++ b/libcxx/test/utilities/function.objects/version.pass.cpp @@ -1 +1,20 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <functional>
#include <functional>
#ifndef _LIBCPP_VERSION
#error _LIBCPP_VERSION not defined
#endif
int main()
{
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <functional> + +#include <functional> + +#ifndef _LIBCPP_VERSION +#error _LIBCPP_VERSION not defined +#endif + +int main() +{ +} diff --git a/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.cnstr/allocs.pass.cpp b/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.cnstr/allocs.pass.cpp index a75ae54444e..19b81a8a5a3 100644 --- a/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.cnstr/allocs.pass.cpp +++ b/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.cnstr/allocs.pass.cpp @@ -108,5 +108,5 @@ int main() std::scoped_allocator_adaptor<A2<int>, A3<int>>(A2<int>(5), A3<int>(6)))); } -#endif +#endif // _LIBCPP_MOVE } diff --git a/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.cnstr/converting_copy.pass.cpp b/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.cnstr/converting_copy.pass.cpp index 64296e3ec7c..49ea9c0679e 100644 --- a/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.cnstr/converting_copy.pass.cpp +++ b/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.cnstr/converting_copy.pass.cpp @@ -65,5 +65,5 @@ int main() assert(a2 == a1); } -#endif +#endif // _LIBCPP_MOVE } diff --git a/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.cnstr/converting_move.pass.cpp b/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.cnstr/converting_move.pass.cpp index 2fae9037ad3..0db40da6ba7 100644 --- a/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.cnstr/converting_move.pass.cpp +++ b/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.cnstr/converting_move.pass.cpp @@ -71,5 +71,5 @@ int main() assert(a2 == a1); } -#endif +#endif // _LIBCPP_MOVE } diff --git a/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.cnstr/copy.pass.cpp b/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.cnstr/copy.pass.cpp index 1bf66370dfa..6db3d3a657e 100644 --- a/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.cnstr/copy.pass.cpp +++ b/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.cnstr/copy.pass.cpp @@ -66,5 +66,5 @@ int main() assert(a2 == a1); } -#endif +#endif // _LIBCPP_MOVE } diff --git a/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.cnstr/default.pass.cpp b/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.cnstr/default.pass.cpp index eeac01607ca..26dc7f55171 100644 --- a/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.cnstr/default.pass.cpp +++ b/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.cnstr/default.pass.cpp @@ -54,5 +54,5 @@ int main() assert(A3<int>::move_called == false); } -#endif +#endif // _LIBCPP_MOVE } diff --git a/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.members/allocate_size.pass.cpp b/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.members/allocate_size.pass.cpp index 220306824f0..1a433cfa453 100644 --- a/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.members/allocate_size.pass.cpp +++ b/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.members/allocate_size.pass.cpp @@ -45,5 +45,5 @@ int main() assert(A1<int>::allocate_called == true); } -#endif +#endif // _LIBCPP_MOVE } diff --git a/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.members/allocate_size_hint.pass.cpp b/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.members/allocate_size_hint.pass.cpp index 9ea3da8011c..43916cb0bba 100644 --- a/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.members/allocate_size_hint.pass.cpp +++ b/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.members/allocate_size_hint.pass.cpp @@ -66,5 +66,5 @@ int main() assert(a.allocate(10, (const void*)20) == (int*)20); assert(A2<int>::allocate_called == true); } -#endif +#endif // _LIBCPP_MOVE } diff --git a/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.members/construct.pass.cpp b/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.members/construct.pass.cpp index 47d3be53c0a..56306f29c16 100644 --- a/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.members/construct.pass.cpp +++ b/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.members/construct.pass.cpp @@ -111,7 +111,7 @@ struct F bool F::constructed = false; -#endif +#endif // _LIBCPP_MOVE int main() { @@ -189,5 +189,5 @@ int main() s->~S(); } -#endif +#endif // _LIBCPP_MOVE } diff --git a/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.members/deallocate.pass.cpp b/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.members/deallocate.pass.cpp index c123cd8b9e9..137d8011d96 100644 --- a/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.members/deallocate.pass.cpp +++ b/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.members/deallocate.pass.cpp @@ -42,5 +42,5 @@ int main() assert((A1<int>::deallocate_called == std::pair<int*, std::size_t>((int*)10, 20))); } -#endif +#endif // _LIBCPP_MOVE } diff --git a/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.members/destroy.pass.cpp b/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.members/destroy.pass.cpp index 6456c12cf99..9201e16eaed 100644 --- a/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.members/destroy.pass.cpp +++ b/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.members/destroy.pass.cpp @@ -66,5 +66,5 @@ int main() assert(A3<S>::destroy_called); } -#endif +#endif // _LIBCPP_MOVE } diff --git a/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.members/inner_allocator.pass.cpp b/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.members/inner_allocator.pass.cpp index 85b7724087f..1eef5beed9a 100644 --- a/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.members/inner_allocator.pass.cpp +++ b/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.members/inner_allocator.pass.cpp @@ -41,5 +41,5 @@ int main() std::scoped_allocator_adaptor<A2<int>, A3<int>>(A2<int>(6), A3<int>(8)))); } -#endif +#endif // _LIBCPP_MOVE } diff --git a/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.members/max_size.pass.cpp b/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.members/max_size.pass.cpp index 8c2db74bdca..22655a36397 100644 --- a/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.members/max_size.pass.cpp +++ b/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.members/max_size.pass.cpp @@ -39,5 +39,5 @@ int main() assert(a.max_size() == 200); } -#endif +#endif // _LIBCPP_MOVE } diff --git a/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.members/outer_allocator.pass.cpp b/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.members/outer_allocator.pass.cpp index 61ac84738d2..23ab0e59961 100644 --- a/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.members/outer_allocator.pass.cpp +++ b/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.members/outer_allocator.pass.cpp @@ -40,5 +40,5 @@ int main() assert(a.outer_allocator() == A1<int>(5)); } -#endif +#endif // _LIBCPP_MOVE } diff --git a/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.members/select_on_container_copy_construction.pass.cpp b/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.members/select_on_container_copy_construction.pass.cpp index 883d57360d3..a5d5b109b81 100644 --- a/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.members/select_on_container_copy_construction.pass.cpp +++ b/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.members/select_on_container_copy_construction.pass.cpp @@ -51,5 +51,5 @@ int main() assert(a2.inner_allocator().inner_allocator().outer_allocator().id() == -1); } -#endif +#endif // _LIBCPP_MOVE } diff --git a/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.types/inner_allocator_type.pass.cpp b/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.types/inner_allocator_type.pass.cpp index 952e31ddd8d..416ac524127 100644 --- a/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.types/inner_allocator_type.pass.cpp +++ b/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.types/inner_allocator_type.pass.cpp @@ -35,5 +35,5 @@ int main() std::scoped_allocator_adaptor<A1<int>, A2<int>, A3<int>>::inner_allocator_type, std::scoped_allocator_adaptor<A2<int>, A3<int>>>::value), ""); -#endif +#endif // _LIBCPP_MOVE } diff --git a/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.types/propagate_on_container_copy_assignment.pass.cpp b/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.types/propagate_on_container_copy_assignment.pass.cpp index 479f65496dd..46ae7812eb6 100644 --- a/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.types/propagate_on_container_copy_assignment.pass.cpp +++ b/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.types/propagate_on_container_copy_assignment.pass.cpp @@ -35,5 +35,5 @@ int main() std::scoped_allocator_adaptor<A1<int>, A2<int>, A3<int>>::propagate_on_container_copy_assignment, std::true_type>::value), ""); -#endif +#endif // _LIBCPP_MOVE } diff --git a/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.types/propagate_on_container_move_assignment.pass.cpp b/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.types/propagate_on_container_move_assignment.pass.cpp index d443b0bfbbd..664c27bd787 100644 --- a/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.types/propagate_on_container_move_assignment.pass.cpp +++ b/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.types/propagate_on_container_move_assignment.pass.cpp @@ -35,5 +35,5 @@ int main() std::scoped_allocator_adaptor<A1<int>, A2<int>, A3<int>>::propagate_on_container_move_assignment, std::true_type>::value), ""); -#endif +#endif // _LIBCPP_MOVE } diff --git a/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.types/propagate_on_container_swap.pass.cpp b/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.types/propagate_on_container_swap.pass.cpp index 76da120de9b..585bd14bc50 100644 --- a/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.types/propagate_on_container_swap.pass.cpp +++ b/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.types/propagate_on_container_swap.pass.cpp @@ -35,5 +35,5 @@ int main() std::scoped_allocator_adaptor<A1<int>, A2<int>, A3<int>>::propagate_on_container_swap, std::true_type>::value), ""); -#endif +#endif // _LIBCPP_MOVE } diff --git a/libcxx/test/utilities/memory/allocator.adaptor/allocators.h b/libcxx/test/utilities/memory/allocator.adaptor/allocators.h index 7075f85e222..0e4b7f3299d 100644 --- a/libcxx/test/utilities/memory/allocator.adaptor/allocators.h +++ b/libcxx/test/utilities/memory/allocator.adaptor/allocators.h @@ -150,8 +150,6 @@ public: A3 select_on_container_copy_construction() const {return A3(-1);} }; - - template <class T> bool A3<T>::copy_called = false; template <class T> bool A3<T>::move_called = false; template <class T> bool A3<T>::constructed = false; @@ -171,6 +169,6 @@ bool operator!=(const A3<T>& x, const A3<U>& y) return !(x == y); } -#endif +#endif // _LIBCPP_MOVE -#endif +#endif // ALLOCATORS_H diff --git a/libcxx/test/utilities/memory/allocator.adaptor/types.pass.cpp b/libcxx/test/utilities/memory/allocator.adaptor/types.pass.cpp index af1e3d24b21..61a347f5ff0 100644 --- a/libcxx/test/utilities/memory/allocator.adaptor/types.pass.cpp +++ b/libcxx/test/utilities/memory/allocator.adaptor/types.pass.cpp @@ -65,7 +65,6 @@ int main() std::scoped_allocator_adaptor<A1<int>>::const_void_pointer, const void*>::value), ""); - static_assert((std::is_base_of< A2<int>, std::scoped_allocator_adaptor<A2<int>, A1<int>> @@ -99,5 +98,5 @@ int main() std::scoped_allocator_adaptor<A2<int>, A1<int>>::const_void_pointer, const void*>::value), ""); -#endif +#endif // _LIBCPP_MOVE } diff --git a/libcxx/test/utilities/memory/allocator.tag/allocator_arg.pass.cpp b/libcxx/test/utilities/memory/allocator.tag/allocator_arg.pass.cpp index fb0b9f69aa5..43331ab35d0 100644 --- a/libcxx/test/utilities/memory/allocator.tag/allocator_arg.pass.cpp +++ b/libcxx/test/utilities/memory/allocator.tag/allocator_arg.pass.cpp @@ -1 +1,22 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// struct allocator_arg_t { };
// const allocator_arg_t allocator_arg = allocator_arg_t();
#include <memory>
void test(std::allocator_arg_t) {}
int main()
{
test(std::allocator_arg);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// struct allocator_arg_t { }; +// const allocator_arg_t allocator_arg = allocator_arg_t(); + +#include <memory> + +void test(std::allocator_arg_t) {} + +int main() +{ + test(std::allocator_arg); +} diff --git a/libcxx/test/utilities/memory/allocator.traits/allocator.traits.members/allocate.pass.cpp b/libcxx/test/utilities/memory/allocator.traits/allocator.traits.members/allocate.pass.cpp index c797b1020bc..ebbfa15d7c5 100644 --- a/libcxx/test/utilities/memory/allocator.traits/allocator.traits.members/allocate.pass.cpp +++ b/libcxx/test/utilities/memory/allocator.traits/allocator.traits.members/allocate.pass.cpp @@ -1 +1,38 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <class Alloc>
// struct allocator_traits
// {
// static pointer allocate(allocator_type& a, size_type n);
// ...
// };
#include <memory>
#include <cassert>
template <class T>
struct A
{
typedef T value_type;
value_type* allocate(std::size_t n)
{
assert(n == 10);
return (value_type*)0xDEADBEEF;
}
};
int main()
{
A<int> a;
assert(std::allocator_traits<A<int> >::allocate(a, 10) == (int*)0xDEADBEEF);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// template <class Alloc> +// struct allocator_traits +// { +// static pointer allocate(allocator_type& a, size_type n); +// ... +// }; + +#include <memory> +#include <cassert> + +template <class T> +struct A +{ + typedef T value_type; + + value_type* allocate(std::size_t n) + { + assert(n == 10); + return (value_type*)0xDEADBEEF; + } +}; + +int main() +{ + A<int> a; + assert(std::allocator_traits<A<int> >::allocate(a, 10) == (int*)0xDEADBEEF); +} diff --git a/libcxx/test/utilities/memory/allocator.traits/allocator.traits.members/allocate_hint.pass.cpp b/libcxx/test/utilities/memory/allocator.traits/allocator.traits.members/allocate_hint.pass.cpp index 9847c2a6053..527f51b1e59 100644 --- a/libcxx/test/utilities/memory/allocator.traits/allocator.traits.members/allocate_hint.pass.cpp +++ b/libcxx/test/utilities/memory/allocator.traits/allocator.traits.members/allocate_hint.pass.cpp @@ -1 +1,60 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <class Alloc>
// struct allocator_traits
// {
// static pointer allocate(allocator_type& a, size_type n, const_void_pointer hint);
// ...
// };
#include <memory>
#include <cassert>
template <class T>
struct A
{
typedef T value_type;
value_type* allocate(std::size_t n)
{
assert(n == 10);
return (value_type*)0xDEADBEEF;
}
};
template <class T>
struct B
{
typedef T value_type;
value_type* allocate(std::size_t n)
{
assert(n == 12);
return (value_type*)0xEEADBEEF;
}
value_type* allocate(std::size_t n, const void* p)
{
assert(n == 11);
assert(p == 0);
return (value_type*)0xFEADBEEF;
}
};
int main()
{
#ifndef _LIBCPP_HAS_NO_ADVANCED_SFINAE
A<int> a;
assert(std::allocator_traits<A<int> >::allocate(a, 10, nullptr) == (int*)0xDEADBEEF);
#endif
B<int> b;
assert(std::allocator_traits<B<int> >::allocate(b, 11, nullptr) == (int*)0xFEADBEEF);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// template <class Alloc> +// struct allocator_traits +// { +// static pointer allocate(allocator_type& a, size_type n, const_void_pointer hint); +// ... +// }; + +#include <memory> +#include <cassert> + +template <class T> +struct A +{ + typedef T value_type; + + value_type* allocate(std::size_t n) + { + assert(n == 10); + return (value_type*)0xDEADBEEF; + } +}; + +template <class T> +struct B +{ + typedef T value_type; + + value_type* allocate(std::size_t n) + { + assert(n == 12); + return (value_type*)0xEEADBEEF; + } + value_type* allocate(std::size_t n, const void* p) + { + assert(n == 11); + assert(p == 0); + return (value_type*)0xFEADBEEF; + } +}; + +int main() +{ +#ifndef _LIBCPP_HAS_NO_ADVANCED_SFINAE + A<int> a; + assert(std::allocator_traits<A<int> >::allocate(a, 10, nullptr) == (int*)0xDEADBEEF); +#endif // _LIBCPP_HAS_NO_ADVANCED_SFINAE + B<int> b; + assert(std::allocator_traits<B<int> >::allocate(b, 11, nullptr) == (int*)0xFEADBEEF); +} diff --git a/libcxx/test/utilities/memory/allocator.traits/allocator.traits.members/construct.pass.cpp b/libcxx/test/utilities/memory/allocator.traits/allocator.traits.members/construct.pass.cpp index 4dda58f8c7a..e2d510e1ef5 100644 --- a/libcxx/test/utilities/memory/allocator.traits/allocator.traits.members/construct.pass.cpp +++ b/libcxx/test/utilities/memory/allocator.traits/allocator.traits.members/construct.pass.cpp @@ -1 +1,143 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <class Alloc>
// struct allocator_traits
// {
// template <class Ptr, class... Args>
// static void construct(allocator_type& a, Ptr p, Args&&... args);
// ...
// };
#include <memory>
#include <new>
#include <type_traits>
#include <cassert>
template <class T>
struct A
{
typedef T value_type;
};
int b_construct = 0;
template <class T>
struct B
{
typedef T value_type;
#ifndef _LIBCPP_HAS_NO_VARIADICS
template <class U, class ...Args>
void construct(U* p, Args&& ...args)
{
++b_construct;
::new ((void*)p) U(std::forward<Args>(args)...);
}
#endif
};
struct A0
{
static int count;
A0() {++count;}
};
int A0::count = 0;
struct A1
{
static int count;
A1(char c)
{
assert(c == 'c');
++count;
}
};
int A1::count = 0;
struct A2
{
static int count;
A2(char c, int i)
{
assert(c == 'd');
assert(i == 5);
++count;
}
};
int A2::count = 0;
int main()
{
{
A0::count = 0;
A<int> a;
std::aligned_storage<sizeof(A0)>::type a0;
assert(A0::count == 0);
std::allocator_traits<A<int> >::construct(a, (A0*)&a0);
assert(A0::count == 1);
}
{
A1::count = 0;
A<int> a;
std::aligned_storage<sizeof(A1)>::type a1;
assert(A1::count == 0);
std::allocator_traits<A<int> >::construct(a, (A1*)&a1, 'c');
assert(A1::count == 1);
}
{
A2::count = 0;
A<int> a;
std::aligned_storage<sizeof(A2)>::type a2;
assert(A2::count == 0);
std::allocator_traits<A<int> >::construct(a, (A2*)&a2, 'd', 5);
assert(A2::count == 1);
}
#ifndef _LIBCPP_HAS_NO_VARIADICS
{
A0::count = 0;
b_construct = 0;
B<int> b;
std::aligned_storage<sizeof(A0)>::type a0;
assert(A0::count == 0);
assert(b_construct == 0);
std::allocator_traits<B<int> >::construct(b, (A0*)&a0);
assert(A0::count == 1);
assert(b_construct == 1);
}
{
A1::count = 0;
b_construct = 0;
B<int> b;
std::aligned_storage<sizeof(A1)>::type a1;
assert(A1::count == 0);
assert(b_construct == 0);
std::allocator_traits<B<int> >::construct(b, (A1*)&a1, 'c');
assert(A1::count == 1);
assert(b_construct == 1);
}
{
A2::count = 0;
b_construct = 0;
B<int> b;
std::aligned_storage<sizeof(A2)>::type a2;
assert(A2::count == 0);
assert(b_construct == 0);
std::allocator_traits<B<int> >::construct(b, (A2*)&a2, 'd', 5);
assert(A2::count == 1);
assert(b_construct == 1);
}
#endif
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// template <class Alloc> +// struct allocator_traits +// { +// template <class Ptr, class... Args> +// static void construct(allocator_type& a, Ptr p, Args&&... args); +// ... +// }; + +#include <memory> +#include <new> +#include <type_traits> +#include <cassert> + +template <class T> +struct A +{ + typedef T value_type; + +}; + +int b_construct = 0; + +template <class T> +struct B +{ + typedef T value_type; + +#ifndef _LIBCPP_HAS_NO_VARIADICS + template <class U, class ...Args> + void construct(U* p, Args&& ...args) + { + ++b_construct; + ::new ((void*)p) U(std::forward<Args>(args)...); + } +#endif // _LIBCPP_HAS_NO_VARIADICS +}; + +struct A0 +{ + static int count; + A0() {++count;} +}; + +int A0::count = 0; + +struct A1 +{ + static int count; + A1(char c) + { + assert(c == 'c'); + ++count; + } +}; + +int A1::count = 0; + +struct A2 +{ + static int count; + A2(char c, int i) + { + assert(c == 'd'); + assert(i == 5); + ++count; + } +}; + +int A2::count = 0; + +int main() +{ + { + A0::count = 0; + A<int> a; + std::aligned_storage<sizeof(A0)>::type a0; + assert(A0::count == 0); + std::allocator_traits<A<int> >::construct(a, (A0*)&a0); + assert(A0::count == 1); + } + { + A1::count = 0; + A<int> a; + std::aligned_storage<sizeof(A1)>::type a1; + assert(A1::count == 0); + std::allocator_traits<A<int> >::construct(a, (A1*)&a1, 'c'); + assert(A1::count == 1); + } + { + A2::count = 0; + A<int> a; + std::aligned_storage<sizeof(A2)>::type a2; + assert(A2::count == 0); + std::allocator_traits<A<int> >::construct(a, (A2*)&a2, 'd', 5); + assert(A2::count == 1); + } +#ifndef _LIBCPP_HAS_NO_VARIADICS + { + A0::count = 0; + b_construct = 0; + B<int> b; + std::aligned_storage<sizeof(A0)>::type a0; + assert(A0::count == 0); + assert(b_construct == 0); + std::allocator_traits<B<int> >::construct(b, (A0*)&a0); + assert(A0::count == 1); + assert(b_construct == 1); + } + { + A1::count = 0; + b_construct = 0; + B<int> b; + std::aligned_storage<sizeof(A1)>::type a1; + assert(A1::count == 0); + assert(b_construct == 0); + std::allocator_traits<B<int> >::construct(b, (A1*)&a1, 'c'); + assert(A1::count == 1); + assert(b_construct == 1); + } + { + A2::count = 0; + b_construct = 0; + B<int> b; + std::aligned_storage<sizeof(A2)>::type a2; + assert(A2::count == 0); + assert(b_construct == 0); + std::allocator_traits<B<int> >::construct(b, (A2*)&a2, 'd', 5); + assert(A2::count == 1); + assert(b_construct == 1); + } +#endif // _LIBCPP_HAS_NO_VARIADICS +} diff --git a/libcxx/test/utilities/memory/allocator.traits/allocator.traits.members/deallocate.pass.cpp b/libcxx/test/utilities/memory/allocator.traits/allocator.traits.members/deallocate.pass.cpp index b4bd79a96e3..33ea63cc164 100644 --- a/libcxx/test/utilities/memory/allocator.traits/allocator.traits.members/deallocate.pass.cpp +++ b/libcxx/test/utilities/memory/allocator.traits/allocator.traits.members/deallocate.pass.cpp @@ -1 +1,42 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <class Alloc>
// struct allocator_traits
// {
// static void deallocate(allocator_type& a, pointer p, size_type n);
// ...
// };
#include <memory>
#include <cassert>
int called = 0;
template <class T>
struct A
{
typedef T value_type;
void deallocate(value_type* p, std::size_t n)
{
assert(p == (value_type*)0xDEADBEEF);
assert(n == 10);
++called;
}
};
int main()
{
A<int> a;
std::allocator_traits<A<int> >::deallocate(a, (int*)0xDEADBEEF, 10);
assert(called == 1);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// template <class Alloc> +// struct allocator_traits +// { +// static void deallocate(allocator_type& a, pointer p, size_type n); +// ... +// }; + +#include <memory> +#include <cassert> + +int called = 0; + +template <class T> +struct A +{ + typedef T value_type; + + void deallocate(value_type* p, std::size_t n) + { + assert(p == (value_type*)0xDEADBEEF); + assert(n == 10); + ++called; + } +}; + +int main() +{ + A<int> a; + std::allocator_traits<A<int> >::deallocate(a, (int*)0xDEADBEEF, 10); + assert(called == 1); +} diff --git a/libcxx/test/utilities/memory/allocator.traits/allocator.traits.members/destroy.pass.cpp b/libcxx/test/utilities/memory/allocator.traits/allocator.traits.members/destroy.pass.cpp index 7996ea42033..d9e8de55e2a 100644 --- a/libcxx/test/utilities/memory/allocator.traits/allocator.traits.members/destroy.pass.cpp +++ b/libcxx/test/utilities/memory/allocator.traits/allocator.traits.members/destroy.pass.cpp @@ -1 +1,80 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <class Alloc>
// struct allocator_traits
// {
// template <class Ptr>
// static void destroy(allocator_type& a, Ptr p);
// ...
// };
#include <memory>
#include <new>
#include <type_traits>
#include <cassert>
template <class T>
struct A
{
typedef T value_type;
};
int b_destroy = 0;
template <class T>
struct B
{
typedef T value_type;
template <class U>
void destroy(U* p)
{
++b_destroy;
p->~U();
}
};
struct A0
{
static int count;
~A0() {++count;}
};
int A0::count = 0;
int main()
{
{
A0::count = 0;
A<int> a;
std::aligned_storage<sizeof(A0)>::type a0;
std::allocator_traits<A<int> >::construct(a, (A0*)&a0);
assert(A0::count == 0);
std::allocator_traits<A<int> >::destroy(a, (A0*)&a0);
assert(A0::count == 1);
}
#ifndef _LIBCPP_HAS_NO_ADVANCED_SFINAE
{
A0::count = 0;
b_destroy = 0;
B<int> b;
std::aligned_storage<sizeof(A0)>::type a0;
std::allocator_traits<B<int> >::construct(b, (A0*)&a0);
assert(A0::count == 0);
assert(b_destroy == 0);
std::allocator_traits<B<int> >::destroy(b, (A0*)&a0);
assert(A0::count == 1);
assert(b_destroy == 1);
}
#endif
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// template <class Alloc> +// struct allocator_traits +// { +// template <class Ptr> +// static void destroy(allocator_type& a, Ptr p); +// ... +// }; + +#include <memory> +#include <new> +#include <type_traits> +#include <cassert> + +template <class T> +struct A +{ + typedef T value_type; + +}; + +int b_destroy = 0; + +template <class T> +struct B +{ + typedef T value_type; + + template <class U> + void destroy(U* p) + { + ++b_destroy; + p->~U(); + } +}; + +struct A0 +{ + static int count; + ~A0() {++count;} +}; + +int A0::count = 0; + +int main() +{ + { + A0::count = 0; + A<int> a; + std::aligned_storage<sizeof(A0)>::type a0; + std::allocator_traits<A<int> >::construct(a, (A0*)&a0); + assert(A0::count == 0); + std::allocator_traits<A<int> >::destroy(a, (A0*)&a0); + assert(A0::count == 1); + } +#ifndef _LIBCPP_HAS_NO_ADVANCED_SFINAE + { + A0::count = 0; + b_destroy = 0; + B<int> b; + std::aligned_storage<sizeof(A0)>::type a0; + std::allocator_traits<B<int> >::construct(b, (A0*)&a0); + assert(A0::count == 0); + assert(b_destroy == 0); + std::allocator_traits<B<int> >::destroy(b, (A0*)&a0); + assert(A0::count == 1); + assert(b_destroy == 1); + } +#endif // _LIBCPP_HAS_NO_ADVANCED_SFINAE +} diff --git a/libcxx/test/utilities/memory/allocator.traits/allocator.traits.members/max_size.pass.cpp b/libcxx/test/utilities/memory/allocator.traits/allocator.traits.members/max_size.pass.cpp index c021ea8c108..1a03f735762 100644 --- a/libcxx/test/utilities/memory/allocator.traits/allocator.traits.members/max_size.pass.cpp +++ b/libcxx/test/utilities/memory/allocator.traits/allocator.traits.members/max_size.pass.cpp @@ -1 +1,64 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <class Alloc>
// struct allocator_traits
// {
// static size_type max_size(const allocator_type& a);
// ...
// };
#include <memory>
#include <new>
#include <type_traits>
#include <cassert>
template <class T>
struct A
{
typedef T value_type;
};
template <class T>
struct B
{
typedef T value_type;
size_t max_size() const
{
return 100;
}
};
int main()
{
#ifndef _LIBCPP_HAS_NO_ADVANCED_SFINAE
{
A<int> a;
assert(std::allocator_traits<A<int> >::max_size(a) ==
std::numeric_limits<std::size_t>::max());
}
{
const A<int> a = {};
assert(std::allocator_traits<A<int> >::max_size(a) ==
std::numeric_limits<std::size_t>::max());
}
#endif
{
B<int> b;
assert(std::allocator_traits<B<int> >::max_size(b) == 100);
}
{
const B<int> b = {};
assert(std::allocator_traits<B<int> >::max_size(b) == 100);
}
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// template <class Alloc> +// struct allocator_traits +// { +// static size_type max_size(const allocator_type& a); +// ... +// }; + +#include <memory> +#include <new> +#include <type_traits> +#include <cassert> + +template <class T> +struct A +{ + typedef T value_type; + +}; + +template <class T> +struct B +{ + typedef T value_type; + + size_t max_size() const + { + return 100; + } +}; + +int main() +{ +#ifndef _LIBCPP_HAS_NO_ADVANCED_SFINAE + { + A<int> a; + assert(std::allocator_traits<A<int> >::max_size(a) == + std::numeric_limits<std::size_t>::max()); + } + { + const A<int> a = {}; + assert(std::allocator_traits<A<int> >::max_size(a) == + std::numeric_limits<std::size_t>::max()); + } +#endif // _LIBCPP_HAS_NO_ADVANCED_SFINAE + { + B<int> b; + assert(std::allocator_traits<B<int> >::max_size(b) == 100); + } + { + const B<int> b = {}; + assert(std::allocator_traits<B<int> >::max_size(b) == 100); + } +} diff --git a/libcxx/test/utilities/memory/allocator.traits/allocator.traits.members/select_on_container_copy_construction.pass.cpp b/libcxx/test/utilities/memory/allocator.traits/allocator.traits.members/select_on_container_copy_construction.pass.cpp index 8fe2365bc10..358017bc520 100644 --- a/libcxx/test/utilities/memory/allocator.traits/allocator.traits.members/select_on_container_copy_construction.pass.cpp +++ b/libcxx/test/utilities/memory/allocator.traits/allocator.traits.members/select_on_container_copy_construction.pass.cpp @@ -1 +1,68 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <class Alloc>
// struct allocator_traits
// {
// static allocator_type
// select_on_container_copy_construction(const allocator_type& a);
// ...
// };
#include <memory>
#include <new>
#include <type_traits>
#include <cassert>
template <class T>
struct A
{
typedef T value_type;
int id;
explicit A(int i = 0) : id(i) {}
};
template <class T>
struct B
{
typedef T value_type;
int id;
explicit B(int i = 0) : id(i) {}
B select_on_container_copy_construction() const
{
return B(100);
}
};
int main()
{
{
A<int> a;
assert(std::allocator_traits<A<int> >::select_on_container_copy_construction(a).id == 0);
}
{
const A<int> a(0);
assert(std::allocator_traits<A<int> >::select_on_container_copy_construction(a).id == 0);
}
#ifndef _LIBCPP_HAS_NO_ADVANCED_SFINAE
{
B<int> b;
assert(std::allocator_traits<B<int> >::select_on_container_copy_construction(b).id == 100);
}
{
const B<int> b(0);
assert(std::allocator_traits<B<int> >::select_on_container_copy_construction(b).id == 100);
}
#endif
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// template <class Alloc> +// struct allocator_traits +// { +// static allocator_type +// select_on_container_copy_construction(const allocator_type& a); +// ... +// }; + +#include <memory> +#include <new> +#include <type_traits> +#include <cassert> + +template <class T> +struct A +{ + typedef T value_type; + int id; + explicit A(int i = 0) : id(i) {} + +}; + +template <class T> +struct B +{ + typedef T value_type; + + int id; + explicit B(int i = 0) : id(i) {} + + B select_on_container_copy_construction() const + { + return B(100); + } +}; + +int main() +{ + { + A<int> a; + assert(std::allocator_traits<A<int> >::select_on_container_copy_construction(a).id == 0); + } + { + const A<int> a(0); + assert(std::allocator_traits<A<int> >::select_on_container_copy_construction(a).id == 0); + } +#ifndef _LIBCPP_HAS_NO_ADVANCED_SFINAE + { + B<int> b; + assert(std::allocator_traits<B<int> >::select_on_container_copy_construction(b).id == 100); + } + { + const B<int> b(0); + assert(std::allocator_traits<B<int> >::select_on_container_copy_construction(b).id == 100); + } +#endif // _LIBCPP_HAS_NO_ADVANCED_SFINAE +} diff --git a/libcxx/test/utilities/memory/allocator.traits/allocator.traits.types/const_pointer.pass.cpp b/libcxx/test/utilities/memory/allocator.traits/allocator.traits.types/const_pointer.pass.cpp index 680583ac3a8..5573fcbfb1b 100644 --- a/libcxx/test/utilities/memory/allocator.traits/allocator.traits.types/const_pointer.pass.cpp +++ b/libcxx/test/utilities/memory/allocator.traits/allocator.traits.types/const_pointer.pass.cpp @@ -1 +1,55 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <class Alloc>
// struct allocator_traits
// {
// typedef Alloc::const_pointer
// | pointer_traits<pointer>::rebind<const value_type>
// ...
// };
#include <memory>
#include <type_traits>
template <class T>
struct Ptr {};
template <class T>
struct A
{
typedef T value_type;
typedef Ptr<T> pointer;
};
template <class T>
struct B
{
typedef T value_type;
};
template <class T>
struct CPtr {};
template <class T>
struct C
{
typedef T value_type;
typedef CPtr<T> pointer;
typedef CPtr<const T> const_pointer;
};
int main()
{
static_assert((std::is_same<std::allocator_traits<A<char> >::const_pointer, Ptr<const char> >::value), "");
static_assert((std::is_same<std::allocator_traits<B<char> >::const_pointer, const char*>::value), "");
static_assert((std::is_same<std::allocator_traits<C<char> >::const_pointer, CPtr<const char> >::value), "");
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// template <class Alloc> +// struct allocator_traits +// { +// typedef Alloc::const_pointer +// | pointer_traits<pointer>::rebind<const value_type> +// ... +// }; + +#include <memory> +#include <type_traits> + +template <class T> +struct Ptr {}; + +template <class T> +struct A +{ + typedef T value_type; + typedef Ptr<T> pointer; +}; + +template <class T> +struct B +{ + typedef T value_type; +}; + +template <class T> +struct CPtr {}; + +template <class T> +struct C +{ + typedef T value_type; + typedef CPtr<T> pointer; + typedef CPtr<const T> const_pointer; +}; + +int main() +{ + static_assert((std::is_same<std::allocator_traits<A<char> >::const_pointer, Ptr<const char> >::value), ""); + static_assert((std::is_same<std::allocator_traits<B<char> >::const_pointer, const char*>::value), ""); + static_assert((std::is_same<std::allocator_traits<C<char> >::const_pointer, CPtr<const char> >::value), ""); +} diff --git a/libcxx/test/utilities/memory/allocator.traits/allocator.traits.types/const_void_pointer.pass.cpp b/libcxx/test/utilities/memory/allocator.traits/allocator.traits.types/const_void_pointer.pass.cpp index afa0cf29d1e..2c881016a3b 100644 --- a/libcxx/test/utilities/memory/allocator.traits/allocator.traits.types/const_void_pointer.pass.cpp +++ b/libcxx/test/utilities/memory/allocator.traits/allocator.traits.types/const_void_pointer.pass.cpp @@ -1 +1,55 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <class Alloc>
// struct allocator_traits
// {
// typedef Alloc::const_void_pointer
// | pointer_traits<pointer>::rebind<const void>
// const_void_pointer;
// ...
// };
#include <memory>
#include <type_traits>
template <class T>
struct Ptr {};
template <class T>
struct A
{
typedef T value_type;
typedef Ptr<T> pointer;
};
template <class T>
struct B
{
typedef T value_type;
};
template <class T>
struct CPtr {};
template <class T>
struct C
{
typedef T value_type;
typedef CPtr<const void> const_void_pointer;
};
int main()
{
static_assert((std::is_same<std::allocator_traits<A<char> >::const_void_pointer, Ptr<const void> >::value), "");
static_assert((std::is_same<std::allocator_traits<B<char> >::const_void_pointer, const void*>::value), "");
static_assert((std::is_same<std::allocator_traits<C<char> >::const_void_pointer, CPtr<const void> >::value), "");
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// template <class Alloc> +// struct allocator_traits +// { +// typedef Alloc::const_void_pointer +// | pointer_traits<pointer>::rebind<const void> +// const_void_pointer; +// ... +// }; + +#include <memory> +#include <type_traits> + +template <class T> +struct Ptr {}; + +template <class T> +struct A +{ + typedef T value_type; + typedef Ptr<T> pointer; +}; + +template <class T> +struct B +{ + typedef T value_type; +}; + +template <class T> +struct CPtr {}; + +template <class T> +struct C +{ + typedef T value_type; + typedef CPtr<const void> const_void_pointer; +}; + +int main() +{ + static_assert((std::is_same<std::allocator_traits<A<char> >::const_void_pointer, Ptr<const void> >::value), ""); + static_assert((std::is_same<std::allocator_traits<B<char> >::const_void_pointer, const void*>::value), ""); + static_assert((std::is_same<std::allocator_traits<C<char> >::const_void_pointer, CPtr<const void> >::value), ""); +} diff --git a/libcxx/test/utilities/memory/allocator.traits/allocator.traits.types/difference_type.pass.cpp b/libcxx/test/utilities/memory/allocator.traits/allocator.traits.types/difference_type.pass.cpp index 7eab2fc5af5..460f47804c0 100644 --- a/libcxx/test/utilities/memory/allocator.traits/allocator.traits.types/difference_type.pass.cpp +++ b/libcxx/test/utilities/memory/allocator.traits/allocator.traits.types/difference_type.pass.cpp @@ -1 +1,40 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <class Alloc>
// struct allocator_traits
// {
// typedef Alloc::difference_type
// | ptrdiff_t difference_type;
// ...
// };
#include <memory>
#include <type_traits>
template <class T>
struct A
{
typedef T value_type;
typedef short difference_type;
};
template <class T>
struct B
{
typedef T value_type;
};
int main()
{
static_assert((std::is_same<std::allocator_traits<A<char> >::difference_type, short>::value), "");
static_assert((std::is_same<std::allocator_traits<B<char> >::difference_type, std::ptrdiff_t>::value), "");
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// template <class Alloc> +// struct allocator_traits +// { +// typedef Alloc::difference_type +// | ptrdiff_t difference_type; +// ... +// }; + +#include <memory> +#include <type_traits> + +template <class T> +struct A +{ + typedef T value_type; + typedef short difference_type; +}; + +template <class T> +struct B +{ + typedef T value_type; +}; + +int main() +{ + static_assert((std::is_same<std::allocator_traits<A<char> >::difference_type, short>::value), ""); + static_assert((std::is_same<std::allocator_traits<B<char> >::difference_type, std::ptrdiff_t>::value), ""); +} diff --git a/libcxx/test/utilities/memory/allocator.traits/allocator.traits.types/pointer.pass.cpp b/libcxx/test/utilities/memory/allocator.traits/allocator.traits.types/pointer.pass.cpp index 6b479cee2a7..a41eabf82ed 100644 --- a/libcxx/test/utilities/memory/allocator.traits/allocator.traits.types/pointer.pass.cpp +++ b/libcxx/test/utilities/memory/allocator.traits/allocator.traits.types/pointer.pass.cpp @@ -1 +1,42 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <class Alloc>
// struct allocator_traits
// {
// typedef Alloc::pointer | value_type* pointer;
// ...
// };
#include <memory>
#include <type_traits>
template <class T>
struct Ptr {};
template <class T>
struct A
{
typedef T value_type;
typedef Ptr<T> pointer;
};
template <class T>
struct B
{
typedef T value_type;
};
int main()
{
static_assert((std::is_same<std::allocator_traits<A<char> >::pointer, Ptr<char> >::value), "");
static_assert((std::is_same<std::allocator_traits<B<char> >::pointer, char*>::value), "");
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// template <class Alloc> +// struct allocator_traits +// { +// typedef Alloc::pointer | value_type* pointer; +// ... +// }; + +#include <memory> +#include <type_traits> + +template <class T> +struct Ptr {}; + +template <class T> +struct A +{ + typedef T value_type; + typedef Ptr<T> pointer; +}; + +template <class T> +struct B +{ + typedef T value_type; +}; + +int main() +{ + static_assert((std::is_same<std::allocator_traits<A<char> >::pointer, Ptr<char> >::value), ""); + static_assert((std::is_same<std::allocator_traits<B<char> >::pointer, char*>::value), ""); +} diff --git a/libcxx/test/utilities/memory/allocator.traits/allocator.traits.types/propagate_on_container_copy_assignment.pass.cpp b/libcxx/test/utilities/memory/allocator.traits/allocator.traits.types/propagate_on_container_copy_assignment.pass.cpp index 8340b582373..0e9a64c148e 100644 --- a/libcxx/test/utilities/memory/allocator.traits/allocator.traits.types/propagate_on_container_copy_assignment.pass.cpp +++ b/libcxx/test/utilities/memory/allocator.traits/allocator.traits.types/propagate_on_container_copy_assignment.pass.cpp @@ -1 +1,40 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <class Alloc>
// struct allocator_traits
// {
// typedef Alloc::propagate_on_container_copy_assignment
// | false_type propagate_on_container_copy_assignment;
// ...
// };
#include <memory>
#include <type_traits>
template <class T>
struct A
{
typedef T value_type;
typedef std::true_type propagate_on_container_copy_assignment;
};
template <class T>
struct B
{
typedef T value_type;
};
int main()
{
static_assert((std::is_same<std::allocator_traits<A<char> >::propagate_on_container_copy_assignment, std::true_type>::value), "");
static_assert((std::is_same<std::allocator_traits<B<char> >::propagate_on_container_copy_assignment, std::false_type>::value), "");
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// template <class Alloc> +// struct allocator_traits +// { +// typedef Alloc::propagate_on_container_copy_assignment +// | false_type propagate_on_container_copy_assignment; +// ... +// }; + +#include <memory> +#include <type_traits> + +template <class T> +struct A +{ + typedef T value_type; + typedef std::true_type propagate_on_container_copy_assignment; +}; + +template <class T> +struct B +{ + typedef T value_type; +}; + +int main() +{ + static_assert((std::is_same<std::allocator_traits<A<char> >::propagate_on_container_copy_assignment, std::true_type>::value), ""); + static_assert((std::is_same<std::allocator_traits<B<char> >::propagate_on_container_copy_assignment, std::false_type>::value), ""); +} diff --git a/libcxx/test/utilities/memory/allocator.traits/allocator.traits.types/propagate_on_container_move_assignment.pass.cpp b/libcxx/test/utilities/memory/allocator.traits/allocator.traits.types/propagate_on_container_move_assignment.pass.cpp index 827201625cd..d389f17e790 100644 --- a/libcxx/test/utilities/memory/allocator.traits/allocator.traits.types/propagate_on_container_move_assignment.pass.cpp +++ b/libcxx/test/utilities/memory/allocator.traits/allocator.traits.types/propagate_on_container_move_assignment.pass.cpp @@ -1 +1,40 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <class Alloc>
// struct allocator_traits
// {
// typedef Alloc::propagate_on_container_move_assignment
// | false_type propagate_on_container_move_assignment;
// ...
// };
#include <memory>
#include <type_traits>
template <class T>
struct A
{
typedef T value_type;
typedef std::true_type propagate_on_container_move_assignment;
};
template <class T>
struct B
{
typedef T value_type;
};
int main()
{
static_assert((std::is_same<std::allocator_traits<A<char> >::propagate_on_container_move_assignment, std::true_type>::value), "");
static_assert((std::is_same<std::allocator_traits<B<char> >::propagate_on_container_move_assignment, std::false_type>::value), "");
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// template <class Alloc> +// struct allocator_traits +// { +// typedef Alloc::propagate_on_container_move_assignment +// | false_type propagate_on_container_move_assignment; +// ... +// }; + +#include <memory> +#include <type_traits> + +template <class T> +struct A +{ + typedef T value_type; + typedef std::true_type propagate_on_container_move_assignment; +}; + +template <class T> +struct B +{ + typedef T value_type; +}; + +int main() +{ + static_assert((std::is_same<std::allocator_traits<A<char> >::propagate_on_container_move_assignment, std::true_type>::value), ""); + static_assert((std::is_same<std::allocator_traits<B<char> >::propagate_on_container_move_assignment, std::false_type>::value), ""); +} diff --git a/libcxx/test/utilities/memory/allocator.traits/allocator.traits.types/propagate_on_container_swap.pass.cpp b/libcxx/test/utilities/memory/allocator.traits/allocator.traits.types/propagate_on_container_swap.pass.cpp index 7c4d36afe0a..193dedde825 100644 --- a/libcxx/test/utilities/memory/allocator.traits/allocator.traits.types/propagate_on_container_swap.pass.cpp +++ b/libcxx/test/utilities/memory/allocator.traits/allocator.traits.types/propagate_on_container_swap.pass.cpp @@ -1 +1,40 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <class Alloc>
// struct allocator_traits
// {
// typedef Alloc::propagate_on_container_swap
// | false_type propagate_on_container_swap;
// ...
// };
#include <memory>
#include <type_traits>
template <class T>
struct A
{
typedef T value_type;
typedef std::true_type propagate_on_container_swap;
};
template <class T>
struct B
{
typedef T value_type;
};
int main()
{
static_assert((std::is_same<std::allocator_traits<A<char> >::propagate_on_container_swap, std::true_type>::value), "");
static_assert((std::is_same<std::allocator_traits<B<char> >::propagate_on_container_swap, std::false_type>::value), "");
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// template <class Alloc> +// struct allocator_traits +// { +// typedef Alloc::propagate_on_container_swap +// | false_type propagate_on_container_swap; +// ... +// }; + +#include <memory> +#include <type_traits> + +template <class T> +struct A +{ + typedef T value_type; + typedef std::true_type propagate_on_container_swap; +}; + +template <class T> +struct B +{ + typedef T value_type; +}; + +int main() +{ + static_assert((std::is_same<std::allocator_traits<A<char> >::propagate_on_container_swap, std::true_type>::value), ""); + static_assert((std::is_same<std::allocator_traits<B<char> >::propagate_on_container_swap, std::false_type>::value), ""); +} diff --git a/libcxx/test/utilities/memory/allocator.traits/allocator.traits.types/rebind_alloc.pass.cpp b/libcxx/test/utilities/memory/allocator.traits/allocator.traits.types/rebind_alloc.pass.cpp index 443ce269725..82fcb71f153 100644 --- a/libcxx/test/utilities/memory/allocator.traits/allocator.traits.types/rebind_alloc.pass.cpp +++ b/libcxx/test/utilities/memory/allocator.traits/allocator.traits.types/rebind_alloc.pass.cpp @@ -1 +1,79 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <class Alloc>
// struct allocator_traits
// {
// template <class T> using rebind_alloc = Alloc::rebind<U>::other | Alloc<T, Args...>;
// ...
// };
#include <memory>
#include <type_traits>
template <class T>
struct ReboundA {};
template <class T>
struct A
{
typedef T value_type;
template <class U> struct rebind {typedef ReboundA<U> other;};
};
template <class T, class U>
struct ReboundB {};
template <class T, class U>
struct B
{
typedef T value_type;
template <class V> struct rebind {typedef ReboundB<V, U> other;};
};
template <class T>
struct C
{
typedef T value_type;
};
template <class T, class U>
struct D
{
typedef T value_type;
};
template <class T>
struct E
{
typedef T value_type;
template <class U> struct rebind {typedef ReboundA<U> otter;};
};
int main()
{
#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
static_assert((std::is_same<std::allocator_traits<A<char> >::rebind_alloc<double>, ReboundA<double> >::value), "");
static_assert((std::is_same<std::allocator_traits<B<int, char> >::rebind_alloc<double>, ReboundB<double, char> >::value), "");
static_assert((std::is_same<std::allocator_traits<C<char> >::rebind_alloc<double>, C<double> >::value), "");
static_assert((std::is_same<std::allocator_traits<D<int, char> >::rebind_alloc<double>, D<double, char> >::value), "");
static_assert((std::is_same<std::allocator_traits<E<char> >::rebind_alloc<double>, E<double> >::value), "");
#else
static_assert((std::is_same<std::allocator_traits<A<char> >::rebind_alloc<double>::other, ReboundA<double> >::value), "");
static_assert((std::is_same<std::allocator_traits<B<int, char> >::rebind_alloc<double>::other, ReboundB<double, char> >::value), "");
static_assert((std::is_same<std::allocator_traits<C<char> >::rebind_alloc<double>::other, C<double> >::value), "");
static_assert((std::is_same<std::allocator_traits<D<int, char> >::rebind_alloc<double>::other, D<double, char> >::value), "");
static_assert((std::is_same<std::allocator_traits<E<char> >::rebind_alloc<double>::other, E<double> >::value), "");
#endif
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// template <class Alloc> +// struct allocator_traits +// { +// template <class T> using rebind_alloc = Alloc::rebind<U>::other | Alloc<T, Args...>; +// ... +// }; + +#include <memory> +#include <type_traits> + +template <class T> +struct ReboundA {}; + +template <class T> +struct A +{ + typedef T value_type; + + template <class U> struct rebind {typedef ReboundA<U> other;}; +}; + +template <class T, class U> +struct ReboundB {}; + +template <class T, class U> +struct B +{ + typedef T value_type; + + template <class V> struct rebind {typedef ReboundB<V, U> other;}; +}; + +template <class T> +struct C +{ + typedef T value_type; +}; + +template <class T, class U> +struct D +{ + typedef T value_type; +}; + +template <class T> +struct E +{ + typedef T value_type; + + template <class U> struct rebind {typedef ReboundA<U> otter;}; +}; + +int main() +{ +#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES + static_assert((std::is_same<std::allocator_traits<A<char> >::rebind_alloc<double>, ReboundA<double> >::value), ""); + static_assert((std::is_same<std::allocator_traits<B<int, char> >::rebind_alloc<double>, ReboundB<double, char> >::value), ""); + static_assert((std::is_same<std::allocator_traits<C<char> >::rebind_alloc<double>, C<double> >::value), ""); + static_assert((std::is_same<std::allocator_traits<D<int, char> >::rebind_alloc<double>, D<double, char> >::value), ""); + static_assert((std::is_same<std::allocator_traits<E<char> >::rebind_alloc<double>, E<double> >::value), ""); +#else // _LIBCPP_HAS_NO_TEMPLATE_ALIASES + static_assert((std::is_same<std::allocator_traits<A<char> >::rebind_alloc<double>::other, ReboundA<double> >::value), ""); + static_assert((std::is_same<std::allocator_traits<B<int, char> >::rebind_alloc<double>::other, ReboundB<double, char> >::value), ""); + static_assert((std::is_same<std::allocator_traits<C<char> >::rebind_alloc<double>::other, C<double> >::value), ""); + static_assert((std::is_same<std::allocator_traits<D<int, char> >::rebind_alloc<double>::other, D<double, char> >::value), ""); + static_assert((std::is_same<std::allocator_traits<E<char> >::rebind_alloc<double>::other, E<double> >::value), ""); +#endif // _LIBCPP_HAS_NO_TEMPLATE_ALIASES +} diff --git a/libcxx/test/utilities/memory/allocator.traits/allocator.traits.types/size_type.pass.cpp b/libcxx/test/utilities/memory/allocator.traits/allocator.traits.types/size_type.pass.cpp index 2eef5d435c7..148daacb547 100644 --- a/libcxx/test/utilities/memory/allocator.traits/allocator.traits.types/size_type.pass.cpp +++ b/libcxx/test/utilities/memory/allocator.traits/allocator.traits.types/size_type.pass.cpp @@ -1 +1,39 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <class Alloc>
// struct allocator_traits
// {
// typedef Alloc::size_type | size_t size_type;
// ...
// };
#include <memory>
#include <type_traits>
template <class T>
struct A
{
typedef T value_type;
typedef unsigned short size_type;
};
template <class T>
struct B
{
typedef T value_type;
};
int main()
{
static_assert((std::is_same<std::allocator_traits<A<char> >::size_type, unsigned short>::value), "");
static_assert((std::is_same<std::allocator_traits<B<char> >::size_type, std::size_t>::value), "");
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// template <class Alloc> +// struct allocator_traits +// { +// typedef Alloc::size_type | size_t size_type; +// ... +// }; + +#include <memory> +#include <type_traits> + +template <class T> +struct A +{ + typedef T value_type; + typedef unsigned short size_type; +}; + +template <class T> +struct B +{ + typedef T value_type; +}; + +int main() +{ + static_assert((std::is_same<std::allocator_traits<A<char> >::size_type, unsigned short>::value), ""); + static_assert((std::is_same<std::allocator_traits<B<char> >::size_type, std::size_t>::value), ""); +} diff --git a/libcxx/test/utilities/memory/allocator.traits/allocator.traits.types/void_pointer.pass.cpp b/libcxx/test/utilities/memory/allocator.traits/allocator.traits.types/void_pointer.pass.cpp index e08dd388b4f..f5ed6a398dd 100644 --- a/libcxx/test/utilities/memory/allocator.traits/allocator.traits.types/void_pointer.pass.cpp +++ b/libcxx/test/utilities/memory/allocator.traits/allocator.traits.types/void_pointer.pass.cpp @@ -1 +1,55 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <class Alloc>
// struct allocator_traits
// {
// typedef Alloc::void_pointer
// | pointer_traits<pointer>::rebind<void>
// void_pointer;
// ...
// };
#include <memory>
#include <type_traits>
template <class T>
struct Ptr {};
template <class T>
struct A
{
typedef T value_type;
typedef Ptr<T> pointer;
};
template <class T>
struct B
{
typedef T value_type;
};
template <class T>
struct CPtr {};
template <class T>
struct C
{
typedef T value_type;
typedef CPtr<void> void_pointer;
};
int main()
{
static_assert((std::is_same<std::allocator_traits<A<char> >::void_pointer, Ptr<void> >::value), "");
static_assert((std::is_same<std::allocator_traits<B<char> >::void_pointer, void*>::value), "");
static_assert((std::is_same<std::allocator_traits<C<char> >::void_pointer, CPtr<void> >::value), "");
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// template <class Alloc> +// struct allocator_traits +// { +// typedef Alloc::void_pointer +// | pointer_traits<pointer>::rebind<void> +// void_pointer; +// ... +// }; + +#include <memory> +#include <type_traits> + +template <class T> +struct Ptr {}; + +template <class T> +struct A +{ + typedef T value_type; + typedef Ptr<T> pointer; +}; + +template <class T> +struct B +{ + typedef T value_type; +}; + +template <class T> +struct CPtr {}; + +template <class T> +struct C +{ + typedef T value_type; + typedef CPtr<void> void_pointer; +}; + +int main() +{ + static_assert((std::is_same<std::allocator_traits<A<char> >::void_pointer, Ptr<void> >::value), ""); + static_assert((std::is_same<std::allocator_traits<B<char> >::void_pointer, void*>::value), ""); + static_assert((std::is_same<std::allocator_traits<C<char> >::void_pointer, CPtr<void> >::value), ""); +} diff --git a/libcxx/test/utilities/memory/allocator.traits/allocator_type.pass.cpp b/libcxx/test/utilities/memory/allocator.traits/allocator_type.pass.cpp index df2539a3a33..3df8b01ff92 100644 --- a/libcxx/test/utilities/memory/allocator.traits/allocator_type.pass.cpp +++ b/libcxx/test/utilities/memory/allocator.traits/allocator_type.pass.cpp @@ -1 +1,31 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <class Alloc>
// struct allocator_traits
// {
// typedef Alloc allocator_type;
// ...
// };
#include <memory>
#include <type_traits>
template <class T>
struct A
{
typedef T value_type;
};
int main()
{
static_assert((std::is_same<std::allocator_traits<A<char> >::allocator_type, A<char> >::value), "");
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// template <class Alloc> +// struct allocator_traits +// { +// typedef Alloc allocator_type; +// ... +// }; + +#include <memory> +#include <type_traits> + +template <class T> +struct A +{ + typedef T value_type; +}; + +int main() +{ + static_assert((std::is_same<std::allocator_traits<A<char> >::allocator_type, A<char> >::value), ""); +} diff --git a/libcxx/test/utilities/memory/allocator.traits/rebind_traits.pass.cpp b/libcxx/test/utilities/memory/allocator.traits/rebind_traits.pass.cpp index 6a4dd13df80..8e99e7f923b 100644 --- a/libcxx/test/utilities/memory/allocator.traits/rebind_traits.pass.cpp +++ b/libcxx/test/utilities/memory/allocator.traits/rebind_traits.pass.cpp @@ -1 +1,79 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <class Alloc>
// struct allocator_traits
// {
// template <class T> using rebind_traits = allocator_traits<rebind_alloc<T>>;
// ...
// };
#include <memory>
#include <type_traits>
template <class T>
struct ReboundA {};
template <class T>
struct A
{
typedef T value_type;
template <class U> struct rebind {typedef ReboundA<U> other;};
};
template <class T, class U>
struct ReboundB {};
template <class T, class U>
struct B
{
typedef T value_type;
template <class V> struct rebind {typedef ReboundB<V, U> other;};
};
template <class T>
struct C
{
typedef T value_type;
};
template <class T, class U>
struct D
{
typedef T value_type;
};
template <class T>
struct E
{
typedef T value_type;
template <class U> struct rebind {typedef ReboundA<U> otter;};
};
int main()
{
#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
static_assert((std::is_same<std::allocator_traits<A<char> >::rebind_traits<double>, std::allocator_traits<ReboundA<double> > >::value), "");
static_assert((std::is_same<std::allocator_traits<B<int, char> >::rebind_traits<double>, std::allocator_traits<ReboundB<double, char> > >::value), "");
static_assert((std::is_same<std::allocator_traits<C<char> >::rebind_traits<double>, std::allocator_traits<C<double> > >::value), "");
static_assert((std::is_same<std::allocator_traits<D<int, char> >::rebind_traits<double>, std::allocator_traits<D<double, char> > >::value), "");
static_assert((std::is_same<std::allocator_traits<E<char> >::rebind_traits<double>, std::allocator_traits<E<double> > >::value), "");
#else
static_assert((std::is_same<std::allocator_traits<A<char> >::rebind_traits<double>::other, std::allocator_traits<ReboundA<double> > >::value), "");
static_assert((std::is_same<std::allocator_traits<B<int, char> >::rebind_traits<double>::other, std::allocator_traits<ReboundB<double, char> > >::value), "");
static_assert((std::is_same<std::allocator_traits<C<char> >::rebind_traits<double>::other, std::allocator_traits<C<double> > >::value), "");
static_assert((std::is_same<std::allocator_traits<D<int, char> >::rebind_traits<double>::other, std::allocator_traits<D<double, char> > >::value), "");
static_assert((std::is_same<std::allocator_traits<E<char> >::rebind_traits<double>::other, std::allocator_traits<E<double> > >::value), "");
#endif
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// template <class Alloc> +// struct allocator_traits +// { +// template <class T> using rebind_traits = allocator_traits<rebind_alloc<T>>; +// ... +// }; + +#include <memory> +#include <type_traits> + +template <class T> +struct ReboundA {}; + +template <class T> +struct A +{ + typedef T value_type; + + template <class U> struct rebind {typedef ReboundA<U> other;}; +}; + +template <class T, class U> +struct ReboundB {}; + +template <class T, class U> +struct B +{ + typedef T value_type; + + template <class V> struct rebind {typedef ReboundB<V, U> other;}; +}; + +template <class T> +struct C +{ + typedef T value_type; +}; + +template <class T, class U> +struct D +{ + typedef T value_type; +}; + +template <class T> +struct E +{ + typedef T value_type; + + template <class U> struct rebind {typedef ReboundA<U> otter;}; +}; + +int main() +{ +#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES + static_assert((std::is_same<std::allocator_traits<A<char> >::rebind_traits<double>, std::allocator_traits<ReboundA<double> > >::value), ""); + static_assert((std::is_same<std::allocator_traits<B<int, char> >::rebind_traits<double>, std::allocator_traits<ReboundB<double, char> > >::value), ""); + static_assert((std::is_same<std::allocator_traits<C<char> >::rebind_traits<double>, std::allocator_traits<C<double> > >::value), ""); + static_assert((std::is_same<std::allocator_traits<D<int, char> >::rebind_traits<double>, std::allocator_traits<D<double, char> > >::value), ""); + static_assert((std::is_same<std::allocator_traits<E<char> >::rebind_traits<double>, std::allocator_traits<E<double> > >::value), ""); +#else // _LIBCPP_HAS_NO_TEMPLATE_ALIASES + static_assert((std::is_same<std::allocator_traits<A<char> >::rebind_traits<double>::other, std::allocator_traits<ReboundA<double> > >::value), ""); + static_assert((std::is_same<std::allocator_traits<B<int, char> >::rebind_traits<double>::other, std::allocator_traits<ReboundB<double, char> > >::value), ""); + static_assert((std::is_same<std::allocator_traits<C<char> >::rebind_traits<double>::other, std::allocator_traits<C<double> > >::value), ""); + static_assert((std::is_same<std::allocator_traits<D<int, char> >::rebind_traits<double>::other, std::allocator_traits<D<double, char> > >::value), ""); + static_assert((std::is_same<std::allocator_traits<E<char> >::rebind_traits<double>::other, std::allocator_traits<E<double> > >::value), ""); +#endif // _LIBCPP_HAS_NO_TEMPLATE_ALIASES +} diff --git a/libcxx/test/utilities/memory/allocator.traits/value_type.pass.cpp b/libcxx/test/utilities/memory/allocator.traits/value_type.pass.cpp index 20015088451..b91467faf3b 100644 --- a/libcxx/test/utilities/memory/allocator.traits/value_type.pass.cpp +++ b/libcxx/test/utilities/memory/allocator.traits/value_type.pass.cpp @@ -1 +1,31 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <class Alloc>
// struct allocator_traits
// {
// typedef typename Alloc::value_type value_type;
// ...
// };
#include <memory>
#include <type_traits>
template <class T>
struct A
{
typedef T value_type;
};
int main()
{
static_assert((std::is_same<std::allocator_traits<A<char> >::value_type, char>::value), "");
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// template <class Alloc> +// struct allocator_traits +// { +// typedef typename Alloc::value_type value_type; +// ... +// }; + +#include <memory> +#include <type_traits> + +template <class T> +struct A +{ + typedef T value_type; +}; + +int main() +{ + static_assert((std::is_same<std::allocator_traits<A<char> >::value_type, char>::value), ""); +} diff --git a/libcxx/test/utilities/memory/allocator.uses/allocator.uses.construction/tested_elsewhere.pass.cpp b/libcxx/test/utilities/memory/allocator.uses/allocator.uses.construction/tested_elsewhere.pass.cpp index e8db90cbee0..b89f168e9c4 100644 --- a/libcxx/test/utilities/memory/allocator.uses/allocator.uses.construction/tested_elsewhere.pass.cpp +++ b/libcxx/test/utilities/memory/allocator.uses/allocator.uses.construction/tested_elsewhere.pass.cpp @@ -1 +1,12 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
int main()
{
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/libcxx/test/utilities/memory/allocator.uses/allocator.uses.trait/uses_allocator.pass.cpp b/libcxx/test/utilities/memory/allocator.uses/allocator.uses.trait/uses_allocator.pass.cpp index 23aa45e31bb..99167b71bbd 100644 --- a/libcxx/test/utilities/memory/allocator.uses/allocator.uses.trait/uses_allocator.pass.cpp +++ b/libcxx/test/utilities/memory/allocator.uses/allocator.uses.trait/uses_allocator.pass.cpp @@ -1 +1,33 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <class T, class Alloc> struct uses_allocator;
#include <memory>
#include <vector>
struct A
{
};
struct B
{
typedef int allocator_type;
};
int main()
{
static_assert((!std::uses_allocator<int, std::allocator<int> >::value), "");
static_assert(( std::uses_allocator<std::vector<int>, std::allocator<int> >::value), "");
static_assert((!std::uses_allocator<A, std::allocator<int> >::value), "");
static_assert((!std::uses_allocator<B, std::allocator<int> >::value), "");
static_assert(( std::uses_allocator<B, double>::value), "");
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// template <class T, class Alloc> struct uses_allocator; + +#include <memory> +#include <vector> + +struct A +{ +}; + +struct B +{ + typedef int allocator_type; +}; + +int main() +{ + static_assert((!std::uses_allocator<int, std::allocator<int> >::value), ""); + static_assert(( std::uses_allocator<std::vector<int>, std::allocator<int> >::value), ""); + static_assert((!std::uses_allocator<A, std::allocator<int> >::value), ""); + static_assert((!std::uses_allocator<B, std::allocator<int> >::value), ""); + static_assert(( std::uses_allocator<B, double>::value), ""); +} diff --git a/libcxx/test/utilities/memory/allocator.uses/nothing_to_do.pass.cpp b/libcxx/test/utilities/memory/allocator.uses/nothing_to_do.pass.cpp index e8db90cbee0..b89f168e9c4 100644 --- a/libcxx/test/utilities/memory/allocator.uses/nothing_to_do.pass.cpp +++ b/libcxx/test/utilities/memory/allocator.uses/nothing_to_do.pass.cpp @@ -1 +1,12 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
int main()
{
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/libcxx/test/utilities/memory/c.malloc/nothing_to_do.pass.cpp b/libcxx/test/utilities/memory/c.malloc/nothing_to_do.pass.cpp index 27846cf94e6..a98f3353ed1 100644 --- a/libcxx/test/utilities/memory/c.malloc/nothing_to_do.pass.cpp +++ b/libcxx/test/utilities/memory/c.malloc/nothing_to_do.pass.cpp @@ -1 +1,14 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <cstdlib> and <cstring> are already tested elsewhere
int main()
{
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <cstdlib> and <cstring> are already tested elsewhere + +int main() +{ +} diff --git a/libcxx/test/utilities/memory/default.allocator/allocator.globals/eq.pass.cpp b/libcxx/test/utilities/memory/default.allocator/allocator.globals/eq.pass.cpp index 49d39da4034..6712a8d0d9b 100644 --- a/libcxx/test/utilities/memory/default.allocator/allocator.globals/eq.pass.cpp +++ b/libcxx/test/utilities/memory/default.allocator/allocator.globals/eq.pass.cpp @@ -1 +1,31 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// allocator:
// template <class T1, class T2>
// bool
// operator==(const allocator<T1>&, const allocator<T2>&) throw();
//
// template <class T1, class T2>
// bool
// operator!=(const allocator<T1>&, const allocator<T2>&) throw();
#include <memory>
#include <cassert>
int main()
{
std::allocator<int> a1;
std::allocator<int> a2;
assert(a1 == a2);
assert(!(a1 != a2));
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// allocator: + +// template <class T1, class T2> +// bool +// operator==(const allocator<T1>&, const allocator<T2>&) throw(); +// +// template <class T1, class T2> +// bool +// operator!=(const allocator<T1>&, const allocator<T2>&) throw(); + +#include <memory> +#include <cassert> + +int main() +{ + std::allocator<int> a1; + std::allocator<int> a2; + assert(a1 == a2); + assert(!(a1 != a2)); +} diff --git a/libcxx/test/utilities/memory/default.allocator/allocator.members/address.pass.cpp b/libcxx/test/utilities/memory/default.allocator/allocator.members/address.pass.cpp index c14607f6cfb..5cb4f950160 100644 --- a/libcxx/test/utilities/memory/default.allocator/allocator.members/address.pass.cpp +++ b/libcxx/test/utilities/memory/default.allocator/allocator.members/address.pass.cpp @@ -1 +1,39 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// allocator:
// pointer address(reference x) const;
// const_pointer address(const_reference x) const;
#include <memory>
#include <cassert>
template <class T>
void test_address()
{
T* tp = new T();
const T* ctp = tp;
const std::allocator<T> a;
assert(a.address(*tp) == tp);
assert(a.address(*ctp) == tp);
delete tp;
}
struct A
{
void operator&() const {}
};
int main()
{
test_address<int>();
test_address<A>();
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// allocator: +// pointer address(reference x) const; +// const_pointer address(const_reference x) const; + +#include <memory> +#include <cassert> + +template <class T> +void test_address() +{ + T* tp = new T(); + const T* ctp = tp; + const std::allocator<T> a; + assert(a.address(*tp) == tp); + assert(a.address(*ctp) == tp); + delete tp; +} + +struct A +{ + void operator&() const {} +}; + +int main() +{ + test_address<int>(); + test_address<A>(); +} diff --git a/libcxx/test/utilities/memory/default.allocator/allocator.members/allocate.pass.cpp b/libcxx/test/utilities/memory/default.allocator/allocator.members/allocate.pass.cpp index 161d3835b3f..84786a813c3 100644 --- a/libcxx/test/utilities/memory/default.allocator/allocator.members/allocate.pass.cpp +++ b/libcxx/test/utilities/memory/default.allocator/allocator.members/allocate.pass.cpp @@ -1 +1,63 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// allocator:
// pointer allocate(size_type n, allocator<void>::const_pointer hint=0);
#include <memory>
#include <new>
#include <cstdlib>
#include <cassert>
int new_called = 0;
void* operator new(std::size_t s) throw(std::bad_alloc)
{
++new_called;
assert(s == 3 * sizeof(int));
return std::malloc(s);
}
void operator delete(void* p) throw()
{
--new_called;
std::free(p);
}
int A_constructed = 0;
struct A
{
int data;
A() {++A_constructed;}
A(const A&) {++A_constructed;}
~A() {--A_constructed;}
};
int main()
{
std::allocator<A> a;
assert(new_called == 0);
assert(A_constructed == 0);
A* ap = a.allocate(3);
assert(new_called == 1);
assert(A_constructed == 0);
a.deallocate(ap, 3);
assert(new_called == 0);
assert(A_constructed == 0);
A* ap2 = a.allocate(3, (const void*)5);
assert(new_called == 1);
assert(A_constructed == 0);
a.deallocate(ap2, 3);
assert(new_called == 0);
assert(A_constructed == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// allocator: +// pointer allocate(size_type n, allocator<void>::const_pointer hint=0); + +#include <memory> +#include <new> +#include <cstdlib> +#include <cassert> + +int new_called = 0; + +void* operator new(std::size_t s) throw(std::bad_alloc) +{ + ++new_called; + assert(s == 3 * sizeof(int)); + return std::malloc(s); +} + +void operator delete(void* p) throw() +{ + --new_called; + std::free(p); +} + +int A_constructed = 0; + +struct A +{ + int data; + A() {++A_constructed;} + A(const A&) {++A_constructed;} + ~A() {--A_constructed;} +}; + +int main() +{ + std::allocator<A> a; + assert(new_called == 0); + assert(A_constructed == 0); + A* ap = a.allocate(3); + assert(new_called == 1); + assert(A_constructed == 0); + a.deallocate(ap, 3); + assert(new_called == 0); + assert(A_constructed == 0); + + A* ap2 = a.allocate(3, (const void*)5); + assert(new_called == 1); + assert(A_constructed == 0); + a.deallocate(ap2, 3); + assert(new_called == 0); + assert(A_constructed == 0); +} diff --git a/libcxx/test/utilities/memory/default.allocator/allocator.members/construct.pass.cpp b/libcxx/test/utilities/memory/default.allocator/allocator.members/construct.pass.cpp index bf6e20ab1f6..c0bea03799e 100644 --- a/libcxx/test/utilities/memory/default.allocator/allocator.members/construct.pass.cpp +++ b/libcxx/test/utilities/memory/default.allocator/allocator.members/construct.pass.cpp @@ -1 +1,153 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// allocator:
// template <class... Args> void construct(pointer p, Args&&... args);
#include <memory>
#include <new>
#include <cstdlib>
#include <cassert>
int new_called = 0;
void* operator new(std::size_t s) throw(std::bad_alloc)
{
++new_called;
assert(s == 3 * sizeof(int));
return std::malloc(s);
}
void operator delete(void* p) throw()
{
--new_called;
std::free(p);
}
int A_constructed = 0;
struct A
{
int data;
A() {++A_constructed;}
A(const A&) {++A_constructed;}
explicit A(int) {++A_constructed;}
A(int, int*) {++A_constructed;}
~A() {--A_constructed;}
};
int move_only_constructed = 0;
class move_only
{
int data;
#ifdef _LIBCPP_MOVE
move_only(const move_only&);
move_only& operator=(const move_only&);
#else
move_only(move_only&);
move_only& operator=(move_only&);
#endif
public:
#ifdef _LIBCPP_MOVE
move_only(move_only&&) {++move_only_constructed;}
move_only& operator=(move_only&&) {}
#else
operator std::__rv<move_only> () {return std::__rv<move_only>(*this);}
move_only(std::__rv<move_only>) {++move_only_constructed;}
#endif
move_only() {++move_only_constructed;}
~move_only() {--move_only_constructed;}
};
int main()
{
{
std::allocator<A> a;
assert(new_called == 0);
assert(A_constructed == 0);
A* ap = a.allocate(3);
assert(new_called == 1);
assert(A_constructed == 0);
a.construct(ap);
assert(new_called == 1);
assert(A_constructed == 1);
a.destroy(ap);
assert(new_called == 1);
assert(A_constructed == 0);
a.construct(ap, A());
assert(new_called == 1);
assert(A_constructed == 1);
a.destroy(ap);
assert(new_called == 1);
assert(A_constructed == 0);
a.construct(ap, 5);
assert(new_called == 1);
assert(A_constructed == 1);
a.destroy(ap);
assert(new_called == 1);
assert(A_constructed == 0);
a.construct(ap, 5, (int*)0);
assert(new_called == 1);
assert(A_constructed == 1);
a.destroy(ap);
assert(new_called == 1);
assert(A_constructed == 0);
a.deallocate(ap, 3);
assert(new_called == 0);
assert(A_constructed == 0);
}
{
std::allocator<move_only> a;
assert(new_called == 0);
assert(move_only_constructed == 0);
move_only* ap = a.allocate(3);
assert(new_called == 1);
assert(move_only_constructed == 0);
a.construct(ap);
assert(new_called == 1);
assert(move_only_constructed == 1);
a.destroy(ap);
assert(new_called == 1);
assert(move_only_constructed == 0);
a.construct(ap, move_only());
assert(new_called == 1);
assert(move_only_constructed == 1);
a.destroy(ap);
assert(new_called == 1);
assert(move_only_constructed == 0);
a.deallocate(ap, 3);
assert(new_called == 0);
assert(move_only_constructed == 0);
}
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// allocator: +// template <class... Args> void construct(pointer p, Args&&... args); + +#include <memory> +#include <new> +#include <cstdlib> +#include <cassert> + +int new_called = 0; + +void* operator new(std::size_t s) throw(std::bad_alloc) +{ + ++new_called; + assert(s == 3 * sizeof(int)); + return std::malloc(s); +} + +void operator delete(void* p) throw() +{ + --new_called; + std::free(p); +} + +int A_constructed = 0; + +struct A +{ + int data; + A() {++A_constructed;} + + A(const A&) {++A_constructed;} + + explicit A(int) {++A_constructed;} + A(int, int*) {++A_constructed;} + + ~A() {--A_constructed;} +}; + +int move_only_constructed = 0; + +class move_only +{ + int data; +#ifdef _LIBCPP_MOVE + move_only(const move_only&); + move_only& operator=(const move_only&); +#else // _LIBCPP_MOVE + move_only(move_only&); + move_only& operator=(move_only&); +#endif // _LIBCPP_MOVE + +public: + +#ifdef _LIBCPP_MOVE + move_only(move_only&&) {++move_only_constructed;} + move_only& operator=(move_only&&) {} +#else // _LIBCPP_MOVE + operator std::__rv<move_only> () {return std::__rv<move_only>(*this);} + move_only(std::__rv<move_only>) {++move_only_constructed;} +#endif // _LIBCPP_MOVE + + move_only() {++move_only_constructed;} + ~move_only() {--move_only_constructed;} +}; + +int main() +{ + { + std::allocator<A> a; + assert(new_called == 0); + assert(A_constructed == 0); + + A* ap = a.allocate(3); + assert(new_called == 1); + assert(A_constructed == 0); + + a.construct(ap); + assert(new_called == 1); + assert(A_constructed == 1); + + a.destroy(ap); + assert(new_called == 1); + assert(A_constructed == 0); + + a.construct(ap, A()); + assert(new_called == 1); + assert(A_constructed == 1); + + a.destroy(ap); + assert(new_called == 1); + assert(A_constructed == 0); + + a.construct(ap, 5); + assert(new_called == 1); + assert(A_constructed == 1); + + a.destroy(ap); + assert(new_called == 1); + assert(A_constructed == 0); + + a.construct(ap, 5, (int*)0); + assert(new_called == 1); + assert(A_constructed == 1); + + a.destroy(ap); + assert(new_called == 1); + assert(A_constructed == 0); + + a.deallocate(ap, 3); + assert(new_called == 0); + assert(A_constructed == 0); + } + { + std::allocator<move_only> a; + assert(new_called == 0); + assert(move_only_constructed == 0); + + move_only* ap = a.allocate(3); + assert(new_called == 1); + assert(move_only_constructed == 0); + + a.construct(ap); + assert(new_called == 1); + assert(move_only_constructed == 1); + + a.destroy(ap); + assert(new_called == 1); + assert(move_only_constructed == 0); + + a.construct(ap, move_only()); + assert(new_called == 1); + assert(move_only_constructed == 1); + + a.destroy(ap); + assert(new_called == 1); + assert(move_only_constructed == 0); + + a.deallocate(ap, 3); + assert(new_called == 0); + assert(move_only_constructed == 0); + } +} diff --git a/libcxx/test/utilities/memory/default.allocator/allocator.members/max_size.pass.cpp b/libcxx/test/utilities/memory/default.allocator/allocator.members/max_size.pass.cpp index eb596f42f2c..7e958ee0ed0 100644 --- a/libcxx/test/utilities/memory/default.allocator/allocator.members/max_size.pass.cpp +++ b/libcxx/test/utilities/memory/default.allocator/allocator.members/max_size.pass.cpp @@ -1 +1,27 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// allocator:
// size_type max_size() const throw();
#include <memory>
#include <limits>
#include <cstddef>
#include <cassert>
int new_called = 0;
int main()
{
const std::allocator<int> a;
std::size_t M = a.max_size() * sizeof(int);
assert(M > 0xFFFF && M <= std::numeric_limits<std::size_t>::max());
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// allocator: +// size_type max_size() const throw(); + +#include <memory> +#include <limits> +#include <cstddef> +#include <cassert> + +int new_called = 0; + +int main() +{ + const std::allocator<int> a; + std::size_t M = a.max_size() * sizeof(int); + assert(M > 0xFFFF && M <= std::numeric_limits<std::size_t>::max()); +} diff --git a/libcxx/test/utilities/memory/default.allocator/allocator_types.pass.cpp b/libcxx/test/utilities/memory/default.allocator/allocator_types.pass.cpp index 7ee46ff06fc..b62a5ef2c04 100644 --- a/libcxx/test/utilities/memory/default.allocator/allocator_types.pass.cpp +++ b/libcxx/test/utilities/memory/default.allocator/allocator_types.pass.cpp @@ -1 +1,49 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// check nested types:
// template <class T>
// class allocator
// {
// public:
// typedef size_t size_type;
// typedef ptrdiff_t difference_type;
// typedef T* pointer;
// typedef const T* const_pointer;
// typedef typename add_lvalue_reference<T>::type reference;
// typedef typename add_lvalue_reference<const T>::type const_reference;
// typedef T value_type;
//
// template <class U> struct rebind {typedef allocator<U> other;};
// ...
// };
#include <memory>
#include <type_traits>
#include <cstddef>
int main()
{
static_assert((std::is_same<std::allocator<char>::size_type, std::size_t>::value), "");
static_assert((std::is_same<std::allocator<char>::difference_type, std::ptrdiff_t>::value), "");
static_assert((std::is_same<std::allocator<char>::pointer, char*>::value), "");
static_assert((std::is_same<std::allocator<char>::const_pointer, const char*>::value), "");
static_assert((std::is_same<std::allocator<char>::value_type, char>::value), "");
static_assert((std::is_same<std::allocator<char>::reference, char&>::value), "");
static_assert((std::is_same<std::allocator<char>::const_reference, const char&>::value), "");
static_assert((std::is_same<std::allocator<char>::rebind<int>::other,
std::allocator<int> >::value), "");
std::allocator<char> a;
std::allocator<char> a2 = a;
a2 = a;
std::allocator<int> a3 = a2;
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// check nested types: + +// template <class T> +// class allocator +// { +// public: +// typedef size_t size_type; +// typedef ptrdiff_t difference_type; +// typedef T* pointer; +// typedef const T* const_pointer; +// typedef typename add_lvalue_reference<T>::type reference; +// typedef typename add_lvalue_reference<const T>::type const_reference; +// typedef T value_type; +// +// template <class U> struct rebind {typedef allocator<U> other;}; +// ... +// }; + +#include <memory> +#include <type_traits> +#include <cstddef> + +int main() +{ + static_assert((std::is_same<std::allocator<char>::size_type, std::size_t>::value), ""); + static_assert((std::is_same<std::allocator<char>::difference_type, std::ptrdiff_t>::value), ""); + static_assert((std::is_same<std::allocator<char>::pointer, char*>::value), ""); + static_assert((std::is_same<std::allocator<char>::const_pointer, const char*>::value), ""); + static_assert((std::is_same<std::allocator<char>::value_type, char>::value), ""); + static_assert((std::is_same<std::allocator<char>::reference, char&>::value), ""); + static_assert((std::is_same<std::allocator<char>::const_reference, const char&>::value), ""); + static_assert((std::is_same<std::allocator<char>::rebind<int>::other, + std::allocator<int> >::value), ""); + std::allocator<char> a; + std::allocator<char> a2 = a; + a2 = a; + std::allocator<int> a3 = a2; +} diff --git a/libcxx/test/utilities/memory/default.allocator/allocator_void.pass.cpp b/libcxx/test/utilities/memory/default.allocator/allocator_void.pass.cpp index 79b0690f3a9..f0af8879f68 100644 --- a/libcxx/test/utilities/memory/default.allocator/allocator_void.pass.cpp +++ b/libcxx/test/utilities/memory/default.allocator/allocator_void.pass.cpp @@ -1 +1,36 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <>
// class allocator<void>
// {
// public:
// typedef void* pointer;
// typedef const void* const_pointer;
// typedef void value_type;
//
// template <class _Up> struct rebind {typedef allocator<_Up> other;};
// };
#include <memory>
#include <type_traits>
int main()
{
static_assert((std::is_same<std::allocator<void>::pointer, void*>::value), "");
static_assert((std::is_same<std::allocator<void>::const_pointer, const void*>::value), "");
static_assert((std::is_same<std::allocator<void>::value_type, void>::value), "");
static_assert((std::is_same<std::allocator<void>::rebind<int>::other,
std::allocator<int> >::value), "");
std::allocator<void> a;
std::allocator<void> a2 = a;
a2 = a;
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// template <> +// class allocator<void> +// { +// public: +// typedef void* pointer; +// typedef const void* const_pointer; +// typedef void value_type; +// +// template <class _Up> struct rebind {typedef allocator<_Up> other;}; +// }; + +#include <memory> +#include <type_traits> + +int main() +{ + static_assert((std::is_same<std::allocator<void>::pointer, void*>::value), ""); + static_assert((std::is_same<std::allocator<void>::const_pointer, const void*>::value), ""); + static_assert((std::is_same<std::allocator<void>::value_type, void>::value), ""); + static_assert((std::is_same<std::allocator<void>::rebind<int>::other, + std::allocator<int> >::value), ""); + std::allocator<void> a; + std::allocator<void> a2 = a; + a2 = a; +} diff --git a/libcxx/test/utilities/memory/pointer.traits/difference_type.pass.cpp b/libcxx/test/utilities/memory/pointer.traits/difference_type.pass.cpp index f28e42f28bd..820b75f6439 100644 --- a/libcxx/test/utilities/memory/pointer.traits/difference_type.pass.cpp +++ b/libcxx/test/utilities/memory/pointer.traits/difference_type.pass.cpp @@ -1 +1,25 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <class T>
// struct pointer_traits<T*>
// {
// typedef ptrdiff_t difference_type;
// ...
// };
#include <memory>
#include <type_traits>
int main()
{
static_assert((std::is_same<std::pointer_traits<double*>::difference_type, std::ptrdiff_t>::value), "");
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// template <class T> +// struct pointer_traits<T*> +// { +// typedef ptrdiff_t difference_type; +// ... +// }; + +#include <memory> +#include <type_traits> + +int main() +{ + static_assert((std::is_same<std::pointer_traits<double*>::difference_type, std::ptrdiff_t>::value), ""); +} diff --git a/libcxx/test/utilities/memory/pointer.traits/element_type.pass.cpp b/libcxx/test/utilities/memory/pointer.traits/element_type.pass.cpp index e944dc8ff35..cf1ddd865c3 100644 --- a/libcxx/test/utilities/memory/pointer.traits/element_type.pass.cpp +++ b/libcxx/test/utilities/memory/pointer.traits/element_type.pass.cpp @@ -1 +1,25 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <class T>
// struct pointer_traits<T*>
// {
// typedef T element_type;
// ...
// };
#include <memory>
#include <type_traits>
int main()
{
static_assert((std::is_same<std::pointer_traits<const short*>::element_type, const short>::value), "");
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// template <class T> +// struct pointer_traits<T*> +// { +// typedef T element_type; +// ... +// }; + +#include <memory> +#include <type_traits> + +int main() +{ + static_assert((std::is_same<std::pointer_traits<const short*>::element_type, const short>::value), ""); +} diff --git a/libcxx/test/utilities/memory/pointer.traits/pointer.pass.cpp b/libcxx/test/utilities/memory/pointer.traits/pointer.pass.cpp index 34fa69454ab..13d15b53d8d 100644 --- a/libcxx/test/utilities/memory/pointer.traits/pointer.pass.cpp +++ b/libcxx/test/utilities/memory/pointer.traits/pointer.pass.cpp @@ -1 +1,32 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <class Ptr>
// struct pointer_traits
// {
// typedef Ptr pointer;
// ...
// };
#include <memory>
#include <type_traits>
struct A
{
typedef short element_type;
typedef char difference_type;
};
int main()
{
static_assert((std::is_same<std::pointer_traits<A>::pointer, A>::value), "");
static_assert((std::is_same<std::pointer_traits<int*>::pointer, int*>::value), "");
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// template <class Ptr> +// struct pointer_traits +// { +// typedef Ptr pointer; +// ... +// }; + +#include <memory> +#include <type_traits> + +struct A +{ + typedef short element_type; + typedef char difference_type; +}; + +int main() +{ + static_assert((std::is_same<std::pointer_traits<A>::pointer, A>::value), ""); + static_assert((std::is_same<std::pointer_traits<int*>::pointer, int*>::value), ""); +} diff --git a/libcxx/test/utilities/memory/pointer.traits/pointer.traits.functions/pointer_to.pass.cpp b/libcxx/test/utilities/memory/pointer.traits/pointer.traits.functions/pointer_to.pass.cpp index 8ed66297f31..10cdb897002 100644 --- a/libcxx/test/utilities/memory/pointer.traits/pointer.traits.functions/pointer_to.pass.cpp +++ b/libcxx/test/utilities/memory/pointer.traits/pointer.traits.functions/pointer_to.pass.cpp @@ -1 +1,48 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <class Ptr>
// struct pointer_traits
// {
// static pointer pointer_to(<details>);
// ...
// };
#include <memory>
#include <cassert>
template <class T>
struct A
{
private:
struct nat {};
public:
typedef T element_type;
element_type* t_;
A(element_type* t) : t_(t) {}
static A pointer_to(typename std::conditional<std::is_void<element_type>::value,
nat, element_type>::type& et)
{return A(&et);}
};
int main()
{
{
int i = 0;
A<int> a = std::pointer_traits<A<int> >::pointer_to(i);
assert(a.t_ = &i);
}
{
(std::pointer_traits<A<void> >::element_type)0;
}
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// template <class Ptr> +// struct pointer_traits +// { +// static pointer pointer_to(<details>); +// ... +// }; + +#include <memory> +#include <cassert> + +template <class T> +struct A +{ +private: + struct nat {}; +public: + typedef T element_type; + element_type* t_; + + A(element_type* t) : t_(t) {} + + static A pointer_to(typename std::conditional<std::is_void<element_type>::value, + nat, element_type>::type& et) + {return A(&et);} +}; + +int main() +{ + { + int i = 0; + A<int> a = std::pointer_traits<A<int> >::pointer_to(i); + assert(a.t_ = &i); + } + { + (std::pointer_traits<A<void> >::element_type)0; + } +} diff --git a/libcxx/test/utilities/memory/pointer.traits/pointer.traits.types/difference_type.pass.cpp b/libcxx/test/utilities/memory/pointer.traits/pointer.traits.types/difference_type.pass.cpp index e2a78d1ddfa..49439dd3701 100644 --- a/libcxx/test/utilities/memory/pointer.traits/pointer.traits.types/difference_type.pass.cpp +++ b/libcxx/test/utilities/memory/pointer.traits/pointer.traits.types/difference_type.pass.cpp @@ -1 +1,48 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <class Ptr>
// struct pointer_traits
// {
// typedef <details> difference_type;
// ...
// };
#include <memory>
#include <type_traits>
struct A
{
typedef short element_type;
typedef char difference_type;
};
struct B
{
typedef short element_type;
};
template <class T>
struct C {};
template <class T>
struct D
{
typedef char difference_type;
};
int main()
{
static_assert((std::is_same<std::pointer_traits<A>::difference_type, char>::value), "");
static_assert((std::is_same<std::pointer_traits<B>::difference_type, std::ptrdiff_t>::value), "");
static_assert((std::is_same<std::pointer_traits<C<double> >::difference_type, std::ptrdiff_t>::value), "");
static_assert((std::is_same<std::pointer_traits<D<int> >::difference_type, char>::value), "");
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// template <class Ptr> +// struct pointer_traits +// { +// typedef <details> difference_type; +// ... +// }; + +#include <memory> +#include <type_traits> + +struct A +{ + typedef short element_type; + typedef char difference_type; +}; + +struct B +{ + typedef short element_type; +}; + +template <class T> +struct C {}; + +template <class T> +struct D +{ + typedef char difference_type; +}; + +int main() +{ + static_assert((std::is_same<std::pointer_traits<A>::difference_type, char>::value), ""); + static_assert((std::is_same<std::pointer_traits<B>::difference_type, std::ptrdiff_t>::value), ""); + static_assert((std::is_same<std::pointer_traits<C<double> >::difference_type, std::ptrdiff_t>::value), ""); + static_assert((std::is_same<std::pointer_traits<D<int> >::difference_type, char>::value), ""); +} diff --git a/libcxx/test/utilities/memory/pointer.traits/pointer.traits.types/element_type.pass.cpp b/libcxx/test/utilities/memory/pointer.traits/pointer.traits.types/element_type.pass.cpp index ca464370c6e..eb48fa26de4 100644 --- a/libcxx/test/utilities/memory/pointer.traits/pointer.traits.types/element_type.pass.cpp +++ b/libcxx/test/utilities/memory/pointer.traits/pointer.traits.types/element_type.pass.cpp @@ -1 +1,49 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <class Ptr>
// struct pointer_traits
// {
// typedef <details> element_type;
// ...
// };
#include <memory>
#include <type_traits>
struct A
{
typedef char element_type;
};
template <class T>
struct B
{
typedef char element_type;
};
template <class T>
struct C
{
};
template <class T, class U>
struct D
{
};
int main()
{
static_assert((std::is_same<std::pointer_traits<A>::element_type, char>::value), "");
static_assert((std::is_same<std::pointer_traits<B<int> >::element_type, char>::value), "");
static_assert((std::is_same<std::pointer_traits<C<int> >::element_type, int>::value), "");
static_assert((std::is_same<std::pointer_traits<D<double, int> >::element_type, double>::value), "");
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// template <class Ptr> +// struct pointer_traits +// { +// typedef <details> element_type; +// ... +// }; + +#include <memory> +#include <type_traits> + +struct A +{ + typedef char element_type; +}; + +template <class T> +struct B +{ + typedef char element_type; +}; + +template <class T> +struct C +{ +}; + +template <class T, class U> +struct D +{ +}; + +int main() +{ + static_assert((std::is_same<std::pointer_traits<A>::element_type, char>::value), ""); + static_assert((std::is_same<std::pointer_traits<B<int> >::element_type, char>::value), ""); + static_assert((std::is_same<std::pointer_traits<C<int> >::element_type, int>::value), ""); + static_assert((std::is_same<std::pointer_traits<D<double, int> >::element_type, double>::value), ""); +} diff --git a/libcxx/test/utilities/memory/pointer.traits/pointer.traits.types/rebind.pass.cpp b/libcxx/test/utilities/memory/pointer.traits/pointer.traits.types/rebind.pass.cpp index ca8a3a27629..4095754c255 100644 --- a/libcxx/test/utilities/memory/pointer.traits/pointer.traits.types/rebind.pass.cpp +++ b/libcxx/test/utilities/memory/pointer.traits/pointer.traits.types/rebind.pass.cpp @@ -1 +1,69 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <class Ptr>
// struct pointer_traits
// {
// template <class U> using rebind = <details>;
// ...
// };
#include <memory>
#include <type_traits>
template <class T>
struct A
{
};
template <class T> struct B1 {};
template <class T>
struct B
{
#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
template <class U> using rebind = B1<U>;
#else
template <class U> struct rebind {typedef B1<U> other;};
#endif
};
template <class T, class U>
struct C
{
};
template <class T, class U> struct D1 {};
template <class T, class U>
struct D
{
#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
template <class V> using rebind = D1<V, U>;
#else
template <class V> struct rebind {typedef D1<V, U> other;};
#endif
};
int main()
{
#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
static_assert((std::is_same<std::pointer_traits<A<int*> >::rebind<double*>, A<double*> >::value), "");
static_assert((std::is_same<std::pointer_traits<B<int> >::rebind<double>, B1<double> >::value), "");
static_assert((std::is_same<std::pointer_traits<C<char, int> >::rebind<double>, C<double, int> >::value), "");
static_assert((std::is_same<std::pointer_traits<D<char, int> >::rebind<double>, D1<double, int> >::value), "");
#else
static_assert((std::is_same<std::pointer_traits<A<int*> >::rebind<double*>::other, A<double*> >::value), "");
static_assert((std::is_same<std::pointer_traits<B<int> >::rebind<double>::other, B1<double> >::value), "");
static_assert((std::is_same<std::pointer_traits<C<char, int> >::rebind<double>::other, C<double, int> >::value), "");
static_assert((std::is_same<std::pointer_traits<D<char, int> >::rebind<double>::other, D1<double, int> >::value), "");
#endif
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// template <class Ptr> +// struct pointer_traits +// { +// template <class U> using rebind = <details>; +// ... +// }; + +#include <memory> +#include <type_traits> + +template <class T> +struct A +{ +}; + +template <class T> struct B1 {}; + +template <class T> +struct B +{ +#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES + template <class U> using rebind = B1<U>; +#else + template <class U> struct rebind {typedef B1<U> other;}; +#endif +}; + +template <class T, class U> +struct C +{ +}; + +template <class T, class U> struct D1 {}; + +template <class T, class U> +struct D +{ +#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES + template <class V> using rebind = D1<V, U>; +#else + template <class V> struct rebind {typedef D1<V, U> other;}; +#endif +}; + +int main() +{ +#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES + static_assert((std::is_same<std::pointer_traits<A<int*> >::rebind<double*>, A<double*> >::value), ""); + static_assert((std::is_same<std::pointer_traits<B<int> >::rebind<double>, B1<double> >::value), ""); + static_assert((std::is_same<std::pointer_traits<C<char, int> >::rebind<double>, C<double, int> >::value), ""); + static_assert((std::is_same<std::pointer_traits<D<char, int> >::rebind<double>, D1<double, int> >::value), ""); +#else // _LIBCPP_HAS_NO_TEMPLATE_ALIASES + static_assert((std::is_same<std::pointer_traits<A<int*> >::rebind<double*>::other, A<double*> >::value), ""); + static_assert((std::is_same<std::pointer_traits<B<int> >::rebind<double>::other, B1<double> >::value), ""); + static_assert((std::is_same<std::pointer_traits<C<char, int> >::rebind<double>::other, C<double, int> >::value), ""); + static_assert((std::is_same<std::pointer_traits<D<char, int> >::rebind<double>::other, D1<double, int> >::value), ""); +#endif // _LIBCPP_HAS_NO_TEMPLATE_ALIASES +} diff --git a/libcxx/test/utilities/memory/pointer.traits/pointer_to.pass.cpp b/libcxx/test/utilities/memory/pointer.traits/pointer_to.pass.cpp index 42fd9300b7d..557bf36b976 100644 --- a/libcxx/test/utilities/memory/pointer.traits/pointer_to.pass.cpp +++ b/libcxx/test/utilities/memory/pointer.traits/pointer_to.pass.cpp @@ -1 +1,32 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <class T>
// struct pointer_traits<T*>
// {
// static pointer pointer_to(<details>);
// ...
// };
#include <memory>
#include <cassert>
int main()
{
{
int i = 0;
int* a = std::pointer_traits<int*>::pointer_to(i);
assert(a = &i);
}
{
(std::pointer_traits<void*>::element_type)0;
}
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// template <class T> +// struct pointer_traits<T*> +// { +// static pointer pointer_to(<details>); +// ... +// }; + +#include <memory> +#include <cassert> + +int main() +{ + { + int i = 0; + int* a = std::pointer_traits<int*>::pointer_to(i); + assert(a = &i); + } + { + (std::pointer_traits<void*>::element_type)0; + } +} diff --git a/libcxx/test/utilities/memory/pointer.traits/rebind.pass.cpp b/libcxx/test/utilities/memory/pointer.traits/rebind.pass.cpp index f63c03521a0..d3a4d794f90 100644 --- a/libcxx/test/utilities/memory/pointer.traits/rebind.pass.cpp +++ b/libcxx/test/utilities/memory/pointer.traits/rebind.pass.cpp @@ -1 +1,29 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <class T>
// struct pointer_traits<T*>
// {
// template <class U> using rebind = U*;
// ...
// };
#include <memory>
#include <type_traits>
int main()
{
#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
static_assert((std::is_same<std::pointer_traits<int*>::rebind<double>, double*>::value), "");
#else
static_assert((std::is_same<std::pointer_traits<int*>::rebind<double>::other, double*>::value), "");
#endif
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// template <class T> +// struct pointer_traits<T*> +// { +// template <class U> using rebind = U*; +// ... +// }; + +#include <memory> +#include <type_traits> + +int main() +{ +#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES + static_assert((std::is_same<std::pointer_traits<int*>::rebind<double>, double*>::value), ""); +#else + static_assert((std::is_same<std::pointer_traits<int*>::rebind<double>::other, double*>::value), ""); +#endif +} diff --git a/libcxx/test/utilities/memory/specialized.algorithms/nothing_to_do.pass.cpp b/libcxx/test/utilities/memory/specialized.algorithms/nothing_to_do.pass.cpp index e8db90cbee0..b89f168e9c4 100644 --- a/libcxx/test/utilities/memory/specialized.algorithms/nothing_to_do.pass.cpp +++ b/libcxx/test/utilities/memory/specialized.algorithms/nothing_to_do.pass.cpp @@ -1 +1,12 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
int main()
{
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/libcxx/test/utilities/memory/specialized.algorithms/specialized.addressof/addressof.pass.cpp b/libcxx/test/utilities/memory/specialized.algorithms/specialized.addressof/addressof.pass.cpp index c4b14d3160c..6f1b01163de 100644 --- a/libcxx/test/utilities/memory/specialized.algorithms/specialized.addressof/addressof.pass.cpp +++ b/libcxx/test/utilities/memory/specialized.algorithms/specialized.addressof/addressof.pass.cpp @@ -1 +1,33 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <ObjectType T> T* addressof(T& r);
#include <memory>
#include <cassert>
struct A
{
void operator&() const {}
};
int main()
{
int i;
double d;
assert(std::addressof(i) == &i);
assert(std::addressof(d) == &d);
A* tp = new A;
const A* ctp = tp;
assert(std::addressof(*tp) == tp);
assert(std::addressof(*ctp) == tp);
delete tp;
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// template <ObjectType T> T* addressof(T& r); + +#include <memory> +#include <cassert> + +struct A +{ + void operator&() const {} +}; + +int main() +{ + int i; + double d; + assert(std::addressof(i) == &i); + assert(std::addressof(d) == &d); + A* tp = new A; + const A* ctp = tp; + assert(std::addressof(*tp) == tp); + assert(std::addressof(*ctp) == tp); + delete tp; +} diff --git a/libcxx/test/utilities/memory/specialized.algorithms/uninitialized.copy/uninitialized_copy.pass.cpp b/libcxx/test/utilities/memory/specialized.algorithms/uninitialized.copy/uninitialized_copy.pass.cpp index d592386557a..401a3948504 100644 --- a/libcxx/test/utilities/memory/specialized.algorithms/uninitialized.copy/uninitialized_copy.pass.cpp +++ b/libcxx/test/utilities/memory/specialized.algorithms/uninitialized.copy/uninitialized_copy.pass.cpp @@ -1 +1,51 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <class InputIterator, class ForwardIterator>
// ForwardIterator
// uninitialized_copy(InputIterator first, InputIterator last,
// ForwardIterator result);
#include <memory>
#include <cassert>
struct B
{
static int count_;
int data_;
explicit B() : data_(1) {}
B(const B& b) {if (++count_ == 3) throw 1; data_ = b.data_;}
~B() {data_ = 0;}
};
int B::count_ = 0;
int main()
{
const int N = 5;
char pool[sizeof(B)*N] = {0};
B* bp = (B*)pool;
B b[N];
try
{
std::uninitialized_copy(b, b+N, bp);
assert(false);
}
catch (...)
{
for (int i = 0; i < N; ++i)
assert(bp[i].data_ == 0);
}
B::count_ = 0;
std::uninitialized_copy(b, b+2, bp);
for (int i = 0; i < 2; ++i)
assert(bp[i].data_ == 1);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// template <class InputIterator, class ForwardIterator> +// ForwardIterator +// uninitialized_copy(InputIterator first, InputIterator last, +// ForwardIterator result); + +#include <memory> +#include <cassert> + +struct B +{ + static int count_; + int data_; + explicit B() : data_(1) {} + B(const B& b) {if (++count_ == 3) throw 1; data_ = b.data_;} + ~B() {data_ = 0;} +}; + +int B::count_ = 0; + +int main() +{ + const int N = 5; + char pool[sizeof(B)*N] = {0}; + B* bp = (B*)pool; + B b[N]; + try + { + std::uninitialized_copy(b, b+N, bp); + assert(false); + } + catch (...) + { + for (int i = 0; i < N; ++i) + assert(bp[i].data_ == 0); + } + B::count_ = 0; + std::uninitialized_copy(b, b+2, bp); + for (int i = 0; i < 2; ++i) + assert(bp[i].data_ == 1); +} diff --git a/libcxx/test/utilities/memory/specialized.algorithms/uninitialized.copy/uninitialized_copy_n.pass.cpp b/libcxx/test/utilities/memory/specialized.algorithms/uninitialized.copy/uninitialized_copy_n.pass.cpp index 0971c61b402..8d51e755141 100644 --- a/libcxx/test/utilities/memory/specialized.algorithms/uninitialized.copy/uninitialized_copy_n.pass.cpp +++ b/libcxx/test/utilities/memory/specialized.algorithms/uninitialized.copy/uninitialized_copy_n.pass.cpp @@ -1 +1,51 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <class InputIterator, class Size, class ForwardIterator>
// ForwardIterator
// uninitialized_copy_n(InputIterator first, Size n,
// ForwardIterator result);
#include <memory>
#include <cassert>
struct B
{
static int count_;
int data_;
explicit B() : data_(1) {}
B(const B& b) {if (++count_ == 3) throw 1; data_ = b.data_;}
~B() {data_ = 0;}
};
int B::count_ = 0;
int main()
{
const int N = 5;
char pool[sizeof(B)*N] = {0};
B* bp = (B*)pool;
B b[N];
try
{
std::uninitialized_copy_n(b, 5, bp);
assert(false);
}
catch (...)
{
for (int i = 0; i < N; ++i)
assert(bp[i].data_ == 0);
}
B::count_ = 0;
std::uninitialized_copy_n(b, 2, bp);
for (int i = 0; i < 2; ++i)
assert(bp[i].data_ == 1);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// template <class InputIterator, class Size, class ForwardIterator> +// ForwardIterator +// uninitialized_copy_n(InputIterator first, Size n, +// ForwardIterator result); + +#include <memory> +#include <cassert> + +struct B +{ + static int count_; + int data_; + explicit B() : data_(1) {} + B(const B& b) {if (++count_ == 3) throw 1; data_ = b.data_;} + ~B() {data_ = 0;} +}; + +int B::count_ = 0; + +int main() +{ + const int N = 5; + char pool[sizeof(B)*N] = {0}; + B* bp = (B*)pool; + B b[N]; + try + { + std::uninitialized_copy_n(b, 5, bp); + assert(false); + } + catch (...) + { + for (int i = 0; i < N; ++i) + assert(bp[i].data_ == 0); + } + B::count_ = 0; + std::uninitialized_copy_n(b, 2, bp); + for (int i = 0; i < 2; ++i) + assert(bp[i].data_ == 1); +} diff --git a/libcxx/test/utilities/memory/specialized.algorithms/uninitialized.fill.n/uninitialized_fill_n.pass.cpp b/libcxx/test/utilities/memory/specialized.algorithms/uninitialized.fill.n/uninitialized_fill_n.pass.cpp index 15518e00f71..1f48d886e53 100644 --- a/libcxx/test/utilities/memory/specialized.algorithms/uninitialized.fill.n/uninitialized_fill_n.pass.cpp +++ b/libcxx/test/utilities/memory/specialized.algorithms/uninitialized.fill.n/uninitialized_fill_n.pass.cpp @@ -1 +1,49 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <class ForwardIterator, class Size, class T>
// void
// uninitialized_fill_n(ForwardIterator first, Size n, const T& x);
#include <memory>
#include <cassert>
struct B
{
static int count_;
int data_;
explicit B() : data_(1) {}
B(const B& b) {if (++count_ == 3) throw 1; data_ = b.data_;}
~B() {data_ = 0;}
};
int B::count_ = 0;
int main()
{
const int N = 5;
char pool[sizeof(B)*N] = {0};
B* bp = (B*)pool;
try
{
std::uninitialized_fill_n(bp, 5, B());
assert(false);
}
catch (...)
{
for (int i = 0; i < N; ++i)
assert(bp[i].data_ == 0);
}
B::count_ = 0;
std::uninitialized_fill_n(bp, 2, B());
for (int i = 0; i < 2; ++i)
assert(bp[i].data_ == 1);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// template <class ForwardIterator, class Size, class T> +// void +// uninitialized_fill_n(ForwardIterator first, Size n, const T& x); + +#include <memory> +#include <cassert> + +struct B +{ + static int count_; + int data_; + explicit B() : data_(1) {} + B(const B& b) {if (++count_ == 3) throw 1; data_ = b.data_;} + ~B() {data_ = 0;} +}; + +int B::count_ = 0; + +int main() +{ + const int N = 5; + char pool[sizeof(B)*N] = {0}; + B* bp = (B*)pool; + try + { + std::uninitialized_fill_n(bp, 5, B()); + assert(false); + } + catch (...) + { + for (int i = 0; i < N; ++i) + assert(bp[i].data_ == 0); + } + B::count_ = 0; + std::uninitialized_fill_n(bp, 2, B()); + for (int i = 0; i < 2; ++i) + assert(bp[i].data_ == 1); +} diff --git a/libcxx/test/utilities/memory/specialized.algorithms/uninitialized.fill/uninitialized_fill.pass.cpp b/libcxx/test/utilities/memory/specialized.algorithms/uninitialized.fill/uninitialized_fill.pass.cpp index eaaa6ca8188..83d2d257714 100644 --- a/libcxx/test/utilities/memory/specialized.algorithms/uninitialized.fill/uninitialized_fill.pass.cpp +++ b/libcxx/test/utilities/memory/specialized.algorithms/uninitialized.fill/uninitialized_fill.pass.cpp @@ -1 +1,50 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <class ForwardIterator, class T>
// void
// uninitialized_fill(ForwardIterator first, ForwardIterator last,
// const T& x);
#include <memory>
#include <cassert>
struct B
{
static int count_;
int data_;
explicit B() : data_(1) {}
B(const B& b) {if (++count_ == 3) throw 1; data_ = b.data_;}
~B() {data_ = 0;}
};
int B::count_ = 0;
int main()
{
const int N = 5;
char pool[sizeof(B)*N] = {0};
B* bp = (B*)pool;
try
{
std::uninitialized_fill(bp, bp+N, B());
assert(false);
}
catch (...)
{
for (int i = 0; i < N; ++i)
assert(bp[i].data_ == 0);
}
B::count_ = 0;
std::uninitialized_fill(bp, bp+2, B());
for (int i = 0; i < 2; ++i)
assert(bp[i].data_ == 1);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// template <class ForwardIterator, class T> +// void +// uninitialized_fill(ForwardIterator first, ForwardIterator last, +// const T& x); + +#include <memory> +#include <cassert> + +struct B +{ + static int count_; + int data_; + explicit B() : data_(1) {} + B(const B& b) {if (++count_ == 3) throw 1; data_ = b.data_;} + ~B() {data_ = 0;} +}; + +int B::count_ = 0; + +int main() +{ + const int N = 5; + char pool[sizeof(B)*N] = {0}; + B* bp = (B*)pool; + try + { + std::uninitialized_fill(bp, bp+N, B()); + assert(false); + } + catch (...) + { + for (int i = 0; i < N; ++i) + assert(bp[i].data_ == 0); + } + B::count_ = 0; + std::uninitialized_fill(bp, bp+2, B()); + for (int i = 0; i < 2; ++i) + assert(bp[i].data_ == 1); +} diff --git a/libcxx/test/utilities/memory/storage.iterator/raw_storag_iterator.pass.cpp b/libcxx/test/utilities/memory/storage.iterator/raw_storag_iterator.pass.cpp index 3f356890915..40792d2c324 100644 --- a/libcxx/test/utilities/memory/storage.iterator/raw_storag_iterator.pass.cpp +++ b/libcxx/test/utilities/memory/storage.iterator/raw_storag_iterator.pass.cpp @@ -1 +1,44 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// raw_storage_iterator
#include <memory>
#include <type_traits>
#include <cassert>
int A_constructed = 0;
struct A
{
int data_;
public:
explicit A(int i) : data_(i) {++A_constructed;}
A(const A& a) : data_(a.data_) {++A_constructed;}
~A() {--A_constructed; data_ = 0;}
bool operator==(int i) const {return data_ == i;}
};
int main()
{
typedef std::aligned_storage<3*sizeof(A), std::alignment_of<A>::value>::type
Storage;
Storage buffer;
std::raw_storage_iterator<A*, A> it((A*)&buffer);
assert(A_constructed == 0);
for (int i = 0; i < 3; ++i)
{
*it++ = A(i+1);
A* ap = (A*)&buffer + i;
assert(*ap == i+1);
assert(A_constructed == i+1);
}
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// raw_storage_iterator + +#include <memory> +#include <type_traits> +#include <cassert> + +int A_constructed = 0; + +struct A +{ + int data_; +public: + explicit A(int i) : data_(i) {++A_constructed;} + + A(const A& a) : data_(a.data_) {++A_constructed;} + ~A() {--A_constructed; data_ = 0;} + + bool operator==(int i) const {return data_ == i;} +}; + +int main() +{ + typedef std::aligned_storage<3*sizeof(A), std::alignment_of<A>::value>::type + Storage; + Storage buffer; + std::raw_storage_iterator<A*, A> it((A*)&buffer); + assert(A_constructed == 0); + for (int i = 0; i < 3; ++i) + { + *it++ = A(i+1); + A* ap = (A*)&buffer + i; + assert(*ap == i+1); + assert(A_constructed == i+1); + } +} diff --git a/libcxx/test/utilities/memory/temporary.buffer/temporary_buffer.pass.cpp b/libcxx/test/utilities/memory/temporary.buffer/temporary_buffer.pass.cpp index 129bae834b9..8e923695c0c 100644 --- a/libcxx/test/utilities/memory/temporary.buffer/temporary_buffer.pass.cpp +++ b/libcxx/test/utilities/memory/temporary.buffer/temporary_buffer.pass.cpp @@ -1 +1,29 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <class T>
// pair<T*, ptrdiff_t>
// get_temporary_buffer(ptrdiff_t n);
//
// template <class T>
// void
// return_temporary_buffer(T* p);
#include <memory>
#include <cassert>
int main()
{
std::pair<int*, std::ptrdiff_t> ip = std::get_temporary_buffer<int>(5);
assert(ip.first);
assert(ip.second == 5);
std::return_temporary_buffer(ip.first);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// template <class T> +// pair<T*, ptrdiff_t> +// get_temporary_buffer(ptrdiff_t n); +// +// template <class T> +// void +// return_temporary_buffer(T* p); + +#include <memory> +#include <cassert> + +int main() +{ + std::pair<int*, std::ptrdiff_t> ip = std::get_temporary_buffer<int>(5); + assert(ip.first); + assert(ip.second == 5); + std::return_temporary_buffer(ip.first); +} diff --git a/libcxx/test/utilities/memory/unique.ptr/deleter.h b/libcxx/test/utilities/memory/unique.ptr/deleter.h index df8b894e1e2..f14c74f87d1 100644 --- a/libcxx/test/utilities/memory/unique.ptr/deleter.h +++ b/libcxx/test/utilities/memory/unique.ptr/deleter.h @@ -1 +1,181 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Example move-only deleter
#ifndef DELETER_H
#define DELETER_H
#include <type_traits>
#include <cassert>
template <class T>
class Deleter
{
int state_;
#ifdef _LIBCPP_MOVE
Deleter(const Deleter&);
Deleter& operator=(const Deleter&);
#else
Deleter(Deleter&);
Deleter& operator=(Deleter&);
#endif
public:
#ifdef _LIBCPP_MOVE
Deleter(Deleter&& r) : state_(r.state_) {r.state_ = 0;}
Deleter& operator=(Deleter&& r)
{
state_ = r.state_;
r.state_ = 0;
return *this;
}
#else
operator std::__rv<Deleter>() {return std::__rv<Deleter>(*this);}
Deleter(std::__rv<Deleter> r) : state_(r->state_) {r->state_ = 0;}
Deleter& operator=(std::__rv<Deleter> r)
{
state_ = r->state_;
r->state_ = 0;
return *this;
}
#endif
Deleter() : state_(0) {}
explicit Deleter(int s) : state_(s) {}
~Deleter() {assert(state_ >= 0); state_ = -1;}
#ifdef _LIBCPP_MOVE
template <class U>
Deleter(Deleter<U>&& d,
typename std::enable_if<!std::is_same<U, T>::value>::type* = 0)
: state_(d.state()) {d.set_state(0);}
private:
template <class U>
Deleter(const Deleter<U>& d,
typename std::enable_if<!std::is_same<U, T>::value>::type* = 0);
#else
template <class U>
Deleter(Deleter<U> d,
typename std::enable_if<!std::is_same<U, T>::value>::type* = 0)
: state_(d.state()) {}
#endif
public:
int state() const {return state_;}
void set_state(int i) {state_ = i;}
void operator()(T* p) {delete p;}
};
template <class T>
class Deleter<T[]>
{
int state_;
#ifdef _LIBCPP_MOVE
Deleter(const Deleter&);
Deleter& operator=(const Deleter&);
#else
Deleter(Deleter&);
Deleter& operator=(Deleter&);
#endif
public:
#ifdef _LIBCPP_MOVE
Deleter(Deleter&& r) : state_(r.state_) {r.state_ = 0;}
Deleter& operator=(Deleter&& r)
{
state_ = r.state_;
r.state_ = 0;
return *this;
}
#else
operator std::__rv<Deleter>() {return std::__rv<Deleter>(*this);}
Deleter(std::__rv<Deleter> r) : state_(r->state_) {r->state_ = 0;}
Deleter& operator=(std::__rv<Deleter> r)
{
state_ = r->state_;
r->state_ = 0;
return *this;
}
#endif
Deleter() : state_(0) {}
explicit Deleter(int s) : state_(s) {}
~Deleter() {assert(state_ >= 0); state_ = -1;}
int state() const {return state_;}
void set_state(int i) {state_ = i;}
void operator()(T* p) {delete [] p;}
};
template <class T>
void
swap(Deleter<T>& x, Deleter<T>& y)
{
Deleter<T> t(std::move(x));
x = std::move(y);
y = std::move(t);
}
template <class T>
class CDeleter
{
int state_;
public:
CDeleter() : state_(0) {}
explicit CDeleter(int s) : state_(s) {}
~CDeleter() {assert(state_ >= 0); state_ = -1;}
template <class U>
CDeleter(const CDeleter<U>& d)
: state_(d.state()) {}
int state() const {return state_;}
void set_state(int i) {state_ = i;}
void operator()(T* p) {delete p;}
};
template <class T>
class CDeleter<T[]>
{
int state_;
public:
CDeleter() : state_(0) {}
explicit CDeleter(int s) : state_(s) {}
~CDeleter() {assert(state_ >= 0); state_ = -1;}
int state() const {return state_;}
void set_state(int i) {state_ = i;}
void operator()(T* p) {delete [] p;}
};
template <class T>
void
swap(CDeleter<T>& x, CDeleter<T>& y)
{
CDeleter<T> t(std::move(x));
x = std::move(y);
y = std::move(t);
}
#endif
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Example move-only deleter + +#ifndef DELETER_H +#define DELETER_H + +#include <type_traits> +#include <cassert> + +template <class T> +class Deleter +{ + int state_; + +#ifdef _LIBCPP_MOVE + Deleter(const Deleter&); + Deleter& operator=(const Deleter&); +#else // _LIBCPP_MOVE + Deleter(Deleter&); + Deleter& operator=(Deleter&); +#endif // _LIBCPP_MOVE + +public: +#ifdef _LIBCPP_MOVE + Deleter(Deleter&& r) : state_(r.state_) {r.state_ = 0;} + Deleter& operator=(Deleter&& r) + { + state_ = r.state_; + r.state_ = 0; + return *this; + } +#else // _LIBCPP_MOVE + operator std::__rv<Deleter>() {return std::__rv<Deleter>(*this);} + Deleter(std::__rv<Deleter> r) : state_(r->state_) {r->state_ = 0;} + Deleter& operator=(std::__rv<Deleter> r) + { + state_ = r->state_; + r->state_ = 0; + return *this; + } +#endif // _LIBCPP_MOVE + + Deleter() : state_(0) {} + explicit Deleter(int s) : state_(s) {} + ~Deleter() {assert(state_ >= 0); state_ = -1;} + +#ifdef _LIBCPP_MOVE + template <class U> + Deleter(Deleter<U>&& d, + typename std::enable_if<!std::is_same<U, T>::value>::type* = 0) + : state_(d.state()) {d.set_state(0);} + +private: + template <class U> + Deleter(const Deleter<U>& d, + typename std::enable_if<!std::is_same<U, T>::value>::type* = 0); +#else // _LIBCPP_MOVE + template <class U> + Deleter(Deleter<U> d, + typename std::enable_if<!std::is_same<U, T>::value>::type* = 0) + : state_(d.state()) {} +#endif // _LIBCPP_MOVE +public: + int state() const {return state_;} + void set_state(int i) {state_ = i;} + + void operator()(T* p) {delete p;} +}; + +template <class T> +class Deleter<T[]> +{ + int state_; + +#ifdef _LIBCPP_MOVE + Deleter(const Deleter&); + Deleter& operator=(const Deleter&); +#else // _LIBCPP_MOVE + Deleter(Deleter&); + Deleter& operator=(Deleter&); +#endif // _LIBCPP_MOVE + +public: +#ifdef _LIBCPP_MOVE + Deleter(Deleter&& r) : state_(r.state_) {r.state_ = 0;} + Deleter& operator=(Deleter&& r) + { + state_ = r.state_; + r.state_ = 0; + return *this; + } +#else // _LIBCPP_MOVE + operator std::__rv<Deleter>() {return std::__rv<Deleter>(*this);} + Deleter(std::__rv<Deleter> r) : state_(r->state_) {r->state_ = 0;} + Deleter& operator=(std::__rv<Deleter> r) + { + state_ = r->state_; + r->state_ = 0; + return *this; + } +#endif // _LIBCPP_MOVE + + Deleter() : state_(0) {} + explicit Deleter(int s) : state_(s) {} + ~Deleter() {assert(state_ >= 0); state_ = -1;} + + int state() const {return state_;} + void set_state(int i) {state_ = i;} + + void operator()(T* p) {delete [] p;} +}; + +template <class T> +void +swap(Deleter<T>& x, Deleter<T>& y) +{ + Deleter<T> t(std::move(x)); + x = std::move(y); + y = std::move(t); +} + +template <class T> +class CDeleter +{ + int state_; + +public: + + CDeleter() : state_(0) {} + explicit CDeleter(int s) : state_(s) {} + ~CDeleter() {assert(state_ >= 0); state_ = -1;} + + template <class U> + CDeleter(const CDeleter<U>& d) + : state_(d.state()) {} + + int state() const {return state_;} + void set_state(int i) {state_ = i;} + + void operator()(T* p) {delete p;} +}; + +template <class T> +class CDeleter<T[]> +{ + int state_; + +public: + + CDeleter() : state_(0) {} + explicit CDeleter(int s) : state_(s) {} + ~CDeleter() {assert(state_ >= 0); state_ = -1;} + + int state() const {return state_;} + void set_state(int i) {state_ = i;} + + void operator()(T* p) {delete [] p;} +}; + +template <class T> +void +swap(CDeleter<T>& x, CDeleter<T>& y) +{ + CDeleter<T> t(std::move(x)); + x = std::move(y); + y = std::move(t); +} + +#endif // DELETER_H diff --git a/libcxx/test/utilities/memory/unique.ptr/nothing_to_do.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/nothing_to_do.pass.cpp index e8db90cbee0..b89f168e9c4 100644 --- a/libcxx/test/utilities/memory/unique.ptr/nothing_to_do.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/nothing_to_do.pass.cpp @@ -1 +1,12 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
int main()
{
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.dltr/nothing_to_do.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.dltr/nothing_to_do.pass.cpp index e8db90cbee0..b89f168e9c4 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.dltr/nothing_to_do.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.dltr/nothing_to_do.pass.cpp @@ -1 +1,12 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
int main()
{
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt/convert_ctor.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt/convert_ctor.pass.cpp index c96b5b980ba..ac9b3741f25 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt/convert_ctor.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt/convert_ctor.pass.cpp @@ -1 +1,48 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// default_delete
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
int main()
{
std::default_delete<B> d2;
std::default_delete<A> d1 = d2;
A* p = new B;
assert(A::count == 1);
assert(B::count == 1);
d1(p);
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// default_delete + +#include <memory> +#include <cassert> + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +int main() +{ + std::default_delete<B> d2; + std::default_delete<A> d1 = d2; + A* p = new B; + assert(A::count == 1); + assert(B::count == 1); + d1(p); + assert(A::count == 0); + assert(B::count == 0); +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt/default.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt/default.pass.cpp index 5f033a36893..e7b1013f06b 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt/default.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt/default.pass.cpp @@ -1 +1,34 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// default_delete
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
std::default_delete<A> d;
A* p = new A;
assert(A::count == 1);
d(p);
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// default_delete + +#include <memory> +#include <cassert> + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +int main() +{ + std::default_delete<A> d; + A* p = new A; + assert(A::count == 1); + d(p); + assert(A::count == 0); +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt/incomplete.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt/incomplete.fail.cpp index a1662526860..a7a3beab0a4 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt/incomplete.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt/incomplete.fail.cpp @@ -1 +1,26 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// default_delete
// Test that default_delete's operator() requires a complete type
#include <memory>
#include <cassert>
struct A;
int main()
{
std::default_delete<A> d;
A* p = 0;
d(p);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// default_delete + +// Test that default_delete's operator() requires a complete type + +#include <memory> +#include <cassert> + +struct A; + +int main() +{ + std::default_delete<A> d; + A* p = 0; + d(p); +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt1/convert_ctor.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt1/convert_ctor.fail.cpp index e1248de8712..edb1dd84d8c 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt1/convert_ctor.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt1/convert_ctor.fail.cpp @@ -1 +1,32 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// default_delete
// Test that default_delete<T[]> does not have a working converting constructor
#include <memory>
#include <cassert>
struct A
{
};
struct B
: public A
{
};
int main()
{
std::default_delete<B[]> d2;
std::default_delete<A[]> d1 = d2;
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// default_delete + +// Test that default_delete<T[]> does not have a working converting constructor + +#include <memory> +#include <cassert> + +struct A +{ +}; + +struct B + : public A +{ +}; + +int main() +{ + std::default_delete<B[]> d2; + std::default_delete<A[]> d1 = d2; +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt1/default.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt1/default.pass.cpp index 1b41e961912..1b11d6a2512 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt1/default.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt1/default.pass.cpp @@ -1 +1,36 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// default_delete
// Test that default_delete<T[]> has a working default constructor
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
std::default_delete<A[]> d;
A* p = new A[3];
assert(A::count == 3);
d(p);
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// default_delete + +// Test that default_delete<T[]> has a working default constructor + +#include <memory> +#include <cassert> + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +int main() +{ + std::default_delete<A[]> d; + A* p = new A[3]; + assert(A::count == 3); + d(p); + assert(A::count == 0); +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt1/incomplete.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt1/incomplete.fail.cpp index 6fcb94c5637..b01a1dd6c1d 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt1/incomplete.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt1/incomplete.fail.cpp @@ -1 +1,26 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// default_delete
// Test that default_delete<T[]>'s operator() requires a complete type
#include <memory>
#include <cassert>
struct A;
int main()
{
std::default_delete<A[]> d;
A* p = 0;
d(p);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// default_delete + +// Test that default_delete<T[]>'s operator() requires a complete type + +#include <memory> +#include <cassert> + +struct A; + +int main() +{ + std::default_delete<A[]> d; + A* p = 0; + d(p); +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.general/nothing_to_do.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.general/nothing_to_do.pass.cpp index e8db90cbee0..b89f168e9c4 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.general/nothing_to_do.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.general/nothing_to_do.pass.cpp @@ -1 +1,12 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
int main()
{
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/move01.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/move01.fail.cpp index 6360686f745..cb123994aa4 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/move01.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/move01.fail.cpp @@ -1 +1,38 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr move assignment
#include <memory>
#include <cassert>
// Can't copy from lvalue
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
std::unique_ptr<A> s(new A);
std::unique_ptr<A> s2;
s2 = s;
}
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr move assignment + +#include <memory> +#include <cassert> + +// Can't copy from lvalue + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +int main() +{ + { + std::unique_ptr<A> s(new A); + std::unique_ptr<A> s2; + s2 = s; + } +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/move01.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/move01.pass.cpp index dfd6a7136ae..0a9a63be405 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/move01.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/move01.pass.cpp @@ -1 +1,78 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr move assignment
// test move assignment. Should only require a MoveConstructible deleter, or if
// deleter is a reference, not even that.
#include <memory>
#include <cassert>
#include "../deleter.h"
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
std::unique_ptr<A[]> s1(new A[3]);
A* p = s1.get();
assert(A::count == 3);
std::unique_ptr<A[]> s2(new A[2]);
assert(A::count == 5);
s2 = std::move(s1);
assert(A::count == 3);
assert(s2.get() == p);
assert(s1.get() == 0);
}
assert(A::count == 0);
{
std::unique_ptr<A[], Deleter<A[]> > s1(new A[4], Deleter<A[]>(5));
A* p = s1.get();
assert(A::count == 4);
std::unique_ptr<A[], Deleter<A[]> > s2(new A[5]);
assert(A::count == 9);
s2 = std::move(s1);
assert(s2.get() == p);
assert(s1.get() == 0);
assert(A::count == 4);
assert(s2.get_deleter().state() == 5);
assert(s1.get_deleter().state() == 0);
}
assert(A::count == 0);
{
CDeleter<A[]> d1(5);
std::unique_ptr<A[], CDeleter<A[]>&> s1(new A[6], d1);
A* p = s1.get();
assert(A::count == 6);
CDeleter<A[]> d2(6);
std::unique_ptr<A[], CDeleter<A[]>&> s2(new A[3], d2);
assert(A::count == 9);
s2 = std::move(s1);
assert(A::count == 6);
assert(s2.get() == p);
assert(s1.get() == 0);
assert(d1.state() == 5);
assert(d2.state() == 5);
}
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr move assignment + +// test move assignment. Should only require a MoveConstructible deleter, or if +// deleter is a reference, not even that. + +#include <memory> +#include <cassert> + +#include "../deleter.h" + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +int main() +{ + { + std::unique_ptr<A[]> s1(new A[3]); + A* p = s1.get(); + assert(A::count == 3); + std::unique_ptr<A[]> s2(new A[2]); + assert(A::count == 5); + s2 = std::move(s1); + assert(A::count == 3); + assert(s2.get() == p); + assert(s1.get() == 0); + } + assert(A::count == 0); + { + std::unique_ptr<A[], Deleter<A[]> > s1(new A[4], Deleter<A[]>(5)); + A* p = s1.get(); + assert(A::count == 4); + std::unique_ptr<A[], Deleter<A[]> > s2(new A[5]); + assert(A::count == 9); + s2 = std::move(s1); + assert(s2.get() == p); + assert(s1.get() == 0); + assert(A::count == 4); + assert(s2.get_deleter().state() == 5); + assert(s1.get_deleter().state() == 0); + } + assert(A::count == 0); + { + CDeleter<A[]> d1(5); + std::unique_ptr<A[], CDeleter<A[]>&> s1(new A[6], d1); + A* p = s1.get(); + assert(A::count == 6); + CDeleter<A[]> d2(6); + std::unique_ptr<A[], CDeleter<A[]>&> s2(new A[3], d2); + assert(A::count == 9); + s2 = std::move(s1); + assert(A::count == 6); + assert(s2.get() == p); + assert(s1.get() == 0); + assert(d1.state() == 5); + assert(d2.state() == 5); + } + assert(A::count == 0); +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/move02.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/move02.fail.cpp index 5e1e5f81483..d343716c741 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/move02.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/move02.fail.cpp @@ -1 +1,38 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr move assignment
#include <memory>
#include <cassert>
// Can't copy from const lvalue
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
const std::unique_ptr<A[]> s(new A[3]);
std::unique_ptr<A[]> s2;
s2 = s;
}
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr move assignment + +#include <memory> +#include <cassert> + +// Can't copy from const lvalue + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +int main() +{ + { + const std::unique_ptr<A[]> s(new A[3]); + std::unique_ptr<A[]> s2; + s2 = s; + } +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/move03.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/move03.fail.cpp index 594704f2a83..53f93869b4d 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/move03.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/move03.fail.cpp @@ -1 +1,56 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr move assignment
#include <memory>
#include <cassert>
// Can't copy from lvalue
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
class Deleter
{
int state_;
public:
Deleter() : state_(5) {}
int state() const {return state_;}
void operator()(A* p) {delete p;}
};
int main()
{
{
std::unique_ptr<A, Deleter> s(new A);
A* p = s.get();
std::unique_ptr<A, Deleter> s2;
s2 = s;
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
}
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr move assignment + +#include <memory> +#include <cassert> + +// Can't copy from lvalue + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +class Deleter +{ + int state_; + +public: + + Deleter() : state_(5) {} + + int state() const {return state_;} + + void operator()(A* p) {delete p;} +}; + +int main() +{ + { + std::unique_ptr<A, Deleter> s(new A); + A* p = s.get(); + std::unique_ptr<A, Deleter> s2; + s2 = s; + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + } + assert(A::count == 0); +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/move04.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/move04.fail.cpp index 89267738d13..0f0c17682a4 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/move04.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/move04.fail.cpp @@ -1 +1,56 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr move ctor
#include <memory>
#include <cassert>
// test move ctor. Can't copy from const lvalue
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
class Deleter
{
int state_;
public:
Deleter() : state_(5) {}
int state() const {return state_;}
void operator()(A* p) {delete p;}
};
int main()
{
{
const std::unique_ptr<A, Deleter> s(new A);
A* p = s.get();
std::unique_ptr<A, Deleter> s2;
s2 = s;
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
}
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr move ctor + +#include <memory> +#include <cassert> + +// test move ctor. Can't copy from const lvalue + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +class Deleter +{ + int state_; + +public: + + Deleter() : state_(5) {} + + int state() const {return state_;} + + void operator()(A* p) {delete p;} +}; + +int main() +{ + { + const std::unique_ptr<A, Deleter> s(new A); + A* p = s.get(); + std::unique_ptr<A, Deleter> s2; + s2 = s; + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + } + assert(A::count == 0); +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert01.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert01.fail.cpp index 45196b630fb..f2792b98833 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert01.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert01.fail.cpp @@ -1 +1,56 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move assignment
#include <memory>
#include <cassert>
// Can't assign from lvalue
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
int main()
{
{
std::unique_ptr<B[]> s(new B);
A* p = s.get();
std::unique_ptr<A[]> s2;
s2 = s;
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr converting move assignment + +#include <memory> +#include <cassert> + +// Can't assign from lvalue + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +int main() +{ + { + std::unique_ptr<B[]> s(new B); + A* p = s.get(); + std::unique_ptr<A[]> s2; + s2 = s; + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + assert(B::count == 1); + } + assert(A::count == 0); + assert(B::count == 0); +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert02.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert02.fail.cpp index 9831ab2283b..e7f64f409a0 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert02.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert02.fail.cpp @@ -1 +1,60 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move assignment
// Can't assign from lvalue
#include <memory>
#include <cassert>
#include "../deleter.h"
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
int main()
{
{
boost::unique_ptr<B[], Deleter<B> > s(new B);
A* p = s.get();
boost::unique_ptr<A[], Deleter<A> > s2;
s2 = s;
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
assert(s2.get_deleter().state() == 5);
assert(s.get_deleter().state() == 0);
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr converting move assignment + +// Can't assign from lvalue + +#include <memory> +#include <cassert> + +#include "../deleter.h" + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +int main() +{ + { + boost::unique_ptr<B[], Deleter<B> > s(new B); + A* p = s.get(); + boost::unique_ptr<A[], Deleter<A> > s2; + s2 = s; + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + assert(B::count == 1); + assert(s2.get_deleter().state() == 5); + assert(s.get_deleter().state() == 0); + } + assert(A::count == 0); + assert(B::count == 0); +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert03.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert03.fail.cpp index 67e5f36435d..c408e4be07b 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert03.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert03.fail.cpp @@ -1 +1,61 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move assignment
// Can't assign from lvalue
#include <memory>
#include <cassert>
#include "../deleter.h"
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
int main()
{
{
Deleter<B> db(5);
boost::unique_ptr<B[], Deleter<B>&> s(new B, db);
A* p = s.get();
Deleter<A> da(6);
boost::unique_ptr<A[], Deleter<A>&> s2(new A, da);
s2 = s;
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
assert(s2.get_deleter().state() == 5);
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr converting move assignment + +// Can't assign from lvalue + +#include <memory> +#include <cassert> + +#include "../deleter.h" + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +int main() +{ + { + Deleter<B> db(5); + boost::unique_ptr<B[], Deleter<B>&> s(new B, db); + A* p = s.get(); + Deleter<A> da(6); + boost::unique_ptr<A[], Deleter<A>&> s2(new A, da); + s2 = s; + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + assert(B::count == 1); + assert(s2.get_deleter().state() == 5); + } + assert(A::count == 0); + assert(B::count == 0); +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert04.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert04.fail.cpp index 64aff20ef4a..b0e2a53d941 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert04.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert04.fail.cpp @@ -1 +1,56 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move assignment
#include <memory>
#include <cassert>
// Can't assign from const lvalue
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
int main()
{
{
const boost::unique_ptr<B[]> s(new B);
A* p = s.get();
boost::unique_ptr<A[]> s2;
s2 = s;
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr converting move assignment + +#include <memory> +#include <cassert> + +// Can't assign from const lvalue + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +int main() +{ + { + const boost::unique_ptr<B[]> s(new B); + A* p = s.get(); + boost::unique_ptr<A[]> s2; + s2 = s; + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + assert(B::count == 1); + } + assert(A::count == 0); + assert(B::count == 0); +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert05.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert05.fail.cpp index 96ef756e099..4bcd542126a 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert05.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert05.fail.cpp @@ -1 +1,60 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move assignment
// Can't assign from const lvalue
#include <memory>
#include <cassert>
#include "../deleter.h"
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
int main()
{
{
const boost::unique_ptr<B[], Deleter<B> > s(new B);
A* p = s.get();
boost::unique_ptr<A[], Deleter<A> > s2;
s2 = s;
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
assert(s2.get_deleter().state() == 5);
assert(s.get_deleter().state() == 0);
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr converting move assignment + +// Can't assign from const lvalue + +#include <memory> +#include <cassert> + +#include "../deleter.h" + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +int main() +{ + { + const boost::unique_ptr<B[], Deleter<B> > s(new B); + A* p = s.get(); + boost::unique_ptr<A[], Deleter<A> > s2; + s2 = s; + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + assert(B::count == 1); + assert(s2.get_deleter().state() == 5); + assert(s.get_deleter().state() == 0); + } + assert(A::count == 0); + assert(B::count == 0); +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert06.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert06.fail.cpp index 5ecec761ae4..bf2090a6175 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert06.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert06.fail.cpp @@ -1 +1,61 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move assignment
// Can't assign from const lvalue
#include <memory>
#include <cassert>
#include "../deleter.h"
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
int main()
{
{
Deleter<B> db(5);
const boost::unique_ptr<B[], Deleter<B>&> s(new B, db);
A* p = s.get();
Deleter<A> da(6);
boost::unique_ptr<A[], Deleter<A>&> s2(new A, da);
s2 = s;
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
assert(s2.get_deleter().state() == 5);
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr converting move assignment + +// Can't assign from const lvalue + +#include <memory> +#include <cassert> + +#include "../deleter.h" + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +int main() +{ + { + Deleter<B> db(5); + const boost::unique_ptr<B[], Deleter<B>&> s(new B, db); + A* p = s.get(); + Deleter<A> da(6); + boost::unique_ptr<A[], Deleter<A>&> s2(new A, da); + s2 = s; + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + assert(B::count == 1); + assert(s2.get_deleter().state() == 5); + } + assert(A::count == 0); + assert(B::count == 0); +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert07.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert07.fail.cpp index 5e959134c66..7d523ea849d 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert07.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert07.fail.cpp @@ -1 +1,55 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move assignment
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
int main()
{
{
boost::unique_ptr<B[]> s(new B);
A* p = s.get();
boost::unique_ptr<A[]> s2(new A);
assert(A::count == 2);
s2 = boost::move(s);
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr converting move assignment + +#include <memory> +#include <cassert> + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +int main() +{ + { + boost::unique_ptr<B[]> s(new B); + A* p = s.get(); + boost::unique_ptr<A[]> s2(new A); + assert(A::count == 2); + s2 = boost::move(s); + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + assert(B::count == 1); + } + assert(A::count == 0); + assert(B::count == 0); +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert08.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert08.fail.cpp index e408aae3f9d..8d90354d3dd 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert08.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert08.fail.cpp @@ -1 +1,59 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move assignment
#include <memory>
#include <cassert>
#include "../deleter.h"
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
int main()
{
{
boost::unique_ptr<B[], Deleter<B> > s(new B);
A* p = s.get();
boost::unique_ptr<A[], Deleter<A> > s2(new A);
assert(A::count == 2);
s2 = (boost::move(s));
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
assert(s2.get_deleter().state() == 5);
assert(s.get_deleter().state() == 0);
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr converting move assignment + +#include <memory> +#include <cassert> + +#include "../deleter.h" + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +int main() +{ + { + boost::unique_ptr<B[], Deleter<B> > s(new B); + A* p = s.get(); + boost::unique_ptr<A[], Deleter<A> > s2(new A); + assert(A::count == 2); + s2 = (boost::move(s)); + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + assert(B::count == 1); + assert(s2.get_deleter().state() == 5); + assert(s.get_deleter().state() == 0); + } + assert(A::count == 0); + assert(B::count == 0); +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert09.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert09.fail.cpp index a1328d62a6f..1f170d110f6 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert09.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert09.fail.cpp @@ -1 +1,61 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move assignment
// test converting move assignment with reference deleters
#include <memory>
#include <cassert>
#include "../deleter.h"
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
int main()
{
{
Deleter<B> db(5);
boost::unique_ptr<B[], Deleter<B>&> s(new B, db);
A* p = s.get();
Deleter<A> da(6);
boost::unique_ptr<A[], Deleter<A>&> s2(new A, da);
s2 = boost::move(s);
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
assert(s2.get_deleter().state() == 5);
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr converting move assignment + +// test converting move assignment with reference deleters + +#include <memory> +#include <cassert> + +#include "../deleter.h" + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +int main() +{ + { + Deleter<B> db(5); + boost::unique_ptr<B[], Deleter<B>&> s(new B, db); + A* p = s.get(); + Deleter<A> da(6); + boost::unique_ptr<A[], Deleter<A>&> s2(new A, da); + s2 = boost::move(s); + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + assert(B::count == 1); + assert(s2.get_deleter().state() == 5); + } + assert(A::count == 0); + assert(B::count == 0); +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/null_asgn.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/null_asgn.pass.cpp index da5d287e4c7..7f328176189 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/null_asgn.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/null_asgn.pass.cpp @@ -1 +1,41 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr move assignment
#include <memory>
#include <cassert>
// test assignment from null
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
std::unique_ptr<A> s2(new A);
assert(A::count == 1);
s2 = 0;
assert(A::count == 0);
assert(s2.get() == 0);
}
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr move assignment + +#include <memory> +#include <cassert> + +// test assignment from null + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +int main() +{ + { + std::unique_ptr<A> s2(new A); + assert(A::count == 1); + s2 = 0; + assert(A::count == 0); + assert(s2.get() == 0); + } + assert(A::count == 0); +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/null_ctor.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/null_ctor.pass.cpp index 31248d50912..d86b812b30f 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/null_ctor.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/null_ctor.pass.cpp @@ -1 +1,44 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// The deleter is not called if get() == 0
#include <memory>
#include <cassert>
class Deleter
{
int state_;
Deleter(Deleter&);
Deleter& operator=(Deleter&);
public:
Deleter() : state_(0) {}
int state() const {return state_;}
void operator()(void*) {++state_;}
};
int main()
{
Deleter d;
assert(d.state() == 0);
{
std::unique_ptr<int[], Deleter&> p(0, d);
assert(p.get() == 0);
assert(&p.get_deleter() == &d);
}
assert(d.state() == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// The deleter is not called if get() == 0 + +#include <memory> +#include <cassert> + +class Deleter +{ + int state_; + + Deleter(Deleter&); + Deleter& operator=(Deleter&); + +public: + Deleter() : state_(0) {} + + int state() const {return state_;} + + void operator()(void*) {++state_;} +}; + +int main() +{ + Deleter d; + assert(d.state() == 0); + { + std::unique_ptr<int[], Deleter&> p(0, d); + assert(p.get() == 0); + assert(&p.get_deleter() == &d); + } + assert(d.state() == 0); +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/nullptr_asgn.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/nullptr_asgn.pass.cpp index a168fdc01ca..1f6d406784b 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/nullptr_asgn.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/nullptr_asgn.pass.cpp @@ -1 +1,41 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr move assignment
#include <memory>
#include <cassert>
// test assignment from null
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
std::unique_ptr<A[]> s2(new A[3]);
assert(A::count == 3);
s2 = nullptr;
assert(A::count == 0);
assert(s2.get() == 0);
}
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr move assignment + +#include <memory> +#include <cassert> + +// test assignment from null + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +int main() +{ + { + std::unique_ptr<A[]> s2(new A[3]); + assert(A::count == 3); + s2 = nullptr; + assert(A::count == 0); + assert(s2.get() == 0); + } + assert(A::count == 0); +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/pointer_type.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/pointer_type.pass.cpp index 690237e5833..d4bfb8fab5f 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/pointer_type.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/pointer_type.pass.cpp @@ -1 +1,34 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr<T[]>::pointer type
#include <memory>
#include <type_traits>
struct Deleter
{
struct pointer {};
};
int main()
{
{
typedef std::unique_ptr<int[]> P;
static_assert((std::is_same<P::pointer, int*>::value), "");
}
{
typedef std::unique_ptr<int[], Deleter> P;
static_assert((std::is_same<P::pointer, Deleter::pointer>::value), "");
}
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr<T[]>::pointer type + +#include <memory> +#include <type_traits> + +struct Deleter +{ + struct pointer {}; +}; + +int main() +{ + { + typedef std::unique_ptr<int[]> P; + static_assert((std::is_same<P::pointer, int*>::value), ""); + } + { + typedef std::unique_ptr<int[], Deleter> P; + static_assert((std::is_same<P::pointer, Deleter::pointer>::value), ""); + } +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/default01.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/default01.fail.cpp index 4a8c0915405..a748150b65f 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/default01.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/default01.fail.cpp @@ -1 +1,36 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr default ctor
// default unique_ptr ctor should require default Deleter ctor
#include <memory>
class Deleter
{
Deleter() {}
public:
Deleter(Deleter&) {}
Deleter& operator=(Deleter&) {}
void operator()(void*) const {}
};
int main()
{
std::unique_ptr<int[], Deleter> p;
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr default ctor + +// default unique_ptr ctor should require default Deleter ctor + +#include <memory> + +class Deleter +{ + + Deleter() {} + +public: + + Deleter(Deleter&) {} + Deleter& operator=(Deleter&) {} + + void operator()(void*) const {} +}; + +int main() +{ + std::unique_ptr<int[], Deleter> p; +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/default01.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/default01.pass.cpp index 280cfd235d6..fa37e3da07d 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/default01.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/default01.pass.cpp @@ -1 +1,47 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr default ctor
// default unique_ptr ctor should only require default Deleter ctor
#include <memory>
#include <cassert>
class Deleter
{
int state_;
Deleter(Deleter&);
Deleter& operator=(Deleter&);
public:
Deleter() : state_(5) {}
int state() const {return state_;}
void operator()(void*) {}
};
int main()
{
{
std::unique_ptr<int[]> p;
assert(p.get() == 0);
}
{
std::unique_ptr<int[], Deleter> p;
assert(p.get() == 0);
assert(p.get_deleter().state() == 5);
}
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr default ctor + +// default unique_ptr ctor should only require default Deleter ctor + +#include <memory> +#include <cassert> + +class Deleter +{ + int state_; + + Deleter(Deleter&); + Deleter& operator=(Deleter&); + +public: + Deleter() : state_(5) {} + + int state() const {return state_;} + + void operator()(void*) {} +}; + +int main() +{ + { + std::unique_ptr<int[]> p; + assert(p.get() == 0); + } + { + std::unique_ptr<int[], Deleter> p; + assert(p.get() == 0); + assert(p.get_deleter().state() == 5); + } +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/default02.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/default02.fail.cpp index b94f9b9c24d..623df931a74 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/default02.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/default02.fail.cpp @@ -1 +1,30 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr default ctor
// default unique_ptr ctor should require non-reference Deleter ctor
#include <memory>
class Deleter
{
public:
void operator()(void*) {}
};
int main()
{
std::unique_ptr<int[], Deleter&> p;
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr default ctor + +// default unique_ptr ctor should require non-reference Deleter ctor + +#include <memory> + +class Deleter +{ +public: + + void operator()(void*) {} +}; + +int main() +{ + std::unique_ptr<int[], Deleter&> p; +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/default02.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/default02.pass.cpp index 41d143996af..98800cc40ac 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/default02.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/default02.pass.cpp @@ -1 +1,87 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test default unique_ptr<T[]> ctor
// default unique_ptr<T[]> ctor shouldn't require complete type
#include <memory>
#include <cassert>
struct A;
class Deleter
{
int state_;
Deleter(Deleter&);
Deleter& operator=(Deleter&);
public:
Deleter() : state_(5) {}
int state() const {return state_;}
void operator()(A* p);
};
void check(int i);
template <class D = std::default_delete<A> >
struct B
{
std::unique_ptr<A[], D> a_;
B();
~B();
A* get() const {return a_.get();}
D& get_deleter() {return a_.get_deleter();}
};
int main()
{
{
B<> s;
assert(s.get() == 0);
}
check(0);
{
B<Deleter> s;
assert(s.get() == 0);
assert(s.get_deleter().state() == 5);
}
check(0);
}
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
void Deleter::operator()(A* p) {delete p;}
void check(int i)
{
assert(A::count == i);
}
template <class D>
B<D>::B() {}
template <class D>
B<D>::~B() {}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test default unique_ptr<T[]> ctor + +// default unique_ptr<T[]> ctor shouldn't require complete type + +#include <memory> +#include <cassert> + +struct A; + +class Deleter +{ + int state_; + + Deleter(Deleter&); + Deleter& operator=(Deleter&); + +public: + Deleter() : state_(5) {} + + int state() const {return state_;} + + void operator()(A* p); +}; + +void check(int i); + +template <class D = std::default_delete<A> > +struct B +{ + std::unique_ptr<A[], D> a_; + B(); + ~B(); + + A* get() const {return a_.get();} + D& get_deleter() {return a_.get_deleter();} +}; + +int main() +{ + { + B<> s; + assert(s.get() == 0); + } + check(0); + { + B<Deleter> s; + assert(s.get() == 0); + assert(s.get_deleter().state() == 5); + } + check(0); +} + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +void Deleter::operator()(A* p) {delete p;} + +void check(int i) +{ + assert(A::count == i); +} + +template <class D> +B<D>::B() {} + +template <class D> +B<D>::~B() {} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/default03.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/default03.fail.cpp index dfa0434ee70..5ab1bbea6b9 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/default03.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/default03.fail.cpp @@ -1 +1,23 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr default ctor
// default unique_ptr ctor should require non-pointer Deleter
#include <memory>
int main()
{
std::unique_ptr<int[], void (*)(void*)> p;
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr default ctor + +// default unique_ptr ctor should require non-pointer Deleter + +#include <memory> + +int main() +{ + std::unique_ptr<int[], void (*)(void*)> p; +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move01.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move01.fail.cpp index b9c23628c79..14f89e317b3 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move01.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move01.fail.cpp @@ -1 +1,42 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr move ctor
#include <memory>
#include <cassert>
// test move ctor. Can't copy from lvalue
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
std::unique_ptr<A[]> s(new A[3]);
A* p = s.get();
std::unique_ptr<A[]> s2 = s;
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
}
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr move ctor + +#include <memory> +#include <cassert> + +// test move ctor. Can't copy from lvalue + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +int main() +{ + { + std::unique_ptr<A[]> s(new A[3]); + A* p = s.get(); + std::unique_ptr<A[]> s2 = s; + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + } + assert(A::count == 0); +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move01.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move01.pass.cpp index f58b18f90dd..661fdab314b 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move01.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move01.pass.cpp @@ -1 +1,85 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr move ctor
// test move ctor. Should only require a MoveConstructible deleter, or if
// deleter is a reference, not even that.
#include <memory>
#include <cassert>
#include "../../deleter.h"
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
class NCDeleter
{
int state_;
NCDeleter(NCDeleter&);
NCDeleter& operator=(NCDeleter&);
public:
NCDeleter() : state_(5) {}
int state() const {return state_;}
void set_state(int s) {state_ = s;}
void operator()(A* p) {delete [] p;}
};
int main()
{
{
std::unique_ptr<A[]> s(new A[3]);
A* p = s.get();
std::unique_ptr<A[]> s2 = std::move(s);
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 3);
}
assert(A::count == 0);
{
std::unique_ptr<A[], Deleter<A[]> > s(new A[3], Deleter<A[]>(5));
A* p = s.get();
std::unique_ptr<A[], Deleter<A[]> > s2 = std::move(s);
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 3);
assert(s2.get_deleter().state() == 5);
assert(s.get_deleter().state() == 0);
}
assert(A::count == 0);
{
NCDeleter d;
std::unique_ptr<A[], NCDeleter&> s(new A[3], d);
A* p = s.get();
std::unique_ptr<A[], NCDeleter&> s2 = std::move(s);
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 3);
d.set_state(6);
assert(s2.get_deleter().state() == d.state());
assert(s.get_deleter().state() == d.state());
}
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr move ctor + +// test move ctor. Should only require a MoveConstructible deleter, or if +// deleter is a reference, not even that. + +#include <memory> +#include <cassert> + +#include "../../deleter.h" + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +class NCDeleter +{ + int state_; + + NCDeleter(NCDeleter&); + NCDeleter& operator=(NCDeleter&); +public: + + NCDeleter() : state_(5) {} + + int state() const {return state_;} + void set_state(int s) {state_ = s;} + + void operator()(A* p) {delete [] p;} +}; + +int main() +{ + { + std::unique_ptr<A[]> s(new A[3]); + A* p = s.get(); + std::unique_ptr<A[]> s2 = std::move(s); + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 3); + } + assert(A::count == 0); + { + std::unique_ptr<A[], Deleter<A[]> > s(new A[3], Deleter<A[]>(5)); + A* p = s.get(); + std::unique_ptr<A[], Deleter<A[]> > s2 = std::move(s); + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 3); + assert(s2.get_deleter().state() == 5); + assert(s.get_deleter().state() == 0); + } + assert(A::count == 0); + { + NCDeleter d; + std::unique_ptr<A[], NCDeleter&> s(new A[3], d); + A* p = s.get(); + std::unique_ptr<A[], NCDeleter&> s2 = std::move(s); + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 3); + d.set_state(6); + assert(s2.get_deleter().state() == d.state()); + assert(s.get_deleter().state() == d.state()); + } + assert(A::count == 0); +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move02.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move02.fail.cpp index 9d387d97a01..8299de7e933 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move02.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move02.fail.cpp @@ -1 +1,42 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr move ctor
// test move ctor. Can't copy from const lvalue
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
const std::unique_ptr<A[]> s(new A[3]);
A* p = s.get();
std::unique_ptr<A[]> s2 = s;
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
}
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr move ctor + +// test move ctor. Can't copy from const lvalue + +#include <memory> +#include <cassert> + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +int main() +{ + { + const std::unique_ptr<A[]> s(new A[3]); + A* p = s.get(); + std::unique_ptr<A[]> s2 = s; + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + } + assert(A::count == 0); +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move02.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move02.pass.cpp index 0cf6da30b3f..6a89015d972 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move02.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move02.pass.cpp @@ -1 +1,87 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr move ctor
// test move ctor. Should only require a MoveConstructible deleter, or if
// deleter is a reference, not even that.
#include <memory>
#include <cassert>
#include "../../deleter.h"
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
class NCDeleter
{
int state_;
NCDeleter(NCDeleter&);
NCDeleter& operator=(NCDeleter&);
public:
NCDeleter() : state_(5) {}
int state() const {return state_;}
void set_state(int s) {state_ = s;}
void operator()(A* p) {delete [] p;}
};
std::unique_ptr<A[]>
source1()
{
return std::unique_ptr<A[]>(new A[3]);
}
void sink1(std::unique_ptr<A[]> p)
{
}
std::unique_ptr<A[], Deleter<A[]> >
source2()
{
return std::unique_ptr<A[], Deleter<A[]> >(new A[3]);
}
void sink2(std::unique_ptr<A[], Deleter<A[]> > p)
{
}
std::unique_ptr<A[], NCDeleter&>
source3()
{
static NCDeleter d;
return std::unique_ptr<A[], NCDeleter&>(new A[3], d);
}
void sink3(std::unique_ptr<A[], NCDeleter&> p)
{
}
int main()
{
sink1(source1());
sink2(source2());
sink3(source3());
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr move ctor + +// test move ctor. Should only require a MoveConstructible deleter, or if +// deleter is a reference, not even that. + +#include <memory> +#include <cassert> + +#include "../../deleter.h" + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +class NCDeleter +{ + int state_; + + NCDeleter(NCDeleter&); + NCDeleter& operator=(NCDeleter&); +public: + + NCDeleter() : state_(5) {} + + int state() const {return state_;} + void set_state(int s) {state_ = s;} + + void operator()(A* p) {delete [] p;} +}; + +std::unique_ptr<A[]> +source1() +{ + return std::unique_ptr<A[]>(new A[3]); +} + +void sink1(std::unique_ptr<A[]> p) +{ +} + +std::unique_ptr<A[], Deleter<A[]> > +source2() +{ + return std::unique_ptr<A[], Deleter<A[]> >(new A[3]); +} + +void sink2(std::unique_ptr<A[], Deleter<A[]> > p) +{ +} + +std::unique_ptr<A[], NCDeleter&> +source3() +{ + static NCDeleter d; + return std::unique_ptr<A[], NCDeleter&>(new A[3], d); +} + +void sink3(std::unique_ptr<A[], NCDeleter&> p) +{ +} + +int main() +{ + sink1(source1()); + sink2(source2()); + sink3(source3()); + assert(A::count == 0); +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move03.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move03.fail.cpp index d3df6146625..f63b7eb8b21 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move03.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move03.fail.cpp @@ -1 +1,55 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr move ctor
// test move ctor. Can't copy from lvalue
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
class Deleter
{
int state_;
public:
Deleter() : state_(5) {}
int state() const {return state_;}
void operator()(A* p) {delete [] p;}
};
int main()
{
{
std::unique_ptr<A[], Deleter> s(new A[3]);
A* p = s.get();
std::unique_ptr<A[], Deleter> s2 = s;
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
}
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr move ctor + +// test move ctor. Can't copy from lvalue + +#include <memory> +#include <cassert> + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +class Deleter +{ + int state_; + +public: + + Deleter() : state_(5) {} + + int state() const {return state_;} + + void operator()(A* p) {delete [] p;} +}; + +int main() +{ + { + std::unique_ptr<A[], Deleter> s(new A[3]); + A* p = s.get(); + std::unique_ptr<A[], Deleter> s2 = s; + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + } + assert(A::count == 0); +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move04.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move04.fail.cpp index 6d11937f567..5a601fd8290 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move04.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move04.fail.cpp @@ -1 +1,55 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr move ctor
// test move ctor. Can't copy from const lvalue
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
class Deleter
{
int state_;
public:
Deleter() : state_(5) {}
int state() const {return state_;}
void operator()(A* p) {delete [] p;}
};
int main()
{
{
const std::unique_ptr<A[], Deleter> s(new A[3]);
A* p = s.get();
std::unique_ptr<A[], Deleter> s2 = s;
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
}
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr move ctor + +// test move ctor. Can't copy from const lvalue + +#include <memory> +#include <cassert> + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +class Deleter +{ + int state_; + +public: + + Deleter() : state_(5) {} + + int state() const {return state_;} + + void operator()(A* p) {delete [] p;} +}; + +int main() +{ + { + const std::unique_ptr<A[], Deleter> s(new A[3]); + A* p = s.get(); + std::unique_ptr<A[], Deleter> s2 = s; + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + } + assert(A::count == 0); +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert01.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert01.fail.cpp index 9a580449fdd..05f8ce02416 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert01.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert01.fail.cpp @@ -1 +1,57 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move ctor
// test converting move ctor. Should only require a MoveConstructible deleter, or if
// deleter is a reference, not even that.
// Explicit version
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
int main()
{
{
std::unique_ptr<B[]> s(new B);
A* p = s.get();
std::unique_ptr<A[]> s2(s);
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr converting move ctor + +// test converting move ctor. Should only require a MoveConstructible deleter, or if +// deleter is a reference, not even that. +// Explicit version + +#include <memory> +#include <cassert> + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +int main() +{ + { + std::unique_ptr<B[]> s(new B); + A* p = s.get(); + std::unique_ptr<A[]> s2(s); + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + assert(B::count == 1); + } + assert(A::count == 0); + assert(B::count == 0); +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert02.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert02.fail.cpp index 86a2cf68ed6..0487804ded6 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert02.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert02.fail.cpp @@ -1 +1,61 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move ctor
// test converting move ctor. Should only require a MoveConstructible deleter, or if
// deleter is a reference, not even that.
// Explicit version
#include <memory>
#include <cassert>
#include "../../deleter.h"
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
int main()
{
{
std::unique_ptr<B[], Deleter<B[]> > s(new B);
A* p = s.get();
std::unique_ptr<A[], Deleter<A[]> > s2(s);
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
assert(s2.get_deleter().state() == 5);
assert(s.get_deleter().state() == 0);
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr converting move ctor + +// test converting move ctor. Should only require a MoveConstructible deleter, or if +// deleter is a reference, not even that. +// Explicit version + +#include <memory> +#include <cassert> + +#include "../../deleter.h" + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +int main() +{ + { + std::unique_ptr<B[], Deleter<B[]> > s(new B); + A* p = s.get(); + std::unique_ptr<A[], Deleter<A[]> > s2(s); + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + assert(B::count == 1); + assert(s2.get_deleter().state() == 5); + assert(s.get_deleter().state() == 0); + } + assert(A::count == 0); + assert(B::count == 0); +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert03.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert03.fail.cpp index 9822dc2b3ba..d5d330ad960 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert03.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert03.fail.cpp @@ -1 +1,78 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move ctor
// test converting move ctor. Should only require a MoveConstructible deleter, or if
// deleter is a reference, not even that.
// Explicit version
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
template <class T>
class CDeleter
{
int state_;
CDeleter(CDeleter&);
CDeleter& operator=(CDeleter&);
public:
CDeleter() : state_(5) {}
int state() const {return state_;}
void set_state(int s) {state_ = s;}
void operator()(T* p) {delete p;}
};
int main()
{
{
CDeleter<A> d;
std::unique_ptr<B[], CDeleter<A>&> s(new B, d);
A* p = s.get();
std::unique_ptr<A[], CDeleter<A>&> s2(s);
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
d.set_state(6);
assert(s2.get_deleter().state() == d.state());
assert(s.get_deleter().state() == d.state());
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr converting move ctor + +// test converting move ctor. Should only require a MoveConstructible deleter, or if +// deleter is a reference, not even that. +// Explicit version + +#include <memory> +#include <cassert> + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +template <class T> +class CDeleter +{ + int state_; + + CDeleter(CDeleter&); + CDeleter& operator=(CDeleter&); +public: + + CDeleter() : state_(5) {} + + int state() const {return state_;} + void set_state(int s) {state_ = s;} + + void operator()(T* p) {delete p;} +}; + +int main() +{ + { + CDeleter<A> d; + std::unique_ptr<B[], CDeleter<A>&> s(new B, d); + A* p = s.get(); + std::unique_ptr<A[], CDeleter<A>&> s2(s); + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + assert(B::count == 1); + d.set_state(6); + assert(s2.get_deleter().state() == d.state()); + assert(s.get_deleter().state() == d.state()); + } + assert(A::count == 0); + assert(B::count == 0); +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert04.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert04.fail.cpp index b0a9bc71075..b423386d31b 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert04.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert04.fail.cpp @@ -1 +1,57 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move ctor
// test converting move ctor. Should only require a MoveConstructible deleter, or if
// deleter is a reference, not even that.
// implicit version
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
int main()
{
{
std::unique_ptr<B[]> s(new B);
A* p = s.get();
std::unique_ptr<A[]> s2 = s;
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr converting move ctor + +// test converting move ctor. Should only require a MoveConstructible deleter, or if +// deleter is a reference, not even that. +// implicit version + +#include <memory> +#include <cassert> + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +int main() +{ + { + std::unique_ptr<B[]> s(new B); + A* p = s.get(); + std::unique_ptr<A[]> s2 = s; + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + assert(B::count == 1); + } + assert(A::count == 0); + assert(B::count == 0); +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert05.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert05.fail.cpp index 983d6c8c51d..d55aac8ba3a 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert05.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert05.fail.cpp @@ -1 +1,61 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move ctor
// test converting move ctor. Should only require a MoveConstructible deleter, or if
// deleter is a reference, not even that.
// Implicit version
#include <memory>
#include <cassert>
#include "../../deleter.h"
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
int main()
{
{
std::unique_ptr<B[], Deleter<B[]> > s(new B);
A* p = s.get();
std::unique_ptr<A[], Deleter<A[]> > s2 = s;
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
assert(s2.get_deleter().state() == 5);
assert(s.get_deleter().state() == 0);
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr converting move ctor + +// test converting move ctor. Should only require a MoveConstructible deleter, or if +// deleter is a reference, not even that. +// Implicit version + +#include <memory> +#include <cassert> + +#include "../../deleter.h" + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +int main() +{ + { + std::unique_ptr<B[], Deleter<B[]> > s(new B); + A* p = s.get(); + std::unique_ptr<A[], Deleter<A[]> > s2 = s; + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + assert(B::count == 1); + assert(s2.get_deleter().state() == 5); + assert(s.get_deleter().state() == 0); + } + assert(A::count == 0); + assert(B::count == 0); +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert06.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert06.fail.cpp index ae87cfe2f56..004e5d0a85c 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert06.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert06.fail.cpp @@ -1 +1,78 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move ctor
// test converting move ctor. Should only require a MoveConstructible deleter, or if
// deleter is a reference, not even that.
// Explicit version
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
template <class T>
class CDeleter
{
int state_;
CDeleter(CDeleter&);
CDeleter& operator=(CDeleter&);
public:
CDeleter() : state_(5) {}
int state() const {return state_;}
void set_state(int s) {state_ = s;}
void operator()(T* p) {delete p;}
};
int main()
{
{
CDeleter<A> d;
std::unique_ptr<B[], CDeleter<A>&> s(new B, d);
A* p = s.get();
std::unique_ptr<A[], CDeleter<A>&> s2 = s;
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
d.set_state(6);
assert(s2.get_deleter().state() == d.state());
assert(s.get_deleter().state() == d.state());
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr converting move ctor + +// test converting move ctor. Should only require a MoveConstructible deleter, or if +// deleter is a reference, not even that. +// Explicit version + +#include <memory> +#include <cassert> + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +template <class T> +class CDeleter +{ + int state_; + + CDeleter(CDeleter&); + CDeleter& operator=(CDeleter&); +public: + + CDeleter() : state_(5) {} + + int state() const {return state_;} + void set_state(int s) {state_ = s;} + + void operator()(T* p) {delete p;} +}; + +int main() +{ + { + CDeleter<A> d; + std::unique_ptr<B[], CDeleter<A>&> s(new B, d); + A* p = s.get(); + std::unique_ptr<A[], CDeleter<A>&> s2 = s; + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + assert(B::count == 1); + d.set_state(6); + assert(s2.get_deleter().state() == d.state()); + assert(s.get_deleter().state() == d.state()); + } + assert(A::count == 0); + assert(B::count == 0); +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert07.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert07.fail.cpp index ce5883a9ad6..164fa4a3aff 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert07.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert07.fail.cpp @@ -1 +1,57 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move ctor
// test converting move ctor. Should only require a MoveConstructible deleter, or if
// deleter is a reference, not even that.
// Explicit version
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
int main()
{
{
const std::unique_ptr<B[]> s(new B);
A* p = s.get();
std::unique_ptr<A[]> s2(s);
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr converting move ctor + +// test converting move ctor. Should only require a MoveConstructible deleter, or if +// deleter is a reference, not even that. +// Explicit version + +#include <memory> +#include <cassert> + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +int main() +{ + { + const std::unique_ptr<B[]> s(new B); + A* p = s.get(); + std::unique_ptr<A[]> s2(s); + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + assert(B::count == 1); + } + assert(A::count == 0); + assert(B::count == 0); +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert08.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert08.fail.cpp index 3203f29e82f..b3a9ce424cd 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert08.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert08.fail.cpp @@ -1 +1,61 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move ctor
// test converting move ctor. Should only require a MoveConstructible deleter, or if
// deleter is a reference, not even that.
// Explicit version
#include <memory>
#include <cassert>
#include "../../deleter.h"
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
int main()
{
{
const std::unique_ptr<B[], Deleter<B[]> > s(new B);
A* p = s.get();
std::unique_ptr<A[], Deleter<A[]> > s2(s);
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
assert(s2.get_deleter().state() == 5);
assert(s.get_deleter().state() == 0);
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr converting move ctor + +// test converting move ctor. Should only require a MoveConstructible deleter, or if +// deleter is a reference, not even that. +// Explicit version + +#include <memory> +#include <cassert> + +#include "../../deleter.h" + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +int main() +{ + { + const std::unique_ptr<B[], Deleter<B[]> > s(new B); + A* p = s.get(); + std::unique_ptr<A[], Deleter<A[]> > s2(s); + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + assert(B::count == 1); + assert(s2.get_deleter().state() == 5); + assert(s.get_deleter().state() == 0); + } + assert(A::count == 0); + assert(B::count == 0); +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert09.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert09.fail.cpp index d2c5eb92224..b81dd40f7d1 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert09.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert09.fail.cpp @@ -1 +1,78 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move ctor
// test converting move ctor. Should only require a MoveConstructible deleter, or if
// deleter is a reference, not even that.
// Explicit version
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
template <class T>
class CDeleter
{
int state_;
CDeleter(CDeleter&);
CDeleter& operator=(CDeleter&);
public:
CDeleter() : state_(5) {}
int state() const {return state_;}
void set_state(int s) {state_ = s;}
void operator()(T* p) {delete p;}
};
int main()
{
{
CDeleter<A> d;
const std::unique_ptr<B[], CDeleter<A>&> s(new B, d);
A* p = s.get();
std::unique_ptr<A[], CDeleter<A>&> s2(s);
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
d.set_state(6);
assert(s2.get_deleter().state() == d.state());
assert(s.get_deleter().state() == d.state());
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr converting move ctor + +// test converting move ctor. Should only require a MoveConstructible deleter, or if +// deleter is a reference, not even that. +// Explicit version + +#include <memory> +#include <cassert> + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +template <class T> +class CDeleter +{ + int state_; + + CDeleter(CDeleter&); + CDeleter& operator=(CDeleter&); +public: + + CDeleter() : state_(5) {} + + int state() const {return state_;} + void set_state(int s) {state_ = s;} + + void operator()(T* p) {delete p;} +}; + +int main() +{ + { + CDeleter<A> d; + const std::unique_ptr<B[], CDeleter<A>&> s(new B, d); + A* p = s.get(); + std::unique_ptr<A[], CDeleter<A>&> s2(s); + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + assert(B::count == 1); + d.set_state(6); + assert(s2.get_deleter().state() == d.state()); + assert(s.get_deleter().state() == d.state()); + } + assert(A::count == 0); + assert(B::count == 0); +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert10.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert10.fail.cpp index ec576470bc1..4d45411901b 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert10.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert10.fail.cpp @@ -1 +1,57 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move ctor
// test converting move ctor. Should only require a MoveConstructible deleter, or if
// deleter is a reference, not even that.
// implicit version
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
int main()
{
{
const std::unique_ptr<B[]> s(new B);
A* p = s.get();
std::unique_ptr<A[]> s2 = s;
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr converting move ctor + +// test converting move ctor. Should only require a MoveConstructible deleter, or if +// deleter is a reference, not even that. +// implicit version + +#include <memory> +#include <cassert> + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +int main() +{ + { + const std::unique_ptr<B[]> s(new B); + A* p = s.get(); + std::unique_ptr<A[]> s2 = s; + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + assert(B::count == 1); + } + assert(A::count == 0); + assert(B::count == 0); +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert11.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert11.fail.cpp index f3c299c0bab..c3641f86e64 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert11.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert11.fail.cpp @@ -1 +1,61 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move ctor
// test converting move ctor. Should only require a MoveConstructible deleter, or if
// deleter is a reference, not even that.
// Implicit version
#include <memory>
#include <cassert>
#include "../../deleter.h"
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
int main()
{
{
const std::unique_ptr<B[], Deleter<B[]> > s(new B);
A* p = s.get();
std::unique_ptr<A[], Deleter<A[]> > s2 = s;
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
assert(s2.get_deleter().state() == 5);
assert(s.get_deleter().state() == 0);
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr converting move ctor + +// test converting move ctor. Should only require a MoveConstructible deleter, or if +// deleter is a reference, not even that. +// Implicit version + +#include <memory> +#include <cassert> + +#include "../../deleter.h" + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +int main() +{ + { + const std::unique_ptr<B[], Deleter<B[]> > s(new B); + A* p = s.get(); + std::unique_ptr<A[], Deleter<A[]> > s2 = s; + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + assert(B::count == 1); + assert(s2.get_deleter().state() == 5); + assert(s.get_deleter().state() == 0); + } + assert(A::count == 0); + assert(B::count == 0); +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert12.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert12.fail.cpp index 26b925da4a8..e429fa88877 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert12.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert12.fail.cpp @@ -1 +1,78 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move ctor
// test converting move ctor. Should only require a MoveConstructible deleter, or if
// deleter is a reference, not even that.
// Explicit version
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
template <class T>
class CDeleter
{
int state_;
CDeleter(CDeleter&);
CDeleter& operator=(CDeleter&);
public:
CDeleter() : state_(5) {}
int state() const {return state_;}
void set_state(int s) {state_ = s;}
void operator()(T* p) {delete p;}
};
int main()
{
{
CDeleter<A> d;
const std::unique_ptr<B[], CDeleter<A>&> s(new B, d);
A* p = s.get();
std::unique_ptr<A[], CDeleter<A>&> s2 = s;
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
d.set_state(6);
assert(s2.get_deleter().state() == d.state());
assert(s.get_deleter().state() == d.state());
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr converting move ctor + +// test converting move ctor. Should only require a MoveConstructible deleter, or if +// deleter is a reference, not even that. +// Explicit version + +#include <memory> +#include <cassert> + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +template <class T> +class CDeleter +{ + int state_; + + CDeleter(CDeleter&); + CDeleter& operator=(CDeleter&); +public: + + CDeleter() : state_(5) {} + + int state() const {return state_;} + void set_state(int s) {state_ = s;} + + void operator()(T* p) {delete p;} +}; + +int main() +{ + { + CDeleter<A> d; + const std::unique_ptr<B[], CDeleter<A>&> s(new B, d); + A* p = s.get(); + std::unique_ptr<A[], CDeleter<A>&> s2 = s; + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + assert(B::count == 1); + d.set_state(6); + assert(s2.get_deleter().state() == d.state()); + assert(s.get_deleter().state() == d.state()); + } + assert(A::count == 0); + assert(B::count == 0); +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert13.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert13.fail.cpp index a6040720ef6..25bdf3dbe0c 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert13.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert13.fail.cpp @@ -1 +1,57 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move ctor
// test converting move ctor. Should only require a MoveConstructible deleter, or if
// deleter is a reference, not even that.
// Explicit version
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
int main()
{
{
std::unique_ptr<B[]> s(new B);
A* p = s.get();
std::unique_ptr<A[]> s2(std::move(s));
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr converting move ctor + +// test converting move ctor. Should only require a MoveConstructible deleter, or if +// deleter is a reference, not even that. +// Explicit version + +#include <memory> +#include <cassert> + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +int main() +{ + { + std::unique_ptr<B[]> s(new B); + A* p = s.get(); + std::unique_ptr<A[]> s2(std::move(s)); + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + assert(B::count == 1); + } + assert(A::count == 0); + assert(B::count == 0); +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert14.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert14.fail.cpp index 2b5b27c68c4..74172f3773f 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert14.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert14.fail.cpp @@ -1 +1,61 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move ctor
// test converting move ctor. Should only require a MoveConstructible deleter, or if
// deleter is a reference, not even that.
// Explicit version
#include <memory>
#include <cassert>
#include "../../deleter.h"
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
int main()
{
{
std::unique_ptr<B[], Deleter<B[]> > s(new B);
A* p = s.get();
std::unique_ptr<A[], Deleter<A[]> > s2(std::move(s));
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
assert(s2.get_deleter().state() == 5);
assert(s.get_deleter().state() == 0);
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr converting move ctor + +// test converting move ctor. Should only require a MoveConstructible deleter, or if +// deleter is a reference, not even that. +// Explicit version + +#include <memory> +#include <cassert> + +#include "../../deleter.h" + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +int main() +{ + { + std::unique_ptr<B[], Deleter<B[]> > s(new B); + A* p = s.get(); + std::unique_ptr<A[], Deleter<A[]> > s2(std::move(s)); + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + assert(B::count == 1); + assert(s2.get_deleter().state() == 5); + assert(s.get_deleter().state() == 0); + } + assert(A::count == 0); + assert(B::count == 0); +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert15.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert15.fail.cpp index ddcdb453a6b..4cbb9950bce 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert15.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert15.fail.cpp @@ -1 +1,78 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move ctor
// test converting move ctor. Should only require a MoveConstructible deleter, or if
// deleter is a reference, not even that.
// Explicit version
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
template <class T>
class CDeleter
{
int state_;
CDeleter(CDeleter&);
CDeleter& operator=(CDeleter&);
public:
CDeleter() : state_(5) {}
int state() const {return state_;}
void set_state(int s) {state_ = s;}
void operator()(T* p) {delete p;}
};
int main()
{
{
CDeleter<A> d;
std::unique_ptr<B[], CDeleter<A>&> s(new B, d);
A* p = s.get();
std::unique_ptr<A[], CDeleter<A>&> s2(std::move(s));
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
d.set_state(6);
assert(s2.get_deleter().state() == d.state());
assert(s.get_deleter().state() == d.state());
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr converting move ctor + +// test converting move ctor. Should only require a MoveConstructible deleter, or if +// deleter is a reference, not even that. +// Explicit version + +#include <memory> +#include <cassert> + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +template <class T> +class CDeleter +{ + int state_; + + CDeleter(CDeleter&); + CDeleter& operator=(CDeleter&); +public: + + CDeleter() : state_(5) {} + + int state() const {return state_;} + void set_state(int s) {state_ = s;} + + void operator()(T* p) {delete p;} +}; + +int main() +{ + { + CDeleter<A> d; + std::unique_ptr<B[], CDeleter<A>&> s(new B, d); + A* p = s.get(); + std::unique_ptr<A[], CDeleter<A>&> s2(std::move(s)); + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + assert(B::count == 1); + d.set_state(6); + assert(s2.get_deleter().state() == d.state()); + assert(s.get_deleter().state() == d.state()); + } + assert(A::count == 0); + assert(B::count == 0); +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert16.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert16.fail.cpp index d9f4d99ad7e..7ce70fbc8c1 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert16.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert16.fail.cpp @@ -1 +1,57 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move ctor
// test converting move ctor. Should only require a MoveConstructible deleter, or if
// deleter is a reference, not even that.
// implicit version
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
int main()
{
{
std::unique_ptr<B[]> s(new B);
A* p = s.get();
std::unique_ptr<A[]> s2 = std::move(s);
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr converting move ctor + +// test converting move ctor. Should only require a MoveConstructible deleter, or if +// deleter is a reference, not even that. +// implicit version + +#include <memory> +#include <cassert> + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +int main() +{ + { + std::unique_ptr<B[]> s(new B); + A* p = s.get(); + std::unique_ptr<A[]> s2 = std::move(s); + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + assert(B::count == 1); + } + assert(A::count == 0); + assert(B::count == 0); +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert17.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert17.fail.cpp index 96ebb838013..002946311af 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert17.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert17.fail.cpp @@ -1 +1,61 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move ctor
// test converting move ctor. Should only require a MoveConstructible deleter, or if
// deleter is a reference, not even that.
// Implicit version
#include <memory>
#include <cassert>
#include "../../deleter.h"
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
int main()
{
{
std::unique_ptr<B[], Deleter<B[]> > s(new B);
A* p = s.get();
std::unique_ptr<A[], Deleter<A[]> > s2 = std::move(s);
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
assert(s2.get_deleter().state() == 5);
assert(s.get_deleter().state() == 0);
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr converting move ctor + +// test converting move ctor. Should only require a MoveConstructible deleter, or if +// deleter is a reference, not even that. +// Implicit version + +#include <memory> +#include <cassert> + +#include "../../deleter.h" + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +int main() +{ + { + std::unique_ptr<B[], Deleter<B[]> > s(new B); + A* p = s.get(); + std::unique_ptr<A[], Deleter<A[]> > s2 = std::move(s); + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + assert(B::count == 1); + assert(s2.get_deleter().state() == 5); + assert(s.get_deleter().state() == 0); + } + assert(A::count == 0); + assert(B::count == 0); +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert18.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert18.fail.cpp index 2852c472e6d..ecb76a0b37e 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert18.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert18.fail.cpp @@ -1 +1,78 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move ctor
// test converting move ctor. Should only require a MoveConstructible deleter, or if
// deleter is a reference, not even that.
// Explicit version
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
template <class T>
class CDeleter
{
int state_;
CDeleter(CDeleter&);
CDeleter& operator=(CDeleter&);
public:
CDeleter() : state_(5) {}
int state() const {return state_;}
void set_state(int s) {state_ = s;}
void operator()(T* p) {delete p;}
};
int main()
{
{
CDeleter<A> d;
std::unique_ptr<B[], CDeleter<A>&> s(new B, d);
A* p = s.get();
std::unique_ptr<A[], CDeleter<A>&> s2 = std::move(s);
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
d.set_state(6);
assert(s2.get_deleter().state() == d.state());
assert(s.get_deleter().state() == d.state());
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr converting move ctor + +// test converting move ctor. Should only require a MoveConstructible deleter, or if +// deleter is a reference, not even that. +// Explicit version + +#include <memory> +#include <cassert> + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +template <class T> +class CDeleter +{ + int state_; + + CDeleter(CDeleter&); + CDeleter& operator=(CDeleter&); +public: + + CDeleter() : state_(5) {} + + int state() const {return state_;} + void set_state(int s) {state_ = s;} + + void operator()(T* p) {delete p;} +}; + +int main() +{ + { + CDeleter<A> d; + std::unique_ptr<B[], CDeleter<A>&> s(new B, d); + A* p = s.get(); + std::unique_ptr<A[], CDeleter<A>&> s2 = std::move(s); + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + assert(B::count == 1); + d.set_state(6); + assert(s2.get_deleter().state() == d.state()); + assert(s.get_deleter().state() == d.state()); + } + assert(A::count == 0); + assert(B::count == 0); +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/nullptr.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/nullptr.pass.cpp index d0fdb9a2d9d..62e777a4af8 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/nullptr.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/nullptr.pass.cpp @@ -1 +1,46 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// unique_ptr(nullptr_t);
#include <memory>
#include <cassert>
// default unique_ptr ctor should only require default Deleter ctor
class Deleter
{
int state_;
Deleter(Deleter&);
Deleter& operator=(Deleter&);
public:
Deleter() : state_(5) {}
int state() const {return state_;}
void operator()(void*) {}
};
int main()
{
{
std::unique_ptr<int[]> p(nullptr);
assert(p.get() == 0);
}
{
std::unique_ptr<int[], Deleter> p(nullptr);
assert(p.get() == 0);
assert(p.get_deleter().state() == 5);
}
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// unique_ptr(nullptr_t); + +#include <memory> +#include <cassert> + +// default unique_ptr ctor should only require default Deleter ctor +class Deleter +{ + int state_; + + Deleter(Deleter&); + Deleter& operator=(Deleter&); + +public: + Deleter() : state_(5) {} + + int state() const {return state_;} + + void operator()(void*) {} +}; + +int main() +{ + { + std::unique_ptr<int[]> p(nullptr); + assert(p.get() == 0); + } + { + std::unique_ptr<int[], Deleter> p(nullptr); + assert(p.get() == 0); + assert(p.get_deleter().state() == 5); + } +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer01.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer01.fail.cpp index bdcd371b5be..14bdf5ba8af 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer01.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer01.fail.cpp @@ -1 +1,36 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr<T[]>(pointer) ctor
// unique_ptr<T[]>(pointer) ctor should require default Deleter ctor
#include <memory>
class Deleter
{
Deleter() {}
public:
Deleter(Deleter&) {}
Deleter& operator=(Deleter&) {}
void operator()(void*) const {}
};
int main()
{
std::unique_ptr<int[], Deleter> p(new int);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr<T[]>(pointer) ctor + +// unique_ptr<T[]>(pointer) ctor should require default Deleter ctor + +#include <memory> + +class Deleter +{ + + Deleter() {} + +public: + + Deleter(Deleter&) {} + Deleter& operator=(Deleter&) {} + + void operator()(void*) const {} +}; + +int main() +{ + std::unique_ptr<int[], Deleter> p(new int); +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer01.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer01.pass.cpp index 25e41cace94..9b00c50b09f 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer01.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer01.pass.cpp @@ -1 +1,63 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr(pointer) ctor
// unique_ptr<T[]>(pointer) ctor should only require default Deleter ctor
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
class Deleter
{
int state_;
Deleter(Deleter&);
Deleter& operator=(Deleter&);
public:
Deleter() : state_(5) {}
int state() const {return state_;}
void operator()(A* p) {delete [] p;}
};
int main()
{
{
A* p = new A[3];
assert(A::count == 3);
std::unique_ptr<A[]> s(p);
assert(s.get() == p);
}
assert(A::count == 0);
{
A* p = new A[3];
assert(A::count == 3);
std::unique_ptr<A[], Deleter> s(p);
assert(s.get() == p);
assert(s.get_deleter().state() == 5);
}
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr(pointer) ctor + +// unique_ptr<T[]>(pointer) ctor should only require default Deleter ctor + +#include <memory> +#include <cassert> + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +class Deleter +{ + int state_; + + Deleter(Deleter&); + Deleter& operator=(Deleter&); + +public: + Deleter() : state_(5) {} + + int state() const {return state_;} + + void operator()(A* p) {delete [] p;} +}; + +int main() +{ + { + A* p = new A[3]; + assert(A::count == 3); + std::unique_ptr<A[]> s(p); + assert(s.get() == p); + } + assert(A::count == 0); + { + A* p = new A[3]; + assert(A::count == 3); + std::unique_ptr<A[], Deleter> s(p); + assert(s.get() == p); + assert(s.get_deleter().state() == 5); + } + assert(A::count == 0); +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer02.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer02.fail.cpp index 8f3767dc5f7..804ed5b5efa 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer02.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer02.fail.cpp @@ -1 +1,29 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr<T[]>(pointer) ctor
#include <memory>
// unique_ptr<T[]>(pointer) ctor should require non-reference Deleter ctor
class Deleter
{
public:
void operator()(void*) {}
};
int main()
{
std::unique_ptr<int[], Deleter&> p(new int);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr<T[]>(pointer) ctor + +#include <memory> + +// unique_ptr<T[]>(pointer) ctor should require non-reference Deleter ctor +class Deleter +{ +public: + + void operator()(void*) {} +}; + +int main() +{ + std::unique_ptr<int[], Deleter&> p(new int); +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer02.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer02.pass.cpp index f70f9851e10..619b0b06373 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer02.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer02.pass.cpp @@ -1 +1,95 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr<T[]>(pointer) ctor
// unique_ptr<T[]>(pointer) ctor shouldn't require complete type
#include <memory>
#include <cassert>
struct A;
class Deleter
{
int state_;
Deleter(Deleter&);
Deleter& operator=(Deleter&);
public:
Deleter() : state_(5) {}
int state() const {return state_;}
void operator()(A* p);
};
void check(int i);
template <class D = std::default_delete<A[]> >
struct B
{
std::unique_ptr<A[], D> a_;
explicit B(A*);
~B();
A* get() const {return a_.get();}
D& get_deleter() {return a_.get_deleter();}
};
A* get();
int main()
{
{
A* p = get();
check(3);
B<> s(p);
assert(s.get() == p);
}
check(0);
{
A* p = get();
check(3);
B<Deleter> s(p);
assert(s.get() == p);
assert(s.get_deleter().state() == 5);
}
check(0);
}
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
A* get() {return new A[3];}
void Deleter::operator()(A* p) {delete [] p;}
void check(int i)
{
assert(A::count == i);
}
template <class D>
B<D>::B(A* a) : a_(a) {}
template <class D>
B<D>::~B() {}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr<T[]>(pointer) ctor + +// unique_ptr<T[]>(pointer) ctor shouldn't require complete type + +#include <memory> +#include <cassert> + +struct A; + +class Deleter +{ + int state_; + + Deleter(Deleter&); + Deleter& operator=(Deleter&); + +public: + Deleter() : state_(5) {} + + int state() const {return state_;} + + void operator()(A* p); +}; + +void check(int i); + +template <class D = std::default_delete<A[]> > +struct B +{ + std::unique_ptr<A[], D> a_; + explicit B(A*); + ~B(); + + A* get() const {return a_.get();} + D& get_deleter() {return a_.get_deleter();} +}; + +A* get(); + +int main() +{ + { + A* p = get(); + check(3); + B<> s(p); + assert(s.get() == p); + } + check(0); + { + A* p = get(); + check(3); + B<Deleter> s(p); + assert(s.get() == p); + assert(s.get_deleter().state() == 5); + } + check(0); +} + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +A* get() {return new A[3];} + +void Deleter::operator()(A* p) {delete [] p;} + +void check(int i) +{ + assert(A::count == i); +} + +template <class D> +B<D>::B(A* a) : a_(a) {} + +template <class D> +B<D>::~B() {} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer03.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer03.fail.cpp index 35c1c764e46..650cab49459 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer03.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer03.fail.cpp @@ -1 +1,23 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr<T[]>(pointer) ctor
// unique_ptr<T[]>(pointer) ctor should require non-pointer Deleter
#include <memory>
int main()
{
std::unique_ptr<int[], void (*)(void*)> p(new int);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr<T[]>(pointer) ctor + +// unique_ptr<T[]>(pointer) ctor should require non-pointer Deleter + +#include <memory> + +int main() +{ + std::unique_ptr<int[], void (*)(void*)> p(new int); +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer04.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer04.fail.cpp index 507610bb2ab..ddc32d8cf57 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer04.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer04.fail.cpp @@ -1 +1,67 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr(pointer) ctor
// unique_ptr(pointer) ctor should not work with derived pointers
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
class Deleter
{
int state_;
Deleter(Deleter&);
Deleter& operator=(Deleter&);
public:
Deleter() : state_(5) {}
int state() const {return state_;}
void operator()(A* p) {delete [] p;}
};
int main()
{
{
B* p = new B[3];
std::unique_ptr<A[]> s(p);
}
{
B* p = new B[3];
std::unique_ptr<A[], Deleter> s(p);
}
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr(pointer) ctor + +// unique_ptr(pointer) ctor should not work with derived pointers + +#include <memory> +#include <cassert> + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +class Deleter +{ + int state_; + + Deleter(Deleter&); + Deleter& operator=(Deleter&); + +public: + Deleter() : state_(5) {} + + int state() const {return state_;} + + void operator()(A* p) {delete [] p;} +}; + +int main() +{ + { + B* p = new B[3]; + std::unique_ptr<A[]> s(p); + } + { + B* p = new B[3]; + std::unique_ptr<A[], Deleter> s(p); + } +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer_deleter01.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer_deleter01.pass.cpp index 4d27319f3ba..73f2b1a7ced 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer_deleter01.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer_deleter01.pass.cpp @@ -1 +1,43 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr(pointer, deleter) ctor
// unique_ptr(pointer, deleter()) only requires MoveConstructible deleter
#include <memory>
#include <cassert>
#include "../../deleter.h"
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
A* p = new A[3];
assert(A::count == 3);
std::unique_ptr<A[], Deleter<A[]> > s(p, Deleter<A[]>());
assert(s.get() == p);
assert(s.get_deleter().state() == 0);
}
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr(pointer, deleter) ctor + +// unique_ptr(pointer, deleter()) only requires MoveConstructible deleter + +#include <memory> +#include <cassert> + +#include "../../deleter.h" + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +int main() +{ + { + A* p = new A[3]; + assert(A::count == 3); + std::unique_ptr<A[], Deleter<A[]> > s(p, Deleter<A[]>()); + assert(s.get() == p); + assert(s.get_deleter().state() == 0); + } + assert(A::count == 0); +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer_deleter02.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer_deleter02.pass.cpp index e25c5b1f8ea..ffa1c1df136 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer_deleter02.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer_deleter02.pass.cpp @@ -1 +1,58 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr(pointer, deleter) ctor
// unique_ptr(pointer, d) requires CopyConstructible deleter
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
class Deleter
{
int state_;
public:
Deleter() : state_(5) {}
int state() const {return state_;}
void set_state(int s) {state_ = s;}
void operator()(A* p) {delete [] p;}
};
int main()
{
{
A* p = new A[3];
assert(A::count == 3);
Deleter d;
std::unique_ptr<A[], Deleter> s(p, d);
assert(s.get() == p);
assert(s.get_deleter().state() == 5);
d.set_state(6);
assert(s.get_deleter().state() == 5);
}
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr(pointer, deleter) ctor + +// unique_ptr(pointer, d) requires CopyConstructible deleter + +#include <memory> +#include <cassert> + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +class Deleter +{ + int state_; + +public: + + Deleter() : state_(5) {} + + int state() const {return state_;} + void set_state(int s) {state_ = s;} + + void operator()(A* p) {delete [] p;} +}; + +int main() +{ + { + A* p = new A[3]; + assert(A::count == 3); + Deleter d; + std::unique_ptr<A[], Deleter> s(p, d); + assert(s.get() == p); + assert(s.get_deleter().state() == 5); + d.set_state(6); + assert(s.get_deleter().state() == 5); + } + assert(A::count == 0); +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer_deleter03.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer_deleter03.pass.cpp index 8f4594c5f78..f6907357769 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer_deleter03.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer_deleter03.pass.cpp @@ -1 +1,60 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr(pointer, deleter) ctor
// unique_ptr<T[], D&>(pointer, d) does not requires CopyConstructible deleter
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
class Deleter
{
int state_;
Deleter(const Deleter&);
Deleter& operator=(const Deleter&);
public:
Deleter() : state_(5) {}
int state() const {return state_;}
void set_state(int s) {state_ = s;}
void operator()(A* p) {delete [] p;}
};
int main()
{
{
A* p = new A[3];
assert(A::count == 3);
Deleter d;
std::unique_ptr<A[], Deleter&> s(p, d);
assert(s.get() == p);
assert(s.get_deleter().state() == 5);
d.set_state(6);
assert(s.get_deleter().state() == 6);
}
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr(pointer, deleter) ctor + +// unique_ptr<T[], D&>(pointer, d) does not requires CopyConstructible deleter + +#include <memory> +#include <cassert> + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +class Deleter +{ + int state_; + + Deleter(const Deleter&); + Deleter& operator=(const Deleter&); +public: + + Deleter() : state_(5) {} + + int state() const {return state_;} + void set_state(int s) {state_ = s;} + + void operator()(A* p) {delete [] p;} +}; + +int main() +{ + { + A* p = new A[3]; + assert(A::count == 3); + Deleter d; + std::unique_ptr<A[], Deleter&> s(p, d); + assert(s.get() == p); + assert(s.get_deleter().state() == 5); + d.set_state(6); + assert(s.get_deleter().state() == 6); + } + assert(A::count == 0); +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer_deleter04.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer_deleter04.fail.cpp index 42b84c174c5..24d563059ad 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer_deleter04.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer_deleter04.fail.cpp @@ -1 +1,55 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr(pointer, deleter) ctor
// unique_ptr<T, const D&>(pointer, D()) should not compile
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
class Deleter
{
int state_;
public:
Deleter() : state_(5) {}
int state() const {return state_;}
void set_state(int s) {state_ = s;}
void operator()(A* p) const {delete [] p;}
};
int main()
{
{
A* p = new A[3];
assert(A::count == 3);
std::unique_ptr<A[], const Deleter&> s(p, Deleter());
assert(s.get() == p);
assert(s.get_deleter().state() == 5);
}
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr(pointer, deleter) ctor + +// unique_ptr<T, const D&>(pointer, D()) should not compile + +#include <memory> +#include <cassert> + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +class Deleter +{ + int state_; + +public: + + Deleter() : state_(5) {} + + int state() const {return state_;} + void set_state(int s) {state_ = s;} + + void operator()(A* p) const {delete [] p;} +}; + +int main() +{ + { + A* p = new A[3]; + assert(A::count == 3); + std::unique_ptr<A[], const Deleter&> s(p, Deleter()); + assert(s.get() == p); + assert(s.get_deleter().state() == 5); + } + assert(A::count == 0); +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer_deleter04.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer_deleter04.pass.cpp index 34b426e16d9..67402064a6a 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer_deleter04.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer_deleter04.pass.cpp @@ -1 +1,58 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr(pointer, deleter) ctor
// unique_ptr<T[], const D&>(pointer, d) does not requires CopyConstructible deleter
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
class Deleter
{
int state_;
Deleter(const Deleter&);
Deleter& operator=(const Deleter&);
public:
Deleter() : state_(5) {}
int state() const {return state_;}
void set_state(int s) {state_ = s;}
void operator()(A* p) const {delete [] p;}
};
int main()
{
{
A* p = new A[3];
assert(A::count == 3);
Deleter d;
std::unique_ptr<A[], const Deleter&> s(p, d);
assert(s.get() == p);
assert(s.get_deleter().state() == 5);
}
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr(pointer, deleter) ctor + +// unique_ptr<T[], const D&>(pointer, d) does not requires CopyConstructible deleter + +#include <memory> +#include <cassert> + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +class Deleter +{ + int state_; + + Deleter(const Deleter&); + Deleter& operator=(const Deleter&); +public: + + Deleter() : state_(5) {} + + int state() const {return state_;} + void set_state(int s) {state_ = s;} + + void operator()(A* p) const {delete [] p;} +}; + +int main() +{ + { + A* p = new A[3]; + assert(A::count == 3); + Deleter d; + std::unique_ptr<A[], const Deleter&> s(p, d); + assert(s.get() == p); + assert(s.get_deleter().state() == 5); + } + assert(A::count == 0); +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer_deleter05.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer_deleter05.fail.cpp index 66a314ae656..b5eeb5c755a 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer_deleter05.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer_deleter05.fail.cpp @@ -1 +1,58 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr(pointer, deleter) ctor
// unique_ptr(pointer, deleter) should not work with derived pointers
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
class Deleter
{
int state_;
public:
Deleter() : state_(5) {}
int state() const {return state_;}
void operator()(A* p) {delete [] p;}
};
int main()
{
B* p = new B[3];
std::unique_ptr<A[], Deleter> s(p, Deleter());
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr(pointer, deleter) ctor + +// unique_ptr(pointer, deleter) should not work with derived pointers + +#include <memory> +#include <cassert> + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +class Deleter +{ + int state_; + +public: + Deleter() : state_(5) {} + + int state() const {return state_;} + + void operator()(A* p) {delete [] p;} +}; + +int main() +{ + B* p = new B[3]; + std::unique_ptr<A[], Deleter> s(p, Deleter()); +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.modifiers/release.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.modifiers/release.pass.cpp index 1f80c9e5a1a..560ba3cce7e 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.modifiers/release.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.modifiers/release.pass.cpp @@ -1 +1,27 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// test release
#include <memory>
#include <cassert>
int main()
{
std::unique_ptr<int[]> p(new int[3]);
int* i = p.get();
int* j = p.release();
assert(p.get() == 0);
assert(i == j);
delete [] j;
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// test release + +#include <memory> +#include <cassert> + +int main() +{ + std::unique_ptr<int[]> p(new int[3]); + int* i = p.get(); + int* j = p.release(); + assert(p.get() == 0); + assert(i == j); + delete [] j; +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.modifiers/reset1.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.modifiers/reset1.pass.cpp index 1cbea933a87..3c69b19aa90 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.modifiers/reset1.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.modifiers/reset1.pass.cpp @@ -1 +1,48 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// test reset
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
std::unique_ptr<A[]> p(new A[3]);
assert(A::count == 3);
A* i = p.get();
p.reset();
assert(A::count == 0);
assert(p.get() == 0);
}
assert(A::count == 0);
{
std::unique_ptr<A[]> p(new A[4]);
assert(A::count == 4);
A* i = p.get();
p.reset(new A[5]);
assert(A::count == 5);
}
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// test reset + +#include <memory> +#include <cassert> + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +int main() +{ + { + std::unique_ptr<A[]> p(new A[3]); + assert(A::count == 3); + A* i = p.get(); + p.reset(); + assert(A::count == 0); + assert(p.get() == 0); + } + assert(A::count == 0); + { + std::unique_ptr<A[]> p(new A[4]); + assert(A::count == 4); + A* i = p.get(); + p.reset(new A[5]); + assert(A::count == 5); + } + assert(A::count == 0); +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.modifiers/reset2.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.modifiers/reset2.fail.cpp index 43bb562e7f4..feae9690f93 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.modifiers/reset2.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.modifiers/reset2.fail.cpp @@ -1 +1,64 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// test reset
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
int main()
{
{
std::unique_ptr<A[]> p(new A);
assert(A::count == 1);
assert(B::count == 0);
A* i = p.get();
p.reset(new B);
assert(A::count == 1);
assert(B::count == 1);
}
assert(A::count == 0);
assert(B::count == 0);
{
std::unique_ptr<A[]> p(new B);
assert(A::count == 1);
assert(B::count == 1);
A* i = p.get();
p.reset(new B);
assert(A::count == 1);
assert(B::count == 1);
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// test reset + +#include <memory> +#include <cassert> + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +int main() +{ + { + std::unique_ptr<A[]> p(new A); + assert(A::count == 1); + assert(B::count == 0); + A* i = p.get(); + p.reset(new B); + assert(A::count == 1); + assert(B::count == 1); + } + assert(A::count == 0); + assert(B::count == 0); + { + std::unique_ptr<A[]> p(new B); + assert(A::count == 1); + assert(B::count == 1); + A* i = p.get(); + p.reset(new B); + assert(A::count == 1); + assert(B::count == 1); + } + assert(A::count == 0); + assert(B::count == 0); +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.modifiers/swap.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.modifiers/swap.pass.cpp index 07eac0228b3..0c63780b3a9 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.modifiers/swap.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.modifiers/swap.pass.cpp @@ -1 +1,56 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// test swap
#include <memory>
#include <cassert>
#include "../../deleter.h"
struct A
{
int state_;
static int count;
A() : state_(0) {++count;}
explicit A(int i) : state_(i) {++count;}
A(const A& a) : state_(a.state_) {++count;}
A& operator=(const A& a) {state_ = a.state_; return *this;}
~A() {--count;}
friend bool operator==(const A& x, const A& y)
{return x.state_ == y.state_;}
};
int A::count = 0;
int main()
{
{
A* p1 = new A[3];
std::unique_ptr<A[], Deleter<A[]> > s1(p1, Deleter<A[]>(1));
A* p2 = new A[3];
std::unique_ptr<A[], Deleter<A[]> > s2(p2, Deleter<A[]>(2));
assert(s1.get() == p1);
assert(s1.get_deleter().state() == 1);
assert(s2.get() == p2);
assert(s2.get_deleter().state() == 2);
s1.swap(s2);
assert(s1.get() == p2);
assert(s1.get_deleter().state() == 2);
assert(s2.get() == p1);
assert(s2.get_deleter().state() == 1);
assert(A::count == 6);
}
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// test swap + +#include <memory> +#include <cassert> + +#include "../../deleter.h" + +struct A +{ + int state_; + static int count; + A() : state_(0) {++count;} + explicit A(int i) : state_(i) {++count;} + A(const A& a) : state_(a.state_) {++count;} + A& operator=(const A& a) {state_ = a.state_; return *this;} + ~A() {--count;} + + friend bool operator==(const A& x, const A& y) + {return x.state_ == y.state_;} +}; + +int A::count = 0; + +int main() +{ + { + A* p1 = new A[3]; + std::unique_ptr<A[], Deleter<A[]> > s1(p1, Deleter<A[]>(1)); + A* p2 = new A[3]; + std::unique_ptr<A[], Deleter<A[]> > s2(p2, Deleter<A[]>(2)); + assert(s1.get() == p1); + assert(s1.get_deleter().state() == 1); + assert(s2.get() == p2); + assert(s2.get_deleter().state() == 2); + s1.swap(s2); + assert(s1.get() == p2); + assert(s1.get_deleter().state() == 2); + assert(s2.get() == p1); + assert(s2.get_deleter().state() == 1); + assert(A::count == 6); + } + assert(A::count == 0); +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.observers/dereference.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.observers/dereference.fail.cpp index 5bfb4de49d0..89597fad43f 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.observers/dereference.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.observers/dereference.fail.cpp @@ -1 +1,23 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// test op*()
#include <memory>
#include <cassert>
int main()
{
std::unique_ptr<int[]> p(new int(3));
assert(*p == 3);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// test op*() + +#include <memory> +#include <cassert> + +int main() +{ + std::unique_ptr<int[]> p(new int(3)); + assert(*p == 3); +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.observers/explicit_bool.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.observers/explicit_bool.pass.cpp index f3b7f01d829..4a4f6c062b1 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.observers/explicit_bool.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.observers/explicit_bool.pass.cpp @@ -1 +1,39 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// test op*()
#include <memory>
#include <cassert>
int main()
{
{
std::unique_ptr<int[]> p(new int [3]);
if (p)
;
else
assert(false);
if (!p)
assert(false);
}
{
std::unique_ptr<int[]> p;
if (!p)
;
else
assert(false);
if (p)
assert(false);
}
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// test op*() + +#include <memory> +#include <cassert> + +int main() +{ + { + std::unique_ptr<int[]> p(new int [3]); + if (p) + ; + else + assert(false); + if (!p) + assert(false); + } + { + std::unique_ptr<int[]> p; + if (!p) + ; + else + assert(false); + if (p) + assert(false); + } +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.observers/get.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.observers/get.pass.cpp index 5ed1a201a3e..015ea2fbfd0 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.observers/get.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.observers/get.pass.cpp @@ -1 +1,24 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// test get
#include <memory>
#include <cassert>
int main()
{
int* p = new int[3];
std::unique_ptr<int[]> s(p);
assert(s.get() == p);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// test get + +#include <memory> +#include <cassert> + +int main() +{ + int* p = new int[3]; + std::unique_ptr<int[]> s(p); + assert(s.get() == p); +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.observers/get_deleter.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.observers/get_deleter.pass.cpp index 0d58c7ac2ce..3e74775d2ba 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.observers/get_deleter.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.observers/get_deleter.pass.cpp @@ -1 +1,37 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// test get_deleter()
#include <memory>
#include <cassert>
struct Deleter
{
void operator()(void*) {}
int test() {return 5;}
int test() const {return 6;}
};
int main()
{
{
std::unique_ptr<int[], Deleter> p;
assert(p.get_deleter().test() == 5);
}
{
const std::unique_ptr<int[], Deleter> p;
assert(p.get_deleter().test() == 6);
}
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// test get_deleter() + +#include <memory> +#include <cassert> + +struct Deleter +{ + void operator()(void*) {} + + int test() {return 5;} + int test() const {return 6;} +}; + +int main() +{ + { + std::unique_ptr<int[], Deleter> p; + assert(p.get_deleter().test() == 5); + } + { + const std::unique_ptr<int[], Deleter> p; + assert(p.get_deleter().test() == 6); + } +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.observers/index.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.observers/index.pass.cpp index 95ad2f26fb3..61e400ade59 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.observers/index.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.observers/index.pass.cpp @@ -1 +1,47 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// test op[](size_t)
#include <memory>
#include <cassert>
class A
{
int state_;
static int next_;
public:
A() : state_(++next_) {}
int get() const {return state_;}
friend bool operator==(const A& x, int y)
{return x.state_ == y;}
A& operator=(int i) {state_ = i; return *this;}
};
int A::next_ = 0;
int main()
{
std::unique_ptr<A[]> p(new A[3]);
assert(p[0] == 1);
assert(p[1] == 2);
assert(p[2] == 3);
p[0] = 3;
p[1] = 2;
p[2] = 1;
assert(p[0] == 3);
assert(p[1] == 2);
assert(p[2] == 1);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// test op[](size_t) + +#include <memory> +#include <cassert> + +class A +{ + int state_; + static int next_; +public: + A() : state_(++next_) {} + int get() const {return state_;} + + friend bool operator==(const A& x, int y) + {return x.state_ == y;} + + A& operator=(int i) {state_ = i; return *this;} +}; + +int A::next_ = 0; + +int main() +{ + std::unique_ptr<A[]> p(new A[3]); + assert(p[0] == 1); + assert(p[1] == 2); + assert(p[2] == 3); + p[0] = 3; + p[1] = 2; + p[2] = 1; + assert(p[0] == 3); + assert(p[1] == 2); + assert(p[2] == 1); +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.observers/op_arrow.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.observers/op_arrow.fail.cpp index f8973e17504..ad0cf3984a4 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.observers/op_arrow.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.observers/op_arrow.fail.cpp @@ -1 +1,30 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// test op->()
#include <memory>
#include <cassert>
struct A
{
int i_;
A() : i_(7) {}
};
int main()
{
std::unique_ptr<A[]> p(new A);
assert(p->i_ == 7);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// test op->() + +#include <memory> +#include <cassert> + +struct A +{ + int i_; + + A() : i_(7) {} +}; + +int main() +{ + std::unique_ptr<A[]> p(new A); + assert(p->i_ == 7); +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/pointer_type.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/pointer_type.pass.cpp index daa83841cd7..05d6d1f37be 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/pointer_type.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/pointer_type.pass.cpp @@ -1 +1,34 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr::pointer type
#include <memory>
#include <type_traits>
struct Deleter
{
struct pointer {};
};
int main()
{
{
typedef std::unique_ptr<int> P;
static_assert((std::is_same<P::pointer, int*>::value), "");
}
{
typedef std::unique_ptr<int, Deleter> P;
static_assert((std::is_same<P::pointer, Deleter::pointer>::value), "");
}
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr::pointer type + +#include <memory> +#include <type_traits> + +struct Deleter +{ + struct pointer {}; +}; + +int main() +{ + { + typedef std::unique_ptr<int> P; + static_assert((std::is_same<P::pointer, int*>::value), ""); + } + { + typedef std::unique_ptr<int, Deleter> P; + static_assert((std::is_same<P::pointer, Deleter::pointer>::value), ""); + } +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move01.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move01.fail.cpp index 6360686f745..cb123994aa4 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move01.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move01.fail.cpp @@ -1 +1,38 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr move assignment
#include <memory>
#include <cassert>
// Can't copy from lvalue
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
std::unique_ptr<A> s(new A);
std::unique_ptr<A> s2;
s2 = s;
}
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr move assignment + +#include <memory> +#include <cassert> + +// Can't copy from lvalue + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +int main() +{ + { + std::unique_ptr<A> s(new A); + std::unique_ptr<A> s2; + s2 = s; + } +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move01.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move01.pass.cpp index 94c8b5b1581..7d3bff0ddc9 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move01.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move01.pass.cpp @@ -1 +1,74 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr move assignment
// test move assignment. Should only require a MoveConstructible deleter, or if
// deleter is a reference, not even that.
#include <memory>
#include <cassert>
#include "../../deleter.h"
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
std::unique_ptr<A> s1(new A);
A* p = s1.get();
std::unique_ptr<A> s2(new A);
assert(A::count == 2);
s2 = std::move(s1);
assert(A::count == 1);
assert(s2.get() == p);
assert(s1.get() == 0);
}
assert(A::count == 0);
{
std::unique_ptr<A, Deleter<A> > s1(new A, Deleter<A>(5));
A* p = s1.get();
std::unique_ptr<A, Deleter<A> > s2(new A);
assert(A::count == 2);
s2 = std::move(s1);
assert(s2.get() == p);
assert(s1.get() == 0);
assert(A::count == 1);
assert(s2.get_deleter().state() == 5);
assert(s1.get_deleter().state() == 0);
}
assert(A::count == 0);
{
CDeleter<A> d1(5);
std::unique_ptr<A, CDeleter<A>&> s1(new A, d1);
A* p = s1.get();
CDeleter<A> d2(6);
std::unique_ptr<A, CDeleter<A>&> s2(new A, d2);
s2 = std::move(s1);
assert(s2.get() == p);
assert(s1.get() == 0);
assert(A::count == 1);
assert(d1.state() == 5);
assert(d2.state() == 5);
}
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr move assignment + +// test move assignment. Should only require a MoveConstructible deleter, or if +// deleter is a reference, not even that. + +#include <memory> +#include <cassert> + +#include "../../deleter.h" + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +int main() +{ + { + std::unique_ptr<A> s1(new A); + A* p = s1.get(); + std::unique_ptr<A> s2(new A); + assert(A::count == 2); + s2 = std::move(s1); + assert(A::count == 1); + assert(s2.get() == p); + assert(s1.get() == 0); + } + assert(A::count == 0); + { + std::unique_ptr<A, Deleter<A> > s1(new A, Deleter<A>(5)); + A* p = s1.get(); + std::unique_ptr<A, Deleter<A> > s2(new A); + assert(A::count == 2); + s2 = std::move(s1); + assert(s2.get() == p); + assert(s1.get() == 0); + assert(A::count == 1); + assert(s2.get_deleter().state() == 5); + assert(s1.get_deleter().state() == 0); + } + assert(A::count == 0); + { + CDeleter<A> d1(5); + std::unique_ptr<A, CDeleter<A>&> s1(new A, d1); + A* p = s1.get(); + CDeleter<A> d2(6); + std::unique_ptr<A, CDeleter<A>&> s2(new A, d2); + s2 = std::move(s1); + assert(s2.get() == p); + assert(s1.get() == 0); + assert(A::count == 1); + assert(d1.state() == 5); + assert(d2.state() == 5); + } + assert(A::count == 0); +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move02.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move02.fail.cpp index e245105ae40..73e608d6340 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move02.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move02.fail.cpp @@ -1 +1,38 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr move assignment
#include <memory>
#include <cassert>
// Can't copy from const lvalue
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
const std::unique_ptr<A> s(new A);
std::unique_ptr<A> s2;
s2 = s;
}
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr move assignment + +#include <memory> +#include <cassert> + +// Can't copy from const lvalue + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +int main() +{ + { + const std::unique_ptr<A> s(new A); + std::unique_ptr<A> s2; + s2 = s; + } +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move03.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move03.fail.cpp index 594704f2a83..53f93869b4d 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move03.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move03.fail.cpp @@ -1 +1,56 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr move assignment
#include <memory>
#include <cassert>
// Can't copy from lvalue
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
class Deleter
{
int state_;
public:
Deleter() : state_(5) {}
int state() const {return state_;}
void operator()(A* p) {delete p;}
};
int main()
{
{
std::unique_ptr<A, Deleter> s(new A);
A* p = s.get();
std::unique_ptr<A, Deleter> s2;
s2 = s;
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
}
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr move assignment + +#include <memory> +#include <cassert> + +// Can't copy from lvalue + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +class Deleter +{ + int state_; + +public: + + Deleter() : state_(5) {} + + int state() const {return state_;} + + void operator()(A* p) {delete p;} +}; + +int main() +{ + { + std::unique_ptr<A, Deleter> s(new A); + A* p = s.get(); + std::unique_ptr<A, Deleter> s2; + s2 = s; + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + } + assert(A::count == 0); +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move04.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move04.fail.cpp index 89267738d13..0f0c17682a4 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move04.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move04.fail.cpp @@ -1 +1,56 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr move ctor
#include <memory>
#include <cassert>
// test move ctor. Can't copy from const lvalue
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
class Deleter
{
int state_;
public:
Deleter() : state_(5) {}
int state() const {return state_;}
void operator()(A* p) {delete p;}
};
int main()
{
{
const std::unique_ptr<A, Deleter> s(new A);
A* p = s.get();
std::unique_ptr<A, Deleter> s2;
s2 = s;
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
}
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr move ctor + +#include <memory> +#include <cassert> + +// test move ctor. Can't copy from const lvalue + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +class Deleter +{ + int state_; + +public: + + Deleter() : state_(5) {} + + int state() const {return state_;} + + void operator()(A* p) {delete p;} +}; + +int main() +{ + { + const std::unique_ptr<A, Deleter> s(new A); + A* p = s.get(); + std::unique_ptr<A, Deleter> s2; + s2 = s; + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + } + assert(A::count == 0); +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert01.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert01.fail.cpp index dc9e6cc731e..4dff75cf66f 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert01.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert01.fail.cpp @@ -1 +1,56 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move assignment
#include <memory>
#include <cassert>
// Can't assign from lvalue
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
int main()
{
{
std::unique_ptr<B> s(new B);
A* p = s.get();
std::unique_ptr<A> s2;
s2 = s;
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr converting move assignment + +#include <memory> +#include <cassert> + +// Can't assign from lvalue + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +int main() +{ + { + std::unique_ptr<B> s(new B); + A* p = s.get(); + std::unique_ptr<A> s2; + s2 = s; + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + assert(B::count == 1); + } + assert(A::count == 0); + assert(B::count == 0); +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert01.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert01.pass.cpp index 68aa7be4f8d..7fd7acb0c93 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert01.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert01.pass.cpp @@ -1 +1,55 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move assignment
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
int main()
{
{
std::unique_ptr<B> s(new B);
A* p = s.get();
std::unique_ptr<A> s2(new A);
assert(A::count == 2);
s2 = std::move(s);
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr converting move assignment + +#include <memory> +#include <cassert> + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +int main() +{ + { + std::unique_ptr<B> s(new B); + A* p = s.get(); + std::unique_ptr<A> s2(new A); + assert(A::count == 2); + s2 = std::move(s); + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + assert(B::count == 1); + } + assert(A::count == 0); + assert(B::count == 0); +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert02.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert02.fail.cpp index 01cdc5754b2..fb1a4491e30 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert02.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert02.fail.cpp @@ -1 +1,60 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move assignment
#include <memory>
#include <cassert>
#include "../../deleter.h"
// Can't assign from lvalue
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
int main()
{
{
std::unique_ptr<B, Deleter<B> > s(new B);
A* p = s.get();
std::unique_ptr<A, Deleter<A> > s2;
s2 = s;
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
assert(s2.get_deleter().state() == 5);
assert(s.get_deleter().state() == 0);
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr converting move assignment + +#include <memory> +#include <cassert> + +#include "../../deleter.h" + +// Can't assign from lvalue + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +int main() +{ + { + std::unique_ptr<B, Deleter<B> > s(new B); + A* p = s.get(); + std::unique_ptr<A, Deleter<A> > s2; + s2 = s; + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + assert(B::count == 1); + assert(s2.get_deleter().state() == 5); + assert(s.get_deleter().state() == 0); + } + assert(A::count == 0); + assert(B::count == 0); +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert02.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert02.pass.cpp index 97217d0ac42..337d3f07971 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert02.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert02.pass.cpp @@ -1 +1,59 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move assignment
#include <memory>
#include <cassert>
#include "../../deleter.h"
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
int main()
{
{
std::unique_ptr<B, Deleter<B> > s(new B, Deleter<B>(5));
A* p = s.get();
std::unique_ptr<A, Deleter<A> > s2(new A);
assert(A::count == 2);
s2 = std::move(s);
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
assert(s2.get_deleter().state() == 5);
assert(s.get_deleter().state() == 0);
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr converting move assignment + +#include <memory> +#include <cassert> + +#include "../../deleter.h" + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +int main() +{ + { + std::unique_ptr<B, Deleter<B> > s(new B, Deleter<B>(5)); + A* p = s.get(); + std::unique_ptr<A, Deleter<A> > s2(new A); + assert(A::count == 2); + s2 = std::move(s); + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + assert(B::count == 1); + assert(s2.get_deleter().state() == 5); + assert(s.get_deleter().state() == 0); + } + assert(A::count == 0); + assert(B::count == 0); +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert03.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert03.fail.cpp index e5b5cb25418..94a0275fa01 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert03.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert03.fail.cpp @@ -1 +1,61 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move assignment
// Can't assign from lvalue
#include <memory>
#include <cassert>
#include "../../deleter.h"
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
int main()
{
{
Deleter<B> db(5);
std::unique_ptr<B, Deleter<B>&> s(new B, db);
A* p = s.get();
Deleter<A> da(6);
std::unique_ptr<A, Deleter<A>&> s2(new A, da);
s2 = s;
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
assert(s2.get_deleter().state() == 5);
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr converting move assignment + +// Can't assign from lvalue + +#include <memory> +#include <cassert> + +#include "../../deleter.h" + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +int main() +{ + { + Deleter<B> db(5); + std::unique_ptr<B, Deleter<B>&> s(new B, db); + A* p = s.get(); + Deleter<A> da(6); + std::unique_ptr<A, Deleter<A>&> s2(new A, da); + s2 = s; + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + assert(B::count == 1); + assert(s2.get_deleter().state() == 5); + } + assert(A::count == 0); + assert(B::count == 0); +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert03.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert03.pass.cpp index 2c421dfe3e6..880ba2ac066 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert03.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert03.pass.cpp @@ -1 +1,62 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move assignment
// test converting move assignment with reference deleters
#include <memory>
#include <cassert>
#include "../../deleter.h"
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
int main()
{
{
CDeleter<B> db(5);
std::unique_ptr<B, CDeleter<B>&> s(new B, db);
A* p = s.get();
CDeleter<A> da(6);
std::unique_ptr<A, CDeleter<A>&> s2(new A, da);
s2 = std::move(s);
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
assert(s.get_deleter().state() == 5);
assert(s2.get_deleter().state() == 5);
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr converting move assignment + +// test converting move assignment with reference deleters + +#include <memory> +#include <cassert> + +#include "../../deleter.h" + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +int main() +{ + { + CDeleter<B> db(5); + std::unique_ptr<B, CDeleter<B>&> s(new B, db); + A* p = s.get(); + CDeleter<A> da(6); + std::unique_ptr<A, CDeleter<A>&> s2(new A, da); + s2 = std::move(s); + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + assert(B::count == 1); + assert(s.get_deleter().state() == 5); + assert(s2.get_deleter().state() == 5); + } + assert(A::count == 0); + assert(B::count == 0); +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert04.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert04.fail.cpp index eef44ceb783..7708ab3fb1d 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert04.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert04.fail.cpp @@ -1 +1,56 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move assignment
#include <memory>
#include <cassert>
// Can't assign from const lvalue
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
int main()
{
{
const std::unique_ptr<B> s(new B);
A* p = s.get();
std::unique_ptr<A> s2;
s2 = s;
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr converting move assignment + +#include <memory> +#include <cassert> + +// Can't assign from const lvalue + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +int main() +{ + { + const std::unique_ptr<B> s(new B); + A* p = s.get(); + std::unique_ptr<A> s2; + s2 = s; + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + assert(B::count == 1); + } + assert(A::count == 0); + assert(B::count == 0); +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert05.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert05.fail.cpp index d796ba36cf3..bb821583fbb 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert05.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert05.fail.cpp @@ -1 +1,60 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move assignment
// Can't assign from const lvalue
#include <memory>
#include <cassert>
#include "../../deleter.h"
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
int main()
{
{
const std::unique_ptr<B, Deleter<B> > s(new B);
A* p = s.get();
std::unique_ptr<A, Deleter<A> > s2;
s2 = s;
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
assert(s2.get_deleter().state() == 5);
assert(s.get_deleter().state() == 0);
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr converting move assignment + +// Can't assign from const lvalue + +#include <memory> +#include <cassert> + +#include "../../deleter.h" + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +int main() +{ + { + const std::unique_ptr<B, Deleter<B> > s(new B); + A* p = s.get(); + std::unique_ptr<A, Deleter<A> > s2; + s2 = s; + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + assert(B::count == 1); + assert(s2.get_deleter().state() == 5); + assert(s.get_deleter().state() == 0); + } + assert(A::count == 0); + assert(B::count == 0); +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert06.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert06.fail.cpp index 0400cbdb7dd..91c2c04a449 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert06.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert06.fail.cpp @@ -1 +1,61 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move assignment
// Can't assign from const lvalue
#include <memory>
#include <cassert>
#include "../../deleter.h"
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
int main()
{
{
Deleter<B> db(5);
const std::unique_ptr<B, Deleter<B>&> s(new B, db);
A* p = s.get();
Deleter<A> da(6);
std::unique_ptr<A, Deleter<A>&> s2(new A, da);
s2 = s;
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
assert(s2.get_deleter().state() == 5);
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr converting move assignment + +// Can't assign from const lvalue + +#include <memory> +#include <cassert> + +#include "../../deleter.h" + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +int main() +{ + { + Deleter<B> db(5); + const std::unique_ptr<B, Deleter<B>&> s(new B, db); + A* p = s.get(); + Deleter<A> da(6); + std::unique_ptr<A, Deleter<A>&> s2(new A, da); + s2 = s; + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + assert(B::count == 1); + assert(s2.get_deleter().state() == 5); + } + assert(A::count == 0); + assert(B::count == 0); +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert13.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert13.fail.cpp index 7ec9e00ef79..af293c22d1b 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert13.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert13.fail.cpp @@ -1 +1,35 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move assignment
// Do not convert from an array unique_ptr
#include <memory>
#include <cassert>
struct A
{
};
struct Deleter
{
void operator()(void*) {}
};
int main()
{
std::unique_ptr<A[], Deleter> s;
std::unique_ptr<A, Deleter> s2;
s2 = std::move(s);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr converting move assignment + +// Do not convert from an array unique_ptr + +#include <memory> +#include <cassert> + +struct A +{ +}; + +struct Deleter +{ + void operator()(void*) {} +}; + +int main() +{ + std::unique_ptr<A[], Deleter> s; + std::unique_ptr<A, Deleter> s2; + s2 = std::move(s); +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/null.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/null.pass.cpp index da5d287e4c7..7f328176189 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/null.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/null.pass.cpp @@ -1 +1,41 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr move assignment
#include <memory>
#include <cassert>
// test assignment from null
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
std::unique_ptr<A> s2(new A);
assert(A::count == 1);
s2 = 0;
assert(A::count == 0);
assert(s2.get() == 0);
}
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr move assignment + +#include <memory> +#include <cassert> + +// test assignment from null + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +int main() +{ + { + std::unique_ptr<A> s2(new A); + assert(A::count == 1); + s2 = 0; + assert(A::count == 0); + assert(s2.get() == 0); + } + assert(A::count == 0); +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/nullptr.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/nullptr.pass.cpp index 3000f7448db..5627e1a2305 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/nullptr.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/nullptr.pass.cpp @@ -1 +1,41 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr move assignment
#include <memory>
#include <cassert>
// test assignment from null
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
std::unique_ptr<A> s2(new A);
assert(A::count == 1);
s2 = nullptr;
assert(A::count == 0);
assert(s2.get() == 0);
}
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr move assignment + +#include <memory> +#include <cassert> + +// test assignment from null + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +int main() +{ + { + std::unique_ptr<A> s2(new A); + assert(A::count == 1); + s2 = nullptr; + assert(A::count == 0); + assert(s2.get() == 0); + } + assert(A::count == 0); +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/auto_pointer.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/auto_pointer.pass.cpp index e12717599a3..62f1c60c3f9 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/auto_pointer.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/auto_pointer.pass.cpp @@ -1 +1,67 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr(pointer) ctor
#include <memory>
#include <cassert>
// template <class U> explicit unique_ptr(auto_ptr<U>&);
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
int main()
{
{
B* p = new B;
std::auto_ptr<B> ap(p);
std::unique_ptr<A> up(std::move(ap));
assert(up.get() == p);
assert(ap.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
}
assert(A::count == 0);
assert(B::count == 0);
{
B* p = new B;
std::auto_ptr<B> ap(p);
std::unique_ptr<A> up;
up = std::move(ap);
assert(up.get() == p);
assert(ap.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr(pointer) ctor + +#include <memory> +#include <cassert> + +// template <class U> explicit unique_ptr(auto_ptr<U>&); + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +int main() +{ + { + B* p = new B; + std::auto_ptr<B> ap(p); + std::unique_ptr<A> up(std::move(ap)); + assert(up.get() == p); + assert(ap.get() == 0); + assert(A::count == 1); + assert(B::count == 1); + } + assert(A::count == 0); + assert(B::count == 0); + { + B* p = new B; + std::auto_ptr<B> ap(p); + std::unique_ptr<A> up; + up = std::move(ap); + assert(up.get() == p); + assert(ap.get() == 0); + assert(A::count == 1); + assert(B::count == 1); + } + assert(A::count == 0); + assert(B::count == 0); +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/auto_pointer01.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/auto_pointer01.fail.cpp index a13af5b9d0b..d11eecb92db 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/auto_pointer01.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/auto_pointer01.fail.cpp @@ -1 +1,67 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr(pointer) ctor
#include <memory>
#include <cassert>
// template <class U> explicit unique_ptr(auto_ptr<U>&);
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
// : public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
int main()
{
{
B* p = new B;
std::auto_ptr<B> ap(p);
std::unique_ptr<A> up(ap);
assert(up.get() == p);
assert(ap.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
}
assert(A::count == 0);
assert(B::count == 0);
{
B* p = new B;
std::auto_ptr<B> ap(p);
std::unique_ptr<A> up;
up = ap;
assert(up.get() == p);
assert(ap.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr(pointer) ctor + +#include <memory> +#include <cassert> + +// template <class U> explicit unique_ptr(auto_ptr<U>&); + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B +// : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +int main() +{ + { + B* p = new B; + std::auto_ptr<B> ap(p); + std::unique_ptr<A> up(ap); + assert(up.get() == p); + assert(ap.get() == 0); + assert(A::count == 1); + assert(B::count == 1); + } + assert(A::count == 0); + assert(B::count == 0); + { + B* p = new B; + std::auto_ptr<B> ap(p); + std::unique_ptr<A> up; + up = ap; + assert(up.get() == p); + assert(ap.get() == 0); + assert(A::count == 1); + assert(B::count == 1); + } + assert(A::count == 0); + assert(B::count == 0); +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/auto_pointer02.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/auto_pointer02.fail.cpp index 9580723069b..cda17b20115 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/auto_pointer02.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/auto_pointer02.fail.cpp @@ -1 +1,61 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr(pointer) ctor
#include <memory>
#include <cassert>
// template <class U> explicit unique_ptr(auto_ptr<U>&);
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
struct Deleter
{
template <class T>
void operator()(T*) {}
};
int main()
{
{
B* p = new B;
std::auto_ptr<B> ap(p);
std::unique_ptr<A, Deleter> up(ap);
assert(up.get() == p);
assert(ap.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr(pointer) ctor + +#include <memory> +#include <cassert> + +// template <class U> explicit unique_ptr(auto_ptr<U>&); + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +struct Deleter +{ + template <class T> + void operator()(T*) {} +}; + +int main() +{ + { + B* p = new B; + std::auto_ptr<B> ap(p); + std::unique_ptr<A, Deleter> up(ap); + assert(up.get() == p); + assert(ap.get() == 0); + assert(A::count == 1); + assert(B::count == 1); + } + assert(A::count == 0); + assert(B::count == 0); +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/default01.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/default01.fail.cpp index d9e9d479f52..fb380ec07b6 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/default01.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/default01.fail.cpp @@ -1 +1,35 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr default ctor
#include <memory>
// default unique_ptr ctor should require default Deleter ctor
class Deleter
{
Deleter() {}
public:
Deleter(Deleter&) {}
Deleter& operator=(Deleter&) {}
void operator()(void*) const {}
};
int main()
{
std::unique_ptr<int, Deleter> p;
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr default ctor + +#include <memory> + +// default unique_ptr ctor should require default Deleter ctor +class Deleter +{ + + Deleter() {} + +public: + + Deleter(Deleter&) {} + Deleter& operator=(Deleter&) {} + + void operator()(void*) const {} +}; + +int main() +{ + std::unique_ptr<int, Deleter> p; +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/default01.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/default01.pass.cpp index e0178ba2f5d..48c7fadf35c 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/default01.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/default01.pass.cpp @@ -1 +1,46 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr default ctor
#include <memory>
#include <cassert>
// default unique_ptr ctor should only require default Deleter ctor
class Deleter
{
int state_;
Deleter(Deleter&);
Deleter& operator=(Deleter&);
public:
Deleter() : state_(5) {}
int state() const {return state_;}
void operator()(void*) {}
};
int main()
{
{
std::unique_ptr<int> p;
assert(p.get() == 0);
}
{
std::unique_ptr<int, Deleter> p;
assert(p.get() == 0);
assert(p.get_deleter().state() == 5);
}
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr default ctor + +#include <memory> +#include <cassert> + +// default unique_ptr ctor should only require default Deleter ctor +class Deleter +{ + int state_; + + Deleter(Deleter&); + Deleter& operator=(Deleter&); + +public: + Deleter() : state_(5) {} + + int state() const {return state_;} + + void operator()(void*) {} +}; + +int main() +{ + { + std::unique_ptr<int> p; + assert(p.get() == 0); + } + { + std::unique_ptr<int, Deleter> p; + assert(p.get() == 0); + assert(p.get_deleter().state() == 5); + } +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/default02.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/default02.fail.cpp index 1255c5c0c03..66df19698ac 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/default02.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/default02.fail.cpp @@ -1 +1,29 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr default ctor
#include <memory>
// default unique_ptr ctor should require non-reference Deleter ctor
class Deleter
{
public:
void operator()(void*) {}
};
int main()
{
std::unique_ptr<int, Deleter&> p;
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr default ctor + +#include <memory> + +// default unique_ptr ctor should require non-reference Deleter ctor +class Deleter +{ +public: + + void operator()(void*) {} +}; + +int main() +{ + std::unique_ptr<int, Deleter&> p; +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/default02.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/default02.pass.cpp index 90cf3752937..67332e4bbdd 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/default02.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/default02.pass.cpp @@ -1 +1,84 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test default unique_ptr ctor
#include <memory>
#include <cassert>
// default unique_ptr ctor shouldn't require complete type
struct A;
class Deleter
{
int state_;
Deleter(Deleter&);
Deleter& operator=(Deleter&);
public:
Deleter() : state_(5) {}
int state() const {return state_;}
void operator()(A* p);
};
void check(int i);
template <class D = std::default_delete<A> >
struct B
{
std::unique_ptr<A, D> a_;
B() {}
~B();
A* get() const {return a_.get();}
D& get_deleter() {return a_.get_deleter();}
};
int main()
{
{
B<> s;
assert(s.get() == 0);
}
check(0);
{
B<Deleter> s;
assert(s.get() == 0);
assert(s.get_deleter().state() == 5);
}
check(0);
}
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
void Deleter::operator()(A* p) {delete p;}
void check(int i)
{
assert(A::count == i);
}
template <class D>
B<D>::~B() {}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test default unique_ptr ctor + +#include <memory> +#include <cassert> + +// default unique_ptr ctor shouldn't require complete type + +struct A; + +class Deleter +{ + int state_; + + Deleter(Deleter&); + Deleter& operator=(Deleter&); + +public: + Deleter() : state_(5) {} + + int state() const {return state_;} + + void operator()(A* p); +}; + +void check(int i); + +template <class D = std::default_delete<A> > +struct B +{ + std::unique_ptr<A, D> a_; + B() {} + ~B(); + + A* get() const {return a_.get();} + D& get_deleter() {return a_.get_deleter();} +}; + +int main() +{ + { + B<> s; + assert(s.get() == 0); + } + check(0); + { + B<Deleter> s; + assert(s.get() == 0); + assert(s.get_deleter().state() == 5); + } + check(0); +} + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +void Deleter::operator()(A* p) {delete p;} + +void check(int i) +{ + assert(A::count == i); +} + +template <class D> +B<D>::~B() {} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/default03.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/default03.fail.cpp index f8de7af2fb2..af86c25a117 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/default03.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/default03.fail.cpp @@ -1 +1,23 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr default ctor
#include <memory>
// default unique_ptr ctor should require non-pointer Deleter
int main()
{
std::unique_ptr<int, void (*)(void*)> p;
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr default ctor + +#include <memory> + +// default unique_ptr ctor should require non-pointer Deleter + +int main() +{ + std::unique_ptr<int, void (*)(void*)> p; +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move01.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move01.fail.cpp index 5d7b6232203..41e4254a9b4 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move01.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move01.fail.cpp @@ -1 +1,42 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr move ctor
#include <memory>
#include <cassert>
// test move ctor. Can't copy from lvalue
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
std::unique_ptr<A> s(new A);
A* p = s.get();
std::unique_ptr<A> s2 = s;
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
}
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr move ctor + +#include <memory> +#include <cassert> + +// test move ctor. Can't copy from lvalue + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +int main() +{ + { + std::unique_ptr<A> s(new A); + A* p = s.get(); + std::unique_ptr<A> s2 = s; + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + } + assert(A::count == 0); +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move01.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move01.pass.cpp index 7d3484d54e3..f3bcbcf23c2 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move01.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move01.pass.cpp @@ -1 +1,141 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr move ctor
#include <memory>
#include <cassert>
// test move ctor. Should only require a MoveConstructible deleter, or if
// deleter is a reference, not even that.
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
template <class T>
class Deleter
{
int state_;
#ifdef _LIBCPP_MOVE
Deleter(const Deleter&);
Deleter& operator=(const Deleter&);
#else
Deleter(Deleter&);
Deleter& operator=(Deleter&);
#endif
public:
#ifdef _LIBCPP_MOVE
Deleter(Deleter&& r) : state_(r.state_) {r.state_ = 0;}
Deleter& operator=(Deleter&& r)
{
state_ = r.state_;
r.state_ = 0;
return *this;
}
#else
operator std::__rv<Deleter>() {return std::__rv<Deleter>(*this);}
Deleter(std::__rv<Deleter> r) : state_(r->state_) {r->state_ = 0;}
Deleter& operator=(std::__rv<Deleter> r)
{
state_ = r->state_;
r->state_ = 0;
return *this;
}
#endif
Deleter() : state_(5) {}
#ifdef _LIBCPP_MOVE
template <class U>
Deleter(Deleter<U>&& d,
typename std::enable_if<!std::is_same<U, T>::value>::type* = 0)
: state_(d.state()) {d.set_state(0);}
private:
template <class U>
Deleter(const Deleter<U>& d,
typename std::enable_if<!std::is_same<U, T>::value>::type* = 0);
#else
template <class U>
Deleter(Deleter<U> d,
typename std::enable_if<!std::is_same<U, T>::value>::type* = 0)
: state_(d.state()) {}
#endif
public:
int state() const {return state_;}
void set_state(int i) {state_ = i;}
void operator()(T* p) {delete p;}
};
class CDeleter
{
int state_;
CDeleter(CDeleter&);
CDeleter& operator=(CDeleter&);
public:
CDeleter() : state_(5) {}
int state() const {return state_;}
void set_state(int s) {state_ = s;}
void operator()(A* p) {delete p;}
};
int main()
{
{
std::unique_ptr<A> s(new A);
A* p = s.get();
std::unique_ptr<A> s2 = std::move(s);
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
}
assert(A::count == 0);
{
std::unique_ptr<A, Deleter<A> > s(new A);
A* p = s.get();
std::unique_ptr<A, Deleter<A> > s2 = std::move(s);
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(s2.get_deleter().state() == 5);
assert(s.get_deleter().state() == 0);
}
assert(A::count == 0);
{
CDeleter d;
std::unique_ptr<A, CDeleter&> s(new A, d);
A* p = s.get();
std::unique_ptr<A, CDeleter&> s2 = std::move(s);
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
d.set_state(6);
assert(s2.get_deleter().state() == d.state());
assert(s.get_deleter().state() == d.state());
}
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr move ctor + +#include <memory> +#include <cassert> + +// test move ctor. Should only require a MoveConstructible deleter, or if +// deleter is a reference, not even that. + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +template <class T> +class Deleter +{ + int state_; + +#ifdef _LIBCPP_MOVE + Deleter(const Deleter&); + Deleter& operator=(const Deleter&); +#else // _LIBCPP_MOVE + Deleter(Deleter&); + Deleter& operator=(Deleter&); +#endif // _LIBCPP_MOVE + +public: +#ifdef _LIBCPP_MOVE + Deleter(Deleter&& r) : state_(r.state_) {r.state_ = 0;} + Deleter& operator=(Deleter&& r) + { + state_ = r.state_; + r.state_ = 0; + return *this; + } +#else // _LIBCPP_MOVE + operator std::__rv<Deleter>() {return std::__rv<Deleter>(*this);} + Deleter(std::__rv<Deleter> r) : state_(r->state_) {r->state_ = 0;} + Deleter& operator=(std::__rv<Deleter> r) + { + state_ = r->state_; + r->state_ = 0; + return *this; + } +#endif // _LIBCPP_MOVE + + Deleter() : state_(5) {} + +#ifdef _LIBCPP_MOVE + template <class U> + Deleter(Deleter<U>&& d, + typename std::enable_if<!std::is_same<U, T>::value>::type* = 0) + : state_(d.state()) {d.set_state(0);} + +private: + template <class U> + Deleter(const Deleter<U>& d, + typename std::enable_if<!std::is_same<U, T>::value>::type* = 0); +#else // _LIBCPP_MOVE + template <class U> + Deleter(Deleter<U> d, + typename std::enable_if<!std::is_same<U, T>::value>::type* = 0) + : state_(d.state()) {} +#endif // _LIBCPP_MOVE +public: + int state() const {return state_;} + void set_state(int i) {state_ = i;} + + void operator()(T* p) {delete p;} +}; + +class CDeleter +{ + int state_; + + CDeleter(CDeleter&); + CDeleter& operator=(CDeleter&); +public: + + CDeleter() : state_(5) {} + + int state() const {return state_;} + void set_state(int s) {state_ = s;} + + void operator()(A* p) {delete p;} +}; + +int main() +{ + { + std::unique_ptr<A> s(new A); + A* p = s.get(); + std::unique_ptr<A> s2 = std::move(s); + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + } + assert(A::count == 0); + { + std::unique_ptr<A, Deleter<A> > s(new A); + A* p = s.get(); + std::unique_ptr<A, Deleter<A> > s2 = std::move(s); + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + assert(s2.get_deleter().state() == 5); + assert(s.get_deleter().state() == 0); + } + assert(A::count == 0); + { + CDeleter d; + std::unique_ptr<A, CDeleter&> s(new A, d); + A* p = s.get(); + std::unique_ptr<A, CDeleter&> s2 = std::move(s); + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + d.set_state(6); + assert(s2.get_deleter().state() == d.state()); + assert(s.get_deleter().state() == d.state()); + } + assert(A::count == 0); +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move02.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move02.fail.cpp index 84470c9e4f2..bf2dd807077 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move02.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move02.fail.cpp @@ -1 +1,42 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr move ctor
#include <memory>
#include <cassert>
// test move ctor. Can't copy from const lvalue
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
const std::unique_ptr<A> s(new A);
A* p = s.get();
std::unique_ptr<A> s2 = s;
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
}
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr move ctor + +#include <memory> +#include <cassert> + +// test move ctor. Can't copy from const lvalue + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +int main() +{ + { + const std::unique_ptr<A> s(new A); + A* p = s.get(); + std::unique_ptr<A> s2 = s; + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + } + assert(A::count == 0); +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move02.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move02.pass.cpp index 5abbb7776a2..e0d8c5acf3f 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move02.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move02.pass.cpp @@ -1 +1,143 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr move ctor
#include <memory>
#include <cassert>
// test move ctor. Should only require a MoveConstructible deleter, or if
// deleter is a reference, not even that.
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
template <class T>
class Deleter
{
int state_;
#ifdef _LIBCPP_MOVE
Deleter(const Deleter&);
Deleter& operator=(const Deleter&);
#else
Deleter(Deleter&);
Deleter& operator=(Deleter&);
#endif
public:
#ifdef _LIBCPP_MOVE
Deleter(Deleter&& r) : state_(r.state_) {r.state_ = 0;}
Deleter& operator=(Deleter&& r)
{
state_ = r.state_;
r.state_ = 0;
return *this;
}
#else
operator std::__rv<Deleter>() {return std::__rv<Deleter>(*this);}
Deleter(std::__rv<Deleter> r) : state_(r->state_) {r->state_ = 0;}
Deleter& operator=(std::__rv<Deleter> r)
{
state_ = r->state_;
r->state_ = 0;
return *this;
}
#endif
Deleter() : state_(5) {}
#ifdef _LIBCPP_MOVE
template <class U>
Deleter(Deleter<U>&& d,
typename std::enable_if<!std::is_same<U, T>::value>::type* = 0)
: state_(d.state()) {d.set_state(0);}
private:
template <class U>
Deleter(const Deleter<U>& d,
typename std::enable_if<!std::is_same<U, T>::value>::type* = 0);
#else
template <class U>
Deleter(Deleter<U> d,
typename std::enable_if<!std::is_same<U, T>::value>::type* = 0)
: state_(d.state()) {}
#endif
public:
int state() const {return state_;}
void set_state(int i) {state_ = i;}
void operator()(T* p) {delete p;}
};
class CDeleter
{
int state_;
CDeleter(CDeleter&);
CDeleter& operator=(CDeleter&);
public:
CDeleter() : state_(5) {}
int state() const {return state_;}
void set_state(int s) {state_ = s;}
void operator()(A* p) {delete p;}
};
std::unique_ptr<A>
source1()
{
return std::unique_ptr<A>(new A);
}
void sink1(std::unique_ptr<A> p)
{
}
std::unique_ptr<A, Deleter<A> >
source2()
{
return std::unique_ptr<A, Deleter<A> >(new A);
}
void sink2(std::unique_ptr<A, Deleter<A> > p)
{
}
std::unique_ptr<A, CDeleter&>
source3()
{
static CDeleter d;
return std::unique_ptr<A, CDeleter&>(new A, d);
}
void sink3(std::unique_ptr<A, CDeleter&> p)
{
}
int main()
{
sink1(source1());
sink2(source2());
sink3(source3());
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr move ctor + +#include <memory> +#include <cassert> + +// test move ctor. Should only require a MoveConstructible deleter, or if +// deleter is a reference, not even that. + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +template <class T> +class Deleter +{ + int state_; + +#ifdef _LIBCPP_MOVE + Deleter(const Deleter&); + Deleter& operator=(const Deleter&); +#else // _LIBCPP_MOVE + Deleter(Deleter&); + Deleter& operator=(Deleter&); +#endif // _LIBCPP_MOVE + +public: +#ifdef _LIBCPP_MOVE + Deleter(Deleter&& r) : state_(r.state_) {r.state_ = 0;} + Deleter& operator=(Deleter&& r) + { + state_ = r.state_; + r.state_ = 0; + return *this; + } +#else // _LIBCPP_MOVE + operator std::__rv<Deleter>() {return std::__rv<Deleter>(*this);} + Deleter(std::__rv<Deleter> r) : state_(r->state_) {r->state_ = 0;} + Deleter& operator=(std::__rv<Deleter> r) + { + state_ = r->state_; + r->state_ = 0; + return *this; + } +#endif // _LIBCPP_MOVE + + Deleter() : state_(5) {} + +#ifdef _LIBCPP_MOVE + template <class U> + Deleter(Deleter<U>&& d, + typename std::enable_if<!std::is_same<U, T>::value>::type* = 0) + : state_(d.state()) {d.set_state(0);} + +private: + template <class U> + Deleter(const Deleter<U>& d, + typename std::enable_if<!std::is_same<U, T>::value>::type* = 0); +#else // _LIBCPP_MOVE + template <class U> + Deleter(Deleter<U> d, + typename std::enable_if<!std::is_same<U, T>::value>::type* = 0) + : state_(d.state()) {} +#endif // _LIBCPP_MOVE +public: + int state() const {return state_;} + void set_state(int i) {state_ = i;} + + void operator()(T* p) {delete p;} +}; + +class CDeleter +{ + int state_; + + CDeleter(CDeleter&); + CDeleter& operator=(CDeleter&); +public: + + CDeleter() : state_(5) {} + + int state() const {return state_;} + void set_state(int s) {state_ = s;} + + void operator()(A* p) {delete p;} +}; + +std::unique_ptr<A> +source1() +{ + return std::unique_ptr<A>(new A); +} + +void sink1(std::unique_ptr<A> p) +{ +} + +std::unique_ptr<A, Deleter<A> > +source2() +{ + return std::unique_ptr<A, Deleter<A> >(new A); +} + +void sink2(std::unique_ptr<A, Deleter<A> > p) +{ +} + +std::unique_ptr<A, CDeleter&> +source3() +{ + static CDeleter d; + return std::unique_ptr<A, CDeleter&>(new A, d); +} + +void sink3(std::unique_ptr<A, CDeleter&> p) +{ +} + +int main() +{ + sink1(source1()); + sink2(source2()); + sink3(source3()); + assert(A::count == 0); +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move03.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move03.fail.cpp index d6bffbec699..5926b9ae551 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move03.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move03.fail.cpp @@ -1 +1,55 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr move ctor
#include <memory>
#include <cassert>
// test move ctor. Can't copy from lvalue
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
class Deleter
{
int state_;
public:
Deleter() : state_(5) {}
int state() const {return state_;}
void operator()(A* p) {delete p;}
};
int main()
{
{
std::unique_ptr<A, Deleter> s(new A);
A* p = s.get();
std::unique_ptr<A, Deleter> s2 = s;
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
}
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr move ctor + +#include <memory> +#include <cassert> + +// test move ctor. Can't copy from lvalue + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +class Deleter +{ + int state_; + +public: + + Deleter() : state_(5) {} + + int state() const {return state_;} + + void operator()(A* p) {delete p;} +}; + +int main() +{ + { + std::unique_ptr<A, Deleter> s(new A); + A* p = s.get(); + std::unique_ptr<A, Deleter> s2 = s; + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + } + assert(A::count == 0); +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move04.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move04.fail.cpp index 876b5899349..dfec0c3b63e 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move04.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move04.fail.cpp @@ -1 +1,55 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr move ctor
#include <memory>
#include <cassert>
// test move ctor. Can't copy from const lvalue
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
class Deleter
{
int state_;
public:
Deleter() : state_(5) {}
int state() const {return state_;}
void operator()(A* p) {delete p;}
};
int main()
{
{
const std::unique_ptr<A, Deleter> s(new A);
A* p = s.get();
std::unique_ptr<A, Deleter> s2 = s;
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
}
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr move ctor + +#include <memory> +#include <cassert> + +// test move ctor. Can't copy from const lvalue + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +class Deleter +{ + int state_; + +public: + + Deleter() : state_(5) {} + + int state() const {return state_;} + + void operator()(A* p) {delete p;} +}; + +int main() +{ + { + const std::unique_ptr<A, Deleter> s(new A); + A* p = s.get(); + std::unique_ptr<A, Deleter> s2 = s; + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + } + assert(A::count == 0); +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert01.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert01.fail.cpp index 7454a2cc543..6dd63a58466 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert01.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert01.fail.cpp @@ -1 +1,55 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move ctor
#include <memory>
#include <cassert>
// Can't construct from lvalue
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
int main()
{
{
std::unique_ptr<B> s(new B);
A* p = s.get();
std::unique_ptr<A> s2(s);
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr converting move ctor + +#include <memory> +#include <cassert> + +// Can't construct from lvalue + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +int main() +{ + { + std::unique_ptr<B> s(new B); + A* p = s.get(); + std::unique_ptr<A> s2(s); + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + assert(B::count == 1); + } + assert(A::count == 0); + assert(B::count == 0); +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert01.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert01.pass.cpp index a82e3f8f1b9..7254261d656 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert01.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert01.pass.cpp @@ -1 +1,57 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move ctor
#include <memory>
#include <cassert>
// test converting move ctor. Should only require a MoveConstructible deleter, or if
// deleter is a reference, not even that.
// Explicit version
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
int main()
{
{
std::unique_ptr<B> s(new B);
A* p = s.get();
std::unique_ptr<A> s2(std::move(s));
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr converting move ctor + +#include <memory> +#include <cassert> + +// test converting move ctor. Should only require a MoveConstructible deleter, or if +// deleter is a reference, not even that. +// Explicit version + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +int main() +{ + { + std::unique_ptr<B> s(new B); + A* p = s.get(); + std::unique_ptr<A> s2(std::move(s)); + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + assert(B::count == 1); + } + assert(A::count == 0); + assert(B::count == 0); +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert02.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert02.fail.cpp index 85388db4d5a..4a631eed7cd 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert02.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert02.fail.cpp @@ -1 +1,61 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move ctor
// test converting move ctor. Should only require a MoveConstructible deleter, or if
// deleter is a reference, not even that.
// Explicit version
#include <memory>
#include <cassert>
#include "../../deleter.h"
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
int main()
{
{
std::unique_ptr<B, Deleter<B> > s(new B);
A* p = s.get();
std::unique_ptr<A, Deleter<A> > s2(s);
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
assert(s2.get_deleter().state() == 5);
assert(s.get_deleter().state() == 0);
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr converting move ctor + +// test converting move ctor. Should only require a MoveConstructible deleter, or if +// deleter is a reference, not even that. +// Explicit version + +#include <memory> +#include <cassert> + +#include "../../deleter.h" + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +int main() +{ + { + std::unique_ptr<B, Deleter<B> > s(new B); + A* p = s.get(); + std::unique_ptr<A, Deleter<A> > s2(s); + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + assert(B::count == 1); + assert(s2.get_deleter().state() == 5); + assert(s.get_deleter().state() == 0); + } + assert(A::count == 0); + assert(B::count == 0); +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert02.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert02.pass.cpp index 091e3fbee97..d084f63b0fa 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert02.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert02.pass.cpp @@ -1 +1,61 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move ctor
#include <memory>
#include <cassert>
#include "../../deleter.h"
// test converting move ctor. Should only require a MoveConstructible deleter, or if
// deleter is a reference, not even that.
// Explicit version
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
int main()
{
{
std::unique_ptr<B, Deleter<B> > s(new B, Deleter<B>(5));
A* p = s.get();
std::unique_ptr<A, Deleter<A> > s2(std::move(s));
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
assert(s2.get_deleter().state() == 5);
assert(s.get_deleter().state() == 0);
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr converting move ctor + +#include <memory> +#include <cassert> + +#include "../../deleter.h" + +// test converting move ctor. Should only require a MoveConstructible deleter, or if +// deleter is a reference, not even that. +// Explicit version + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +int main() +{ + { + std::unique_ptr<B, Deleter<B> > s(new B, Deleter<B>(5)); + A* p = s.get(); + std::unique_ptr<A, Deleter<A> > s2(std::move(s)); + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + assert(B::count == 1); + assert(s2.get_deleter().state() == 5); + assert(s.get_deleter().state() == 0); + } + assert(A::count == 0); + assert(B::count == 0); +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert03.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert03.fail.cpp index 0fb4a4cd058..0435e73631d 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert03.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert03.fail.cpp @@ -1 +1,78 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move ctor
#include <memory>
#include <cassert>
// test converting move ctor. Should only require a MoveConstructible deleter, or if
// deleter is a reference, not even that.
// Explicit version
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
template <class T>
class CDeleter
{
int state_;
CDeleter(CDeleter&);
CDeleter& operator=(CDeleter&);
public:
CDeleter() : state_(5) {}
int state() const {return state_;}
void set_state(int s) {state_ = s;}
void operator()(T* p) {delete p;}
};
int main()
{
{
CDeleter<A> d;
std::unique_ptr<B, CDeleter<A>&> s(new B, d);
A* p = s.get();
std::unique_ptr<A, CDeleter<A>&> s2(s);
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
d.set_state(6);
assert(s2.get_deleter().state() == d.state());
assert(s.get_deleter().state() == d.state());
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr converting move ctor + +#include <memory> +#include <cassert> + +// test converting move ctor. Should only require a MoveConstructible deleter, or if +// deleter is a reference, not even that. +// Explicit version + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +template <class T> +class CDeleter +{ + int state_; + + CDeleter(CDeleter&); + CDeleter& operator=(CDeleter&); +public: + + CDeleter() : state_(5) {} + + int state() const {return state_;} + void set_state(int s) {state_ = s;} + + void operator()(T* p) {delete p;} +}; + +int main() +{ + { + CDeleter<A> d; + std::unique_ptr<B, CDeleter<A>&> s(new B, d); + A* p = s.get(); + std::unique_ptr<A, CDeleter<A>&> s2(s); + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + assert(B::count == 1); + d.set_state(6); + assert(s2.get_deleter().state() == d.state()); + assert(s.get_deleter().state() == d.state()); + } + assert(A::count == 0); + assert(B::count == 0); +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert03.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert03.pass.cpp index ecda031dbf6..0accb534f86 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert03.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert03.pass.cpp @@ -1 +1,78 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move ctor
#include <memory>
#include <cassert>
// test converting move ctor. Should only require a MoveConstructible deleter, or if
// deleter is a reference, not even that.
// Explicit version
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
template <class T>
class CDeleter
{
int state_;
CDeleter(CDeleter&);
CDeleter& operator=(CDeleter&);
public:
CDeleter() : state_(5) {}
int state() const {return state_;}
void set_state(int s) {state_ = s;}
void operator()(T* p) {delete p;}
};
int main()
{
{
CDeleter<A> d;
std::unique_ptr<B, CDeleter<A>&> s(new B, d);
A* p = s.get();
std::unique_ptr<A, CDeleter<A>&> s2(std::move(s));
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
d.set_state(6);
assert(s2.get_deleter().state() == d.state());
assert(s.get_deleter().state() == d.state());
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr converting move ctor + +#include <memory> +#include <cassert> + +// test converting move ctor. Should only require a MoveConstructible deleter, or if +// deleter is a reference, not even that. +// Explicit version + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +template <class T> +class CDeleter +{ + int state_; + + CDeleter(CDeleter&); + CDeleter& operator=(CDeleter&); +public: + + CDeleter() : state_(5) {} + + int state() const {return state_;} + void set_state(int s) {state_ = s;} + + void operator()(T* p) {delete p;} +}; + +int main() +{ + { + CDeleter<A> d; + std::unique_ptr<B, CDeleter<A>&> s(new B, d); + A* p = s.get(); + std::unique_ptr<A, CDeleter<A>&> s2(std::move(s)); + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + assert(B::count == 1); + d.set_state(6); + assert(s2.get_deleter().state() == d.state()); + assert(s.get_deleter().state() == d.state()); + } + assert(A::count == 0); + assert(B::count == 0); +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert04.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert04.fail.cpp index 58a911a6dd2..c691d72cf97 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert04.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert04.fail.cpp @@ -1 +1,57 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move ctor
#include <memory>
#include <cassert>
// test converting move ctor. Should only require a MoveConstructible deleter, or if
// deleter is a reference, not even that.
// implicit version
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
int main()
{
{
std::unique_ptr<B> s(new B);
A* p = s.get();
std::unique_ptr<A> s2 = s;
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr converting move ctor + +#include <memory> +#include <cassert> + +// test converting move ctor. Should only require a MoveConstructible deleter, or if +// deleter is a reference, not even that. +// implicit version + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +int main() +{ + { + std::unique_ptr<B> s(new B); + A* p = s.get(); + std::unique_ptr<A> s2 = s; + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + assert(B::count == 1); + } + assert(A::count == 0); + assert(B::count == 0); +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert04.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert04.pass.cpp index 79b616139e3..94f932eebe7 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert04.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert04.pass.cpp @@ -1 +1,57 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move ctor
#include <memory>
#include <cassert>
// test converting move ctor. Should only require a MoveConstructible deleter, or if
// deleter is a reference, not even that.
// implicit version
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
int main()
{
{
std::unique_ptr<B> s(new B);
A* p = s.get();
std::unique_ptr<A> s2 = std::move(s);
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr converting move ctor + +#include <memory> +#include <cassert> + +// test converting move ctor. Should only require a MoveConstructible deleter, or if +// deleter is a reference, not even that. +// implicit version + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +int main() +{ + { + std::unique_ptr<B> s(new B); + A* p = s.get(); + std::unique_ptr<A> s2 = std::move(s); + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + assert(B::count == 1); + } + assert(A::count == 0); + assert(B::count == 0); +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert05.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert05.fail.cpp index 591bc79bc47..540ece084b7 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert05.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert05.fail.cpp @@ -1 +1,50 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move ctor
#include <memory>
#include <cassert>
#include "../../deleter.h"
// test converting move ctor. Should only require a MoveConstructible deleter, or if
// deleter is a reference, not even that.
// Implicit version
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
int main()
{
std::unique_ptr<B, Deleter<B> > s(new B);
std::unique_ptr<A, Deleter<A> > s2 = s;
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr converting move ctor + +#include <memory> +#include <cassert> + +#include "../../deleter.h" + +// test converting move ctor. Should only require a MoveConstructible deleter, or if +// deleter is a reference, not even that. +// Implicit version + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +int main() +{ + std::unique_ptr<B, Deleter<B> > s(new B); + std::unique_ptr<A, Deleter<A> > s2 = s; +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert05.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert05.pass.cpp index e4faba25b6e..ee1d80fc2fd 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert05.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert05.pass.cpp @@ -1 +1,61 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move ctor
#include <memory>
#include <cassert>
#include "../../deleter.h"
// test converting move ctor. Should only require a MoveConstructible deleter, or if
// deleter is a reference, not even that.
// Implicit version
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
int main()
{
{
std::unique_ptr<B, Deleter<B> > s(new B, Deleter<B>(5));
A* p = s.get();
std::unique_ptr<A, Deleter<A> > s2 = std::move(s);
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
assert(s2.get_deleter().state() == 5);
assert(s.get_deleter().state() == 0);
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr converting move ctor + +#include <memory> +#include <cassert> + +#include "../../deleter.h" + +// test converting move ctor. Should only require a MoveConstructible deleter, or if +// deleter is a reference, not even that. +// Implicit version + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +int main() +{ + { + std::unique_ptr<B, Deleter<B> > s(new B, Deleter<B>(5)); + A* p = s.get(); + std::unique_ptr<A, Deleter<A> > s2 = std::move(s); + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + assert(B::count == 1); + assert(s2.get_deleter().state() == 5); + assert(s.get_deleter().state() == 0); + } + assert(A::count == 0); + assert(B::count == 0); +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert06.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert06.fail.cpp index 9fd6649dbd4..d204c0e4dfe 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert06.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert06.fail.cpp @@ -1 +1,78 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move ctor
#include <memory>
#include <cassert>
// test converting move ctor. Should only require a MoveConstructible deleter, or if
// deleter is a reference, not even that.
// Explicit version
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
template <class T>
class CDeleter
{
int state_;
CDeleter(CDeleter&);
CDeleter& operator=(CDeleter&);
public:
CDeleter() : state_(5) {}
int state() const {return state_;}
void set_state(int s) {state_ = s;}
void operator()(T* p) {delete p;}
};
int main()
{
{
CDeleter<A> d;
std::unique_ptr<B, CDeleter<A>&> s(new B, d);
A* p = s.get();
std::unique_ptr<A, CDeleter<A>&> s2 = s;
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
d.set_state(6);
assert(s2.get_deleter().state() == d.state());
assert(s.get_deleter().state() == d.state());
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr converting move ctor + +#include <memory> +#include <cassert> + +// test converting move ctor. Should only require a MoveConstructible deleter, or if +// deleter is a reference, not even that. +// Explicit version + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +template <class T> +class CDeleter +{ + int state_; + + CDeleter(CDeleter&); + CDeleter& operator=(CDeleter&); +public: + + CDeleter() : state_(5) {} + + int state() const {return state_;} + void set_state(int s) {state_ = s;} + + void operator()(T* p) {delete p;} +}; + +int main() +{ + { + CDeleter<A> d; + std::unique_ptr<B, CDeleter<A>&> s(new B, d); + A* p = s.get(); + std::unique_ptr<A, CDeleter<A>&> s2 = s; + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + assert(B::count == 1); + d.set_state(6); + assert(s2.get_deleter().state() == d.state()); + assert(s.get_deleter().state() == d.state()); + } + assert(A::count == 0); + assert(B::count == 0); +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert06.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert06.pass.cpp index 4961a53a669..55aa13d7354 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert06.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert06.pass.cpp @@ -1 +1,78 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move ctor
#include <memory>
#include <cassert>
// test converting move ctor. Should only require a MoveConstructible deleter, or if
// deleter is a reference, not even that.
// Explicit version
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
template <class T>
class CDeleter
{
int state_;
CDeleter(CDeleter&);
CDeleter& operator=(CDeleter&);
public:
CDeleter() : state_(5) {}
int state() const {return state_;}
void set_state(int s) {state_ = s;}
void operator()(T* p) {delete p;}
};
int main()
{
{
CDeleter<A> d;
std::unique_ptr<B, CDeleter<A>&> s(new B, d);
A* p = s.get();
std::unique_ptr<A, CDeleter<A>&> s2 = std::move(s);
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
d.set_state(6);
assert(s2.get_deleter().state() == d.state());
assert(s.get_deleter().state() == d.state());
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr converting move ctor + +#include <memory> +#include <cassert> + +// test converting move ctor. Should only require a MoveConstructible deleter, or if +// deleter is a reference, not even that. +// Explicit version + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +template <class T> +class CDeleter +{ + int state_; + + CDeleter(CDeleter&); + CDeleter& operator=(CDeleter&); +public: + + CDeleter() : state_(5) {} + + int state() const {return state_;} + void set_state(int s) {state_ = s;} + + void operator()(T* p) {delete p;} +}; + +int main() +{ + { + CDeleter<A> d; + std::unique_ptr<B, CDeleter<A>&> s(new B, d); + A* p = s.get(); + std::unique_ptr<A, CDeleter<A>&> s2 = std::move(s); + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + assert(B::count == 1); + d.set_state(6); + assert(s2.get_deleter().state() == d.state()); + assert(s.get_deleter().state() == d.state()); + } + assert(A::count == 0); + assert(B::count == 0); +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert07.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert07.fail.cpp index d05e81e45e7..54bc4e9f9b2 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert07.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert07.fail.cpp @@ -1 +1,57 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move ctor
#include <memory>
#include <cassert>
// test converting move ctor. Should only require a MoveConstructible deleter, or if
// deleter is a reference, not even that.
// Explicit version
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
int main()
{
{
const std::unique_ptr<B> s(new B);
A* p = s.get();
std::unique_ptr<A> s2(s);
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr converting move ctor + +#include <memory> +#include <cassert> + +// test converting move ctor. Should only require a MoveConstructible deleter, or if +// deleter is a reference, not even that. +// Explicit version + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +int main() +{ + { + const std::unique_ptr<B> s(new B); + A* p = s.get(); + std::unique_ptr<A> s2(s); + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + assert(B::count == 1); + } + assert(A::count == 0); + assert(B::count == 0); +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert07.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert07.pass.cpp index 3ef4da00c71..1d4ec6d974a 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert07.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert07.pass.cpp @@ -1 +1,62 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move ctor
#include <memory>
#include <cassert>
#include "../../deleter.h"
// test converting move ctor. Should only require a MoveConstructible deleter, or if
// deleter is a reference, not even that.
// Implicit version
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
int main()
{
{
CDeleter<B> b(5);
std::unique_ptr<B, CDeleter<B>&> s(new B, b);
A* p = s.get();
std::unique_ptr<A, CDeleter<A> > s2 = std::move(s);
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
assert(s2.get_deleter().state() == 5);
assert(s.get_deleter().state() == 5);
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr converting move ctor + +#include <memory> +#include <cassert> + +#include "../../deleter.h" + +// test converting move ctor. Should only require a MoveConstructible deleter, or if +// deleter is a reference, not even that. +// Implicit version + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +int main() +{ + { + CDeleter<B> b(5); + std::unique_ptr<B, CDeleter<B>&> s(new B, b); + A* p = s.get(); + std::unique_ptr<A, CDeleter<A> > s2 = std::move(s); + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + assert(B::count == 1); + assert(s2.get_deleter().state() == 5); + assert(s.get_deleter().state() == 5); + } + assert(A::count == 0); + assert(B::count == 0); +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert08.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert08.fail.cpp index cdd0fd7f0eb..1da66eaef73 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert08.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert08.fail.cpp @@ -1 +1,117 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move ctor
#include <memory>
#include <cassert>
// test converting move ctor. Should only require a MoveConstructible deleter, or if
// deleter is a reference, not even that.
// Explicit version
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
template <class T>
class Deleter
{
int state_;
#ifdef _LIBCPP_MOVE
Deleter(const Deleter&);
Deleter& operator=(const Deleter&);
#else
Deleter(Deleter&);
Deleter& operator=(Deleter&);
#endif
public:
#ifdef _LIBCPP_MOVE
Deleter(Deleter&& r) : state_(r.state_) {r.state_ = 0;}
Deleter& operator=(Deleter&& r)
{
state_ = r.state_;
r.state_ = 0;
return *this;
}
#else
operator std::__rv<Deleter>() {return std::__rv<Deleter>(*this);}
Deleter(std::__rv<Deleter> r) : state_(r->state_) {r->state_ = 0;}
Deleter& operator=(std::__rv<Deleter> r)
{
state_ = r->state_;
r->state_ = 0;
return *this;
}
#endif
Deleter() : state_(5) {}
#ifdef _LIBCPP_MOVE
template <class U>
Deleter(Deleter<U>&& d,
typename std::enable_if<!std::is_same<U, T>::value>::type* = 0)
: state_(d.state()) {d.set_state(0);}
private:
template <class U>
Deleter(const Deleter<U>& d,
typename std::enable_if<!std::is_same<U, T>::value>::type* = 0);
#else
template <class U>
Deleter(Deleter<U> d,
typename std::enable_if<!std::is_same<U, T>::value>::type* = 0)
: state_(d.state()) {}
#endif
public:
int state() const {return state_;}
void set_state(int i) {state_ = i;}
void operator()(T* p) {delete p;}
};
int main()
{
{
const std::unique_ptr<B, Deleter<B> > s(new B);
A* p = s.get();
std::unique_ptr<A, Deleter<A> > s2(s);
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
assert(s2.get_deleter().state() == 5);
assert(s.get_deleter().state() == 0);
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr converting move ctor + +#include <memory> +#include <cassert> + +// test converting move ctor. Should only require a MoveConstructible deleter, or if +// deleter is a reference, not even that. +// Explicit version + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +template <class T> +class Deleter +{ + int state_; + +#ifdef _LIBCPP_MOVE + Deleter(const Deleter&); + Deleter& operator=(const Deleter&); +#else // _LIBCPP_MOVE + Deleter(Deleter&); + Deleter& operator=(Deleter&); +#endif // _LIBCPP_MOVE + +public: +#ifdef _LIBCPP_MOVE + Deleter(Deleter&& r) : state_(r.state_) {r.state_ = 0;} + Deleter& operator=(Deleter&& r) + { + state_ = r.state_; + r.state_ = 0; + return *this; + } +#else // _LIBCPP_MOVE + operator std::__rv<Deleter>() {return std::__rv<Deleter>(*this);} + Deleter(std::__rv<Deleter> r) : state_(r->state_) {r->state_ = 0;} + Deleter& operator=(std::__rv<Deleter> r) + { + state_ = r->state_; + r->state_ = 0; + return *this; + } +#endif // _LIBCPP_MOVE + + Deleter() : state_(5) {} + +#ifdef _LIBCPP_MOVE + template <class U> + Deleter(Deleter<U>&& d, + typename std::enable_if<!std::is_same<U, T>::value>::type* = 0) + : state_(d.state()) {d.set_state(0);} + +private: + template <class U> + Deleter(const Deleter<U>& d, + typename std::enable_if<!std::is_same<U, T>::value>::type* = 0); +#else // _LIBCPP_MOVE + template <class U> + Deleter(Deleter<U> d, + typename std::enable_if<!std::is_same<U, T>::value>::type* = 0) + : state_(d.state()) {} +#endif // _LIBCPP_MOVE +public: + int state() const {return state_;} + void set_state(int i) {state_ = i;} + + void operator()(T* p) {delete p;} +}; + +int main() +{ + { + const std::unique_ptr<B, Deleter<B> > s(new B); + A* p = s.get(); + std::unique_ptr<A, Deleter<A> > s2(s); + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + assert(B::count == 1); + assert(s2.get_deleter().state() == 5); + assert(s.get_deleter().state() == 0); + } + assert(A::count == 0); + assert(B::count == 0); +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert09.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert09.fail.cpp index 18a7b07e0d4..f79b52ff01b 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert09.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert09.fail.cpp @@ -1 +1,78 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move ctor
#include <memory>
#include <cassert>
// test converting move ctor. Should only require a MoveConstructible deleter, or if
// deleter is a reference, not even that.
// Explicit version
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
template <class T>
class CDeleter
{
int state_;
CDeleter(CDeleter&);
CDeleter& operator=(CDeleter&);
public:
CDeleter() : state_(5) {}
int state() const {return state_;}
void set_state(int s) {state_ = s;}
void operator()(T* p) {delete p;}
};
int main()
{
{
CDeleter<A> d;
const std::unique_ptr<B, CDeleter<A>&> s(new B, d);
A* p = s.get();
std::unique_ptr<A, CDeleter<A>&> s2(s);
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
d.set_state(6);
assert(s2.get_deleter().state() == d.state());
assert(s.get_deleter().state() == d.state());
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr converting move ctor + +#include <memory> +#include <cassert> + +// test converting move ctor. Should only require a MoveConstructible deleter, or if +// deleter is a reference, not even that. +// Explicit version + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +template <class T> +class CDeleter +{ + int state_; + + CDeleter(CDeleter&); + CDeleter& operator=(CDeleter&); +public: + + CDeleter() : state_(5) {} + + int state() const {return state_;} + void set_state(int s) {state_ = s;} + + void operator()(T* p) {delete p;} +}; + +int main() +{ + { + CDeleter<A> d; + const std::unique_ptr<B, CDeleter<A>&> s(new B, d); + A* p = s.get(); + std::unique_ptr<A, CDeleter<A>&> s2(s); + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + assert(B::count == 1); + d.set_state(6); + assert(s2.get_deleter().state() == d.state()); + assert(s.get_deleter().state() == d.state()); + } + assert(A::count == 0); + assert(B::count == 0); +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert10.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert10.fail.cpp index 0bed30c2c26..9fd1e910817 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert10.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert10.fail.cpp @@ -1 +1,57 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move ctor
#include <memory>
#include <cassert>
// test converting move ctor. Should only require a MoveConstructible deleter, or if
// deleter is a reference, not even that.
// implicit version
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
int main()
{
{
const std::unique_ptr<B> s(new B);
A* p = s.get();
std::unique_ptr<A> s2 = s;
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr converting move ctor + +#include <memory> +#include <cassert> + +// test converting move ctor. Should only require a MoveConstructible deleter, or if +// deleter is a reference, not even that. +// implicit version + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +int main() +{ + { + const std::unique_ptr<B> s(new B); + A* p = s.get(); + std::unique_ptr<A> s2 = s; + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + assert(B::count == 1); + } + assert(A::count == 0); + assert(B::count == 0); +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert11.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert11.fail.cpp index 3b7d5f81672..fe981de133d 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert11.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert11.fail.cpp @@ -1 +1,117 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move ctor
#include <memory>
#include <cassert>
// test converting move ctor. Should only require a MoveConstructible deleter, or if
// deleter is a reference, not even that.
// Implicit version
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
template <class T>
class Deleter
{
int state_;
#ifdef _LIBCPP_MOVE
Deleter(const Deleter&);
Deleter& operator=(const Deleter&);
#else
Deleter(Deleter&);
Deleter& operator=(Deleter&);
#endif
public:
#ifdef _LIBCPP_MOVE
Deleter(Deleter&& r) : state_(r.state_) {r.state_ = 0;}
Deleter& operator=(Deleter&& r)
{
state_ = r.state_;
r.state_ = 0;
return *this;
}
#else
operator std::__rv<Deleter>() {return std::__rv<Deleter>(*this);}
Deleter(std::__rv<Deleter> r) : state_(r->state_) {r->state_ = 0;}
Deleter& operator=(std::__rv<Deleter> r)
{
state_ = r->state_;
r->state_ = 0;
return *this;
}
#endif
Deleter() : state_(5) {}
#ifdef _LIBCPP_MOVE
template <class U>
Deleter(Deleter<U>&& d,
typename std::enable_if<!std::is_same<U, T>::value>::type* = 0)
: state_(d.state()) {d.set_state(0);}
private:
template <class U>
Deleter(const Deleter<U>& d,
typename std::enable_if<!std::is_same<U, T>::value>::type* = 0);
#else
template <class U>
Deleter(Deleter<U> d,
typename std::enable_if<!std::is_same<U, T>::value>::type* = 0)
: state_(d.state()) {}
#endif
public:
int state() const {return state_;}
void set_state(int i) {state_ = i;}
void operator()(T* p) {delete p;}
};
int main()
{
{
const std::unique_ptr<B, Deleter<B> > s(new B);
A* p = s.get();
std::unique_ptr<A, Deleter<A> > s2 = s;
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
assert(s2.get_deleter().state() == 5);
assert(s.get_deleter().state() == 0);
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr converting move ctor + +#include <memory> +#include <cassert> + +// test converting move ctor. Should only require a MoveConstructible deleter, or if +// deleter is a reference, not even that. +// Implicit version + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +template <class T> +class Deleter +{ + int state_; + +#ifdef _LIBCPP_MOVE + Deleter(const Deleter&); + Deleter& operator=(const Deleter&); +#else // _LIBCPP_MOVE + Deleter(Deleter&); + Deleter& operator=(Deleter&); +#endif // _LIBCPP_MOVE + +public: +#ifdef _LIBCPP_MOVE + Deleter(Deleter&& r) : state_(r.state_) {r.state_ = 0;} + Deleter& operator=(Deleter&& r) + { + state_ = r.state_; + r.state_ = 0; + return *this; + } +#else // _LIBCPP_MOVE + operator std::__rv<Deleter>() {return std::__rv<Deleter>(*this);} + Deleter(std::__rv<Deleter> r) : state_(r->state_) {r->state_ = 0;} + Deleter& operator=(std::__rv<Deleter> r) + { + state_ = r->state_; + r->state_ = 0; + return *this; + } +#endif // _LIBCPP_MOVE + + Deleter() : state_(5) {} + +#ifdef _LIBCPP_MOVE + template <class U> + Deleter(Deleter<U>&& d, + typename std::enable_if<!std::is_same<U, T>::value>::type* = 0) + : state_(d.state()) {d.set_state(0);} + +private: + template <class U> + Deleter(const Deleter<U>& d, + typename std::enable_if<!std::is_same<U, T>::value>::type* = 0); +#else // _LIBCPP_MOVE + template <class U> + Deleter(Deleter<U> d, + typename std::enable_if<!std::is_same<U, T>::value>::type* = 0) + : state_(d.state()) {} +#endif // _LIBCPP_MOVE +public: + int state() const {return state_;} + void set_state(int i) {state_ = i;} + + void operator()(T* p) {delete p;} +}; + +int main() +{ + { + const std::unique_ptr<B, Deleter<B> > s(new B); + A* p = s.get(); + std::unique_ptr<A, Deleter<A> > s2 = s; + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + assert(B::count == 1); + assert(s2.get_deleter().state() == 5); + assert(s.get_deleter().state() == 0); + } + assert(A::count == 0); + assert(B::count == 0); +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert12.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert12.fail.cpp index 42d7a189a11..8534110b932 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert12.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert12.fail.cpp @@ -1 +1,78 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move ctor
#include <memory>
#include <cassert>
// test converting move ctor. Should only require a MoveConstructible deleter, or if
// deleter is a reference, not even that.
// Explicit version
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
template <class T>
class CDeleter
{
int state_;
CDeleter(CDeleter&);
CDeleter& operator=(CDeleter&);
public:
CDeleter() : state_(5) {}
int state() const {return state_;}
void set_state(int s) {state_ = s;}
void operator()(T* p) {delete p;}
};
int main()
{
{
CDeleter<A> d;
const std::unique_ptr<B, CDeleter<A>&> s(new B, d);
A* p = s.get();
std::unique_ptr<A, CDeleter<A>&> s2 = s;
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
d.set_state(6);
assert(s2.get_deleter().state() == d.state());
assert(s.get_deleter().state() == d.state());
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr converting move ctor + +#include <memory> +#include <cassert> + +// test converting move ctor. Should only require a MoveConstructible deleter, or if +// deleter is a reference, not even that. +// Explicit version + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +template <class T> +class CDeleter +{ + int state_; + + CDeleter(CDeleter&); + CDeleter& operator=(CDeleter&); +public: + + CDeleter() : state_(5) {} + + int state() const {return state_;} + void set_state(int s) {state_ = s;} + + void operator()(T* p) {delete p;} +}; + +int main() +{ + { + CDeleter<A> d; + const std::unique_ptr<B, CDeleter<A>&> s(new B, d); + A* p = s.get(); + std::unique_ptr<A, CDeleter<A>&> s2 = s; + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + assert(B::count == 1); + d.set_state(6); + assert(s2.get_deleter().state() == d.state()); + assert(s.get_deleter().state() == d.state()); + } + assert(A::count == 0); + assert(B::count == 0); +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert13.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert13.fail.cpp index e5b666e581b..ee02f0d0256 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert13.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert13.fail.cpp @@ -1 +1,34 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move ctor
// Do not convert from an array unique_ptr
#include <memory>
#include <cassert>
struct A
{
};
struct Deleter
{
void operator()(void*) {}
};
int main()
{
std::unique_ptr<A[], Deleter> s;
std::unique_ptr<A, Deleter> s2(std::move(s));
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr converting move ctor + +// Do not convert from an array unique_ptr + +#include <memory> +#include <cassert> + +struct A +{ +}; + +struct Deleter +{ + void operator()(void*) {} +}; + +int main() +{ + std::unique_ptr<A[], Deleter> s; + std::unique_ptr<A, Deleter> s2(std::move(s)); +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/nullptr.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/nullptr.pass.cpp index c49c9c8deca..f4f6662cf65 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/nullptr.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/nullptr.pass.cpp @@ -1 +1,46 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// unique_ptr(nullptr_t);
#include <memory>
#include <cassert>
// default unique_ptr ctor should only require default Deleter ctor
class Deleter
{
int state_;
Deleter(Deleter&);
Deleter& operator=(Deleter&);
public:
Deleter() : state_(5) {}
int state() const {return state_;}
void operator()(void*) {}
};
int main()
{
{
std::unique_ptr<int> p(nullptr);
assert(p.get() == 0);
}
{
std::unique_ptr<int, Deleter> p(nullptr);
assert(p.get() == 0);
assert(p.get_deleter().state() == 5);
}
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// unique_ptr(nullptr_t); + +#include <memory> +#include <cassert> + +// default unique_ptr ctor should only require default Deleter ctor +class Deleter +{ + int state_; + + Deleter(Deleter&); + Deleter& operator=(Deleter&); + +public: + Deleter() : state_(5) {} + + int state() const {return state_;} + + void operator()(void*) {} +}; + +int main() +{ + { + std::unique_ptr<int> p(nullptr); + assert(p.get() == 0); + } + { + std::unique_ptr<int, Deleter> p(nullptr); + assert(p.get() == 0); + assert(p.get_deleter().state() == 5); + } +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer01.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer01.fail.cpp index eaffc6dc2a6..08b7ef29bb9 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer01.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer01.fail.cpp @@ -1 +1,35 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr(pointer) ctor
#include <memory>
// unique_ptr(pointer) ctor should require default Deleter ctor
class Deleter
{
Deleter() {}
public:
Deleter(Deleter&) {}
Deleter& operator=(Deleter&) {}
void operator()(void*) const {}
};
int main()
{
std::unique_ptr<int, Deleter> p(new int);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr(pointer) ctor + +#include <memory> + +// unique_ptr(pointer) ctor should require default Deleter ctor +class Deleter +{ + + Deleter() {} + +public: + + Deleter(Deleter&) {} + Deleter& operator=(Deleter&) {} + + void operator()(void*) const {} +}; + +int main() +{ + std::unique_ptr<int, Deleter> p(new int); +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer01.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer01.pass.cpp index 74f4f7fbfa7..b1c2b120839 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer01.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer01.pass.cpp @@ -1 +1,63 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr(pointer) ctor
#include <memory>
#include <cassert>
// unique_ptr(pointer) ctor should only require default Deleter ctor
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
class Deleter
{
int state_;
Deleter(Deleter&);
Deleter& operator=(Deleter&);
public:
Deleter() : state_(5) {}
int state() const {return state_;}
void operator()(A* p) {delete p;}
};
int main()
{
{
A* p = new A;
assert(A::count == 1);
std::unique_ptr<A> s(p);
assert(s.get() == p);
}
assert(A::count == 0);
{
A* p = new A;
assert(A::count == 1);
std::unique_ptr<A, Deleter> s(p);
assert(s.get() == p);
assert(s.get_deleter().state() == 5);
}
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr(pointer) ctor + +#include <memory> +#include <cassert> + +// unique_ptr(pointer) ctor should only require default Deleter ctor + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +class Deleter +{ + int state_; + + Deleter(Deleter&); + Deleter& operator=(Deleter&); + +public: + Deleter() : state_(5) {} + + int state() const {return state_;} + + void operator()(A* p) {delete p;} +}; + +int main() +{ + { + A* p = new A; + assert(A::count == 1); + std::unique_ptr<A> s(p); + assert(s.get() == p); + } + assert(A::count == 0); + { + A* p = new A; + assert(A::count == 1); + std::unique_ptr<A, Deleter> s(p); + assert(s.get() == p); + assert(s.get_deleter().state() == 5); + } + assert(A::count == 0); +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer02.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer02.fail.cpp index 7780932a4b5..d25470b4f70 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer02.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer02.fail.cpp @@ -1 +1,29 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr(pointer) ctor
#include <memory>
// unique_ptr(pointer) ctor should require non-reference Deleter ctor
class Deleter
{
public:
void operator()(void*) {}
};
int main()
{
std::unique_ptr<int, Deleter&> p(new int);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr(pointer) ctor + +#include <memory> + +// unique_ptr(pointer) ctor should require non-reference Deleter ctor +class Deleter +{ +public: + + void operator()(void*) {} +}; + +int main() +{ + std::unique_ptr<int, Deleter&> p(new int); +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer02.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer02.pass.cpp index f8ff88d2e86..7a5b75cba1e 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer02.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer02.pass.cpp @@ -1 +1,95 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr(pointer) ctor
#include <memory>
#include <cassert>
// unique_ptr(pointer) ctor shouldn't require complete type
struct A;
class Deleter
{
int state_;
Deleter(Deleter&);
Deleter& operator=(Deleter&);
public:
Deleter() : state_(5) {}
int state() const {return state_;}
void operator()(A* p);
};
void check(int i);
template <class D = std::default_delete<A> >
struct B
{
std::unique_ptr<A, D> a_;
explicit B(A*);
~B();
A* get() const {return a_.get();}
D& get_deleter() {return a_.get_deleter();}
};
A* get();
int main()
{
{
A* p = get();
check(1);
B<> s(p);
assert(s.get() == p);
}
check(0);
{
A* p = get();
check(1);
B<Deleter> s(p);
assert(s.get() == p);
assert(s.get_deleter().state() == 5);
}
check(0);
}
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
A* get() {return new A;}
void Deleter::operator()(A* p) {delete p;}
void check(int i)
{
assert(A::count == i);
}
template <class D>
B<D>::B(A* a) : a_(a) {}
template <class D>
B<D>::~B() {}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr(pointer) ctor + +#include <memory> +#include <cassert> + +// unique_ptr(pointer) ctor shouldn't require complete type + +struct A; + +class Deleter +{ + int state_; + + Deleter(Deleter&); + Deleter& operator=(Deleter&); + +public: + Deleter() : state_(5) {} + + int state() const {return state_;} + + void operator()(A* p); +}; + +void check(int i); + +template <class D = std::default_delete<A> > +struct B +{ + std::unique_ptr<A, D> a_; + explicit B(A*); + ~B(); + + A* get() const {return a_.get();} + D& get_deleter() {return a_.get_deleter();} +}; + +A* get(); + +int main() +{ + { + A* p = get(); + check(1); + B<> s(p); + assert(s.get() == p); + } + check(0); + { + A* p = get(); + check(1); + B<Deleter> s(p); + assert(s.get() == p); + assert(s.get_deleter().state() == 5); + } + check(0); +} + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +A* get() {return new A;} + +void Deleter::operator()(A* p) {delete p;} + +void check(int i) +{ + assert(A::count == i); +} + +template <class D> +B<D>::B(A* a) : a_(a) {} + +template <class D> +B<D>::~B() {} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer03.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer03.fail.cpp index f3f09535b33..32e66471cc2 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer03.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer03.fail.cpp @@ -1 +1,23 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr(pointer) ctor
#include <memory>
// unique_ptr(pointer) ctor should require non-pointer Deleter
int main()
{
std::unique_ptr<int, void (*)(void*)> p(new int);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr(pointer) ctor + +#include <memory> + +// unique_ptr(pointer) ctor should require non-pointer Deleter + +int main() +{ + std::unique_ptr<int, void (*)(void*)> p(new int); +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer03.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer03.pass.cpp index ef4542564e0..1608adee945 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer03.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer03.pass.cpp @@ -1 +1,78 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr(pointer) ctor
#include <memory>
#include <cassert>
// unique_ptr(pointer) ctor should work with derived pointers
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
class Deleter
{
int state_;
Deleter(Deleter&);
Deleter& operator=(Deleter&);
public:
Deleter() : state_(5) {}
int state() const {return state_;}
void operator()(A* p) {delete p;}
};
int main()
{
{
B* p = new B;
assert(A::count == 1);
assert(B::count == 1);
std::unique_ptr<A> s(p);
assert(s.get() == p);
}
assert(A::count == 0);
assert(B::count == 0);
{
B* p = new B;
assert(A::count == 1);
assert(B::count == 1);
std::unique_ptr<A, Deleter> s(p);
assert(s.get() == p);
assert(s.get_deleter().state() == 5);
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr(pointer) ctor + +#include <memory> +#include <cassert> + +// unique_ptr(pointer) ctor should work with derived pointers + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +class Deleter +{ + int state_; + + Deleter(Deleter&); + Deleter& operator=(Deleter&); + +public: + Deleter() : state_(5) {} + + int state() const {return state_;} + + void operator()(A* p) {delete p;} +}; + +int main() +{ + { + B* p = new B; + assert(A::count == 1); + assert(B::count == 1); + std::unique_ptr<A> s(p); + assert(s.get() == p); + } + assert(A::count == 0); + assert(B::count == 0); + { + B* p = new B; + assert(A::count == 1); + assert(B::count == 1); + std::unique_ptr<A, Deleter> s(p); + assert(s.get() == p); + assert(s.get_deleter().state() == 5); + } + assert(A::count == 0); + assert(B::count == 0); +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer_deleter01.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer_deleter01.pass.cpp index 8305a399a3c..1faff87269a 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer_deleter01.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer_deleter01.pass.cpp @@ -1 +1,99 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr(pointer) ctor
#include <memory>
#include <cassert>
// unique_ptr(pointer, deleter()) only requires MoveConstructible deleter
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
template <class T>
class Deleter
{
int state_;
#ifdef _LIBCPP_MOVE
Deleter(const Deleter&);
Deleter& operator=(const Deleter&);
#else
Deleter(Deleter&);
Deleter& operator=(Deleter&);
#endif
public:
#ifdef _LIBCPP_MOVE
Deleter(Deleter&& r) : state_(r.state_) {r.state_ = 0;}
Deleter& operator=(Deleter&& r)
{
state_ = r.state_;
r.state_ = 0;
return *this;
}
#else
operator std::__rv<Deleter>() {return std::__rv<Deleter>(*this);}
Deleter(std::__rv<Deleter> r) : state_(r->state_) {r->state_ = 0;}
Deleter& operator=(std::__rv<Deleter> r)
{
state_ = r->state_;
r->state_ = 0;
return *this;
}
#endif
Deleter() : state_(5) {}
#ifdef _LIBCPP_MOVE
template <class U>
Deleter(Deleter<U>&& d,
typename std::enable_if<!std::is_same<U, T>::value>::type* = 0)
: state_(d.state()) {d.set_state(0);}
private:
template <class U>
Deleter(const Deleter<U>& d,
typename std::enable_if<!std::is_same<U, T>::value>::type* = 0);
#else
template <class U>
Deleter(Deleter<U> d,
typename std::enable_if<!std::is_same<U, T>::value>::type* = 0)
: state_(d.state()) {}
#endif
public:
int state() const {return state_;}
void set_state(int i) {state_ = i;}
void operator()(T* p) {delete p;}
};
int main()
{
{
A* p = new A;
assert(A::count == 1);
std::unique_ptr<A, Deleter<A> > s(p, Deleter<A>());
assert(s.get() == p);
assert(s.get_deleter().state() == 5);
}
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr(pointer) ctor + +#include <memory> +#include <cassert> + +// unique_ptr(pointer, deleter()) only requires MoveConstructible deleter + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +template <class T> +class Deleter +{ + int state_; + +#ifdef _LIBCPP_MOVE + Deleter(const Deleter&); + Deleter& operator=(const Deleter&); +#else // _LIBCPP_MOVE + Deleter(Deleter&); + Deleter& operator=(Deleter&); +#endif // _LIBCPP_MOVE + +public: +#ifdef _LIBCPP_MOVE + Deleter(Deleter&& r) : state_(r.state_) {r.state_ = 0;} + Deleter& operator=(Deleter&& r) + { + state_ = r.state_; + r.state_ = 0; + return *this; + } +#else // _LIBCPP_MOVE + operator std::__rv<Deleter>() {return std::__rv<Deleter>(*this);} + Deleter(std::__rv<Deleter> r) : state_(r->state_) {r->state_ = 0;} + Deleter& operator=(std::__rv<Deleter> r) + { + state_ = r->state_; + r->state_ = 0; + return *this; + } +#endif // _LIBCPP_MOVE + + Deleter() : state_(5) {} + +#ifdef _LIBCPP_MOVE + template <class U> + Deleter(Deleter<U>&& d, + typename std::enable_if<!std::is_same<U, T>::value>::type* = 0) + : state_(d.state()) {d.set_state(0);} + +private: + template <class U> + Deleter(const Deleter<U>& d, + typename std::enable_if<!std::is_same<U, T>::value>::type* = 0); +#else // _LIBCPP_MOVE + template <class U> + Deleter(Deleter<U> d, + typename std::enable_if<!std::is_same<U, T>::value>::type* = 0) + : state_(d.state()) {} +#endif // _LIBCPP_MOVE +public: + int state() const {return state_;} + void set_state(int i) {state_ = i;} + + void operator()(T* p) {delete p;} +}; + +int main() +{ + { + A* p = new A; + assert(A::count == 1); + std::unique_ptr<A, Deleter<A> > s(p, Deleter<A>()); + assert(s.get() == p); + assert(s.get_deleter().state() == 5); + } + assert(A::count == 0); +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer_deleter02.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer_deleter02.pass.cpp index e5c9e24a72d..2372d9edbf3 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer_deleter02.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer_deleter02.pass.cpp @@ -1 +1,58 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr(pointer) ctor
#include <memory>
#include <cassert>
// unique_ptr(pointer, d) requires CopyConstructible deleter
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
class Deleter
{
int state_;
public:
Deleter() : state_(5) {}
int state() const {return state_;}
void set_state(int s) {state_ = s;}
void operator()(A* p) {delete p;}
};
int main()
{
{
A* p = new A;
assert(A::count == 1);
Deleter d;
std::unique_ptr<A, Deleter> s(p, d);
assert(s.get() == p);
assert(s.get_deleter().state() == 5);
d.set_state(6);
assert(s.get_deleter().state() == 5);
}
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr(pointer) ctor + +#include <memory> +#include <cassert> + +// unique_ptr(pointer, d) requires CopyConstructible deleter + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +class Deleter +{ + int state_; + +public: + + Deleter() : state_(5) {} + + int state() const {return state_;} + void set_state(int s) {state_ = s;} + + void operator()(A* p) {delete p;} +}; + +int main() +{ + { + A* p = new A; + assert(A::count == 1); + Deleter d; + std::unique_ptr<A, Deleter> s(p, d); + assert(s.get() == p); + assert(s.get_deleter().state() == 5); + d.set_state(6); + assert(s.get_deleter().state() == 5); + } + assert(A::count == 0); +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer_deleter03.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer_deleter03.pass.cpp index d94eaaf2f29..4ad22d495c9 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer_deleter03.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer_deleter03.pass.cpp @@ -1 +1,60 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr(pointer) ctor
#include <memory>
#include <cassert>
// unique_ptr<T, D&>(pointer, d) does not requires CopyConstructible deleter
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
class Deleter
{
int state_;
Deleter(const Deleter&);
Deleter& operator=(const Deleter&);
public:
Deleter() : state_(5) {}
int state() const {return state_;}
void set_state(int s) {state_ = s;}
void operator()(A* p) {delete p;}
};
int main()
{
{
A* p = new A;
assert(A::count == 1);
Deleter d;
std::unique_ptr<A, Deleter&> s(p, d);
assert(s.get() == p);
assert(s.get_deleter().state() == 5);
d.set_state(6);
assert(s.get_deleter().state() == 6);
}
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr(pointer) ctor + +#include <memory> +#include <cassert> + +// unique_ptr<T, D&>(pointer, d) does not requires CopyConstructible deleter + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +class Deleter +{ + int state_; + + Deleter(const Deleter&); + Deleter& operator=(const Deleter&); +public: + + Deleter() : state_(5) {} + + int state() const {return state_;} + void set_state(int s) {state_ = s;} + + void operator()(A* p) {delete p;} +}; + +int main() +{ + { + A* p = new A; + assert(A::count == 1); + Deleter d; + std::unique_ptr<A, Deleter&> s(p, d); + assert(s.get() == p); + assert(s.get_deleter().state() == 5); + d.set_state(6); + assert(s.get_deleter().state() == 6); + } + assert(A::count == 0); +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer_deleter04.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer_deleter04.fail.cpp index 0912ba9aa3a..6a617875fdd 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer_deleter04.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer_deleter04.fail.cpp @@ -1 +1,55 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr(pointer) ctor
#include <memory>
#include <cassert>
// unique_ptr<T, const D&>(pointer, D()) should not compile
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
class Deleter
{
int state_;
public:
Deleter() : state_(5) {}
int state() const {return state_;}
void set_state(int s) {state_ = s;}
void operator()(A* p) const {delete p;}
};
int main()
{
{
A* p = new A;
assert(A::count == 1);
std::unique_ptr<A, const Deleter&> s(p, Deleter());
assert(s.get() == p);
assert(s.get_deleter().state() == 5);
}
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr(pointer) ctor + +#include <memory> +#include <cassert> + +// unique_ptr<T, const D&>(pointer, D()) should not compile + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +class Deleter +{ + int state_; + +public: + + Deleter() : state_(5) {} + + int state() const {return state_;} + void set_state(int s) {state_ = s;} + + void operator()(A* p) const {delete p;} +}; + +int main() +{ + { + A* p = new A; + assert(A::count == 1); + std::unique_ptr<A, const Deleter&> s(p, Deleter()); + assert(s.get() == p); + assert(s.get_deleter().state() == 5); + } + assert(A::count == 0); +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer_deleter04.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer_deleter04.pass.cpp index b5ff2702579..3c03340ec62 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer_deleter04.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer_deleter04.pass.cpp @@ -1 +1,58 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr(pointer) ctor
#include <memory>
#include <cassert>
// unique_ptr<T, const D&>(pointer, d) does not requires CopyConstructible deleter
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
class Deleter
{
int state_;
Deleter(const Deleter&);
Deleter& operator=(const Deleter&);
public:
Deleter() : state_(5) {}
int state() const {return state_;}
void set_state(int s) {state_ = s;}
void operator()(A* p) const {delete p;}
};
int main()
{
{
A* p = new A;
assert(A::count == 1);
Deleter d;
std::unique_ptr<A, const Deleter&> s(p, d);
assert(s.get() == p);
assert(s.get_deleter().state() == 5);
}
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr(pointer) ctor + +#include <memory> +#include <cassert> + +// unique_ptr<T, const D&>(pointer, d) does not requires CopyConstructible deleter + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +class Deleter +{ + int state_; + + Deleter(const Deleter&); + Deleter& operator=(const Deleter&); +public: + + Deleter() : state_(5) {} + + int state() const {return state_;} + void set_state(int s) {state_ = s;} + + void operator()(A* p) const {delete p;} +}; + +int main() +{ + { + A* p = new A; + assert(A::count == 1); + Deleter d; + std::unique_ptr<A, const Deleter&> s(p, d); + assert(s.get() == p); + assert(s.get_deleter().state() == 5); + } + assert(A::count == 0); +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer_deleter05.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer_deleter05.pass.cpp index 93d324285c4..37d4f125af9 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer_deleter05.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer_deleter05.pass.cpp @@ -1 +1,66 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr(pointer, deleter) ctor
#include <memory>
#include <cassert>
// unique_ptr(pointer, deleter) should work with derived pointers
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
class Deleter
{
int state_;
public:
Deleter() : state_(5) {}
int state() const {return state_;}
void operator()(A* p) {delete p;}
};
int main()
{
{
B* p = new B;
assert(A::count == 1);
assert(B::count == 1);
std::unique_ptr<A, Deleter> s(p, Deleter());
assert(s.get() == p);
assert(s.get_deleter().state() == 5);
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr(pointer, deleter) ctor + +#include <memory> +#include <cassert> + +// unique_ptr(pointer, deleter) should work with derived pointers + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +class Deleter +{ + int state_; + +public: + Deleter() : state_(5) {} + + int state() const {return state_;} + + void operator()(A* p) {delete p;} +}; + +int main() +{ + { + B* p = new B; + assert(A::count == 1); + assert(B::count == 1); + std::unique_ptr<A, Deleter> s(p, Deleter()); + assert(s.get() == p); + assert(s.get_deleter().state() == 5); + } + assert(A::count == 0); + assert(B::count == 0); +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer_deleter06.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer_deleter06.pass.cpp index 527666fa4df..e802e9e5d14 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer_deleter06.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer_deleter06.pass.cpp @@ -1 +1,39 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr(pointer, deleter) ctor
#include <memory>
#include <cassert>
// unique_ptr(pointer, deleter) should work with function pointers
// unique_ptr<void> should work
bool my_free_called = false;
void my_free(void*)
{
my_free_called = true;
}
int main()
{
{
int i = 0;
std::unique_ptr<void, void (*)(void*)> s(&i, my_free);
assert(s.get() == &i);
assert(s.get_deleter() == my_free);
assert(!my_free_called);
}
assert(my_free_called);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr(pointer, deleter) ctor + +#include <memory> +#include <cassert> + +// unique_ptr(pointer, deleter) should work with function pointers +// unique_ptr<void> should work + +bool my_free_called = false; + +void my_free(void*) +{ + my_free_called = true; +} + +int main() +{ + { + int i = 0; + std::unique_ptr<void, void (*)(void*)> s(&i, my_free); + assert(s.get() == &i); + assert(s.get_deleter() == my_free); + assert(!my_free_called); + } + assert(my_free_called); +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.dtor/null.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.dtor/null.pass.cpp index 20f3d00f4aa..a530351df93 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.dtor/null.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.dtor/null.pass.cpp @@ -1 +1,44 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// The deleter is not called if get() == 0
#include <memory>
#include <cassert>
class Deleter
{
int state_;
Deleter(Deleter&);
Deleter& operator=(Deleter&);
public:
Deleter() : state_(0) {}
int state() const {return state_;}
void operator()(void*) {++state_;}
};
int main()
{
Deleter d;
assert(d.state() == 0);
{
std::unique_ptr<int, Deleter&> p(0, d);
assert(p.get() == 0);
assert(&p.get_deleter() == &d);
}
assert(d.state() == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// The deleter is not called if get() == 0 + +#include <memory> +#include <cassert> + +class Deleter +{ + int state_; + + Deleter(Deleter&); + Deleter& operator=(Deleter&); + +public: + Deleter() : state_(0) {} + + int state() const {return state_;} + + void operator()(void*) {++state_;} +}; + +int main() +{ + Deleter d; + assert(d.state() == 0); + { + std::unique_ptr<int, Deleter&> p(0, d); + assert(p.get() == 0); + assert(&p.get_deleter() == &d); + } + assert(d.state() == 0); +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.modifiers/release.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.modifiers/release.pass.cpp index da593d124be..d0df6073d70 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.modifiers/release.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.modifiers/release.pass.cpp @@ -1 +1,27 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// test release
#include <memory>
#include <cassert>
int main()
{
std::unique_ptr<int> p(new int(3));
int* i = p.get();
int* j = p.release();
assert(p.get() == 0);
assert(i == j);
delete j;
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// test release + +#include <memory> +#include <cassert> + +int main() +{ + std::unique_ptr<int> p(new int(3)); + int* i = p.get(); + int* j = p.release(); + assert(p.get() == 0); + assert(i == j); + delete j; +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.modifiers/reset1.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.modifiers/reset1.pass.cpp index 806b5d787e6..29419317b31 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.modifiers/reset1.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.modifiers/reset1.pass.cpp @@ -1 +1,48 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// test reset
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
std::unique_ptr<A> p(new A);
assert(A::count == 1);
A* i = p.get();
p.reset();
assert(A::count == 0);
assert(p.get() == 0);
}
assert(A::count == 0);
{
std::unique_ptr<A> p(new A);
assert(A::count == 1);
A* i = p.get();
p.reset(new A);
assert(A::count == 1);
}
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// test reset + +#include <memory> +#include <cassert> + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +int main() +{ + { + std::unique_ptr<A> p(new A); + assert(A::count == 1); + A* i = p.get(); + p.reset(); + assert(A::count == 0); + assert(p.get() == 0); + } + assert(A::count == 0); + { + std::unique_ptr<A> p(new A); + assert(A::count == 1); + A* i = p.get(); + p.reset(new A); + assert(A::count == 1); + } + assert(A::count == 0); +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.modifiers/reset2.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.modifiers/reset2.pass.cpp index 78da880bc22..e43fa1a2bc1 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.modifiers/reset2.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.modifiers/reset2.pass.cpp @@ -1 +1,64 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// test reset
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
int main()
{
{
std::unique_ptr<A> p(new A);
assert(A::count == 1);
assert(B::count == 0);
A* i = p.get();
p.reset(new B);
assert(A::count == 1);
assert(B::count == 1);
}
assert(A::count == 0);
assert(B::count == 0);
{
std::unique_ptr<A> p(new B);
assert(A::count == 1);
assert(B::count == 1);
A* i = p.get();
p.reset(new B);
assert(A::count == 1);
assert(B::count == 1);
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// test reset + +#include <memory> +#include <cassert> + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +int main() +{ + { + std::unique_ptr<A> p(new A); + assert(A::count == 1); + assert(B::count == 0); + A* i = p.get(); + p.reset(new B); + assert(A::count == 1); + assert(B::count == 1); + } + assert(A::count == 0); + assert(B::count == 0); + { + std::unique_ptr<A> p(new B); + assert(A::count == 1); + assert(B::count == 1); + A* i = p.get(); + p.reset(new B); + assert(A::count == 1); + assert(B::count == 1); + } + assert(A::count == 0); + assert(B::count == 0); +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.modifiers/reset_self.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.modifiers/reset_self.pass.cpp index c31c56fa127..23e419e5e43 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.modifiers/reset_self.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.modifiers/reset_self.pass.cpp @@ -1 +1,29 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// test reset against resetting self
#include <memory>
struct A
{
std::unique_ptr<A> ptr_;
A() : ptr_(this) {}
void reset() {ptr_.reset();}
};
int main()
{
(new A)->reset();
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// test reset against resetting self + +#include <memory> + +struct A +{ + std::unique_ptr<A> ptr_; + + A() : ptr_(this) {} + void reset() {ptr_.reset();} +}; + +int main() +{ + (new A)->reset(); +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.modifiers/swap.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.modifiers/swap.pass.cpp index 853273aef2d..03ea92411bf 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.modifiers/swap.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.modifiers/swap.pass.cpp @@ -1 +1,59 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// test swap
#include <memory>
#include <cassert>
#include "../../deleter.h"
struct A
{
int state_;
static int count;
explicit A(int i) : state_(i) {++count;}
A(const A& a) : state_(a.state_) {++count;}
A& operator=(const A& a) {state_ = a.state_; return *this;}
~A() {--count;}
friend bool operator==(const A& x, const A& y)
{return x.state_ == y.state_;}
};
int A::count = 0;
int main()
{
{
A* p1 = new A(1);
std::unique_ptr<A, Deleter<A> > s1(p1, Deleter<A>(1));
A* p2 = new A(2);
std::unique_ptr<A, Deleter<A> > s2(p2, Deleter<A>(2));
assert(s1.get() == p1);
assert(*s1 == A(1));
assert(s1.get_deleter().state() == 1);
assert(s2.get() == p2);
assert(*s2 == A(2));
assert(s2.get_deleter().state() == 2);
s1.swap(s2);
assert(s1.get() == p2);
assert(*s1 == A(2));
assert(s1.get_deleter().state() == 2);
assert(s2.get() == p1);
assert(*s2 == A(1));
assert(s2.get_deleter().state() == 1);
assert(A::count == 2);
}
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// test swap + +#include <memory> +#include <cassert> + +#include "../../deleter.h" + +struct A +{ + int state_; + static int count; + explicit A(int i) : state_(i) {++count;} + A(const A& a) : state_(a.state_) {++count;} + A& operator=(const A& a) {state_ = a.state_; return *this;} + ~A() {--count;} + + friend bool operator==(const A& x, const A& y) + {return x.state_ == y.state_;} +}; + +int A::count = 0; + +int main() +{ + { + A* p1 = new A(1); + std::unique_ptr<A, Deleter<A> > s1(p1, Deleter<A>(1)); + A* p2 = new A(2); + std::unique_ptr<A, Deleter<A> > s2(p2, Deleter<A>(2)); + assert(s1.get() == p1); + assert(*s1 == A(1)); + assert(s1.get_deleter().state() == 1); + assert(s2.get() == p2); + assert(*s2 == A(2)); + assert(s2.get_deleter().state() == 2); + s1.swap(s2); + assert(s1.get() == p2); + assert(*s1 == A(2)); + assert(s1.get_deleter().state() == 2); + assert(s2.get() == p1); + assert(*s2 == A(1)); + assert(s2.get_deleter().state() == 1); + assert(A::count == 2); + } + assert(A::count == 0); +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.observers/dereference.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.observers/dereference.pass.cpp index 08092ec2ab1..b70f865d5b7 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.observers/dereference.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.observers/dereference.pass.cpp @@ -1 +1,23 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// test op*()
#include <memory>
#include <cassert>
int main()
{
std::unique_ptr<int> p(new int(3));
assert(*p == 3);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// test op*() + +#include <memory> +#include <cassert> + +int main() +{ + std::unique_ptr<int> p(new int(3)); + assert(*p == 3); +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.observers/explicit_bool.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.observers/explicit_bool.pass.cpp index 3fbfb3826a5..7982f9e59a0 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.observers/explicit_bool.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.observers/explicit_bool.pass.cpp @@ -1 +1,39 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// test op*()
#include <memory>
#include <cassert>
int main()
{
{
std::unique_ptr<int> p(new int(3));
if (p)
;
else
assert(false);
if (!p)
assert(false);
}
{
std::unique_ptr<int> p;
if (!p)
;
else
assert(false);
if (p)
assert(false);
}
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// test op*() + +#include <memory> +#include <cassert> + +int main() +{ + { + std::unique_ptr<int> p(new int(3)); + if (p) + ; + else + assert(false); + if (!p) + assert(false); + } + { + std::unique_ptr<int> p; + if (!p) + ; + else + assert(false); + if (p) + assert(false); + } +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.observers/get.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.observers/get.pass.cpp index d453724c0e8..62bc3269e68 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.observers/get.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.observers/get.pass.cpp @@ -1 +1,24 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// test get
#include <memory>
#include <cassert>
int main()
{
int* p = new int;
std::unique_ptr<int> s(p);
assert(s.get() == p);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// test get + +#include <memory> +#include <cassert> + +int main() +{ + int* p = new int; + std::unique_ptr<int> s(p); + assert(s.get() == p); +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.observers/get_deleter.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.observers/get_deleter.pass.cpp index 8cefe172f38..34504b6b8c9 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.observers/get_deleter.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.observers/get_deleter.pass.cpp @@ -1 +1,37 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// test get_deleter()
#include <memory>
#include <cassert>
struct Deleter
{
void operator()(void*) {}
int test() {return 5;}
int test() const {return 6;}
};
int main()
{
{
std::unique_ptr<int, Deleter> p;
assert(p.get_deleter().test() == 5);
}
{
const std::unique_ptr<int, Deleter> p;
assert(p.get_deleter().test() == 6);
}
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// test get_deleter() + +#include <memory> +#include <cassert> + +struct Deleter +{ + void operator()(void*) {} + + int test() {return 5;} + int test() const {return 6;} +}; + +int main() +{ + { + std::unique_ptr<int, Deleter> p; + assert(p.get_deleter().test() == 5); + } + { + const std::unique_ptr<int, Deleter> p; + assert(p.get_deleter().test() == 6); + } +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.observers/index.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.observers/index.fail.cpp index 4e9657067ed..93807cc1874 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.observers/index.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.observers/index.fail.cpp @@ -1 +1,47 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// test op[](size_t)
#include <memory>
#include <cassert>
class A
{
int state_;
static int next_;
public:
A() : state_(++next_) {}
int get() const {return state_;}
friend bool operator==(const A& x, int y)
{return x.state_ == y;}
A& operator=(int i) {state_ = i; return *this;}
};
int A::next_ = 0;
int main()
{
std::unique_ptr<A> p(new A[3]);
assert(p[0] == 1);
assert(p[1] == 2);
assert(p[2] == 3);
p[0] = 3;
p[1] = 2;
p[2] = 1;
assert(p[0] == 3);
assert(p[1] == 2);
assert(p[2] == 1);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// test op[](size_t) + +#include <memory> +#include <cassert> + +class A +{ + int state_; + static int next_; +public: + A() : state_(++next_) {} + int get() const {return state_;} + + friend bool operator==(const A& x, int y) + {return x.state_ == y;} + + A& operator=(int i) {state_ = i; return *this;} +}; + +int A::next_ = 0; + +int main() +{ + std::unique_ptr<A> p(new A[3]); + assert(p[0] == 1); + assert(p[1] == 2); + assert(p[2] == 3); + p[0] = 3; + p[1] = 2; + p[2] = 1; + assert(p[0] == 3); + assert(p[1] == 2); + assert(p[2] == 1); +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.observers/op_arrow.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.observers/op_arrow.pass.cpp index 4a00ea233e5..eb63dc2444b 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.observers/op_arrow.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.observers/op_arrow.pass.cpp @@ -1 +1,30 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// test op->()
#include <memory>
#include <cassert>
struct A
{
int i_;
A() : i_(7) {}
};
int main()
{
std::unique_ptr<A> p(new A);
assert(p->i_ == 7);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// test op->() + +#include <memory> +#include <cassert> + +struct A +{ + int i_; + + A() : i_(7) {} +}; + +int main() +{ + std::unique_ptr<A> p(new A); + assert(p->i_ == 7); +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.special/eq.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.special/eq.pass.cpp index 683378ec140..595e5777f92 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.special/eq.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.special/eq.pass.cpp @@ -1 +1,86 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// template <class T1, class D1, class T2, class D2>
// bool
// operator==(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
// template <class T1, class D1, class T2, class D2>
// bool
// operator!=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
#include <memory>
#include <cassert>
#include "../deleter.h"
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
int main()
{
{
const std::unique_ptr<A, Deleter<A> > p1(new A);
const std::unique_ptr<A, Deleter<A> > p2(new A);
assert(!(p1 == p2));
assert(p1 != p2);
}
{
const std::unique_ptr<A, Deleter<A> > p1(new A);
const std::unique_ptr<B, Deleter<B> > p2(new B);
assert(!(p1 == p2));
assert(p1 != p2);
}
{
const std::unique_ptr<A[], Deleter<A[]> > p1(new A[3]);
const std::unique_ptr<A[], Deleter<A[]> > p2(new A[3]);
assert(!(p1 == p2));
assert(p1 != p2);
}
{
const std::unique_ptr<A[], Deleter<A[]> > p1(new A[3]);
const std::unique_ptr<B[], Deleter<B[]> > p2(new B[3]);
assert(!(p1 == p2));
assert(p1 != p2);
}
{
const std::unique_ptr<A, Deleter<A> > p1;
const std::unique_ptr<A, Deleter<A> > p2;
assert(p1 == p2);
assert(!(p1 != p2));
}
{
const std::unique_ptr<A, Deleter<A> > p1;
const std::unique_ptr<B, Deleter<B> > p2;
assert(p1 == p2);
assert(!(p1 != p2));
}
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// template <class T1, class D1, class T2, class D2> +// bool +// operator==(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y); + +// template <class T1, class D1, class T2, class D2> +// bool +// operator!=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y); + +#include <memory> +#include <cassert> + +#include "../deleter.h" + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +int main() +{ + { + const std::unique_ptr<A, Deleter<A> > p1(new A); + const std::unique_ptr<A, Deleter<A> > p2(new A); + assert(!(p1 == p2)); + assert(p1 != p2); + } + { + const std::unique_ptr<A, Deleter<A> > p1(new A); + const std::unique_ptr<B, Deleter<B> > p2(new B); + assert(!(p1 == p2)); + assert(p1 != p2); + } + { + const std::unique_ptr<A[], Deleter<A[]> > p1(new A[3]); + const std::unique_ptr<A[], Deleter<A[]> > p2(new A[3]); + assert(!(p1 == p2)); + assert(p1 != p2); + } + { + const std::unique_ptr<A[], Deleter<A[]> > p1(new A[3]); + const std::unique_ptr<B[], Deleter<B[]> > p2(new B[3]); + assert(!(p1 == p2)); + assert(p1 != p2); + } + { + const std::unique_ptr<A, Deleter<A> > p1; + const std::unique_ptr<A, Deleter<A> > p2; + assert(p1 == p2); + assert(!(p1 != p2)); + } + { + const std::unique_ptr<A, Deleter<A> > p1; + const std::unique_ptr<B, Deleter<B> > p2; + assert(p1 == p2); + assert(!(p1 != p2)); + } +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.special/rel.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.special/rel.pass.cpp index 93052283ae3..a9a197be90a 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.special/rel.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.special/rel.pass.cpp @@ -1 +1,100 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// template <class T1, class D1, class T2, class D2>
// bool
// operator< (const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
// template <class T1, class D1, class T2, class D2>
// bool
// operator> (const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
// template <class T1, class D1, class T2, class D2>
// bool
// operator<=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
// template <class T1, class D1, class T2, class D2>
// bool
// operator>=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
#include <memory>
#include <cassert>
#include "../deleter.h"
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
int main()
{
{
const std::unique_ptr<A, Deleter<A> > p1(new A);
const std::unique_ptr<A, Deleter<A> > p2(new A);
assert((p1 < p2) == !(p1 > p2));
assert((p1 < p2) == (p1 <= p2));
assert((p1 < p2) == !(p1 >= p2));
}
{
const std::unique_ptr<A, Deleter<A> > p1(new A);
const std::unique_ptr<B, Deleter<B> > p2(new B);
assert((p1 < p2) == !(p1 > p2));
assert((p1 < p2) == (p1 <= p2));
assert((p1 < p2) == !(p1 >= p2));
}
{
const std::unique_ptr<A[], Deleter<A[]> > p1(new A[3]);
const std::unique_ptr<A[], Deleter<A[]> > p2(new A[3]);
assert((p1 < p2) == !(p1 > p2));
assert((p1 < p2) == (p1 <= p2));
assert((p1 < p2) == !(p1 >= p2));
}
{
const std::unique_ptr<A[], Deleter<A[]> > p1(new A[3]);
const std::unique_ptr<B[], Deleter<B[]> > p2(new B[3]);
assert((p1 < p2) == !(p1 > p2));
assert((p1 < p2) == (p1 <= p2));
assert((p1 < p2) == !(p1 >= p2));
}
{
const std::unique_ptr<A, Deleter<A> > p1;
const std::unique_ptr<A, Deleter<A> > p2;
assert((p1 < p2) == (p1 > p2));
assert((p1 < p2) == !(p1 <= p2));
assert((p1 < p2) == !(p1 >= p2));
}
{
const std::unique_ptr<A, Deleter<A> > p1;
const std::unique_ptr<B, Deleter<B> > p2;
assert((p1 < p2) == (p1 > p2));
assert((p1 < p2) == !(p1 <= p2));
assert((p1 < p2) == !(p1 >= p2));
}
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// template <class T1, class D1, class T2, class D2> +// bool +// operator< (const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y); + +// template <class T1, class D1, class T2, class D2> +// bool +// operator> (const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y); + +// template <class T1, class D1, class T2, class D2> +// bool +// operator<=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y); + +// template <class T1, class D1, class T2, class D2> +// bool +// operator>=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y); + +#include <memory> +#include <cassert> + +#include "../deleter.h" + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +int main() +{ + { + const std::unique_ptr<A, Deleter<A> > p1(new A); + const std::unique_ptr<A, Deleter<A> > p2(new A); + assert((p1 < p2) == !(p1 > p2)); + assert((p1 < p2) == (p1 <= p2)); + assert((p1 < p2) == !(p1 >= p2)); + } + { + const std::unique_ptr<A, Deleter<A> > p1(new A); + const std::unique_ptr<B, Deleter<B> > p2(new B); + assert((p1 < p2) == !(p1 > p2)); + assert((p1 < p2) == (p1 <= p2)); + assert((p1 < p2) == !(p1 >= p2)); + } + { + const std::unique_ptr<A[], Deleter<A[]> > p1(new A[3]); + const std::unique_ptr<A[], Deleter<A[]> > p2(new A[3]); + assert((p1 < p2) == !(p1 > p2)); + assert((p1 < p2) == (p1 <= p2)); + assert((p1 < p2) == !(p1 >= p2)); + } + { + const std::unique_ptr<A[], Deleter<A[]> > p1(new A[3]); + const std::unique_ptr<B[], Deleter<B[]> > p2(new B[3]); + assert((p1 < p2) == !(p1 > p2)); + assert((p1 < p2) == (p1 <= p2)); + assert((p1 < p2) == !(p1 >= p2)); + } + { + const std::unique_ptr<A, Deleter<A> > p1; + const std::unique_ptr<A, Deleter<A> > p2; + assert((p1 < p2) == (p1 > p2)); + assert((p1 < p2) == !(p1 <= p2)); + assert((p1 < p2) == !(p1 >= p2)); + } + { + const std::unique_ptr<A, Deleter<A> > p1; + const std::unique_ptr<B, Deleter<B> > p2; + assert((p1 < p2) == (p1 > p2)); + assert((p1 < p2) == !(p1 <= p2)); + assert((p1 < p2) == !(p1 >= p2)); + } +} diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.special/swap.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.special/swap.pass.cpp index c0bdfea88ca..a38910e56dd 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.special/swap.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.special/swap.pass.cpp @@ -1 +1,77 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test swap
#include <memory>
#include <cassert>
#include "../deleter.h"
struct A
{
int state_;
static int count;
A() : state_(0) {++count;}
explicit A(int i) : state_(i) {++count;}
A(const A& a) : state_(a.state_) {++count;}
A& operator=(const A& a) {state_ = a.state_; return *this;}
~A() {--count;}
friend bool operator==(const A& x, const A& y)
{return x.state_ == y.state_;}
};
int A::count = 0;
int main()
{
{
A* p1 = new A(1);
std::unique_ptr<A, Deleter<A> > s1(p1, Deleter<A>(1));
A* p2 = new A(2);
std::unique_ptr<A, Deleter<A> > s2(p2, Deleter<A>(2));
assert(s1.get() == p1);
assert(*s1 == A(1));
assert(s1.get_deleter().state() == 1);
assert(s2.get() == p2);
assert(*s2 == A(2));
assert(s2.get_deleter().state() == 2);
swap(s1, s2);
assert(s1.get() == p2);
assert(*s1 == A(2));
assert(s1.get_deleter().state() == 2);
assert(s2.get() == p1);
assert(*s2 == A(1));
assert(s2.get_deleter().state() == 1);
assert(A::count == 2);
}
assert(A::count == 0);
{
A* p1 = new A[3];
std::unique_ptr<A[], Deleter<A[]> > s1(p1, Deleter<A[]>(1));
A* p2 = new A[3];
std::unique_ptr<A[], Deleter<A[]> > s2(p2, Deleter<A[]>(2));
assert(s1.get() == p1);
assert(s1.get_deleter().state() == 1);
assert(s2.get() == p2);
assert(s2.get_deleter().state() == 2);
swap(s1, s2);
assert(s1.get() == p2);
assert(s1.get_deleter().state() == 2);
assert(s2.get() == p1);
assert(s2.get_deleter().state() == 1);
assert(A::count == 6);
}
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test swap + +#include <memory> +#include <cassert> + +#include "../deleter.h" + +struct A +{ + int state_; + static int count; + A() : state_(0) {++count;} + explicit A(int i) : state_(i) {++count;} + A(const A& a) : state_(a.state_) {++count;} + A& operator=(const A& a) {state_ = a.state_; return *this;} + ~A() {--count;} + + friend bool operator==(const A& x, const A& y) + {return x.state_ == y.state_;} +}; + +int A::count = 0; + +int main() +{ + { + A* p1 = new A(1); + std::unique_ptr<A, Deleter<A> > s1(p1, Deleter<A>(1)); + A* p2 = new A(2); + std::unique_ptr<A, Deleter<A> > s2(p2, Deleter<A>(2)); + assert(s1.get() == p1); + assert(*s1 == A(1)); + assert(s1.get_deleter().state() == 1); + assert(s2.get() == p2); + assert(*s2 == A(2)); + assert(s2.get_deleter().state() == 2); + swap(s1, s2); + assert(s1.get() == p2); + assert(*s1 == A(2)); + assert(s1.get_deleter().state() == 2); + assert(s2.get() == p1); + assert(*s2 == A(1)); + assert(s2.get_deleter().state() == 1); + assert(A::count == 2); + } + assert(A::count == 0); + { + A* p1 = new A[3]; + std::unique_ptr<A[], Deleter<A[]> > s1(p1, Deleter<A[]>(1)); + A* p2 = new A[3]; + std::unique_ptr<A[], Deleter<A[]> > s2(p2, Deleter<A[]>(2)); + assert(s1.get() == p1); + assert(s1.get_deleter().state() == 1); + assert(s2.get() == p2); + assert(s2.get_deleter().state() == 2); + swap(s1, s2); + assert(s1.get() == p2); + assert(s1.get_deleter().state() == 2); + assert(s2.get() == p1); + assert(s2.get_deleter().state() == 1); + assert(A::count == 6); + } + assert(A::count == 0); +} diff --git a/libcxx/test/utilities/memory/util.smartptr/nothing_to_do.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/nothing_to_do.pass.cpp index e8db90cbee0..b89f168e9c4 100644 --- a/libcxx/test/utilities/memory/util.smartptr/nothing_to_do.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/nothing_to_do.pass.cpp @@ -1 +1,12 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
int main()
{
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.enab/enable_shared_from_this.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.enab/enable_shared_from_this.pass.cpp index d4618719cfb..c3aa6b06556 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.enab/enable_shared_from_this.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.enab/enable_shared_from_this.pass.cpp @@ -1 +1,49 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// template<class T>
// class enable_shared_from_this
// {
// protected:
// enable_shared_from_this();
// enable_shared_from_this(enable_shared_from_this const&);
// enable_shared_from_this& operator=(enable_shared_from_this const&);
// ~enable_shared_from_this();
// public:
// shared_ptr<T> shared_from_this();
// shared_ptr<T const> shared_from_this() const;
// };
#include <memory>
#include <cassert>
struct T
: public std::enable_shared_from_this<T>
{
};
struct Y : T {};
struct Z : Y {};
int main()
{
{
std::shared_ptr<Y> p(new Z);
std::shared_ptr<T> q = p->shared_from_this();
assert(p == q);
assert(!p.owner_before(q) && !q.owner_before(p)); // p and q share ownership
}
{
std::shared_ptr<Y> p = std::make_shared<Z>();
std::shared_ptr<T> q = p->shared_from_this();
assert(p == q);
assert(!p.owner_before(q) && !q.owner_before(p)); // p and q share ownership
}
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// template<class T> +// class enable_shared_from_this +// { +// protected: +// enable_shared_from_this(); +// enable_shared_from_this(enable_shared_from_this const&); +// enable_shared_from_this& operator=(enable_shared_from_this const&); +// ~enable_shared_from_this(); +// public: +// shared_ptr<T> shared_from_this(); +// shared_ptr<T const> shared_from_this() const; +// }; + +#include <memory> +#include <cassert> + +struct T + : public std::enable_shared_from_this<T> +{ +}; + +struct Y : T {}; + +struct Z : Y {}; + +int main() +{ + { + std::shared_ptr<Y> p(new Z); + std::shared_ptr<T> q = p->shared_from_this(); + assert(p == q); + assert(!p.owner_before(q) && !q.owner_before(p)); // p and q share ownership + } + { + std::shared_ptr<Y> p = std::make_shared<Z>(); + std::shared_ptr<T> q = p->shared_from_this(); + assert(p == q); + assert(!p.owner_before(q) && !q.owner_before(p)); // p and q share ownership + } +} diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.hash/hash_shared_ptr.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.hash/hash_shared_ptr.pass.cpp index 9912d1b8f22..ec12d286f69 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.hash/hash_shared_ptr.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.hash/hash_shared_ptr.pass.cpp @@ -1 +1,30 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <class T>
// struct hash<shared_ptr<T>>
// {
// typedef shared_ptr<T> argument_type;
// typedef size_t result_type;
// size_t operator()(const shared_ptr<T>& p) const;
// };
#include <memory>
#include <cassert>
int main()
{
int* ptr = new int;
std::shared_ptr<int> p(ptr);
std::hash<std::shared_ptr<int> > f;
std::size_t h = f(p);
assert(h == std::hash<int*>()(ptr));
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// template <class T> +// struct hash<shared_ptr<T>> +// { +// typedef shared_ptr<T> argument_type; +// typedef size_t result_type; +// size_t operator()(const shared_ptr<T>& p) const; +// }; + +#include <memory> +#include <cassert> + +int main() +{ + int* ptr = new int; + std::shared_ptr<int> p(ptr); + std::hash<std::shared_ptr<int> > f; + std::size_t h = f(p); + assert(h == std::hash<int*>()(ptr)); +} diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.hash/hash_unique_ptr.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.hash/hash_unique_ptr.pass.cpp index 0541e57a8a2..c8e13b2bc4e 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.hash/hash_unique_ptr.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.hash/hash_unique_ptr.pass.cpp @@ -1 +1,30 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <class T, class D>
// struct hash<unique_ptr<T, D>>
// {
// typedef unique_ptr<T, D> argument_type;
// typedef size_t result_type;
// size_t operator()(const unique_ptr<T, D>& p) const;
// };
#include <memory>
#include <cassert>
int main()
{
int* ptr = new int;
std::unique_ptr<int> p(ptr);
std::hash<std::unique_ptr<int> > f;
std::size_t h = f(p);
assert(h == std::hash<int*>()(ptr));
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// template <class T, class D> +// struct hash<unique_ptr<T, D>> +// { +// typedef unique_ptr<T, D> argument_type; +// typedef size_t result_type; +// size_t operator()(const unique_ptr<T, D>& p) const; +// }; + +#include <memory> +#include <cassert> + +int main() +{ + int* ptr = new int; + std::unique_ptr<int> p(ptr); + std::hash<std::unique_ptr<int> > f; + std::size_t h = f(p); + assert(h == std::hash<int*>()(ptr)); +} diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/test_allocator.h b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/test_allocator.h index 0c1eaf3dc90..795f6e1f77e 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/test_allocator.h +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/test_allocator.h @@ -74,4 +74,4 @@ public: {return !(x == y);} }; -#endif +#endif // TEST_ALLOCATOR_H diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/test_deleter.h b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/test_deleter.h index b9aeeebcd66..0a8b08eebcb 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/test_deleter.h +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/test_deleter.h @@ -1 +1,60 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// Example move-only deleter
#ifndef DELETER_H
#define DELETER_H
#include <type_traits>
#include <cassert>
struct test_deleter_base
{
static int count;
static int dealloc_count;
};
int test_deleter_base::count = 0;
int test_deleter_base::dealloc_count = 0;
template <class T>
class test_deleter
: public test_deleter_base
{
int state_;
public:
test_deleter() : state_(0) {++count;}
explicit test_deleter(int s) : state_(s) {++count;}
test_deleter(const test_deleter& d)
: state_(d.state_) {++count;}
~test_deleter() {assert(state_ >= 0); --count; state_ = -1;}
int state() const {return state_;}
void set_state(int i) {state_ = i;}
void operator()(T* p) {assert(state_ >= 0); ++dealloc_count; delete p;}
};
template <class T>
void
swap(test_deleter<T>& x, test_deleter<T>& y)
{
test_deleter<T> t(std::move(x));
x = std::move(y);
y = std::move(t);
}
#endif
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// shared_ptr + +// Example move-only deleter + +#ifndef DELETER_H +#define DELETER_H + +#include <type_traits> +#include <cassert> + +struct test_deleter_base +{ + static int count; + static int dealloc_count; +}; + +int test_deleter_base::count = 0; +int test_deleter_base::dealloc_count = 0; + +template <class T> +class test_deleter + : public test_deleter_base +{ + int state_; + +public: + + test_deleter() : state_(0) {++count;} + explicit test_deleter(int s) : state_(s) {++count;} + test_deleter(const test_deleter& d) + : state_(d.state_) {++count;} + ~test_deleter() {assert(state_ >= 0); --count; state_ = -1;} + + int state() const {return state_;} + void set_state(int i) {state_ = i;} + + void operator()(T* p) {assert(state_ >= 0); ++dealloc_count; delete p;} +}; + +template <class T> +void +swap(test_deleter<T>& x, test_deleter<T>& y) +{ + test_deleter<T> t(std::move(x)); + x = std::move(y); + y = std::move(t); +} + +#endif // DELETER_H diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/types.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/types.pass.cpp index 09aa877d2cd..ff1424c5c4e 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/types.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/types.pass.cpp @@ -1 +1,26 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template<class T> class shared_ptr
// {
// public:
// typedef T element_type;
// ...
// };
#include <memory>
struct A; // purposefully incomplete
int main()
{
static_assert((std::is_same<std::shared_ptr<A>::element_type, A>::value), "");
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// template<class T> class shared_ptr +// { +// public: +// typedef T element_type; +// ... +// }; + +#include <memory> + +struct A; // purposefully incomplete + +int main() +{ + static_assert((std::is_same<std::shared_ptr<A>::element_type, A>::value), ""); +} diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.getdeleter/get_deleter.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.getdeleter/get_deleter.pass.cpp index e12dc2fa6c7..84356569c1c 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.getdeleter/get_deleter.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.getdeleter/get_deleter.pass.cpp @@ -1 +1,67 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// template<class D, class T> D* get_deleter(const shared_ptr<T>& p);
#include <memory>
#include <cassert>
#include "../test_deleter.h"
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
{
A* ptr = new A;
std::shared_ptr<A> p(ptr, test_deleter<A>(3));
test_deleter<A>* d = std::get_deleter<test_deleter<A> >(p);
assert(test_deleter<A>::count == 1);
assert(test_deleter<A>::dealloc_count == 0);
assert(d);
assert(d->state() == 3);
}
assert(A::count == 0);
assert(test_deleter<A>::count == 0);
assert(test_deleter<A>::dealloc_count == 1);
}
test_deleter<A>::dealloc_count = 0;
{
{
std::shared_ptr<A> p(nullptr, test_deleter<A>(3));
test_deleter<A>* d = std::get_deleter<test_deleter<A> >(p);
assert(test_deleter<A>::count == 1);
assert(test_deleter<A>::dealloc_count == 0);
assert(d);
assert(d->state() == 3);
}
assert(A::count == 0);
assert(test_deleter<A>::count == 0);
assert(test_deleter<A>::dealloc_count == 1);
}
test_deleter<A>::dealloc_count = 0;
{
std::shared_ptr<A> p(nullptr, test_deleter<A>(3));
std::default_delete<A>* d = std::get_deleter<std::default_delete<A> >(p);
assert(d == 0);
}
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// shared_ptr + +// template<class D, class T> D* get_deleter(const shared_ptr<T>& p); + +#include <memory> +#include <cassert> +#include "../test_deleter.h" + +struct A +{ + static int count; + + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +int main() +{ + { + { + A* ptr = new A; + std::shared_ptr<A> p(ptr, test_deleter<A>(3)); + test_deleter<A>* d = std::get_deleter<test_deleter<A> >(p); + assert(test_deleter<A>::count == 1); + assert(test_deleter<A>::dealloc_count == 0); + assert(d); + assert(d->state() == 3); + } + assert(A::count == 0); + assert(test_deleter<A>::count == 0); + assert(test_deleter<A>::dealloc_count == 1); + } + test_deleter<A>::dealloc_count = 0; + { + { + std::shared_ptr<A> p(nullptr, test_deleter<A>(3)); + test_deleter<A>* d = std::get_deleter<test_deleter<A> >(p); + assert(test_deleter<A>::count == 1); + assert(test_deleter<A>::dealloc_count == 0); + assert(d); + assert(d->state() == 3); + } + assert(A::count == 0); + assert(test_deleter<A>::count == 0); + assert(test_deleter<A>::dealloc_count == 1); + } + test_deleter<A>::dealloc_count = 0; + { + std::shared_ptr<A> p(nullptr, test_deleter<A>(3)); + std::default_delete<A>* d = std::get_deleter<std::default_delete<A> >(p); + assert(d == 0); + } +} diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.assign/auto_ptr_Y.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.assign/auto_ptr_Y.pass.cpp index 09a95ec2478..27732823300 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.assign/auto_ptr_Y.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.assign/auto_ptr_Y.pass.cpp @@ -1 +1,113 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// template<class Y> shared_ptr& operator=(auto_ptr<Y>&& r);
#include <memory>
#include <type_traits>
#include <cassert>
struct B
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
struct A
: public B
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
std::auto_ptr<A> pA(new A);
A* ptrA = pA.get();
{
std::shared_ptr<B> pB(new B);
pB = pA;
assert(B::count == 1);
assert(A::count == 1);
assert(pB.use_count() == 1);
assert(pA.get() == 0);
assert(pB.get() == ptrA);
}
assert(B::count == 0);
assert(A::count == 0);
}
assert(B::count == 0);
assert(A::count == 0);
{
std::auto_ptr<A> pA;
A* ptrA = pA.get();
{
std::shared_ptr<B> pB(new B);
pB = pA;
assert(B::count == 0);
assert(A::count == 0);
assert(pB.use_count() == 1);
assert(pA.get() == 0);
assert(pB.get() == ptrA);
}
assert(B::count == 0);
assert(A::count == 0);
}
assert(B::count == 0);
assert(A::count == 0);
{
std::auto_ptr<A> pA(new A);
A* ptrA = pA.get();
{
std::shared_ptr<B> pB;
pB = pA;
assert(B::count == 1);
assert(A::count == 1);
assert(pB.use_count() == 1);
assert(pA.get() == 0);
assert(pB.get() == ptrA);
}
assert(B::count == 0);
assert(A::count == 0);
}
assert(B::count == 0);
assert(A::count == 0);
{
std::auto_ptr<A> pA;
A* ptrA = pA.get();
{
std::shared_ptr<B> pB;
pB = pA;
assert(B::count == 0);
assert(A::count == 0);
assert(pB.use_count() == 1);
assert(pA.get() == 0);
assert(pB.get() == ptrA);
}
assert(B::count == 0);
assert(A::count == 0);
}
assert(B::count == 0);
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// shared_ptr + +// template<class Y> shared_ptr& operator=(auto_ptr<Y>&& r); + +#include <memory> +#include <type_traits> +#include <cassert> + +struct B +{ + static int count; + + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +struct A + : public B +{ + static int count; + + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +int main() +{ + { + std::auto_ptr<A> pA(new A); + A* ptrA = pA.get(); + { + std::shared_ptr<B> pB(new B); + pB = pA; + assert(B::count == 1); + assert(A::count == 1); + assert(pB.use_count() == 1); + assert(pA.get() == 0); + assert(pB.get() == ptrA); + } + assert(B::count == 0); + assert(A::count == 0); + } + assert(B::count == 0); + assert(A::count == 0); + { + std::auto_ptr<A> pA; + A* ptrA = pA.get(); + { + std::shared_ptr<B> pB(new B); + pB = pA; + assert(B::count == 0); + assert(A::count == 0); + assert(pB.use_count() == 1); + assert(pA.get() == 0); + assert(pB.get() == ptrA); + } + assert(B::count == 0); + assert(A::count == 0); + } + assert(B::count == 0); + assert(A::count == 0); + { + std::auto_ptr<A> pA(new A); + A* ptrA = pA.get(); + { + std::shared_ptr<B> pB; + pB = pA; + assert(B::count == 1); + assert(A::count == 1); + assert(pB.use_count() == 1); + assert(pA.get() == 0); + assert(pB.get() == ptrA); + } + assert(B::count == 0); + assert(A::count == 0); + } + assert(B::count == 0); + assert(A::count == 0); + { + std::auto_ptr<A> pA; + A* ptrA = pA.get(); + { + std::shared_ptr<B> pB; + pB = pA; + assert(B::count == 0); + assert(A::count == 0); + assert(pB.use_count() == 1); + assert(pA.get() == 0); + assert(pB.get() == ptrA); + } + assert(B::count == 0); + assert(A::count == 0); + } + assert(B::count == 0); + assert(A::count == 0); +} diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.assign/shared_ptr.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.assign/shared_ptr.pass.cpp index 8e1bb81afcc..45dbc060e1f 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.assign/shared_ptr.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.assign/shared_ptr.pass.cpp @@ -1 +1,121 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// shared_ptr& operator=(const shared_ptr& r);
#include <memory>
#include <type_traits>
#include <cassert>
struct B
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
struct A
: public B
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
const std::shared_ptr<A> pA(new A);
A* ptrA = pA.get();
{
std::shared_ptr<A> pB(new A);
pB = pA;
assert(B::count == 1);
assert(A::count == 1);
assert(pB.use_count() == 2);
assert(pA.use_count() == 2);
assert(pA.get() == pB.get());
assert(pB.get() == ptrA);
}
assert(pA.use_count() == 1);
assert(B::count == 1);
assert(A::count == 1);
}
assert(B::count == 0);
assert(A::count == 0);
{
const std::shared_ptr<A> pA;
A* ptrA = pA.get();
{
std::shared_ptr<A> pB(new A);
pB = pA;
assert(B::count == 0);
assert(A::count == 0);
assert(pB.use_count() == 0);
assert(pA.use_count() == 0);
assert(pA.get() == pB.get());
assert(pB.get() == ptrA);
}
assert(pA.use_count() == 0);
assert(B::count == 0);
assert(A::count == 0);
}
assert(B::count == 0);
assert(A::count == 0);
{
const std::shared_ptr<A> pA(new A);
A* ptrA = pA.get();
{
std::shared_ptr<A> pB;
pB = pA;
assert(B::count == 1);
assert(A::count == 1);
assert(pB.use_count() == 2);
assert(pA.use_count() == 2);
assert(pA.get() == pB.get());
assert(pB.get() == ptrA);
}
assert(pA.use_count() == 1);
assert(B::count == 1);
assert(A::count == 1);
}
assert(B::count == 0);
assert(A::count == 0);
{
const std::shared_ptr<A> pA;
A* ptrA = pA.get();
{
std::shared_ptr<A> pB;
pB = pA;
assert(B::count == 0);
assert(A::count == 0);
assert(pB.use_count() == 0);
assert(pA.use_count() == 0);
assert(pA.get() == pB.get());
assert(pB.get() == ptrA);
}
assert(pA.use_count() == 0);
assert(B::count == 0);
assert(A::count == 0);
}
assert(B::count == 0);
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// shared_ptr + +// shared_ptr& operator=(const shared_ptr& r); + +#include <memory> +#include <type_traits> +#include <cassert> + +struct B +{ + static int count; + + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +struct A + : public B +{ + static int count; + + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +int main() +{ + { + const std::shared_ptr<A> pA(new A); + A* ptrA = pA.get(); + { + std::shared_ptr<A> pB(new A); + pB = pA; + assert(B::count == 1); + assert(A::count == 1); + assert(pB.use_count() == 2); + assert(pA.use_count() == 2); + assert(pA.get() == pB.get()); + assert(pB.get() == ptrA); + } + assert(pA.use_count() == 1); + assert(B::count == 1); + assert(A::count == 1); + } + assert(B::count == 0); + assert(A::count == 0); + { + const std::shared_ptr<A> pA; + A* ptrA = pA.get(); + { + std::shared_ptr<A> pB(new A); + pB = pA; + assert(B::count == 0); + assert(A::count == 0); + assert(pB.use_count() == 0); + assert(pA.use_count() == 0); + assert(pA.get() == pB.get()); + assert(pB.get() == ptrA); + } + assert(pA.use_count() == 0); + assert(B::count == 0); + assert(A::count == 0); + } + assert(B::count == 0); + assert(A::count == 0); + { + const std::shared_ptr<A> pA(new A); + A* ptrA = pA.get(); + { + std::shared_ptr<A> pB; + pB = pA; + assert(B::count == 1); + assert(A::count == 1); + assert(pB.use_count() == 2); + assert(pA.use_count() == 2); + assert(pA.get() == pB.get()); + assert(pB.get() == ptrA); + } + assert(pA.use_count() == 1); + assert(B::count == 1); + assert(A::count == 1); + } + assert(B::count == 0); + assert(A::count == 0); + { + const std::shared_ptr<A> pA; + A* ptrA = pA.get(); + { + std::shared_ptr<A> pB; + pB = pA; + assert(B::count == 0); + assert(A::count == 0); + assert(pB.use_count() == 0); + assert(pA.use_count() == 0); + assert(pA.get() == pB.get()); + assert(pB.get() == ptrA); + } + assert(pA.use_count() == 0); + assert(B::count == 0); + assert(A::count == 0); + } + assert(B::count == 0); + assert(A::count == 0); +} diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.assign/shared_ptr_Y.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.assign/shared_ptr_Y.pass.cpp index a13b1fd2fef..be6b1659571 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.assign/shared_ptr_Y.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.assign/shared_ptr_Y.pass.cpp @@ -1 +1,121 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// template<class Y> shared_ptr& operator=(const shared_ptr<Y>& r);
#include <memory>
#include <type_traits>
#include <cassert>
struct B
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
struct A
: public B
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
const std::shared_ptr<A> pA(new A);
A* ptrA = pA.get();
{
std::shared_ptr<B> pB(new B);
pB = pA;
assert(B::count == 1);
assert(A::count == 1);
assert(pB.use_count() == 2);
assert(pA.use_count() == 2);
assert(pA.get() == pB.get());
assert(pB.get() == ptrA);
}
assert(pA.use_count() == 1);
assert(B::count == 1);
assert(A::count == 1);
}
assert(B::count == 0);
assert(A::count == 0);
{
const std::shared_ptr<A> pA;
A* ptrA = pA.get();
{
std::shared_ptr<B> pB(new B);
pB = pA;
assert(B::count == 0);
assert(A::count == 0);
assert(pB.use_count() == 0);
assert(pA.use_count() == 0);
assert(pA.get() == pB.get());
assert(pB.get() == ptrA);
}
assert(pA.use_count() == 0);
assert(B::count == 0);
assert(A::count == 0);
}
assert(B::count == 0);
assert(A::count == 0);
{
const std::shared_ptr<A> pA(new A);
A* ptrA = pA.get();
{
std::shared_ptr<B> pB;
pB = pA;
assert(B::count == 1);
assert(A::count == 1);
assert(pB.use_count() == 2);
assert(pA.use_count() == 2);
assert(pA.get() == pB.get());
assert(pB.get() == ptrA);
}
assert(pA.use_count() == 1);
assert(B::count == 1);
assert(A::count == 1);
}
assert(B::count == 0);
assert(A::count == 0);
{
const std::shared_ptr<A> pA;
A* ptrA = pA.get();
{
std::shared_ptr<B> pB;
pB = pA;
assert(B::count == 0);
assert(A::count == 0);
assert(pB.use_count() == 0);
assert(pA.use_count() == 0);
assert(pA.get() == pB.get());
assert(pB.get() == ptrA);
}
assert(pA.use_count() == 0);
assert(B::count == 0);
assert(A::count == 0);
}
assert(B::count == 0);
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// shared_ptr + +// template<class Y> shared_ptr& operator=(const shared_ptr<Y>& r); + +#include <memory> +#include <type_traits> +#include <cassert> + +struct B +{ + static int count; + + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +struct A + : public B +{ + static int count; + + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +int main() +{ + { + const std::shared_ptr<A> pA(new A); + A* ptrA = pA.get(); + { + std::shared_ptr<B> pB(new B); + pB = pA; + assert(B::count == 1); + assert(A::count == 1); + assert(pB.use_count() == 2); + assert(pA.use_count() == 2); + assert(pA.get() == pB.get()); + assert(pB.get() == ptrA); + } + assert(pA.use_count() == 1); + assert(B::count == 1); + assert(A::count == 1); + } + assert(B::count == 0); + assert(A::count == 0); + { + const std::shared_ptr<A> pA; + A* ptrA = pA.get(); + { + std::shared_ptr<B> pB(new B); + pB = pA; + assert(B::count == 0); + assert(A::count == 0); + assert(pB.use_count() == 0); + assert(pA.use_count() == 0); + assert(pA.get() == pB.get()); + assert(pB.get() == ptrA); + } + assert(pA.use_count() == 0); + assert(B::count == 0); + assert(A::count == 0); + } + assert(B::count == 0); + assert(A::count == 0); + { + const std::shared_ptr<A> pA(new A); + A* ptrA = pA.get(); + { + std::shared_ptr<B> pB; + pB = pA; + assert(B::count == 1); + assert(A::count == 1); + assert(pB.use_count() == 2); + assert(pA.use_count() == 2); + assert(pA.get() == pB.get()); + assert(pB.get() == ptrA); + } + assert(pA.use_count() == 1); + assert(B::count == 1); + assert(A::count == 1); + } + assert(B::count == 0); + assert(A::count == 0); + { + const std::shared_ptr<A> pA; + A* ptrA = pA.get(); + { + std::shared_ptr<B> pB; + pB = pA; + assert(B::count == 0); + assert(A::count == 0); + assert(pB.use_count() == 0); + assert(pA.use_count() == 0); + assert(pA.get() == pB.get()); + assert(pB.get() == ptrA); + } + assert(pA.use_count() == 0); + assert(B::count == 0); + assert(A::count == 0); + } + assert(B::count == 0); + assert(A::count == 0); +} diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.assign/shared_ptr_Y_rv.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.assign/shared_ptr_Y_rv.pass.cpp index e4142cda701..8a72f6c0185 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.assign/shared_ptr_Y_rv.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.assign/shared_ptr_Y_rv.pass.cpp @@ -1 +1,121 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// template<class Y> shared_ptr& operator=(shared_ptr<Y>&& r);
#include <memory>
#include <type_traits>
#include <cassert>
struct B
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
struct A
: public B
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
std::shared_ptr<A> pA(new A);
A* ptrA = pA.get();
{
std::shared_ptr<B> pB(new B);
pB = std::move(pA);
assert(B::count == 1);
assert(A::count == 1);
assert(pB.use_count() == 1);
assert(pA.use_count() == 0);
assert(pA.get() == 0);
assert(pB.get() == ptrA);
}
assert(pA.use_count() == 0);
assert(B::count == 0);
assert(A::count == 0);
}
assert(B::count == 0);
assert(A::count == 0);
{
std::shared_ptr<A> pA;
A* ptrA = pA.get();
{
std::shared_ptr<B> pB(new B);
pB = std::move(pA);
assert(B::count == 0);
assert(A::count == 0);
assert(pB.use_count() == 0);
assert(pA.use_count() == 0);
assert(pA.get() == 0);
assert(pB.get() == ptrA);
}
assert(pA.use_count() == 0);
assert(B::count == 0);
assert(A::count == 0);
}
assert(B::count == 0);
assert(A::count == 0);
{
std::shared_ptr<A> pA(new A);
A* ptrA = pA.get();
{
std::shared_ptr<B> pB;
pB = std::move(pA);
assert(B::count == 1);
assert(A::count == 1);
assert(pB.use_count() == 1);
assert(pA.use_count() == 0);
assert(pA.get() == 0);
assert(pB.get() == ptrA);
}
assert(pA.use_count() == 0);
assert(B::count == 0);
assert(A::count == 0);
}
assert(B::count == 0);
assert(A::count == 0);
{
std::shared_ptr<A> pA;
A* ptrA = pA.get();
{
std::shared_ptr<B> pB;
pB = std::move(pA);
assert(B::count == 0);
assert(A::count == 0);
assert(pB.use_count() == 0);
assert(pA.use_count() == 0);
assert(pA.get() == 0);
assert(pB.get() == ptrA);
}
assert(pA.use_count() == 0);
assert(B::count == 0);
assert(A::count == 0);
}
assert(B::count == 0);
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// shared_ptr + +// template<class Y> shared_ptr& operator=(shared_ptr<Y>&& r); + +#include <memory> +#include <type_traits> +#include <cassert> + +struct B +{ + static int count; + + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +struct A + : public B +{ + static int count; + + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +int main() +{ + { + std::shared_ptr<A> pA(new A); + A* ptrA = pA.get(); + { + std::shared_ptr<B> pB(new B); + pB = std::move(pA); + assert(B::count == 1); + assert(A::count == 1); + assert(pB.use_count() == 1); + assert(pA.use_count() == 0); + assert(pA.get() == 0); + assert(pB.get() == ptrA); + } + assert(pA.use_count() == 0); + assert(B::count == 0); + assert(A::count == 0); + } + assert(B::count == 0); + assert(A::count == 0); + { + std::shared_ptr<A> pA; + A* ptrA = pA.get(); + { + std::shared_ptr<B> pB(new B); + pB = std::move(pA); + assert(B::count == 0); + assert(A::count == 0); + assert(pB.use_count() == 0); + assert(pA.use_count() == 0); + assert(pA.get() == 0); + assert(pB.get() == ptrA); + } + assert(pA.use_count() == 0); + assert(B::count == 0); + assert(A::count == 0); + } + assert(B::count == 0); + assert(A::count == 0); + { + std::shared_ptr<A> pA(new A); + A* ptrA = pA.get(); + { + std::shared_ptr<B> pB; + pB = std::move(pA); + assert(B::count == 1); + assert(A::count == 1); + assert(pB.use_count() == 1); + assert(pA.use_count() == 0); + assert(pA.get() == 0); + assert(pB.get() == ptrA); + } + assert(pA.use_count() == 0); + assert(B::count == 0); + assert(A::count == 0); + } + assert(B::count == 0); + assert(A::count == 0); + { + std::shared_ptr<A> pA; + A* ptrA = pA.get(); + { + std::shared_ptr<B> pB; + pB = std::move(pA); + assert(B::count == 0); + assert(A::count == 0); + assert(pB.use_count() == 0); + assert(pA.use_count() == 0); + assert(pA.get() == 0); + assert(pB.get() == ptrA); + } + assert(pA.use_count() == 0); + assert(B::count == 0); + assert(A::count == 0); + } + assert(B::count == 0); + assert(A::count == 0); +} diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.assign/shared_ptr_rv.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.assign/shared_ptr_rv.pass.cpp index d2691b06700..3e8a51fcc0a 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.assign/shared_ptr_rv.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.assign/shared_ptr_rv.pass.cpp @@ -1 +1,121 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// shared_ptr& operator=(shared_ptr&& r);
#include <memory>
#include <type_traits>
#include <cassert>
struct B
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
struct A
: public B
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
std::shared_ptr<A> pA(new A);
A* ptrA = pA.get();
{
std::shared_ptr<A> pB(new A);
pB = std::move(pA);
assert(B::count == 1);
assert(A::count == 1);
assert(pB.use_count() == 1);
assert(pA.use_count() == 0);
assert(pA.get() == 0);
assert(pB.get() == ptrA);
}
assert(pA.use_count() == 0);
assert(B::count == 0);
assert(A::count == 0);
}
assert(B::count == 0);
assert(A::count == 0);
{
std::shared_ptr<A> pA;
A* ptrA = pA.get();
{
std::shared_ptr<A> pB(new A);
pB = std::move(pA);
assert(B::count == 0);
assert(A::count == 0);
assert(pB.use_count() == 0);
assert(pA.use_count() == 0);
assert(pA.get() == 0);
assert(pB.get() == ptrA);
}
assert(pA.use_count() == 0);
assert(B::count == 0);
assert(A::count == 0);
}
assert(B::count == 0);
assert(A::count == 0);
{
std::shared_ptr<A> pA(new A);
A* ptrA = pA.get();
{
std::shared_ptr<A> pB;
pB = std::move(pA);
assert(B::count == 1);
assert(A::count == 1);
assert(pB.use_count() == 1);
assert(pA.use_count() == 0);
assert(pA.get() == 0);
assert(pB.get() == ptrA);
}
assert(pA.use_count() == 0);
assert(B::count == 0);
assert(A::count == 0);
}
assert(B::count == 0);
assert(A::count == 0);
{
std::shared_ptr<A> pA;
A* ptrA = pA.get();
{
std::shared_ptr<A> pB;
pB = std::move(pA);
assert(B::count == 0);
assert(A::count == 0);
assert(pB.use_count() == 0);
assert(pA.use_count() == 0);
assert(pA.get() == 0);
assert(pB.get() == ptrA);
}
assert(pA.use_count() == 0);
assert(B::count == 0);
assert(A::count == 0);
}
assert(B::count == 0);
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// shared_ptr + +// shared_ptr& operator=(shared_ptr&& r); + +#include <memory> +#include <type_traits> +#include <cassert> + +struct B +{ + static int count; + + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +struct A + : public B +{ + static int count; + + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +int main() +{ + { + std::shared_ptr<A> pA(new A); + A* ptrA = pA.get(); + { + std::shared_ptr<A> pB(new A); + pB = std::move(pA); + assert(B::count == 1); + assert(A::count == 1); + assert(pB.use_count() == 1); + assert(pA.use_count() == 0); + assert(pA.get() == 0); + assert(pB.get() == ptrA); + } + assert(pA.use_count() == 0); + assert(B::count == 0); + assert(A::count == 0); + } + assert(B::count == 0); + assert(A::count == 0); + { + std::shared_ptr<A> pA; + A* ptrA = pA.get(); + { + std::shared_ptr<A> pB(new A); + pB = std::move(pA); + assert(B::count == 0); + assert(A::count == 0); + assert(pB.use_count() == 0); + assert(pA.use_count() == 0); + assert(pA.get() == 0); + assert(pB.get() == ptrA); + } + assert(pA.use_count() == 0); + assert(B::count == 0); + assert(A::count == 0); + } + assert(B::count == 0); + assert(A::count == 0); + { + std::shared_ptr<A> pA(new A); + A* ptrA = pA.get(); + { + std::shared_ptr<A> pB; + pB = std::move(pA); + assert(B::count == 1); + assert(A::count == 1); + assert(pB.use_count() == 1); + assert(pA.use_count() == 0); + assert(pA.get() == 0); + assert(pB.get() == ptrA); + } + assert(pA.use_count() == 0); + assert(B::count == 0); + assert(A::count == 0); + } + assert(B::count == 0); + assert(A::count == 0); + { + std::shared_ptr<A> pA; + A* ptrA = pA.get(); + { + std::shared_ptr<A> pB; + pB = std::move(pA); + assert(B::count == 0); + assert(A::count == 0); + assert(pB.use_count() == 0); + assert(pA.use_count() == 0); + assert(pA.get() == 0); + assert(pB.get() == ptrA); + } + assert(pA.use_count() == 0); + assert(B::count == 0); + assert(A::count == 0); + } + assert(B::count == 0); + assert(A::count == 0); +} diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.assign/unique_ptr_Y.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.assign/unique_ptr_Y.pass.cpp index 75b20bfd12b..11ad6021103 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.assign/unique_ptr_Y.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.assign/unique_ptr_Y.pass.cpp @@ -1 +1,113 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// template <class Y, class D> shared_ptr& operator=(unique_ptr<Y, D>&& r);
#include <memory>
#include <type_traits>
#include <cassert>
struct B
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
struct A
: public B
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
std::unique_ptr<A> pA(new A);
A* ptrA = pA.get();
{
std::shared_ptr<B> pB(new B);
pB = std::move(pA);
assert(B::count == 1);
assert(A::count == 1);
assert(pB.use_count() == 1);
assert(pA.get() == 0);
assert(pB.get() == ptrA);
}
assert(B::count == 0);
assert(A::count == 0);
}
assert(B::count == 0);
assert(A::count == 0);
{
std::unique_ptr<A> pA;
A* ptrA = pA.get();
{
std::shared_ptr<B> pB(new B);
pB = std::move(pA);
assert(B::count == 0);
assert(A::count == 0);
assert(pB.use_count() == 1);
assert(pA.get() == 0);
assert(pB.get() == ptrA);
}
assert(B::count == 0);
assert(A::count == 0);
}
assert(B::count == 0);
assert(A::count == 0);
{
std::unique_ptr<A> pA(new A);
A* ptrA = pA.get();
{
std::shared_ptr<B> pB;
pB = std::move(pA);
assert(B::count == 1);
assert(A::count == 1);
assert(pB.use_count() == 1);
assert(pA.get() == 0);
assert(pB.get() == ptrA);
}
assert(B::count == 0);
assert(A::count == 0);
}
assert(B::count == 0);
assert(A::count == 0);
{
std::unique_ptr<A> pA;
A* ptrA = pA.get();
{
std::shared_ptr<B> pB;
pB = std::move(pA);
assert(B::count == 0);
assert(A::count == 0);
assert(pB.use_count() == 1);
assert(pA.get() == 0);
assert(pB.get() == ptrA);
}
assert(B::count == 0);
assert(A::count == 0);
}
assert(B::count == 0);
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// shared_ptr + +// template <class Y, class D> shared_ptr& operator=(unique_ptr<Y, D>&& r); + +#include <memory> +#include <type_traits> +#include <cassert> + +struct B +{ + static int count; + + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +struct A + : public B +{ + static int count; + + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +int main() +{ + { + std::unique_ptr<A> pA(new A); + A* ptrA = pA.get(); + { + std::shared_ptr<B> pB(new B); + pB = std::move(pA); + assert(B::count == 1); + assert(A::count == 1); + assert(pB.use_count() == 1); + assert(pA.get() == 0); + assert(pB.get() == ptrA); + } + assert(B::count == 0); + assert(A::count == 0); + } + assert(B::count == 0); + assert(A::count == 0); + { + std::unique_ptr<A> pA; + A* ptrA = pA.get(); + { + std::shared_ptr<B> pB(new B); + pB = std::move(pA); + assert(B::count == 0); + assert(A::count == 0); + assert(pB.use_count() == 1); + assert(pA.get() == 0); + assert(pB.get() == ptrA); + } + assert(B::count == 0); + assert(A::count == 0); + } + assert(B::count == 0); + assert(A::count == 0); + { + std::unique_ptr<A> pA(new A); + A* ptrA = pA.get(); + { + std::shared_ptr<B> pB; + pB = std::move(pA); + assert(B::count == 1); + assert(A::count == 1); + assert(pB.use_count() == 1); + assert(pA.get() == 0); + assert(pB.get() == ptrA); + } + assert(B::count == 0); + assert(A::count == 0); + } + assert(B::count == 0); + assert(A::count == 0); + { + std::unique_ptr<A> pA; + A* ptrA = pA.get(); + { + std::shared_ptr<B> pB; + pB = std::move(pA); + assert(B::count == 0); + assert(A::count == 0); + assert(pB.use_count() == 1); + assert(pA.get() == 0); + assert(pB.get() == ptrA); + } + assert(B::count == 0); + assert(A::count == 0); + } + assert(B::count == 0); + assert(A::count == 0); +} diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.cast/const_pointer_cast.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.cast/const_pointer_cast.pass.cpp index 0196cf9b26b..9b98af0edab 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.cast/const_pointer_cast.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.cast/const_pointer_cast.pass.cpp @@ -1 +1,57 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// template<class T, class U> shared_ptr<T> const_pointer_cast(const shared_ptr<U>& r);
#include <memory>
#include <type_traits>
#include <cassert>
struct B
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
struct A
: public B
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
const std::shared_ptr<const A> pA(new A);
std::shared_ptr<A> pB = std::const_pointer_cast<A>(pA);
assert(pB.get() == pA.get());
assert(!pB.owner_before(pA) && !pA.owner_before(pB));
}
{
const std::shared_ptr<const A> pA;
std::shared_ptr<A> pB = std::const_pointer_cast<A>(pA);
assert(pB.get() == pA.get());
assert(!pB.owner_before(pA) && !pA.owner_before(pB));
}
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// shared_ptr + +// template<class T, class U> shared_ptr<T> const_pointer_cast(const shared_ptr<U>& r); + +#include <memory> +#include <type_traits> +#include <cassert> + +struct B +{ + static int count; + + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +struct A + : public B +{ + static int count; + + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +int main() +{ + { + const std::shared_ptr<const A> pA(new A); + std::shared_ptr<A> pB = std::const_pointer_cast<A>(pA); + assert(pB.get() == pA.get()); + assert(!pB.owner_before(pA) && !pA.owner_before(pB)); + } + { + const std::shared_ptr<const A> pA; + std::shared_ptr<A> pB = std::const_pointer_cast<A>(pA); + assert(pB.get() == pA.get()); + assert(!pB.owner_before(pA) && !pA.owner_before(pB)); + } +} diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.cast/dynamic_pointer_cast.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.cast/dynamic_pointer_cast.pass.cpp index ad2b6a4b72e..1f99c8c991b 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.cast/dynamic_pointer_cast.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.cast/dynamic_pointer_cast.pass.cpp @@ -1 +1,57 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// template<class T, class U> shared_ptr<T> dynamic_pointer_cast(const shared_ptr<U>& r);
#include <memory>
#include <type_traits>
#include <cassert>
struct B
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
struct A
: public B
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
const std::shared_ptr<B> pB(new A);
std::shared_ptr<A> pA = std::dynamic_pointer_cast<A>(pB);
assert(pA.get() == pB.get());
assert(!pB.owner_before(pA) && !pA.owner_before(pB));
}
{
const std::shared_ptr<B> pB(new B);
std::shared_ptr<A> pA = std::dynamic_pointer_cast<A>(pB);
assert(pA.get() == 0);
assert(pA.use_count() == 0);
}
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// shared_ptr + +// template<class T, class U> shared_ptr<T> dynamic_pointer_cast(const shared_ptr<U>& r); + +#include <memory> +#include <type_traits> +#include <cassert> + +struct B +{ + static int count; + + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +struct A + : public B +{ + static int count; + + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +int main() +{ + { + const std::shared_ptr<B> pB(new A); + std::shared_ptr<A> pA = std::dynamic_pointer_cast<A>(pB); + assert(pA.get() == pB.get()); + assert(!pB.owner_before(pA) && !pA.owner_before(pB)); + } + { + const std::shared_ptr<B> pB(new B); + std::shared_ptr<A> pA = std::dynamic_pointer_cast<A>(pB); + assert(pA.get() == 0); + assert(pA.use_count() == 0); + } +} diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.cast/static_pointer_cast.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.cast/static_pointer_cast.pass.cpp index 03146c1c4e2..f67c54b4398 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.cast/static_pointer_cast.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.cast/static_pointer_cast.pass.cpp @@ -1 +1,69 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// template<class T, class U> shared_ptr<T> static_pointer_cast(const shared_ptr<U>& r);
#include <memory>
#include <type_traits>
#include <cassert>
struct B
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
struct A
: public B
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
const std::shared_ptr<A> pA(new A);
std::shared_ptr<B> pB = std::static_pointer_cast<B>(pA);
assert(pB.get() == pA.get());
assert(!pB.owner_before(pA) && !pA.owner_before(pB));
}
{
const std::shared_ptr<B> pA(new A);
std::shared_ptr<A> pB = std::static_pointer_cast<A>(pA);
assert(pB.get() == pA.get());
assert(!pB.owner_before(pA) && !pA.owner_before(pB));
}
{
const std::shared_ptr<A> pA;
std::shared_ptr<B> pB = std::static_pointer_cast<B>(pA);
assert(pB.get() == pA.get());
assert(!pB.owner_before(pA) && !pA.owner_before(pB));
}
{
const std::shared_ptr<B> pA;
std::shared_ptr<A> pB = std::static_pointer_cast<A>(pA);
assert(pB.get() == pA.get());
assert(!pB.owner_before(pA) && !pA.owner_before(pB));
}
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// shared_ptr + +// template<class T, class U> shared_ptr<T> static_pointer_cast(const shared_ptr<U>& r); + +#include <memory> +#include <type_traits> +#include <cassert> + +struct B +{ + static int count; + + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +struct A + : public B +{ + static int count; + + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +int main() +{ + { + const std::shared_ptr<A> pA(new A); + std::shared_ptr<B> pB = std::static_pointer_cast<B>(pA); + assert(pB.get() == pA.get()); + assert(!pB.owner_before(pA) && !pA.owner_before(pB)); + } + { + const std::shared_ptr<B> pA(new A); + std::shared_ptr<A> pB = std::static_pointer_cast<A>(pA); + assert(pB.get() == pA.get()); + assert(!pB.owner_before(pA) && !pA.owner_before(pB)); + } + { + const std::shared_ptr<A> pA; + std::shared_ptr<B> pB = std::static_pointer_cast<B>(pA); + assert(pB.get() == pA.get()); + assert(!pB.owner_before(pA) && !pA.owner_before(pB)); + } + { + const std::shared_ptr<B> pA; + std::shared_ptr<A> pB = std::static_pointer_cast<A>(pA); + assert(pB.get() == pA.get()); + assert(!pB.owner_before(pA) && !pA.owner_before(pB)); + } +} diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.cmp/eq.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.cmp/eq.pass.cpp index a8ae78813a8..692dec7dcb4 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.cmp/eq.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.cmp/eq.pass.cpp @@ -1 +1,31 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// template<class T, class U> bool operator==(const shared_ptr<T>& a, const shared_ptr<U>& b);
// template<class T, class U> bool operator!=(const shared_ptr<T>& a, const shared_ptr<U>& b);
#include <memory>
#include <cassert>
void do_nothing(int*) {}
int main()
{
int* ptr1(new int);
int* ptr2(new int);
const std::shared_ptr<int> p1(ptr1);
const std::shared_ptr<int> p2(ptr2);
const std::shared_ptr<int> p3(ptr2, do_nothing);
assert(p1 != p2);
assert(p2 == p3);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// shared_ptr + +// template<class T, class U> bool operator==(const shared_ptr<T>& a, const shared_ptr<U>& b); +// template<class T, class U> bool operator!=(const shared_ptr<T>& a, const shared_ptr<U>& b); + +#include <memory> +#include <cassert> + +void do_nothing(int*) {} + +int main() +{ + int* ptr1(new int); + int* ptr2(new int); + const std::shared_ptr<int> p1(ptr1); + const std::shared_ptr<int> p2(ptr2); + const std::shared_ptr<int> p3(ptr2, do_nothing); + assert(p1 != p2); + assert(p2 == p3); +} diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.cmp/lt.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.cmp/lt.pass.cpp index e5a94e9324b..8c328fdc91e 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.cmp/lt.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.cmp/lt.pass.cpp @@ -1 +1,30 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// template<class T, class U> bool operator<(const shared_ptr<T>& a, const shared_ptr<U>& b);
#include <memory>
#include <cassert>
void do_nothing(int*) {}
int main()
{
int* ptr1(new int);
int* ptr2(new int);
const std::shared_ptr<int> p1(ptr1);
const std::shared_ptr<int> p2(ptr2);
const std::shared_ptr<int> p3(ptr2, do_nothing);
assert((p1 < p2) == (ptr1 < ptr2));
assert(!(p2 < p3) && !(p3 < p2));
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// shared_ptr + +// template<class T, class U> bool operator<(const shared_ptr<T>& a, const shared_ptr<U>& b); + +#include <memory> +#include <cassert> + +void do_nothing(int*) {} + +int main() +{ + int* ptr1(new int); + int* ptr2(new int); + const std::shared_ptr<int> p1(ptr1); + const std::shared_ptr<int> p2(ptr2); + const std::shared_ptr<int> p3(ptr2, do_nothing); + assert((p1 < p2) == (ptr1 < ptr2)); + assert(!(p2 < p3) && !(p3 < p2)); +} diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/auto_ptr.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/auto_ptr.pass.cpp index eca83722175..dcc594e132e 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/auto_ptr.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/auto_ptr.pass.cpp @@ -1 +1,94 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template<class Y> explicit shared_ptr(auto_ptr<Y>&& r);
#include <memory>
#include <new>
#include <cstdlib>
#include <cassert>
bool throw_next = false;
void* operator new(std::size_t s) throw(std::bad_alloc)
{
if (throw_next)
throw std::bad_alloc();
return std::malloc(s);
}
void operator delete(void* p) throw()
{
std::free(p);
}
struct B
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
struct A
: public B
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
std::auto_ptr<A> ptr(new A);
A* raw_ptr = ptr.get();
#ifdef _LIBCPP_MOVE
std::shared_ptr<B> p(std::move(ptr));
#else
std::shared_ptr<B> p(ptr);
#endif
assert(A::count == 1);
assert(B::count == 1);
assert(p.use_count() == 1);
assert(p.get() == raw_ptr);
assert(ptr.get() == 0);
}
assert(A::count == 0);
{
std::auto_ptr<A> ptr(new A);
A* raw_ptr = ptr.get();
throw_next = true;
try
{
#ifdef _LIBCPP_MOVE
std::shared_ptr<B> p(std::move(ptr));
#else
std::shared_ptr<B> p(ptr);
#endif
assert(false);
}
catch (...)
{
assert(A::count == 1);
assert(B::count == 1);
assert(ptr.get() == raw_ptr);
}
}
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// template<class Y> explicit shared_ptr(auto_ptr<Y>&& r); + +#include <memory> +#include <new> +#include <cstdlib> +#include <cassert> + +bool throw_next = false; + +void* operator new(std::size_t s) throw(std::bad_alloc) +{ + if (throw_next) + throw std::bad_alloc(); + return std::malloc(s); +} + +void operator delete(void* p) throw() +{ + std::free(p); +} + +struct B +{ + static int count; + + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +struct A + : public B +{ + static int count; + + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +int main() +{ + { + std::auto_ptr<A> ptr(new A); + A* raw_ptr = ptr.get(); +#ifdef _LIBCPP_MOVE + std::shared_ptr<B> p(std::move(ptr)); +#else + std::shared_ptr<B> p(ptr); +#endif + assert(A::count == 1); + assert(B::count == 1); + assert(p.use_count() == 1); + assert(p.get() == raw_ptr); + assert(ptr.get() == 0); + } + assert(A::count == 0); + { + std::auto_ptr<A> ptr(new A); + A* raw_ptr = ptr.get(); + throw_next = true; + try + { +#ifdef _LIBCPP_MOVE + std::shared_ptr<B> p(std::move(ptr)); +#else + std::shared_ptr<B> p(ptr); +#endif + assert(false); + } + catch (...) + { + assert(A::count == 1); + assert(B::count == 1); + assert(ptr.get() == raw_ptr); + } + } + assert(A::count == 0); +} diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/default.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/default.pass.cpp index fa55289d9f4..50f3195def0 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/default.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/default.pass.cpp @@ -1 +1,22 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr();
#include <memory>
#include <cassert>
int main()
{
std::shared_ptr<int> p;
assert(p.use_count() == 0);
assert(p.get() == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// shared_ptr(); + +#include <memory> +#include <cassert> + +int main() +{ + std::shared_ptr<int> p; + assert(p.use_count() == 0); + assert(p.get() == 0); +} diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t.pass.cpp index 6853ca698ab..4a442157d61 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t.pass.cpp @@ -1 +1,22 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr(nullptr_t)
#include <memory>
#include <cassert>
int main()
{
std::shared_ptr<int> p(nullptr);
assert(p.use_count() == 0);
assert(p.get() == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// shared_ptr(nullptr_t) + +#include <memory> +#include <cassert> + +int main() +{ + std::shared_ptr<int> p(nullptr); + assert(p.use_count() == 0); + assert(p.get() == 0); +} diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t_deleter.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t_deleter.pass.cpp index 6e75c3f2e22..025d09f55c4 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t_deleter.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t_deleter.pass.cpp @@ -1 +1,47 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// template<class D> shared_ptr(nullptr_t, D d);
#include <memory>
#include <cassert>
#include "../test_deleter.h"
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
std::shared_ptr<A> p(nullptr, test_deleter<A>(3));
assert(A::count == 0);
assert(p.use_count() == 1);
assert(p.get() == 0);
test_deleter<A>* d = std::get_deleter<test_deleter<A> >(p);
assert(test_deleter<A>::count == 1);
assert(test_deleter<A>::dealloc_count == 0);
assert(d);
assert(d->state() == 3);
}
assert(A::count == 0);
assert(test_deleter<A>::count == 0);
assert(test_deleter<A>::dealloc_count == 1);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// shared_ptr + +// template<class D> shared_ptr(nullptr_t, D d); + +#include <memory> +#include <cassert> +#include "../test_deleter.h" + +struct A +{ + static int count; + + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +int main() +{ + { + std::shared_ptr<A> p(nullptr, test_deleter<A>(3)); + assert(A::count == 0); + assert(p.use_count() == 1); + assert(p.get() == 0); + test_deleter<A>* d = std::get_deleter<test_deleter<A> >(p); + assert(test_deleter<A>::count == 1); + assert(test_deleter<A>::dealloc_count == 0); + assert(d); + assert(d->state() == 3); + } + assert(A::count == 0); + assert(test_deleter<A>::count == 0); + assert(test_deleter<A>::dealloc_count == 1); +} diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t_deleter_allocator.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t_deleter_allocator.pass.cpp index c27df0e9a37..1eeb3cefc1f 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t_deleter_allocator.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t_deleter_allocator.pass.cpp @@ -1 +1,50 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template<class D, class A> shared_ptr(nullptr_t, D d, A a);
#include <memory>
#include <cassert>
#include "../test_deleter.h"
#include "../test_allocator.h"
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
std::shared_ptr<A> p(nullptr, test_deleter<A>(3), test_allocator<A>(5));
assert(A::count == 0);
assert(p.use_count() == 1);
assert(p.get() == 0);
test_deleter<A>* d = std::get_deleter<test_deleter<A> >(p);
assert(test_deleter<A>::count == 1);
assert(test_deleter<A>::dealloc_count == 0);
assert(d);
assert(d->state() == 3);
assert(test_allocator<A>::count == 1);
assert(test_allocator<A>::alloc_count == 1);
}
assert(A::count == 0);
assert(test_deleter<A>::count == 0);
assert(test_deleter<A>::dealloc_count == 1);
assert(test_allocator<A>::count == 0);
assert(test_allocator<A>::alloc_count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// template<class D, class A> shared_ptr(nullptr_t, D d, A a); + +#include <memory> +#include <cassert> +#include "../test_deleter.h" +#include "../test_allocator.h" + +struct A +{ + static int count; + + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +int main() +{ + { + std::shared_ptr<A> p(nullptr, test_deleter<A>(3), test_allocator<A>(5)); + assert(A::count == 0); + assert(p.use_count() == 1); + assert(p.get() == 0); + test_deleter<A>* d = std::get_deleter<test_deleter<A> >(p); + assert(test_deleter<A>::count == 1); + assert(test_deleter<A>::dealloc_count == 0); + assert(d); + assert(d->state() == 3); + assert(test_allocator<A>::count == 1); + assert(test_allocator<A>::alloc_count == 1); + } + assert(A::count == 0); + assert(test_deleter<A>::count == 0); + assert(test_deleter<A>::dealloc_count == 1); + assert(test_allocator<A>::count == 0); + assert(test_allocator<A>::alloc_count == 0); +} diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t_deleter_allocator_throw.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t_deleter_allocator_throw.pass.cpp index 017fa7aaa95..e3f1a5a8e8c 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t_deleter_allocator_throw.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t_deleter_allocator_throw.pass.cpp @@ -1 +1,46 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template<class D, class A> shared_ptr(nullptr_t, D d, A a);
#include <memory>
#include <cassert>
#include "../test_deleter.h"
#include "../test_allocator.h"
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
try
{
test_allocator<A>::throw_after = 0;
std::shared_ptr<A> p(nullptr, test_deleter<A>(3), test_allocator<A>(5));
assert(false);
}
catch (std::bad_alloc&)
{
assert(A::count == 0);
assert(test_deleter<A>::count == 0);
assert(test_deleter<A>::dealloc_count == 1);
assert(test_allocator<A>::count == 0);
assert(test_allocator<A>::alloc_count == 0);
}
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// template<class D, class A> shared_ptr(nullptr_t, D d, A a); + +#include <memory> +#include <cassert> +#include "../test_deleter.h" +#include "../test_allocator.h" + +struct A +{ + static int count; + + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +int main() +{ + try + { + test_allocator<A>::throw_after = 0; + std::shared_ptr<A> p(nullptr, test_deleter<A>(3), test_allocator<A>(5)); + assert(false); + } + catch (std::bad_alloc&) + { + assert(A::count == 0); + assert(test_deleter<A>::count == 0); + assert(test_deleter<A>::dealloc_count == 1); + assert(test_allocator<A>::count == 0); + assert(test_allocator<A>::alloc_count == 0); + } +} diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t_deleter_throw.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t_deleter_throw.pass.cpp index 86e9e7a14d8..878c417876d 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t_deleter_throw.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t_deleter_throw.pass.cpp @@ -1 +1,61 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// template<class D> shared_ptr(nullptr_t, D d);
#include <memory>
#include <cassert>
#include <new>
#include <cstdlib>
#include "../test_deleter.h"
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
bool throw_next = false;
void* operator new(std::size_t s) throw(std::bad_alloc)
{
if (throw_next)
throw std::bad_alloc();
return std::malloc(s);
}
void operator delete(void* p) throw()
{
std::free(p);
}
int main()
{
throw_next = true;
try
{
std::shared_ptr<A> p(nullptr, test_deleter<A>(3));
assert(false);
}
catch (std::bad_alloc&)
{
assert(A::count == 0);
assert(test_deleter<A>::count == 0);
assert(test_deleter<A>::dealloc_count == 1);
}
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// shared_ptr + +// template<class D> shared_ptr(nullptr_t, D d); + +#include <memory> +#include <cassert> +#include <new> +#include <cstdlib> +#include "../test_deleter.h" + +struct A +{ + static int count; + + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +bool throw_next = false; + +void* operator new(std::size_t s) throw(std::bad_alloc) +{ + if (throw_next) + throw std::bad_alloc(); + return std::malloc(s); +} + +void operator delete(void* p) throw() +{ + std::free(p); +} + +int main() +{ + throw_next = true; + try + { + std::shared_ptr<A> p(nullptr, test_deleter<A>(3)); + assert(false); + } + catch (std::bad_alloc&) + { + assert(A::count == 0); + assert(test_deleter<A>::count == 0); + assert(test_deleter<A>::dealloc_count == 1); + } +} diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer.pass.cpp index 28a5a57edea..ed6396ef750 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer.pass.cpp @@ -1 +1,46 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template<class Y> explicit shared_ptr(Y* p);
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
A* ptr = new A;
std::shared_ptr<A> p(ptr);
assert(A::count == 1);
assert(p.use_count() == 1);
assert(p.get() == ptr);
}
assert(A::count == 0);
{
A* ptr = new A;
std::shared_ptr<void> p(ptr);
assert(A::count == 1);
assert(p.use_count() == 1);
assert(p.get() == ptr);
}
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// template<class Y> explicit shared_ptr(Y* p); + +#include <memory> +#include <cassert> + +struct A +{ + static int count; + + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +int main() +{ + { + A* ptr = new A; + std::shared_ptr<A> p(ptr); + assert(A::count == 1); + assert(p.use_count() == 1); + assert(p.get() == ptr); + } + assert(A::count == 0); + { + A* ptr = new A; + std::shared_ptr<void> p(ptr); + assert(A::count == 1); + assert(p.use_count() == 1); + assert(p.get() == ptr); + } + assert(A::count == 0); +} diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter.pass.cpp index 9db6b0c8d68..d75d46ad686 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter.pass.cpp @@ -1 +1,48 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// template<class Y, class D> shared_ptr(Y* p, D d);
#include <memory>
#include <cassert>
#include "../test_deleter.h"
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
A* ptr = new A;
std::shared_ptr<A> p(ptr, test_deleter<A>(3));
assert(A::count == 1);
assert(p.use_count() == 1);
assert(p.get() == ptr);
test_deleter<A>* d = std::get_deleter<test_deleter<A> >(p);
assert(test_deleter<A>::count == 1);
assert(test_deleter<A>::dealloc_count == 0);
assert(d);
assert(d->state() == 3);
}
assert(A::count == 0);
assert(test_deleter<A>::count == 0);
assert(test_deleter<A>::dealloc_count == 1);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// shared_ptr + +// template<class Y, class D> shared_ptr(Y* p, D d); + +#include <memory> +#include <cassert> +#include "../test_deleter.h" + +struct A +{ + static int count; + + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +int main() +{ + { + A* ptr = new A; + std::shared_ptr<A> p(ptr, test_deleter<A>(3)); + assert(A::count == 1); + assert(p.use_count() == 1); + assert(p.get() == ptr); + test_deleter<A>* d = std::get_deleter<test_deleter<A> >(p); + assert(test_deleter<A>::count == 1); + assert(test_deleter<A>::dealloc_count == 0); + assert(d); + assert(d->state() == 3); + } + assert(A::count == 0); + assert(test_deleter<A>::count == 0); + assert(test_deleter<A>::dealloc_count == 1); +} diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter_allocator.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter_allocator.pass.cpp index e340c76e248..08d1d6f84b2 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter_allocator.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter_allocator.pass.cpp @@ -1 +1,51 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template<class Y, class D, class A> shared_ptr(Y* p, D d, A a);
#include <memory>
#include <cassert>
#include "../test_deleter.h"
#include "../test_allocator.h"
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
A* ptr = new A;
std::shared_ptr<A> p(ptr, test_deleter<A>(3), test_allocator<A>(5));
assert(A::count == 1);
assert(p.use_count() == 1);
assert(p.get() == ptr);
test_deleter<A>* d = std::get_deleter<test_deleter<A> >(p);
assert(test_deleter<A>::count == 1);
assert(test_deleter<A>::dealloc_count == 0);
assert(d);
assert(d->state() == 3);
assert(test_allocator<A>::count == 1);
assert(test_allocator<A>::alloc_count == 1);
}
assert(A::count == 0);
assert(test_deleter<A>::count == 0);
assert(test_deleter<A>::dealloc_count == 1);
assert(test_allocator<A>::count == 0);
assert(test_allocator<A>::alloc_count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// template<class Y, class D, class A> shared_ptr(Y* p, D d, A a); + +#include <memory> +#include <cassert> +#include "../test_deleter.h" +#include "../test_allocator.h" + +struct A +{ + static int count; + + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +int main() +{ + { + A* ptr = new A; + std::shared_ptr<A> p(ptr, test_deleter<A>(3), test_allocator<A>(5)); + assert(A::count == 1); + assert(p.use_count() == 1); + assert(p.get() == ptr); + test_deleter<A>* d = std::get_deleter<test_deleter<A> >(p); + assert(test_deleter<A>::count == 1); + assert(test_deleter<A>::dealloc_count == 0); + assert(d); + assert(d->state() == 3); + assert(test_allocator<A>::count == 1); + assert(test_allocator<A>::alloc_count == 1); + } + assert(A::count == 0); + assert(test_deleter<A>::count == 0); + assert(test_deleter<A>::dealloc_count == 1); + assert(test_allocator<A>::count == 0); + assert(test_allocator<A>::alloc_count == 0); +} diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter_allocator_throw.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter_allocator_throw.pass.cpp index 4fd7f6c1396..5b738c8965c 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter_allocator_throw.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter_allocator_throw.pass.cpp @@ -1 +1,47 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template<class Y, class D, class A> shared_ptr(Y* p, D d, A a);
#include <memory>
#include <cassert>
#include "../test_deleter.h"
#include "../test_allocator.h"
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
A* ptr = new A;
try
{
test_allocator<A>::throw_after = 0;
std::shared_ptr<A> p(ptr, test_deleter<A>(3), test_allocator<A>(5));
assert(false);
}
catch (std::bad_alloc&)
{
assert(A::count == 0);
assert(test_deleter<A>::count == 0);
assert(test_deleter<A>::dealloc_count == 1);
assert(test_allocator<A>::count == 0);
assert(test_allocator<A>::alloc_count == 0);
}
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// template<class Y, class D, class A> shared_ptr(Y* p, D d, A a); + +#include <memory> +#include <cassert> +#include "../test_deleter.h" +#include "../test_allocator.h" + +struct A +{ + static int count; + + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +int main() +{ + A* ptr = new A; + try + { + test_allocator<A>::throw_after = 0; + std::shared_ptr<A> p(ptr, test_deleter<A>(3), test_allocator<A>(5)); + assert(false); + } + catch (std::bad_alloc&) + { + assert(A::count == 0); + assert(test_deleter<A>::count == 0); + assert(test_deleter<A>::dealloc_count == 1); + assert(test_allocator<A>::count == 0); + assert(test_allocator<A>::alloc_count == 0); + } +} diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter_throw.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter_throw.pass.cpp index 5596cdaec9b..ba723e3f645 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter_throw.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter_throw.pass.cpp @@ -1 +1,62 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// template<class Y, class D> shared_ptr(Y* p, D d);
#include <memory>
#include <cassert>
#include <new>
#include <cstdlib>
#include "../test_deleter.h"
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
bool throw_next = false;
void* operator new(std::size_t s) throw(std::bad_alloc)
{
if (throw_next)
throw std::bad_alloc();
return std::malloc(s);
}
void operator delete(void* p) throw()
{
std::free(p);
}
int main()
{
A* ptr = new A;
throw_next = true;
try
{
std::shared_ptr<A> p(ptr, test_deleter<A>(3));
assert(false);
}
catch (std::bad_alloc&)
{
assert(A::count == 0);
assert(test_deleter<A>::count == 0);
assert(test_deleter<A>::dealloc_count == 1);
}
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// shared_ptr + +// template<class Y, class D> shared_ptr(Y* p, D d); + +#include <memory> +#include <cassert> +#include <new> +#include <cstdlib> +#include "../test_deleter.h" + +struct A +{ + static int count; + + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +bool throw_next = false; + +void* operator new(std::size_t s) throw(std::bad_alloc) +{ + if (throw_next) + throw std::bad_alloc(); + return std::malloc(s); +} + +void operator delete(void* p) throw() +{ + std::free(p); +} + +int main() +{ + A* ptr = new A; + throw_next = true; + try + { + std::shared_ptr<A> p(ptr, test_deleter<A>(3)); + assert(false); + } + catch (std::bad_alloc&) + { + assert(A::count == 0); + assert(test_deleter<A>::count == 0); + assert(test_deleter<A>::dealloc_count == 1); + } +} diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_throw.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_throw.pass.cpp index 4b47a5c0aa6..298b9b40492 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_throw.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_throw.pass.cpp @@ -1 +1,60 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template<class Y> explicit shared_ptr(Y* p);
#include <memory>
#include <new>
#include <cstdlib>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
bool throw_next = false;
void* operator new(std::size_t s) throw(std::bad_alloc)
{
if (throw_next)
throw std::bad_alloc();
return std::malloc(s);
}
void operator delete(void* p) throw()
{
std::free(p);
}
int main()
{
{
A* ptr = new A;
throw_next = true;
assert(A::count == 1);
try
{
std::shared_ptr<A> p(ptr);
assert(false);
}
catch (std::bad_alloc&)
{
assert(A::count == 0);
}
}
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// template<class Y> explicit shared_ptr(Y* p); + +#include <memory> +#include <new> +#include <cstdlib> +#include <cassert> + +struct A +{ + static int count; + + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +bool throw_next = false; + +void* operator new(std::size_t s) throw(std::bad_alloc) +{ + if (throw_next) + throw std::bad_alloc(); + return std::malloc(s); +} + +void operator delete(void* p) throw() +{ + std::free(p); +} + +int main() +{ + { + A* ptr = new A; + throw_next = true; + assert(A::count == 1); + try + { + std::shared_ptr<A> p(ptr); + assert(false); + } + catch (std::bad_alloc&) + { + assert(A::count == 0); + } + } +} diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr.pass.cpp index 0ee5cca1dc7..9a1d8e5e69e 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr.pass.cpp @@ -1 +1,62 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// shared_ptr(const shared_ptr& r);
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
std::shared_ptr<A> pA(new A);
assert(pA.use_count() == 1);
assert(A::count == 1);
{
std::shared_ptr<A> pA2(pA);
assert(A::count == 1);
assert(pA.use_count() == 2);
assert(pA2.use_count() == 2);
assert(pA2.get() == pA.get());
}
assert(pA.use_count() == 1);
assert(A::count == 1);
}
assert(A::count == 0);
{
std::shared_ptr<A> pA;
assert(pA.use_count() == 0);
assert(A::count == 0);
{
std::shared_ptr<A> pA2(pA);
assert(A::count == 0);
assert(pA.use_count() == 0);
assert(pA2.use_count() == 0);
assert(pA2.get() == pA.get());
}
assert(pA.use_count() == 0);
assert(A::count == 0);
}
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// shared_ptr + +// shared_ptr(const shared_ptr& r); + +#include <memory> +#include <cassert> + +struct A +{ + static int count; + + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +int main() +{ + { + std::shared_ptr<A> pA(new A); + assert(pA.use_count() == 1); + assert(A::count == 1); + { + std::shared_ptr<A> pA2(pA); + assert(A::count == 1); + assert(pA.use_count() == 2); + assert(pA2.use_count() == 2); + assert(pA2.get() == pA.get()); + } + assert(pA.use_count() == 1); + assert(A::count == 1); + } + assert(A::count == 0); + { + std::shared_ptr<A> pA; + assert(pA.use_count() == 0); + assert(A::count == 0); + { + std::shared_ptr<A> pA2(pA); + assert(A::count == 0); + assert(pA.use_count() == 0); + assert(pA2.use_count() == 0); + assert(pA2.get() == pA.get()); + } + assert(pA.use_count() == 0); + assert(A::count == 0); + } + assert(A::count == 0); +} diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr_Y.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr_Y.pass.cpp index a2bc56202bb..ca44ea621f4 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr_Y.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr_Y.pass.cpp @@ -1 +1,97 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// template<class Y> shared_ptr(const shared_ptr<Y>& r);
#include <memory>
#include <type_traits>
#include <cassert>
struct B
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
struct A
: public B
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
struct C
{
static int count;
C() {++count;}
C(const C&) {++count;}
virtual ~C() {--count;}
};
int C::count = 0;
int main()
{
static_assert(( std::is_convertible<std::shared_ptr<A>, std::shared_ptr<B> >::value), "");
static_assert((!std::is_convertible<std::shared_ptr<B>, std::shared_ptr<A> >::value), "");
static_assert((!std::is_convertible<std::shared_ptr<A>, std::shared_ptr<C> >::value), "");
{
const std::shared_ptr<A> pA(new A);
assert(pA.use_count() == 1);
assert(B::count == 1);
assert(A::count == 1);
{
std::shared_ptr<B> pB(pA);
assert(B::count == 1);
assert(A::count == 1);
assert(pB.use_count() == 2);
assert(pA.use_count() == 2);
assert(pA.get() == pB.get());
}
assert(pA.use_count() == 1);
assert(B::count == 1);
assert(A::count == 1);
}
assert(B::count == 0);
assert(A::count == 0);
{
std::shared_ptr<A> pA;
assert(pA.use_count() == 0);
assert(B::count == 0);
assert(A::count == 0);
{
std::shared_ptr<B> pB(pA);
assert(B::count == 0);
assert(A::count == 0);
assert(pB.use_count() == 0);
assert(pA.use_count() == 0);
assert(pA.get() == pB.get());
}
assert(pA.use_count() == 0);
assert(B::count == 0);
assert(A::count == 0);
}
assert(B::count == 0);
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// shared_ptr + +// template<class Y> shared_ptr(const shared_ptr<Y>& r); + +#include <memory> +#include <type_traits> +#include <cassert> + +struct B +{ + static int count; + + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +struct A + : public B +{ + static int count; + + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +struct C +{ + static int count; + + C() {++count;} + C(const C&) {++count;} + virtual ~C() {--count;} +}; + +int C::count = 0; + +int main() +{ + static_assert(( std::is_convertible<std::shared_ptr<A>, std::shared_ptr<B> >::value), ""); + static_assert((!std::is_convertible<std::shared_ptr<B>, std::shared_ptr<A> >::value), ""); + static_assert((!std::is_convertible<std::shared_ptr<A>, std::shared_ptr<C> >::value), ""); + { + const std::shared_ptr<A> pA(new A); + assert(pA.use_count() == 1); + assert(B::count == 1); + assert(A::count == 1); + { + std::shared_ptr<B> pB(pA); + assert(B::count == 1); + assert(A::count == 1); + assert(pB.use_count() == 2); + assert(pA.use_count() == 2); + assert(pA.get() == pB.get()); + } + assert(pA.use_count() == 1); + assert(B::count == 1); + assert(A::count == 1); + } + assert(B::count == 0); + assert(A::count == 0); + { + std::shared_ptr<A> pA; + assert(pA.use_count() == 0); + assert(B::count == 0); + assert(A::count == 0); + { + std::shared_ptr<B> pB(pA); + assert(B::count == 0); + assert(A::count == 0); + assert(pB.use_count() == 0); + assert(pA.use_count() == 0); + assert(pA.get() == pB.get()); + } + assert(pA.use_count() == 0); + assert(B::count == 0); + assert(A::count == 0); + } + assert(B::count == 0); + assert(A::count == 0); +} diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr_Y_rv.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr_Y_rv.pass.cpp index a7b1b1cff05..7f9c142afea 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr_Y_rv.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr_Y_rv.pass.cpp @@ -1 +1,109 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// template<class Y> shared_ptr(shared_ptr<Y>&& r);
#include <memory>
#include <type_traits>
#include <cassert>
struct B
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
struct A
: public B
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
struct C
{
static int count;
C() {++count;}
C(const C&) {++count;}
virtual ~C() {--count;}
};
int C::count = 0;
int main()
{
static_assert(( std::is_convertible<std::shared_ptr<A>, std::shared_ptr<B> >::value), "");
static_assert((!std::is_convertible<std::shared_ptr<B>, std::shared_ptr<A> >::value), "");
static_assert((!std::is_convertible<std::shared_ptr<A>, std::shared_ptr<C> >::value), "");
{
std::shared_ptr<A> pA(new A);
assert(pA.use_count() == 1);
assert(B::count == 1);
assert(A::count == 1);
{
B* p = pA.get();
std::shared_ptr<B> pB(std::move(pA));
assert(B::count == 1);
assert(A::count == 1);
#ifdef _LIBCPP_MOVE
assert(pB.use_count() == 1);
assert(pA.use_count() == 0);
#else
assert(pB.use_count() == 2);
assert(pA.use_count() == 2);
#endif
assert(p == pB.get());
}
#ifdef _LIBCPP_MOVE
assert(pA.use_count() == 0);
assert(B::count == 0);
assert(A::count == 0);
#else
assert(pA.use_count() == 1);
assert(B::count == 1);
assert(A::count == 1);
#endif
}
assert(B::count == 0);
assert(A::count == 0);
{
std::shared_ptr<A> pA;
assert(pA.use_count() == 0);
assert(B::count == 0);
assert(A::count == 0);
{
std::shared_ptr<B> pB(pA);
assert(B::count == 0);
assert(A::count == 0);
assert(pB.use_count() == 0);
assert(pA.use_count() == 0);
assert(pA.get() == pB.get());
}
assert(pA.use_count() == 0);
assert(B::count == 0);
assert(A::count == 0);
}
assert(B::count == 0);
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// shared_ptr + +// template<class Y> shared_ptr(shared_ptr<Y>&& r); + +#include <memory> +#include <type_traits> +#include <cassert> + +struct B +{ + static int count; + + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +struct A + : public B +{ + static int count; + + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +struct C +{ + static int count; + + C() {++count;} + C(const C&) {++count;} + virtual ~C() {--count;} +}; + +int C::count = 0; + +int main() +{ + static_assert(( std::is_convertible<std::shared_ptr<A>, std::shared_ptr<B> >::value), ""); + static_assert((!std::is_convertible<std::shared_ptr<B>, std::shared_ptr<A> >::value), ""); + static_assert((!std::is_convertible<std::shared_ptr<A>, std::shared_ptr<C> >::value), ""); + { + std::shared_ptr<A> pA(new A); + assert(pA.use_count() == 1); + assert(B::count == 1); + assert(A::count == 1); + { + B* p = pA.get(); + std::shared_ptr<B> pB(std::move(pA)); + assert(B::count == 1); + assert(A::count == 1); +#ifdef _LIBCPP_MOVE + assert(pB.use_count() == 1); + assert(pA.use_count() == 0); +#else // _LIBCPP_MOVE + assert(pB.use_count() == 2); + assert(pA.use_count() == 2); +#endif // _LIBCPP_MOVE + assert(p == pB.get()); + } +#ifdef _LIBCPP_MOVE + assert(pA.use_count() == 0); + assert(B::count == 0); + assert(A::count == 0); +#else // _LIBCPP_MOVE + assert(pA.use_count() == 1); + assert(B::count == 1); + assert(A::count == 1); +#endif // _LIBCPP_MOVE + } + assert(B::count == 0); + assert(A::count == 0); + { + std::shared_ptr<A> pA; + assert(pA.use_count() == 0); + assert(B::count == 0); + assert(A::count == 0); + { + std::shared_ptr<B> pB(pA); + assert(B::count == 0); + assert(A::count == 0); + assert(pB.use_count() == 0); + assert(pA.use_count() == 0); + assert(pA.get() == pB.get()); + } + assert(pA.use_count() == 0); + assert(B::count == 0); + assert(A::count == 0); + } + assert(B::count == 0); + assert(A::count == 0); +} diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr_pointer.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr_pointer.pass.cpp index 565d77ff71a..6c2ee0a821e 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr_pointer.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr_pointer.pass.cpp @@ -1 +1,61 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// template<class Y> shared_ptr(const shared_ptr<Y>& r, T *p);
#include <memory>
#include <cassert>
struct B
{
static int count;
B() {++count;}
B(const B&) {++count;}
~B() {--count;}
};
int B::count = 0;
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
std::shared_ptr<A> pA(new A);
assert(pA.use_count() == 1);
{
B b;
std::shared_ptr<B> pB(pA, &b);
assert(A::count == 1);
assert(B::count == 1);
assert(pA.use_count() == 2);
assert(pB.use_count() == 2);
assert(pB.get() == &b);
}
assert(pA.use_count() == 1);
assert(A::count == 1);
assert(B::count == 0);
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// shared_ptr + +// template<class Y> shared_ptr(const shared_ptr<Y>& r, T *p); + +#include <memory> +#include <cassert> + +struct B +{ + static int count; + + B() {++count;} + B(const B&) {++count;} + ~B() {--count;} +}; + +int B::count = 0; + +struct A +{ + static int count; + + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +int main() +{ + { + std::shared_ptr<A> pA(new A); + assert(pA.use_count() == 1); + { + B b; + std::shared_ptr<B> pB(pA, &b); + assert(A::count == 1); + assert(B::count == 1); + assert(pA.use_count() == 2); + assert(pB.use_count() == 2); + assert(pB.get() == &b); + } + assert(pA.use_count() == 1); + assert(A::count == 1); + assert(B::count == 0); + } + assert(A::count == 0); + assert(B::count == 0); +} diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr_rv.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr_rv.pass.cpp index f6528b2cb28..ae3faede98d 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr_rv.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr_rv.pass.cpp @@ -1 +1,73 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// shared_ptr(shared_ptr&& r);
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
std::shared_ptr<A> pA(new A);
assert(pA.use_count() == 1);
assert(A::count == 1);
{
A* p = pA.get();
std::shared_ptr<A> pA2(std::move(pA));
assert(A::count == 1);
#ifdef _LIBCPP_MOVE
assert(pA.use_count() == 0);
assert(pA2.use_count() == 1);
#else
assert(pA.use_count() == 2);
assert(pA2.use_count() == 2);
#endif
assert(pA2.get() == p);
}
#ifdef _LIBCPP_MOVE
assert(pA.use_count() == 0);
assert(A::count == 0);
#else
assert(pA.use_count() == 1);
assert(A::count == 1);
#endif
}
assert(A::count == 0);
{
std::shared_ptr<A> pA;
assert(pA.use_count() == 0);
assert(A::count == 0);
{
std::shared_ptr<A> pA2(std::move(pA));
assert(A::count == 0);
assert(pA.use_count() == 0);
assert(pA2.use_count() == 0);
assert(pA2.get() == pA.get());
}
assert(pA.use_count() == 0);
assert(A::count == 0);
}
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// shared_ptr + +// shared_ptr(shared_ptr&& r); + +#include <memory> +#include <cassert> + +struct A +{ + static int count; + + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +int main() +{ + { + std::shared_ptr<A> pA(new A); + assert(pA.use_count() == 1); + assert(A::count == 1); + { + A* p = pA.get(); + std::shared_ptr<A> pA2(std::move(pA)); + assert(A::count == 1); +#ifdef _LIBCPP_MOVE + assert(pA.use_count() == 0); + assert(pA2.use_count() == 1); +#else // _LIBCPP_MOVE + assert(pA.use_count() == 2); + assert(pA2.use_count() == 2); +#endif // _LIBCPP_MOVE + assert(pA2.get() == p); + } +#ifdef _LIBCPP_MOVE + assert(pA.use_count() == 0); + assert(A::count == 0); +#else // _LIBCPP_MOVE + assert(pA.use_count() == 1); + assert(A::count == 1); +#endif // _LIBCPP_MOVE + } + assert(A::count == 0); + { + std::shared_ptr<A> pA; + assert(pA.use_count() == 0); + assert(A::count == 0); + { + std::shared_ptr<A> pA2(std::move(pA)); + assert(A::count == 0); + assert(pA.use_count() == 0); + assert(pA2.use_count() == 0); + assert(pA2.get() == pA.get()); + } + assert(pA.use_count() == 0); + assert(A::count == 0); + } + assert(A::count == 0); +} diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/unique_ptr.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/unique_ptr.pass.cpp index 9f57052860e..d5833fe9479 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/unique_ptr.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/unique_ptr.pass.cpp @@ -1 +1,86 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <class Y, class D> explicit shared_ptr(unique_ptr<Y, D>&&r);
#include <memory>
#include <new>
#include <cstdlib>
#include <cassert>
bool throw_next = false;
void* operator new(std::size_t s) throw(std::bad_alloc)
{
if (throw_next)
throw std::bad_alloc();
return std::malloc(s);
}
void operator delete(void* p) throw()
{
std::free(p);
}
struct B
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
struct A
: public B
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
std::unique_ptr<A> ptr(new A);
A* raw_ptr = ptr.get();
std::shared_ptr<B> p(std::move(ptr));
assert(A::count == 1);
assert(B::count == 1);
assert(p.use_count() == 1);
assert(p.get() == raw_ptr);
assert(ptr.get() == 0);
}
assert(A::count == 0);
{
std::unique_ptr<A> ptr(new A);
A* raw_ptr = ptr.get();
throw_next = true;
try
{
std::shared_ptr<B> p(std::move(ptr));
assert(false);
}
catch (...)
{
assert(A::count == 1);
assert(B::count == 1);
assert(ptr.get() == raw_ptr);
}
}
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// template <class Y, class D> explicit shared_ptr(unique_ptr<Y, D>&&r); + +#include <memory> +#include <new> +#include <cstdlib> +#include <cassert> + +bool throw_next = false; + +void* operator new(std::size_t s) throw(std::bad_alloc) +{ + if (throw_next) + throw std::bad_alloc(); + return std::malloc(s); +} + +void operator delete(void* p) throw() +{ + std::free(p); +} + +struct B +{ + static int count; + + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +struct A + : public B +{ + static int count; + + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +int main() +{ + { + std::unique_ptr<A> ptr(new A); + A* raw_ptr = ptr.get(); + std::shared_ptr<B> p(std::move(ptr)); + assert(A::count == 1); + assert(B::count == 1); + assert(p.use_count() == 1); + assert(p.get() == raw_ptr); + assert(ptr.get() == 0); + } + assert(A::count == 0); + { + std::unique_ptr<A> ptr(new A); + A* raw_ptr = ptr.get(); + throw_next = true; + try + { + std::shared_ptr<B> p(std::move(ptr)); + assert(false); + } + catch (...) + { + assert(A::count == 1); + assert(B::count == 1); + assert(ptr.get() == raw_ptr); + } + } + assert(A::count == 0); +} diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/weak_ptr.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/weak_ptr.pass.cpp index aa9fbf50377..5ff710411f5 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/weak_ptr.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/weak_ptr.pass.cpp @@ -1 +1,79 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// template<class Y> explicit shared_ptr(const weak_ptr<Y>& r);
#include <memory>
#include <cassert>
struct B
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
struct A
: public B
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
std::weak_ptr<A> wp;
try
{
std::shared_ptr<A> sp(wp);
assert(false);
}
catch (std::bad_weak_ptr&)
{
}
assert(A::count == 0);
}
{
std::shared_ptr<A> sp0(new A);
std::weak_ptr<A> wp(sp0);
std::shared_ptr<A> sp(wp);
assert(sp.use_count() == 2);
assert(sp.get() == sp0.get());
assert(A::count == 1);
}
assert(A::count == 0);
{
std::shared_ptr<A> sp0(new A);
std::weak_ptr<A> wp(sp0);
sp0.reset();
try
{
std::shared_ptr<A> sp(wp);
assert(false);
}
catch (std::bad_weak_ptr&)
{
}
}
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// shared_ptr + +// template<class Y> explicit shared_ptr(const weak_ptr<Y>& r); + +#include <memory> +#include <cassert> + +struct B +{ + static int count; + + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +struct A + : public B +{ + static int count; + + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +int main() +{ + { + std::weak_ptr<A> wp; + try + { + std::shared_ptr<A> sp(wp); + assert(false); + } + catch (std::bad_weak_ptr&) + { + } + assert(A::count == 0); + } + { + std::shared_ptr<A> sp0(new A); + std::weak_ptr<A> wp(sp0); + std::shared_ptr<A> sp(wp); + assert(sp.use_count() == 2); + assert(sp.get() == sp0.get()); + assert(A::count == 1); + } + assert(A::count == 0); + { + std::shared_ptr<A> sp0(new A); + std::weak_ptr<A> wp(sp0); + sp0.reset(); + try + { + std::shared_ptr<A> sp(wp); + assert(false); + } + catch (std::bad_weak_ptr&) + { + } + } + assert(A::count == 0); +} diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/allocate_shared.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/allocate_shared.pass.cpp index 49ad98cd279..3286400ace9 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/allocate_shared.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/allocate_shared.pass.cpp @@ -1 +1,57 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// template<class T, class A, class... Args>
// shared_ptr<T> allocate_shared(const A& a, Args&&... args);
#include <memory>
#include <new>
#include <cstdlib>
#include <cassert>
#include "../test_allocator.h"
int new_count = 0;
struct A
{
static int count;
A(int i, char c) : int_(i), char_(c) {++count;}
A(const A& a)
: int_(a.int_), char_(a.char_)
{++count;}
~A() {--count;}
int get_int() const {return int_;}
char get_char() const {return char_;}
private:
int int_;
char char_;
};
int A::count = 0;
int main()
{
{
int i = 67;
char c = 'e';
std::shared_ptr<A> p = std::allocate_shared<A>(test_allocator<A>(54), i, c);
assert(test_allocator<A>::alloc_count == 1);
assert(A::count == 1);
assert(p->get_int() == 67);
assert(p->get_char() == 'e');
}
assert(A::count == 0);
assert(test_allocator<A>::alloc_count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// shared_ptr + +// template<class T, class A, class... Args> +// shared_ptr<T> allocate_shared(const A& a, Args&&... args); + +#include <memory> +#include <new> +#include <cstdlib> +#include <cassert> +#include "../test_allocator.h" + +int new_count = 0; + +struct A +{ + static int count; + + A(int i, char c) : int_(i), char_(c) {++count;} + A(const A& a) + : int_(a.int_), char_(a.char_) + {++count;} + ~A() {--count;} + + int get_int() const {return int_;} + char get_char() const {return char_;} +private: + int int_; + char char_; +}; + +int A::count = 0; + +int main() +{ + { + int i = 67; + char c = 'e'; + std::shared_ptr<A> p = std::allocate_shared<A>(test_allocator<A>(54), i, c); + assert(test_allocator<A>::alloc_count == 1); + assert(A::count == 1); + assert(p->get_int() == 67); + assert(p->get_char() == 'e'); + } + assert(A::count == 0); + assert(test_allocator<A>::alloc_count == 0); +} diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/make_shared.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/make_shared.pass.cpp index 2db9c66569e..51ae74f37d2 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/make_shared.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/make_shared.pass.cpp @@ -1 +1,66 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// template<class T, class... Args> shared_ptr<T> make_shared(Args&&... args);
#include <memory>
#include <new>
#include <cstdlib>
#include <cassert>
int new_count = 0;
void* operator new(std::size_t s) throw(std::bad_alloc)
{
++new_count;
return std::malloc(s);
}
void operator delete(void* p) throw()
{
std::free(p);
}
struct A
{
static int count;
A(int i, char c) : int_(i), char_(c) {++count;}
A(const A& a)
: int_(a.int_), char_(a.char_)
{++count;}
~A() {--count;}
int get_int() const {return int_;}
char get_char() const {return char_;}
private:
int int_;
char char_;
};
int A::count = 0;
int main()
{
int nc = new_count;
{
int i = 67;
char c = 'e';
std::shared_ptr<A> p = std::make_shared<A>(i, c);
assert(new_count == nc+1);
assert(A::count == 1);
assert(p->get_int() == 67);
assert(p->get_char() == 'e');
}
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// shared_ptr + +// template<class T, class... Args> shared_ptr<T> make_shared(Args&&... args); + +#include <memory> +#include <new> +#include <cstdlib> +#include <cassert> + +int new_count = 0; + +void* operator new(std::size_t s) throw(std::bad_alloc) +{ + ++new_count; + return std::malloc(s); +} + +void operator delete(void* p) throw() +{ + std::free(p); +} + +struct A +{ + static int count; + + A(int i, char c) : int_(i), char_(c) {++count;} + A(const A& a) + : int_(a.int_), char_(a.char_) + {++count;} + ~A() {--count;} + + int get_int() const {return int_;} + char get_char() const {return char_;} +private: + int int_; + char char_; +}; + +int A::count = 0; + +int main() +{ + int nc = new_count; + { + int i = 67; + char c = 'e'; + std::shared_ptr<A> p = std::make_shared<A>(i, c); + assert(new_count == nc+1); + assert(A::count == 1); + assert(p->get_int() == 67); + assert(p->get_char() == 'e'); + } + assert(A::count == 0); +} diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.dest/tested_elsewhere.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.dest/tested_elsewhere.pass.cpp index e8db90cbee0..b89f168e9c4 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.dest/tested_elsewhere.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.dest/tested_elsewhere.pass.cpp @@ -1 +1,12 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
int main()
{
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.mod/reset.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.mod/reset.pass.cpp index 27d9eb93450..745a8bf7d69 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.mod/reset.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.mod/reset.pass.cpp @@ -1 +1,62 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// void reset();
#include <memory>
#include <cassert>
struct B
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
struct A
: public B
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
std::shared_ptr<B> p(new B);
p.reset();
assert(A::count == 0);
assert(B::count == 0);
assert(p.use_count() == 0);
assert(p.get() == 0);
}
assert(A::count == 0);
{
std::shared_ptr<B> p;
p.reset();
assert(A::count == 0);
assert(B::count == 0);
assert(p.use_count() == 0);
assert(p.get() == 0);
}
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// shared_ptr + +// void reset(); + +#include <memory> +#include <cassert> + +struct B +{ + static int count; + + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +struct A + : public B +{ + static int count; + + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +int main() +{ + { + std::shared_ptr<B> p(new B); + p.reset(); + assert(A::count == 0); + assert(B::count == 0); + assert(p.use_count() == 0); + assert(p.get() == 0); + } + assert(A::count == 0); + { + std::shared_ptr<B> p; + p.reset(); + assert(A::count == 0); + assert(B::count == 0); + assert(p.use_count() == 0); + assert(p.get() == 0); + } + assert(A::count == 0); +} diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.mod/reset_pointer.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.mod/reset_pointer.pass.cpp index 13656f51849..8841a096571 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.mod/reset_pointer.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.mod/reset_pointer.pass.cpp @@ -1 +1,64 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// template<class Y> void reset(Y* p);
#include <memory>
#include <cassert>
struct B
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
struct A
: public B
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
std::shared_ptr<B> p(new B);
A* ptr = new A;
p.reset(ptr);
assert(A::count == 1);
assert(B::count == 1);
assert(p.use_count() == 1);
assert(p.get() == ptr);
}
assert(A::count == 0);
{
std::shared_ptr<B> p;
A* ptr = new A;
p.reset(ptr);
assert(A::count == 1);
assert(B::count == 1);
assert(p.use_count() == 1);
assert(p.get() == ptr);
}
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// shared_ptr + +// template<class Y> void reset(Y* p); + +#include <memory> +#include <cassert> + +struct B +{ + static int count; + + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +struct A + : public B +{ + static int count; + + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +int main() +{ + { + std::shared_ptr<B> p(new B); + A* ptr = new A; + p.reset(ptr); + assert(A::count == 1); + assert(B::count == 1); + assert(p.use_count() == 1); + assert(p.get() == ptr); + } + assert(A::count == 0); + { + std::shared_ptr<B> p; + A* ptr = new A; + p.reset(ptr); + assert(A::count == 1); + assert(B::count == 1); + assert(p.use_count() == 1); + assert(p.get() == ptr); + } + assert(A::count == 0); +} diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.mod/reset_pointer_deleter.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.mod/reset_pointer_deleter.pass.cpp index b4bdd8654e5..b8db36fef30 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.mod/reset_pointer_deleter.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.mod/reset_pointer_deleter.pass.cpp @@ -1 +1,79 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// template<class Y, class D> void reset(Y* p, D d);
#include <memory>
#include <cassert>
#include "../test_deleter.h"
struct B
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
struct A
: public B
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
std::shared_ptr<B> p(new B);
A* ptr = new A;
p.reset(ptr, test_deleter<A>(3));
assert(A::count == 1);
assert(B::count == 1);
assert(p.use_count() == 1);
assert(p.get() == ptr);
test_deleter<A>* d = std::get_deleter<test_deleter<A> >(p);
assert(test_deleter<A>::count == 1);
assert(test_deleter<A>::dealloc_count == 0);
assert(d);
assert(d->state() == 3);
}
assert(A::count == 0);
assert(test_deleter<A>::count == 0);
assert(test_deleter<A>::dealloc_count == 1);
{
std::shared_ptr<B> p;
A* ptr = new A;
p.reset(ptr, test_deleter<A>(3));
assert(A::count == 1);
assert(B::count == 1);
assert(p.use_count() == 1);
assert(p.get() == ptr);
test_deleter<A>* d = std::get_deleter<test_deleter<A> >(p);
assert(test_deleter<A>::count == 1);
assert(test_deleter<A>::dealloc_count == 1);
assert(d);
assert(d->state() == 3);
}
assert(A::count == 0);
assert(test_deleter<A>::count == 0);
assert(test_deleter<A>::dealloc_count == 2);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// shared_ptr + +// template<class Y, class D> void reset(Y* p, D d); + +#include <memory> +#include <cassert> +#include "../test_deleter.h" + +struct B +{ + static int count; + + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +struct A + : public B +{ + static int count; + + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +int main() +{ + { + std::shared_ptr<B> p(new B); + A* ptr = new A; + p.reset(ptr, test_deleter<A>(3)); + assert(A::count == 1); + assert(B::count == 1); + assert(p.use_count() == 1); + assert(p.get() == ptr); + test_deleter<A>* d = std::get_deleter<test_deleter<A> >(p); + assert(test_deleter<A>::count == 1); + assert(test_deleter<A>::dealloc_count == 0); + assert(d); + assert(d->state() == 3); + } + assert(A::count == 0); + assert(test_deleter<A>::count == 0); + assert(test_deleter<A>::dealloc_count == 1); + { + std::shared_ptr<B> p; + A* ptr = new A; + p.reset(ptr, test_deleter<A>(3)); + assert(A::count == 1); + assert(B::count == 1); + assert(p.use_count() == 1); + assert(p.get() == ptr); + test_deleter<A>* d = std::get_deleter<test_deleter<A> >(p); + assert(test_deleter<A>::count == 1); + assert(test_deleter<A>::dealloc_count == 1); + assert(d); + assert(d->state() == 3); + } + assert(A::count == 0); + assert(test_deleter<A>::count == 0); + assert(test_deleter<A>::dealloc_count == 2); +} diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.mod/reset_pointer_deleter_allocator.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.mod/reset_pointer_deleter_allocator.pass.cpp index a318f68caf4..bf6279a24a4 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.mod/reset_pointer_deleter_allocator.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.mod/reset_pointer_deleter_allocator.pass.cpp @@ -1 +1,88 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// template<class Y, class D, class A> void reset(Y* p, D d, A a);
#include <memory>
#include <cassert>
#include "../test_deleter.h"
#include "../test_allocator.h"
struct B
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
struct A
: public B
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
std::shared_ptr<B> p(new B);
A* ptr = new A;
p.reset(ptr, test_deleter<A>(3), test_allocator<A>(4));
assert(A::count == 1);
assert(B::count == 1);
assert(p.use_count() == 1);
assert(p.get() == ptr);
test_deleter<A>* d = std::get_deleter<test_deleter<A> >(p);
assert(test_deleter<A>::count == 1);
assert(test_deleter<A>::dealloc_count == 0);
assert(d);
assert(d->state() == 3);
assert(test_allocator<A>::count == 1);
assert(test_allocator<A>::alloc_count == 1);
}
assert(A::count == 0);
assert(test_deleter<A>::count == 0);
assert(test_deleter<A>::dealloc_count == 1);
assert(test_allocator<A>::count == 0);
assert(test_allocator<A>::alloc_count == 0);
{
std::shared_ptr<B> p;
A* ptr = new A;
p.reset(ptr, test_deleter<A>(3), test_allocator<A>(4));
assert(A::count == 1);
assert(B::count == 1);
assert(p.use_count() == 1);
assert(p.get() == ptr);
test_deleter<A>* d = std::get_deleter<test_deleter<A> >(p);
assert(test_deleter<A>::count == 1);
assert(test_deleter<A>::dealloc_count == 1);
assert(d);
assert(d->state() == 3);
assert(test_allocator<A>::count == 1);
assert(test_allocator<A>::alloc_count == 1);
}
assert(A::count == 0);
assert(test_deleter<A>::count == 0);
assert(test_deleter<A>::dealloc_count == 2);
assert(test_allocator<A>::count == 0);
assert(test_allocator<A>::alloc_count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// shared_ptr + +// template<class Y, class D, class A> void reset(Y* p, D d, A a); + +#include <memory> +#include <cassert> +#include "../test_deleter.h" +#include "../test_allocator.h" + +struct B +{ + static int count; + + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +struct A + : public B +{ + static int count; + + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +int main() +{ + { + std::shared_ptr<B> p(new B); + A* ptr = new A; + p.reset(ptr, test_deleter<A>(3), test_allocator<A>(4)); + assert(A::count == 1); + assert(B::count == 1); + assert(p.use_count() == 1); + assert(p.get() == ptr); + test_deleter<A>* d = std::get_deleter<test_deleter<A> >(p); + assert(test_deleter<A>::count == 1); + assert(test_deleter<A>::dealloc_count == 0); + assert(d); + assert(d->state() == 3); + assert(test_allocator<A>::count == 1); + assert(test_allocator<A>::alloc_count == 1); + } + assert(A::count == 0); + assert(test_deleter<A>::count == 0); + assert(test_deleter<A>::dealloc_count == 1); + assert(test_allocator<A>::count == 0); + assert(test_allocator<A>::alloc_count == 0); + { + std::shared_ptr<B> p; + A* ptr = new A; + p.reset(ptr, test_deleter<A>(3), test_allocator<A>(4)); + assert(A::count == 1); + assert(B::count == 1); + assert(p.use_count() == 1); + assert(p.get() == ptr); + test_deleter<A>* d = std::get_deleter<test_deleter<A> >(p); + assert(test_deleter<A>::count == 1); + assert(test_deleter<A>::dealloc_count == 1); + assert(d); + assert(d->state() == 3); + assert(test_allocator<A>::count == 1); + assert(test_allocator<A>::alloc_count == 1); + } + assert(A::count == 0); + assert(test_deleter<A>::count == 0); + assert(test_deleter<A>::dealloc_count == 2); + assert(test_allocator<A>::count == 0); + assert(test_allocator<A>::alloc_count == 0); +} diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.mod/swap.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.mod/swap.pass.cpp index 6f75444e632..8b0ebf7473f 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.mod/swap.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.mod/swap.pass.cpp @@ -1 +1,104 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// void swap(shared_ptr& r);
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
A* ptr1 = new A;
A* ptr2 = new A;
std::shared_ptr<A> p1(ptr1);
{
std::shared_ptr<A> p2(ptr2);
p1.swap(p2);
assert(p1.use_count() == 1);
assert(p1.get() == ptr2);
assert(p2.use_count() == 1);
assert(p2.get() == ptr1);
assert(A::count == 2);
}
assert(p1.use_count() == 1);
assert(p1.get() == ptr2);
assert(A::count == 1);
}
assert(A::count == 0);
{
A* ptr1 = new A;
A* ptr2 = 0;
std::shared_ptr<A> p1(ptr1);
{
std::shared_ptr<A> p2;
p1.swap(p2);
assert(p1.use_count() == 0);
assert(p1.get() == ptr2);
assert(p2.use_count() == 1);
assert(p2.get() == ptr1);
assert(A::count == 1);
}
assert(p1.use_count() == 0);
assert(p1.get() == ptr2);
assert(A::count == 0);
}
assert(A::count == 0);
{
A* ptr1 = 0;
A* ptr2 = new A;
std::shared_ptr<A> p1;
{
std::shared_ptr<A> p2(ptr2);
p1.swap(p2);
assert(p1.use_count() == 1);
assert(p1.get() == ptr2);
assert(p2.use_count() == 0);
assert(p2.get() == ptr1);
assert(A::count == 1);
}
assert(p1.use_count() == 1);
assert(p1.get() == ptr2);
assert(A::count == 1);
}
assert(A::count == 0);
{
A* ptr1 = 0;
A* ptr2 = 0;
std::shared_ptr<A> p1;
{
std::shared_ptr<A> p2;
p1.swap(p2);
assert(p1.use_count() == 0);
assert(p1.get() == ptr2);
assert(p2.use_count() == 0);
assert(p2.get() == ptr1);
assert(A::count == 0);
}
assert(p1.use_count() == 0);
assert(p1.get() == ptr2);
assert(A::count == 0);
}
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// shared_ptr + +// void swap(shared_ptr& r); + +#include <memory> +#include <cassert> + +struct A +{ + static int count; + + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +int main() +{ + { + A* ptr1 = new A; + A* ptr2 = new A; + std::shared_ptr<A> p1(ptr1); + { + std::shared_ptr<A> p2(ptr2); + p1.swap(p2); + assert(p1.use_count() == 1); + assert(p1.get() == ptr2); + assert(p2.use_count() == 1); + assert(p2.get() == ptr1); + assert(A::count == 2); + } + assert(p1.use_count() == 1); + assert(p1.get() == ptr2); + assert(A::count == 1); + } + assert(A::count == 0); + { + A* ptr1 = new A; + A* ptr2 = 0; + std::shared_ptr<A> p1(ptr1); + { + std::shared_ptr<A> p2; + p1.swap(p2); + assert(p1.use_count() == 0); + assert(p1.get() == ptr2); + assert(p2.use_count() == 1); + assert(p2.get() == ptr1); + assert(A::count == 1); + } + assert(p1.use_count() == 0); + assert(p1.get() == ptr2); + assert(A::count == 0); + } + assert(A::count == 0); + { + A* ptr1 = 0; + A* ptr2 = new A; + std::shared_ptr<A> p1; + { + std::shared_ptr<A> p2(ptr2); + p1.swap(p2); + assert(p1.use_count() == 1); + assert(p1.get() == ptr2); + assert(p2.use_count() == 0); + assert(p2.get() == ptr1); + assert(A::count == 1); + } + assert(p1.use_count() == 1); + assert(p1.get() == ptr2); + assert(A::count == 1); + } + assert(A::count == 0); + { + A* ptr1 = 0; + A* ptr2 = 0; + std::shared_ptr<A> p1; + { + std::shared_ptr<A> p2; + p1.swap(p2); + assert(p1.use_count() == 0); + assert(p1.get() == ptr2); + assert(p2.use_count() == 0); + assert(p2.get() == ptr1); + assert(A::count == 0); + } + assert(p1.use_count() == 0); + assert(p1.get() == ptr2); + assert(A::count == 0); + } + assert(A::count == 0); +} diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.obs/arrow.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.obs/arrow.pass.cpp index 14646f0392a..30ce67f9038 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.obs/arrow.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.obs/arrow.pass.cpp @@ -1 +1,29 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// T* operator->() const;
#include <memory>
#include <utility>
#include <cassert>
int main()
{
const std::shared_ptr<std::pair<int, int> > p(new std::pair<int, int>(3, 4));
assert(p->first == 3);
assert(p->second == 4);
p->first = 5;
p->second = 6;
assert(p->first == 5);
assert(p->second == 6);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// shared_ptr + +// T* operator->() const; + +#include <memory> +#include <utility> +#include <cassert> + +int main() +{ + const std::shared_ptr<std::pair<int, int> > p(new std::pair<int, int>(3, 4)); + assert(p->first == 3); + assert(p->second == 4); + p->first = 5; + p->second = 6; + assert(p->first == 5); + assert(p->second == 6); +} diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.obs/dereference.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.obs/dereference.pass.cpp index b02af0f1cfb..786f02ddf54 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.obs/dereference.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.obs/dereference.pass.cpp @@ -1 +1,25 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// T& operator*() const;
#include <memory>
#include <cassert>
int main()
{
const std::shared_ptr<int> p(new int(32));
assert(*p == 32);
*p = 3;
assert(*p == 3);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// shared_ptr + +// T& operator*() const; + +#include <memory> +#include <cassert> + +int main() +{ + const std::shared_ptr<int> p(new int(32)); + assert(*p == 32); + *p = 3; + assert(*p == 3); +} diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.obs/op_bool.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.obs/op_bool.pass.cpp index f0661fb318c..10b4d142525 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.obs/op_bool.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.obs/op_bool.pass.cpp @@ -1 +1,29 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// explicit operator bool() const;
#include <memory>
#include <cassert>
int main()
{
{
const std::shared_ptr<int> p(new int(32));
assert(p);
}
{
const std::shared_ptr<int> p;
assert(!p);
}
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// shared_ptr + +// explicit operator bool() const; + +#include <memory> +#include <cassert> + +int main() +{ + { + const std::shared_ptr<int> p(new int(32)); + assert(p); + } + { + const std::shared_ptr<int> p; + assert(!p); + } +} diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.obs/owner_before_shared_ptr.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.obs/owner_before_shared_ptr.pass.cpp index b5aeff5e818..0854cda6b6c 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.obs/owner_before_shared_ptr.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.obs/owner_before_shared_ptr.pass.cpp @@ -1 +1,28 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// template <class U> bool owner_before(shared_ptr<U> const& b) const;
#include <memory>
#include <cassert>
int main()
{
const std::shared_ptr<int> p1(new int);
const std::shared_ptr<int> p2 = p1;
const std::shared_ptr<int> p3(new int);
assert(!p1.owner_before(p2));
assert(!p2.owner_before(p1));
assert(p1.owner_before(p3) || p3.owner_before(p1));
assert(p3.owner_before(p1) == p3.owner_before(p2));
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// shared_ptr + +// template <class U> bool owner_before(shared_ptr<U> const& b) const; + +#include <memory> +#include <cassert> + +int main() +{ + const std::shared_ptr<int> p1(new int); + const std::shared_ptr<int> p2 = p1; + const std::shared_ptr<int> p3(new int); + assert(!p1.owner_before(p2)); + assert(!p2.owner_before(p1)); + assert(p1.owner_before(p3) || p3.owner_before(p1)); + assert(p3.owner_before(p1) == p3.owner_before(p2)); +} diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.obs/owner_before_weak_ptr.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.obs/owner_before_weak_ptr.pass.cpp index 8e8059b2056..d112e64d2cf 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.obs/owner_before_weak_ptr.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.obs/owner_before_weak_ptr.pass.cpp @@ -1 +1,31 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// template <class U> bool owner_before(weak_ptr<U> const& b) const;
#include <memory>
#include <cassert>
int main()
{
const std::shared_ptr<int> p1(new int);
const std::shared_ptr<int> p2 = p1;
const std::shared_ptr<int> p3(new int);
const std::weak_ptr<int> w1(p1);
const std::weak_ptr<int> w2(p2);
const std::weak_ptr<int> w3(p3);
assert(!p1.owner_before(w2));
assert(!p2.owner_before(w1));
assert(p1.owner_before(w3) || p3.owner_before(w1));
assert(p3.owner_before(w1) == p3.owner_before(w2));
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// shared_ptr + +// template <class U> bool owner_before(weak_ptr<U> const& b) const; + +#include <memory> +#include <cassert> + +int main() +{ + const std::shared_ptr<int> p1(new int); + const std::shared_ptr<int> p2 = p1; + const std::shared_ptr<int> p3(new int); + const std::weak_ptr<int> w1(p1); + const std::weak_ptr<int> w2(p2); + const std::weak_ptr<int> w3(p3); + assert(!p1.owner_before(w2)); + assert(!p2.owner_before(w1)); + assert(p1.owner_before(w3) || p3.owner_before(w1)); + assert(p3.owner_before(w1) == p3.owner_before(w2)); +} diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.obs/unique.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.obs/unique.pass.cpp index 429e7e9d58a..3d779ec2b39 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.obs/unique.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.obs/unique.pass.cpp @@ -1 +1,28 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// bool unique() const;
#include <memory>
#include <cassert>
int main()
{
const std::shared_ptr<int> p(new int(32));
assert(p.unique());
{
std::shared_ptr<int> p2 = p;
assert(!p.unique());
}
assert(p.unique());
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// shared_ptr + +// bool unique() const; + +#include <memory> +#include <cassert> + +int main() +{ + const std::shared_ptr<int> p(new int(32)); + assert(p.unique()); + { + std::shared_ptr<int> p2 = p; + assert(!p.unique()); + } + assert(p.unique()); +} diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.spec/swap.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.spec/swap.pass.cpp index 850125f8cf2..d21a50bb860 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.spec/swap.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.spec/swap.pass.cpp @@ -1 +1,104 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// template<class T> void swap(shared_ptr<T>& a, shared_ptr<T>& b);
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
A* ptr1 = new A;
A* ptr2 = new A;
std::shared_ptr<A> p1(ptr1);
{
std::shared_ptr<A> p2(ptr2);
swap(p1, p2);
assert(p1.use_count() == 1);
assert(p1.get() == ptr2);
assert(p2.use_count() == 1);
assert(p2.get() == ptr1);
assert(A::count == 2);
}
assert(p1.use_count() == 1);
assert(p1.get() == ptr2);
assert(A::count == 1);
}
assert(A::count == 0);
{
A* ptr1 = new A;
A* ptr2 = 0;
std::shared_ptr<A> p1(ptr1);
{
std::shared_ptr<A> p2;
swap(p1, p2);
assert(p1.use_count() == 0);
assert(p1.get() == ptr2);
assert(p2.use_count() == 1);
assert(p2.get() == ptr1);
assert(A::count == 1);
}
assert(p1.use_count() == 0);
assert(p1.get() == ptr2);
assert(A::count == 0);
}
assert(A::count == 0);
{
A* ptr1 = 0;
A* ptr2 = new A;
std::shared_ptr<A> p1;
{
std::shared_ptr<A> p2(ptr2);
swap(p1, p2);
assert(p1.use_count() == 1);
assert(p1.get() == ptr2);
assert(p2.use_count() == 0);
assert(p2.get() == ptr1);
assert(A::count == 1);
}
assert(p1.use_count() == 1);
assert(p1.get() == ptr2);
assert(A::count == 1);
}
assert(A::count == 0);
{
A* ptr1 = 0;
A* ptr2 = 0;
std::shared_ptr<A> p1;
{
std::shared_ptr<A> p2;
swap(p1, p2);
assert(p1.use_count() == 0);
assert(p1.get() == ptr2);
assert(p2.use_count() == 0);
assert(p2.get() == ptr1);
assert(A::count == 0);
}
assert(p1.use_count() == 0);
assert(p1.get() == ptr2);
assert(A::count == 0);
}
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// shared_ptr + +// template<class T> void swap(shared_ptr<T>& a, shared_ptr<T>& b); + +#include <memory> +#include <cassert> + +struct A +{ + static int count; + + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +int main() +{ + { + A* ptr1 = new A; + A* ptr2 = new A; + std::shared_ptr<A> p1(ptr1); + { + std::shared_ptr<A> p2(ptr2); + swap(p1, p2); + assert(p1.use_count() == 1); + assert(p1.get() == ptr2); + assert(p2.use_count() == 1); + assert(p2.get() == ptr1); + assert(A::count == 2); + } + assert(p1.use_count() == 1); + assert(p1.get() == ptr2); + assert(A::count == 1); + } + assert(A::count == 0); + { + A* ptr1 = new A; + A* ptr2 = 0; + std::shared_ptr<A> p1(ptr1); + { + std::shared_ptr<A> p2; + swap(p1, p2); + assert(p1.use_count() == 0); + assert(p1.get() == ptr2); + assert(p2.use_count() == 1); + assert(p2.get() == ptr1); + assert(A::count == 1); + } + assert(p1.use_count() == 0); + assert(p1.get() == ptr2); + assert(A::count == 0); + } + assert(A::count == 0); + { + A* ptr1 = 0; + A* ptr2 = new A; + std::shared_ptr<A> p1; + { + std::shared_ptr<A> p2(ptr2); + swap(p1, p2); + assert(p1.use_count() == 1); + assert(p1.get() == ptr2); + assert(p2.use_count() == 0); + assert(p2.get() == ptr1); + assert(A::count == 1); + } + assert(p1.use_count() == 1); + assert(p1.get() == ptr2); + assert(A::count == 1); + } + assert(A::count == 0); + { + A* ptr1 = 0; + A* ptr2 = 0; + std::shared_ptr<A> p1; + { + std::shared_ptr<A> p2; + swap(p1, p2); + assert(p1.use_count() == 0); + assert(p1.get() == ptr2); + assert(p2.use_count() == 0); + assert(p2.get() == ptr1); + assert(A::count == 0); + } + assert(p1.use_count() == 0); + assert(p1.get() == ptr2); + assert(A::count == 0); + } + assert(A::count == 0); +} diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/types.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/types.pass.cpp index 359bfa7c48a..cfb2708fa8a 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/types.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/types.pass.cpp @@ -1 +1,26 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template<class T> class weak_ptr
// {
// public:
// typedef T element_type;
// ...
// };
#include <memory>
struct A; // purposefully incomplete
int main()
{
static_assert((std::is_same<std::weak_ptr<A>::element_type, A>::value), "");
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// template<class T> class weak_ptr +// { +// public: +// typedef T element_type; +// ... +// }; + +#include <memory> + +struct A; // purposefully incomplete + +int main() +{ + static_assert((std::is_same<std::weak_ptr<A>::element_type, A>::value), ""); +} diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.ownerless/owner_less.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.ownerless/owner_less.pass.cpp index eb16e033d04..fbaf44fcae3 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.ownerless/owner_less.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.ownerless/owner_less.pass.cpp @@ -1 +1,74 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <class T> struct owner_less;
//
// template <class T>
// struct owner_less<shared_ptr<T> >
// : binary_function<shared_ptr<T>, shared_ptr<T>, bool>
// {
// typedef bool result_type;
// bool operator()(shared_ptr<T> const&, shared_ptr<T> const&) const;
// bool operator()(shared_ptr<T> const&, weak_ptr<T> const&) const;
// bool operator()(weak_ptr<T> const&, shared_ptr<T> const&) const;
// };
//
// template <class T>
// struct owner_less<weak_ptr<T> >
// : binary_function<weak_ptr<T>, weak_ptr<T>, bool>
// {
// typedef bool result_type;
// bool operator()(weak_ptr<T> const&, weak_ptr<T> const&) const;
// bool operator()(shared_ptr<T> const&, weak_ptr<T> const&) const;
// bool operator()(weak_ptr<T> const&, shared_ptr<T> const&) const;
// };
#include <memory>
#include <cassert>
int main()
{
const std::shared_ptr<int> p1(new int);
const std::shared_ptr<int> p2 = p1;
const std::shared_ptr<int> p3(new int);
const std::weak_ptr<int> w1(p1);
const std::weak_ptr<int> w2(p2);
const std::weak_ptr<int> w3(p3);
{
typedef std::owner_less<std::shared_ptr<int> > CS;
CS cs;
assert(!cs(p1, p2));
assert(!cs(p2, p1));
assert(cs(p1 ,p3) || cs(p3, p1));
assert(cs(p3, p1) == cs(p3, p2));
assert(!cs(p1, w2));
assert(!cs(p2, w1));
assert(cs(p1, w3) || cs(p3, w1));
assert(cs(p3, w1) == cs(p3, w2));
}
{
typedef std::owner_less<std::weak_ptr<int> > CS;
CS cs;
assert(!cs(w1, w2));
assert(!cs(w2, w1));
assert(cs(w1, w3) || cs(w3, w1));
assert(cs(w3, w1) == cs(w3, w2));
assert(!cs(w1, p2));
assert(!cs(w2, p1));
assert(cs(w1, p3) || cs(w3, p1));
assert(cs(w3, p1) == cs(w3, p2));
}
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// template <class T> struct owner_less; +// +// template <class T> +// struct owner_less<shared_ptr<T> > +// : binary_function<shared_ptr<T>, shared_ptr<T>, bool> +// { +// typedef bool result_type; +// bool operator()(shared_ptr<T> const&, shared_ptr<T> const&) const; +// bool operator()(shared_ptr<T> const&, weak_ptr<T> const&) const; +// bool operator()(weak_ptr<T> const&, shared_ptr<T> const&) const; +// }; +// +// template <class T> +// struct owner_less<weak_ptr<T> > +// : binary_function<weak_ptr<T>, weak_ptr<T>, bool> +// { +// typedef bool result_type; +// bool operator()(weak_ptr<T> const&, weak_ptr<T> const&) const; +// bool operator()(shared_ptr<T> const&, weak_ptr<T> const&) const; +// bool operator()(weak_ptr<T> const&, shared_ptr<T> const&) const; +// }; + +#include <memory> +#include <cassert> + +int main() +{ + const std::shared_ptr<int> p1(new int); + const std::shared_ptr<int> p2 = p1; + const std::shared_ptr<int> p3(new int); + const std::weak_ptr<int> w1(p1); + const std::weak_ptr<int> w2(p2); + const std::weak_ptr<int> w3(p3); + + { + typedef std::owner_less<std::shared_ptr<int> > CS; + CS cs; + + assert(!cs(p1, p2)); + assert(!cs(p2, p1)); + assert(cs(p1 ,p3) || cs(p3, p1)); + assert(cs(p3, p1) == cs(p3, p2)); + + assert(!cs(p1, w2)); + assert(!cs(p2, w1)); + assert(cs(p1, w3) || cs(p3, w1)); + assert(cs(p3, w1) == cs(p3, w2)); + } + { + typedef std::owner_less<std::weak_ptr<int> > CS; + CS cs; + + assert(!cs(w1, w2)); + assert(!cs(w2, w1)); + assert(cs(w1, w3) || cs(w3, w1)); + assert(cs(w3, w1) == cs(w3, w2)); + + assert(!cs(w1, p2)); + assert(!cs(w2, p1)); + assert(cs(w1, p3) || cs(w3, p1)); + assert(cs(w3, p1) == cs(w3, p2)); + } +} diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.assign/shared_ptr_Y.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.assign/shared_ptr_Y.pass.cpp index 87569aadb20..12091630dff 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.assign/shared_ptr_Y.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.assign/shared_ptr_Y.pass.cpp @@ -1 +1,61 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// weak_ptr
// template<class Y> weak_ptr& operator=(const shared_ptr<Y>& r);
#include <memory>
#include <type_traits>
#include <cassert>
struct B
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
struct A
: public B
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
const std::shared_ptr<A> pA(new A);
{
std::weak_ptr<B> pB;
pB = pA;
assert(B::count == 1);
assert(A::count == 1);
assert(pB.use_count() == 1);
assert(pA.use_count() == 1);
}
assert(pA.use_count() == 1);
assert(B::count == 1);
assert(A::count == 1);
}
assert(B::count == 0);
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// weak_ptr + +// template<class Y> weak_ptr& operator=(const shared_ptr<Y>& r); + +#include <memory> +#include <type_traits> +#include <cassert> + +struct B +{ + static int count; + + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +struct A + : public B +{ + static int count; + + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +int main() +{ + { + const std::shared_ptr<A> pA(new A); + { + std::weak_ptr<B> pB; + pB = pA; + assert(B::count == 1); + assert(A::count == 1); + assert(pB.use_count() == 1); + assert(pA.use_count() == 1); + } + assert(pA.use_count() == 1); + assert(B::count == 1); + assert(A::count == 1); + } + assert(B::count == 0); + assert(A::count == 0); +} diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.assign/weak_ptr.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.assign/weak_ptr.pass.cpp index 853d43265ea..a472c1c873a 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.assign/weak_ptr.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.assign/weak_ptr.pass.cpp @@ -1 +1,62 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// weak_ptr
// weak_ptr& operator=(const weak_ptr& r);
#include <memory>
#include <type_traits>
#include <cassert>
struct B
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
struct A
: public B
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
const std::shared_ptr<A> ps(new A);
const std::weak_ptr<A> pA(ps);
{
std::weak_ptr<A> pB;
pB = pA;
assert(B::count == 1);
assert(A::count == 1);
assert(pB.use_count() == 1);
assert(pA.use_count() == 1);
}
assert(pA.use_count() == 1);
assert(B::count == 1);
assert(A::count == 1);
}
assert(B::count == 0);
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// weak_ptr + +// weak_ptr& operator=(const weak_ptr& r); + +#include <memory> +#include <type_traits> +#include <cassert> + +struct B +{ + static int count; + + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +struct A + : public B +{ + static int count; + + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +int main() +{ + { + const std::shared_ptr<A> ps(new A); + const std::weak_ptr<A> pA(ps); + { + std::weak_ptr<A> pB; + pB = pA; + assert(B::count == 1); + assert(A::count == 1); + assert(pB.use_count() == 1); + assert(pA.use_count() == 1); + } + assert(pA.use_count() == 1); + assert(B::count == 1); + assert(A::count == 1); + } + assert(B::count == 0); + assert(A::count == 0); +} diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.assign/weak_ptr_Y.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.assign/weak_ptr_Y.pass.cpp index 85461b90f7e..422de83d594 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.assign/weak_ptr_Y.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.assign/weak_ptr_Y.pass.cpp @@ -1 +1,62 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// weak_ptr
// template<class Y> weak_ptr& operator=(const weak_ptr<Y>& r);
#include <memory>
#include <type_traits>
#include <cassert>
struct B
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
struct A
: public B
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
const std::shared_ptr<A> ps(new A);
const std::weak_ptr<A> pA(ps);
{
std::weak_ptr<B> pB;
pB = pA;
assert(B::count == 1);
assert(A::count == 1);
assert(pB.use_count() == 1);
assert(pA.use_count() == 1);
}
assert(pA.use_count() == 1);
assert(B::count == 1);
assert(A::count == 1);
}
assert(B::count == 0);
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// weak_ptr + +// template<class Y> weak_ptr& operator=(const weak_ptr<Y>& r); + +#include <memory> +#include <type_traits> +#include <cassert> + +struct B +{ + static int count; + + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +struct A + : public B +{ + static int count; + + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +int main() +{ + { + const std::shared_ptr<A> ps(new A); + const std::weak_ptr<A> pA(ps); + { + std::weak_ptr<B> pB; + pB = pA; + assert(B::count == 1); + assert(A::count == 1); + assert(pB.use_count() == 1); + assert(pA.use_count() == 1); + } + assert(pA.use_count() == 1); + assert(B::count == 1); + assert(A::count == 1); + } + assert(B::count == 0); + assert(A::count == 0); +} diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.const/default.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.const/default.pass.cpp index ef62c139a7e..01047a22978 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.const/default.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.const/default.pass.cpp @@ -1 +1,25 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template<class T> class weak_ptr
// weak_ptr();
#include <memory>
#include <cassert>
struct A;
int main()
{
std::weak_ptr<A> p;
assert(p.use_count() == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// template<class T> class weak_ptr + +// weak_ptr(); + +#include <memory> +#include <cassert> + +struct A; + +int main() +{ + std::weak_ptr<A> p; + assert(p.use_count() == 0); +} diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.const/shared_ptr_Y.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.const/shared_ptr_Y.pass.cpp index 1efdb03774b..3f7e890b897 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.const/shared_ptr_Y.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.const/shared_ptr_Y.pass.cpp @@ -1 +1,95 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// weak_ptr
// template<class Y> weak_ptr(const shared_ptr<Y>& r);
#include <memory>
#include <type_traits>
#include <cassert>
struct B
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
struct A
: public B
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
struct C
{
static int count;
C() {++count;}
C(const C&) {++count;}
virtual ~C() {--count;}
};
int C::count = 0;
int main()
{
static_assert(( std::is_convertible<std::shared_ptr<A>, std::weak_ptr<B> >::value), "");
static_assert((!std::is_convertible<std::weak_ptr<B>, std::shared_ptr<A> >::value), "");
static_assert((!std::is_convertible<std::shared_ptr<A>, std::weak_ptr<C> >::value), "");
{
const std::shared_ptr<A> pA(new A);
assert(pA.use_count() == 1);
assert(B::count == 1);
assert(A::count == 1);
{
std::weak_ptr<B> pB(pA);
assert(B::count == 1);
assert(A::count == 1);
assert(pB.use_count() == 1);
assert(pA.use_count() == 1);
}
assert(pA.use_count() == 1);
assert(B::count == 1);
assert(A::count == 1);
}
assert(B::count == 0);
assert(A::count == 0);
{
std::shared_ptr<A> pA;
assert(pA.use_count() == 0);
assert(B::count == 0);
assert(A::count == 0);
{
std::weak_ptr<B> pB(pA);
assert(B::count == 0);
assert(A::count == 0);
assert(pB.use_count() == 0);
assert(pA.use_count() == 0);
}
assert(pA.use_count() == 0);
assert(B::count == 0);
assert(A::count == 0);
}
assert(B::count == 0);
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// weak_ptr + +// template<class Y> weak_ptr(const shared_ptr<Y>& r); + +#include <memory> +#include <type_traits> +#include <cassert> + +struct B +{ + static int count; + + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +struct A + : public B +{ + static int count; + + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +struct C +{ + static int count; + + C() {++count;} + C(const C&) {++count;} + virtual ~C() {--count;} +}; + +int C::count = 0; + +int main() +{ + static_assert(( std::is_convertible<std::shared_ptr<A>, std::weak_ptr<B> >::value), ""); + static_assert((!std::is_convertible<std::weak_ptr<B>, std::shared_ptr<A> >::value), ""); + static_assert((!std::is_convertible<std::shared_ptr<A>, std::weak_ptr<C> >::value), ""); + { + const std::shared_ptr<A> pA(new A); + assert(pA.use_count() == 1); + assert(B::count == 1); + assert(A::count == 1); + { + std::weak_ptr<B> pB(pA); + assert(B::count == 1); + assert(A::count == 1); + assert(pB.use_count() == 1); + assert(pA.use_count() == 1); + } + assert(pA.use_count() == 1); + assert(B::count == 1); + assert(A::count == 1); + } + assert(B::count == 0); + assert(A::count == 0); + { + std::shared_ptr<A> pA; + assert(pA.use_count() == 0); + assert(B::count == 0); + assert(A::count == 0); + { + std::weak_ptr<B> pB(pA); + assert(B::count == 0); + assert(A::count == 0); + assert(pB.use_count() == 0); + assert(pA.use_count() == 0); + } + assert(pA.use_count() == 0); + assert(B::count == 0); + assert(A::count == 0); + } + assert(B::count == 0); + assert(A::count == 0); +} diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.const/weak_ptr.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.const/weak_ptr.pass.cpp index fabf4324536..80e50ea9e5e 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.const/weak_ptr.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.const/weak_ptr.pass.cpp @@ -1 +1,93 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// weak_ptr
// weak_ptr(const weak_ptr& r);
#include <memory>
#include <type_traits>
#include <cassert>
struct B
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
struct A
: public B
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
struct C
{
static int count;
C() {++count;}
C(const C&) {++count;}
virtual ~C() {--count;}
};
int C::count = 0;
int main()
{
{
const std::shared_ptr<A> ps(new A);
const std::weak_ptr<A> pA(ps);
assert(pA.use_count() == 1);
assert(B::count == 1);
assert(A::count == 1);
{
std::weak_ptr<A> pB(pA);
assert(B::count == 1);
assert(A::count == 1);
assert(pB.use_count() == 1);
assert(pA.use_count() == 1);
}
assert(pA.use_count() == 1);
assert(B::count == 1);
assert(A::count == 1);
}
assert(B::count == 0);
assert(A::count == 0);
{
std::weak_ptr<A> pA;
assert(pA.use_count() == 0);
assert(B::count == 0);
assert(A::count == 0);
{
std::weak_ptr<A> pB(pA);
assert(B::count == 0);
assert(A::count == 0);
assert(pB.use_count() == 0);
assert(pA.use_count() == 0);
}
assert(pA.use_count() == 0);
assert(B::count == 0);
assert(A::count == 0);
}
assert(B::count == 0);
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// weak_ptr + +// weak_ptr(const weak_ptr& r); + +#include <memory> +#include <type_traits> +#include <cassert> + +struct B +{ + static int count; + + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +struct A + : public B +{ + static int count; + + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +struct C +{ + static int count; + + C() {++count;} + C(const C&) {++count;} + virtual ~C() {--count;} +}; + +int C::count = 0; + +int main() +{ + { + const std::shared_ptr<A> ps(new A); + const std::weak_ptr<A> pA(ps); + assert(pA.use_count() == 1); + assert(B::count == 1); + assert(A::count == 1); + { + std::weak_ptr<A> pB(pA); + assert(B::count == 1); + assert(A::count == 1); + assert(pB.use_count() == 1); + assert(pA.use_count() == 1); + } + assert(pA.use_count() == 1); + assert(B::count == 1); + assert(A::count == 1); + } + assert(B::count == 0); + assert(A::count == 0); + { + std::weak_ptr<A> pA; + assert(pA.use_count() == 0); + assert(B::count == 0); + assert(A::count == 0); + { + std::weak_ptr<A> pB(pA); + assert(B::count == 0); + assert(A::count == 0); + assert(pB.use_count() == 0); + assert(pA.use_count() == 0); + } + assert(pA.use_count() == 0); + assert(B::count == 0); + assert(A::count == 0); + } + assert(B::count == 0); + assert(A::count == 0); +} diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.const/weak_ptr_Y.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.const/weak_ptr_Y.pass.cpp index 8b2db201d6d..c82d4027c13 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.const/weak_ptr_Y.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.const/weak_ptr_Y.pass.cpp @@ -1 +1,95 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// weak_ptr
// template<class Y> weak_ptr(const weak_ptr<Y>& r);
#include <memory>
#include <type_traits>
#include <cassert>
struct B
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
struct A
: public B
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
struct C
{
static int count;
C() {++count;}
C(const C&) {++count;}
virtual ~C() {--count;}
};
int C::count = 0;
int main()
{
static_assert(( std::is_convertible<std::weak_ptr<A>, std::weak_ptr<B> >::value), "");
static_assert((!std::is_convertible<std::weak_ptr<B>, std::weak_ptr<A> >::value), "");
static_assert((!std::is_convertible<std::weak_ptr<A>, std::weak_ptr<C> >::value), "");
{
const std::weak_ptr<A> pA(std::shared_ptr<A>(new A));
assert(pA.use_count() == 0);
assert(B::count == 0);
assert(A::count == 0);
{
std::weak_ptr<B> pB(pA);
assert(B::count == 0);
assert(A::count == 0);
assert(pB.use_count() == 0);
assert(pA.use_count() == 0);
}
assert(pA.use_count() == 0);
assert(B::count == 0);
assert(A::count == 0);
}
assert(B::count == 0);
assert(A::count == 0);
{
std::weak_ptr<A> pA;
assert(pA.use_count() == 0);
assert(B::count == 0);
assert(A::count == 0);
{
std::weak_ptr<B> pB(pA);
assert(B::count == 0);
assert(A::count == 0);
assert(pB.use_count() == 0);
assert(pA.use_count() == 0);
}
assert(pA.use_count() == 0);
assert(B::count == 0);
assert(A::count == 0);
}
assert(B::count == 0);
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// weak_ptr + +// template<class Y> weak_ptr(const weak_ptr<Y>& r); + +#include <memory> +#include <type_traits> +#include <cassert> + +struct B +{ + static int count; + + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +struct A + : public B +{ + static int count; + + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +struct C +{ + static int count; + + C() {++count;} + C(const C&) {++count;} + virtual ~C() {--count;} +}; + +int C::count = 0; + +int main() +{ + static_assert(( std::is_convertible<std::weak_ptr<A>, std::weak_ptr<B> >::value), ""); + static_assert((!std::is_convertible<std::weak_ptr<B>, std::weak_ptr<A> >::value), ""); + static_assert((!std::is_convertible<std::weak_ptr<A>, std::weak_ptr<C> >::value), ""); + { + const std::weak_ptr<A> pA(std::shared_ptr<A>(new A)); + assert(pA.use_count() == 0); + assert(B::count == 0); + assert(A::count == 0); + { + std::weak_ptr<B> pB(pA); + assert(B::count == 0); + assert(A::count == 0); + assert(pB.use_count() == 0); + assert(pA.use_count() == 0); + } + assert(pA.use_count() == 0); + assert(B::count == 0); + assert(A::count == 0); + } + assert(B::count == 0); + assert(A::count == 0); + { + std::weak_ptr<A> pA; + assert(pA.use_count() == 0); + assert(B::count == 0); + assert(A::count == 0); + { + std::weak_ptr<B> pB(pA); + assert(B::count == 0); + assert(A::count == 0); + assert(pB.use_count() == 0); + assert(pA.use_count() == 0); + } + assert(pA.use_count() == 0); + assert(B::count == 0); + assert(A::count == 0); + } + assert(B::count == 0); + assert(A::count == 0); +} diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.dest/tested_elsewhere.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.dest/tested_elsewhere.pass.cpp index e8db90cbee0..b89f168e9c4 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.dest/tested_elsewhere.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.dest/tested_elsewhere.pass.cpp @@ -1 +1,12 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
int main()
{
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.mod/reset.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.mod/reset.pass.cpp index 50aa527232a..7efe4ae5c26 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.mod/reset.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.mod/reset.pass.cpp @@ -1 +1,41 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// weak_ptr
// void swap(weak_ptr& r);
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
std::shared_ptr<A> p1(new A);
std::weak_ptr<A> w1(p1);
assert(w1.use_count() == 1);
w1.reset();
assert(w1.use_count() == 0);
assert(p1.use_count() == 1);
}
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// weak_ptr + +// void swap(weak_ptr& r); + +#include <memory> +#include <cassert> + +struct A +{ + static int count; + + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +int main() +{ + { + std::shared_ptr<A> p1(new A); + std::weak_ptr<A> w1(p1); + assert(w1.use_count() == 1); + w1.reset(); + assert(w1.use_count() == 0); + assert(p1.use_count() == 1); + } + assert(A::count == 0); +} diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.mod/swap.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.mod/swap.pass.cpp index 1bd3a3f6c50..c80598ff2da 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.mod/swap.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.mod/swap.pass.cpp @@ -1 +1,49 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// weak_ptr
// void swap(weak_ptr& r);
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
A* ptr1 = new A;
A* ptr2 = new A;
std::shared_ptr<A> p1(ptr1);
std::weak_ptr<A> w1(p1);
{
std::shared_ptr<A> p2(ptr2);
std::weak_ptr<A> w2(p2);
w1.swap(w2);
assert(w1.use_count() == 1);
assert(w1.lock().get() == ptr2);
assert(w2.use_count() == 1);
assert(w2.lock().get() == ptr1);
assert(A::count == 2);
}
}
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// weak_ptr + +// void swap(weak_ptr& r); + +#include <memory> +#include <cassert> + +struct A +{ + static int count; + + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +int main() +{ + { + A* ptr1 = new A; + A* ptr2 = new A; + std::shared_ptr<A> p1(ptr1); + std::weak_ptr<A> w1(p1); + { + std::shared_ptr<A> p2(ptr2); + std::weak_ptr<A> w2(p2); + w1.swap(w2); + assert(w1.use_count() == 1); + assert(w1.lock().get() == ptr2); + assert(w2.use_count() == 1); + assert(w2.lock().get() == ptr1); + assert(A::count == 2); + } + } + assert(A::count == 0); +} diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.obs/expired.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.obs/expired.pass.cpp index 3d93fb93e9e..7212923cd4b 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.obs/expired.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.obs/expired.pass.cpp @@ -1 +1,46 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// weak_ptr
// bool expired() const;
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
std::weak_ptr<A> wp;
assert(wp.use_count() == 0);
assert(wp.expired() == (wp.use_count() == 0));
}
{
std::shared_ptr<A> sp0(new A);
std::weak_ptr<A> wp(sp0);
assert(wp.use_count() == 1);
assert(wp.expired() == (wp.use_count() == 0));
sp0.reset();
assert(wp.use_count() == 0);
assert(wp.expired() == (wp.use_count() == 0));
}
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// weak_ptr + +// bool expired() const; + +#include <memory> +#include <cassert> + +struct A +{ + static int count; + + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +int main() +{ + { + std::weak_ptr<A> wp; + assert(wp.use_count() == 0); + assert(wp.expired() == (wp.use_count() == 0)); + } + { + std::shared_ptr<A> sp0(new A); + std::weak_ptr<A> wp(sp0); + assert(wp.use_count() == 1); + assert(wp.expired() == (wp.use_count() == 0)); + sp0.reset(); + assert(wp.use_count() == 0); + assert(wp.expired() == (wp.use_count() == 0)); + } +} diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.obs/lock.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.obs/lock.pass.cpp index c68792058fc..93895ba6f94 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.obs/lock.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.obs/lock.pass.cpp @@ -1 +1,58 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// weak_ptr
// shared_ptr<T> lock() const;
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
std::weak_ptr<A> wp;
std::shared_ptr<A> sp = wp.lock();
assert(sp.use_count() == 0);
assert(sp.get() == 0);
assert(A::count == 0);
}
{
std::shared_ptr<A> sp0(new A);
std::weak_ptr<A> wp(sp0);
std::shared_ptr<A> sp = wp.lock();
assert(sp.use_count() == 2);
assert(sp.get() == sp0.get());
assert(A::count == 1);
}
assert(A::count == 0);
{
std::shared_ptr<A> sp0(new A);
std::weak_ptr<A> wp(sp0);
sp0.reset();
std::shared_ptr<A> sp = wp.lock();
assert(sp.use_count() == 0);
assert(sp.get() == 0);
assert(A::count == 0);
}
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// weak_ptr + +// shared_ptr<T> lock() const; + +#include <memory> +#include <cassert> + +struct A +{ + static int count; + + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +int main() +{ + { + std::weak_ptr<A> wp; + std::shared_ptr<A> sp = wp.lock(); + assert(sp.use_count() == 0); + assert(sp.get() == 0); + assert(A::count == 0); + } + { + std::shared_ptr<A> sp0(new A); + std::weak_ptr<A> wp(sp0); + std::shared_ptr<A> sp = wp.lock(); + assert(sp.use_count() == 2); + assert(sp.get() == sp0.get()); + assert(A::count == 1); + } + assert(A::count == 0); + { + std::shared_ptr<A> sp0(new A); + std::weak_ptr<A> wp(sp0); + sp0.reset(); + std::shared_ptr<A> sp = wp.lock(); + assert(sp.use_count() == 0); + assert(sp.get() == 0); + assert(A::count == 0); + } + assert(A::count == 0); +} diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.obs/not_less_than.fail.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.obs/not_less_than.fail.cpp index 18bacf4a43a..acd9558ee93 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.obs/not_less_than.fail.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.obs/not_less_than.fail.cpp @@ -1 +1,27 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <class T> class weak_ptr;
//
// not less than comparable
#include <memory>
#include <cassert>
int main()
{
const std::shared_ptr<int> p1(new int);
const std::shared_ptr<int> p2(new int);
const std::weak_ptr<int> w1(p1);
const std::weak_ptr<int> w2(p2);
bool b = w1 < w2;
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// template <class T> class weak_ptr; +// +// not less than comparable + +#include <memory> +#include <cassert> + +int main() +{ + const std::shared_ptr<int> p1(new int); + const std::shared_ptr<int> p2(new int); + const std::weak_ptr<int> w1(p1); + const std::weak_ptr<int> w2(p2); + + bool b = w1 < w2; +} diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.obs/owner_before_shared_ptr.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.obs/owner_before_shared_ptr.pass.cpp index e3ad3807ea3..a8e88b0dcc6 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.obs/owner_before_shared_ptr.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.obs/owner_before_shared_ptr.pass.cpp @@ -1 +1,31 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// weak_ptr
// template<class U> bool owner_before(const shared_ptr<U>& b);
#include <memory>
#include <cassert>
int main()
{
const std::shared_ptr<int> p1(new int);
const std::shared_ptr<int> p2 = p1;
const std::shared_ptr<int> p3(new int);
const std::weak_ptr<int> w1(p1);
const std::weak_ptr<int> w2(p2);
const std::weak_ptr<int> w3(p3);
assert(!w1.owner_before(p2));
assert(!w2.owner_before(p1));
assert(w1.owner_before(p3) || w3.owner_before(p1));
assert(w3.owner_before(p1) == w3.owner_before(p2));
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// weak_ptr + +// template<class U> bool owner_before(const shared_ptr<U>& b); + +#include <memory> +#include <cassert> + +int main() +{ + const std::shared_ptr<int> p1(new int); + const std::shared_ptr<int> p2 = p1; + const std::shared_ptr<int> p3(new int); + const std::weak_ptr<int> w1(p1); + const std::weak_ptr<int> w2(p2); + const std::weak_ptr<int> w3(p3); + assert(!w1.owner_before(p2)); + assert(!w2.owner_before(p1)); + assert(w1.owner_before(p3) || w3.owner_before(p1)); + assert(w3.owner_before(p1) == w3.owner_before(p2)); +} diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.obs/owner_before_weak_ptr.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.obs/owner_before_weak_ptr.pass.cpp index 6f123821233..f6e3f0e74f7 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.obs/owner_before_weak_ptr.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.obs/owner_before_weak_ptr.pass.cpp @@ -1 +1,31 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// weak_ptr
// template<class U> bool owner_before(const weak_ptr<U>& b);
#include <memory>
#include <cassert>
int main()
{
const std::shared_ptr<int> p1(new int);
const std::shared_ptr<int> p2 = p1;
const std::shared_ptr<int> p3(new int);
const std::weak_ptr<int> w1(p1);
const std::weak_ptr<int> w2(p2);
const std::weak_ptr<int> w3(p3);
assert(!w1.owner_before(w2));
assert(!w2.owner_before(w1));
assert(w1.owner_before(w3) || w3.owner_before(w1));
assert(w3.owner_before(w1) == w3.owner_before(w2));
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// weak_ptr + +// template<class U> bool owner_before(const weak_ptr<U>& b); + +#include <memory> +#include <cassert> + +int main() +{ + const std::shared_ptr<int> p1(new int); + const std::shared_ptr<int> p2 = p1; + const std::shared_ptr<int> p3(new int); + const std::weak_ptr<int> w1(p1); + const std::weak_ptr<int> w2(p2); + const std::weak_ptr<int> w3(p3); + assert(!w1.owner_before(w2)); + assert(!w2.owner_before(w1)); + assert(w1.owner_before(w3) || w3.owner_before(w1)); + assert(w3.owner_before(w1) == w3.owner_before(w2)); +} diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.spec/swap.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.spec/swap.pass.cpp index c349f90b638..c3d89fa5612 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.spec/swap.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.spec/swap.pass.cpp @@ -1 +1,49 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// weak_ptr
// template<class T> void swap(weak_ptr<T>& a, weak_ptr<T>& b)
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
A* ptr1 = new A;
A* ptr2 = new A;
std::shared_ptr<A> p1(ptr1);
std::weak_ptr<A> w1(p1);
{
std::shared_ptr<A> p2(ptr2);
std::weak_ptr<A> w2(p2);
swap(w1, w2);
assert(w1.use_count() == 1);
assert(w1.lock().get() == ptr2);
assert(w2.use_count() == 1);
assert(w2.lock().get() == ptr1);
assert(A::count == 2);
}
}
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// weak_ptr + +// template<class T> void swap(weak_ptr<T>& a, weak_ptr<T>& b) + +#include <memory> +#include <cassert> + +struct A +{ + static int count; + + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +int main() +{ + { + A* ptr1 = new A; + A* ptr2 = new A; + std::shared_ptr<A> p1(ptr1); + std::weak_ptr<A> w1(p1); + { + std::shared_ptr<A> p2(ptr2); + std::weak_ptr<A> w2(p2); + swap(w1, w2); + assert(w1.use_count() == 1); + assert(w1.lock().get() == ptr2); + assert(w2.use_count() == 1); + assert(w2.lock().get() == ptr1); + assert(A::count == 2); + } + } + assert(A::count == 0); +} diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weakptr/bad_weak_ptr.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weakptr/bad_weak_ptr.pass.cpp index ae75b4fe810..3b0eb934ab9 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weakptr/bad_weak_ptr.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weakptr/bad_weak_ptr.pass.cpp @@ -1 +1,31 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// class bad_weak_ptr
// : public std::exception
// {
// public:
// bad_weak_ptr();
// };
#include <memory>
#include <type_traits>
#include <cassert>
#include <cstring>
int main()
{
static_assert((std::is_base_of<std::exception, std::bad_weak_ptr>::value), "");
std::bad_weak_ptr e;
std::bad_weak_ptr e2 = e;
e2 = e;
assert(std::strcmp(e.what(), "bad_weak_ptr") == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// class bad_weak_ptr +// : public std::exception +// { +// public: +// bad_weak_ptr(); +// }; + +#include <memory> +#include <type_traits> +#include <cassert> +#include <cstring> + +int main() +{ + static_assert((std::is_base_of<std::exception, std::bad_weak_ptr>::value), ""); + std::bad_weak_ptr e; + std::bad_weak_ptr e2 = e; + e2 = e; + assert(std::strcmp(e.what(), "bad_weak_ptr") == 0); +} diff --git a/libcxx/test/utilities/memory/version.pass.cpp b/libcxx/test/utilities/memory/version.pass.cpp index e05afd07802..bc84501f1b8 100644 --- a/libcxx/test/utilities/memory/version.pass.cpp +++ b/libcxx/test/utilities/memory/version.pass.cpp @@ -1 +1,20 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
#include <memory>
#ifndef _LIBCPP_VERSION
#error _LIBCPP_VERSION not defined
#endif
int main()
{
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +#include <memory> + +#ifndef _LIBCPP_VERSION +#error _LIBCPP_VERSION not defined +#endif + +int main() +{ +} diff --git a/libcxx/test/utilities/meta/meta.hel/integral_constant.pass.cpp b/libcxx/test/utilities/meta/meta.hel/integral_constant.pass.cpp index f963769d9c0..47b8eaf18b2 100644 --- a/libcxx/test/utilities/meta/meta.hel/integral_constant.pass.cpp +++ b/libcxx/test/utilities/meta/meta.hel/integral_constant.pass.cpp @@ -1 +1,36 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// type_traits
// integral_constant
#include <type_traits>
int main()
{
typedef std::integral_constant<int, 5> _5;
static_assert(_5::value == 5, "");
static_assert((std::is_same<_5::value_type, int>::value), "");
static_assert((std::is_same<_5::type, _5>::value), "");
static_assert(std::false_type::value == false, "");
static_assert((std::is_same<std::false_type::value_type, bool>::value), "");
static_assert((std::is_same<std::false_type::type, std::false_type>::value), "");
static_assert(std::true_type::value == true, "");
static_assert((std::is_same<std::true_type::value_type, bool>::value), "");
static_assert((std::is_same<std::true_type::type, std::true_type>::value), "");
std::false_type f1;
std::false_type f2 = f1;
std::true_type t1;
std::true_type t2 = t1;
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// integral_constant + +#include <type_traits> + +int main() +{ + typedef std::integral_constant<int, 5> _5; + static_assert(_5::value == 5, ""); + static_assert((std::is_same<_5::value_type, int>::value), ""); + static_assert((std::is_same<_5::type, _5>::value), ""); + + static_assert(std::false_type::value == false, ""); + static_assert((std::is_same<std::false_type::value_type, bool>::value), ""); + static_assert((std::is_same<std::false_type::type, std::false_type>::value), ""); + + static_assert(std::true_type::value == true, ""); + static_assert((std::is_same<std::true_type::value_type, bool>::value), ""); + static_assert((std::is_same<std::true_type::type, std::true_type>::value), ""); + + std::false_type f1; + std::false_type f2 = f1; + + std::true_type t1; + std::true_type t2 = t1; +} diff --git a/libcxx/test/utilities/meta/meta.rel/is_base_of.pass.cpp b/libcxx/test/utilities/meta/meta.rel/is_base_of.pass.cpp index 319fb6cceae..2d38d5524e2 100644 --- a/libcxx/test/utilities/meta/meta.rel/is_base_of.pass.cpp +++ b/libcxx/test/utilities/meta/meta.rel/is_base_of.pass.cpp @@ -1 +1,50 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// type_traits
// is_base_of
#include <type_traits>
template <class T, class U>
void test_is_base_of()
{
static_assert((std::is_base_of<T, U>::value), "");
static_assert((std::is_base_of<const T, U>::value), "");
static_assert((std::is_base_of<T, const U>::value), "");
static_assert((std::is_base_of<const T, const U>::value), "");
}
template <class T, class U>
void test_is_not_base_of()
{
static_assert((!std::is_base_of<T, U>::value), "");
}
struct B {};
struct B1 : B {};
struct B2 : B {};
struct D : private B1, private B2 {};
int main()
{
test_is_base_of<B, D>();
test_is_base_of<B1, D>();
test_is_base_of<B2, D>();
test_is_base_of<B, B1>();
test_is_base_of<B, B2>();
test_is_base_of<B, B>();
test_is_not_base_of<D, B>();
test_is_not_base_of<B&, D&>();
test_is_not_base_of<B[3], D[3]>();
test_is_not_base_of<int, int>();
test_is_not_base_of<int, int>();
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// is_base_of + +#include <type_traits> + +template <class T, class U> +void test_is_base_of() +{ + static_assert((std::is_base_of<T, U>::value), ""); + static_assert((std::is_base_of<const T, U>::value), ""); + static_assert((std::is_base_of<T, const U>::value), ""); + static_assert((std::is_base_of<const T, const U>::value), ""); +} + +template <class T, class U> +void test_is_not_base_of() +{ + static_assert((!std::is_base_of<T, U>::value), ""); +} + +struct B {}; +struct B1 : B {}; +struct B2 : B {}; +struct D : private B1, private B2 {}; + +int main() +{ + test_is_base_of<B, D>(); + test_is_base_of<B1, D>(); + test_is_base_of<B2, D>(); + test_is_base_of<B, B1>(); + test_is_base_of<B, B2>(); + test_is_base_of<B, B>(); + + test_is_not_base_of<D, B>(); + test_is_not_base_of<B&, D&>(); + test_is_not_base_of<B[3], D[3]>(); + test_is_not_base_of<int, int>(); + test_is_not_base_of<int, int>(); +} diff --git a/libcxx/test/utilities/meta/meta.rel/is_convertible.pass.cpp b/libcxx/test/utilities/meta/meta.rel/is_convertible.pass.cpp index 96c8a5e8ac2..a77d54a2085 100644 --- a/libcxx/test/utilities/meta/meta.rel/is_convertible.pass.cpp +++ b/libcxx/test/utilities/meta/meta.rel/is_convertible.pass.cpp @@ -1 +1,369 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// type_traits
// is_convertible
#include <type_traits>
typedef void Function();
typedef char Array[1];
int main()
{
{
static_assert(( std::is_convertible<void, void>::value), "");
static_assert(( std::is_convertible<const void, void>::value), "");
static_assert(( std::is_convertible<void, const void>::value), "");
static_assert(( std::is_convertible<const void, const void>::value), "");
static_assert((!std::is_convertible<void, Function>::value), "");
static_assert((!std::is_convertible<const void, Function>::value), "");
static_assert((!std::is_convertible<void, Function&>::value), "");
static_assert((!std::is_convertible<const void, Function&>::value), "");
static_assert((!std::is_convertible<void, Function*>::value), "");
static_assert((!std::is_convertible<void, Function* const>::value), "");
static_assert((!std::is_convertible<const void, Function*>::value), "");
static_assert((!std::is_convertible<const void, Function*const >::value), "");
static_assert((!std::is_convertible<void, Array>::value), "");
static_assert((!std::is_convertible<void, const Array>::value), "");
static_assert((!std::is_convertible<const void, Array>::value), "");
static_assert((!std::is_convertible<const void, const Array>::value), "");
static_assert((!std::is_convertible<void, Array&>::value), "");
static_assert((!std::is_convertible<void, const Array&>::value), "");
static_assert((!std::is_convertible<const void, Array&>::value), "");
static_assert((!std::is_convertible<const void, const Array&>::value), "");
static_assert((!std::is_convertible<void, char>::value), "");
static_assert((!std::is_convertible<void, const char>::value), "");
static_assert((!std::is_convertible<const void, char>::value), "");
static_assert((!std::is_convertible<const void, const char>::value), "");
static_assert((!std::is_convertible<void, char&>::value), "");
static_assert((!std::is_convertible<void, const char&>::value), "");
static_assert((!std::is_convertible<const void, char&>::value), "");
static_assert((!std::is_convertible<const void, const char&>::value), "");
static_assert((!std::is_convertible<void, char*>::value), "");
static_assert((!std::is_convertible<void, const char*>::value), "");
static_assert((!std::is_convertible<const void, char*>::value), "");
static_assert((!std::is_convertible<const void, const char*>::value), "");
}
{
static_assert((!std::is_convertible<Function, void>::value), "");
static_assert((!std::is_convertible<Function, const void>::value), "");
static_assert((!std::is_convertible<Function, Function>::value), "");
static_assert((!std::is_convertible<Function, Function&>::value), "");
static_assert((!std::is_convertible<Function, Function&>::value), "");
static_assert(( std::is_convertible<Function, Function*>::value), "");
static_assert(( std::is_convertible<Function, Function* const>::value), "");
static_assert((!std::is_convertible<Function, Array>::value), "");
static_assert((!std::is_convertible<Function, const Array>::value), "");
static_assert((!std::is_convertible<Function, Array&>::value), "");
static_assert((!std::is_convertible<Function, const Array&>::value), "");
static_assert((!std::is_convertible<Function, char>::value), "");
static_assert((!std::is_convertible<Function, const char>::value), "");
static_assert((!std::is_convertible<Function, char&>::value), "");
static_assert((!std::is_convertible<Function, const char&>::value), "");
static_assert((!std::is_convertible<Function, char*>::value), "");
static_assert((!std::is_convertible<Function, const char*>::value), "");
}
{
static_assert((!std::is_convertible<Function&, void>::value), "");
static_assert((!std::is_convertible<Function&, const void>::value), "");
static_assert((!std::is_convertible<Function&, Function>::value), "");
static_assert(( std::is_convertible<Function&, Function&>::value), "");
static_assert(( std::is_convertible<Function&, const Function&>::value), "");
static_assert(( std::is_convertible<Function&, Function*>::value), "");
static_assert(( std::is_convertible<Function&, Function* const>::value), "");
static_assert((!std::is_convertible<Function&, Array>::value), "");
static_assert((!std::is_convertible<Function&, const Array>::value), "");
static_assert((!std::is_convertible<Function&, Array&>::value), "");
static_assert((!std::is_convertible<Function&, const Array&>::value), "");
static_assert((!std::is_convertible<Function&, char>::value), "");
static_assert((!std::is_convertible<Function&, const char>::value), "");
static_assert((!std::is_convertible<Function&, char&>::value), "");
static_assert((!std::is_convertible<Function&, const char&>::value), "");
static_assert((!std::is_convertible<Function&, char*>::value), "");
static_assert((!std::is_convertible<Function&, const char*>::value), "");
}
{
static_assert((!std::is_convertible<Function*, void>::value), "");
static_assert((!std::is_convertible<Function*const, void>::value), "");
static_assert((!std::is_convertible<Function*, const void>::value), "");
static_assert((!std::is_convertible<Function*const, const void>::value), "");
static_assert((!std::is_convertible<Function*, Function>::value), "");
static_assert((!std::is_convertible<Function*const, Function>::value), "");
static_assert((!std::is_convertible<Function*, Function&>::value), "");
static_assert((!std::is_convertible<Function*const, Function&>::value), "");
static_assert(( std::is_convertible<Function*, Function*>::value), "");
static_assert(( std::is_convertible<Function*, Function* const>::value), "");
static_assert(( std::is_convertible<Function*const, Function*>::value), "");
static_assert(( std::is_convertible<Function*const, Function*const >::value), "");
static_assert((!std::is_convertible<Function*, Array>::value), "");
static_assert((!std::is_convertible<Function*, const Array>::value), "");
static_assert((!std::is_convertible<Function*const, Array>::value), "");
static_assert((!std::is_convertible<Function*const, const Array>::value), "");
static_assert((!std::is_convertible<Function*, Array&>::value), "");
static_assert((!std::is_convertible<Function*, const Array&>::value), "");
static_assert((!std::is_convertible<Function*const, Array&>::value), "");
static_assert((!std::is_convertible<Function*const, const Array&>::value), "");
static_assert((!std::is_convertible<Function*, char>::value), "");
static_assert((!std::is_convertible<Function*, const char>::value), "");
static_assert((!std::is_convertible<Function*const, char>::value), "");
static_assert((!std::is_convertible<Function*const, const char>::value), "");
static_assert((!std::is_convertible<Function*, char&>::value), "");
static_assert((!std::is_convertible<Function*, const char&>::value), "");
static_assert((!std::is_convertible<Function*const, char&>::value), "");
static_assert((!std::is_convertible<Function*const, const char&>::value), "");
static_assert((!std::is_convertible<Function*, char*>::value), "");
static_assert((!std::is_convertible<Function*, const char*>::value), "");
static_assert((!std::is_convertible<Function*const, char*>::value), "");
static_assert((!std::is_convertible<Function*const, const char*>::value), "");
}
{
static_assert((!std::is_convertible<Array, void>::value), "");
static_assert((!std::is_convertible<const Array, void>::value), "");
static_assert((!std::is_convertible<Array, const void>::value), "");
static_assert((!std::is_convertible<const Array, const void>::value), "");
static_assert((!std::is_convertible<Array, Function>::value), "");
static_assert((!std::is_convertible<const Array, Function>::value), "");
static_assert((!std::is_convertible<Array, Function&>::value), "");
static_assert((!std::is_convertible<const Array, Function&>::value), "");
static_assert((!std::is_convertible<Array, Function*>::value), "");
static_assert((!std::is_convertible<Array, Function* const>::value), "");
static_assert((!std::is_convertible<const Array, Function*>::value), "");
static_assert((!std::is_convertible<const Array, Function*const >::value), "");
static_assert((!std::is_convertible<Array, Array>::value), "");
static_assert((!std::is_convertible<Array, const Array>::value), "");
static_assert((!std::is_convertible<const Array, Array>::value), "");
static_assert((!std::is_convertible<const Array, const Array>::value), "");
static_assert((!std::is_convertible<Array, Array&>::value), "");
static_assert(( std::is_convertible<Array, const Array&>::value), "");
static_assert((!std::is_convertible<const Array, Array&>::value), "");
static_assert((!std::is_convertible<const Array, const Array&>::value), "");
static_assert((!std::is_convertible<Array, char>::value), "");
static_assert((!std::is_convertible<Array, const char>::value), "");
static_assert((!std::is_convertible<const Array, char>::value), "");
static_assert((!std::is_convertible<const Array, const char>::value), "");
static_assert((!std::is_convertible<Array, char&>::value), "");
static_assert((!std::is_convertible<Array, const char&>::value), "");
static_assert((!std::is_convertible<const Array, char&>::value), "");
static_assert((!std::is_convertible<const Array, const char&>::value), "");
static_assert(( std::is_convertible<Array, char*>::value), "");
static_assert(( std::is_convertible<Array, const char*>::value), "");
static_assert((!std::is_convertible<const Array, char*>::value), "");
static_assert(( std::is_convertible<const Array, const char*>::value), "");
}
{
static_assert((!std::is_convertible<Array&, void>::value), "");
static_assert((!std::is_convertible<const Array&, void>::value), "");
static_assert((!std::is_convertible<Array&, const void>::value), "");
static_assert((!std::is_convertible<const Array&, const void>::value), "");
static_assert((!std::is_convertible<Array&, Function>::value), "");
static_assert((!std::is_convertible<const Array&, Function>::value), "");
static_assert((!std::is_convertible<Array&, Function&>::value), "");
static_assert((!std::is_convertible<const Array&, Function&>::value), "");
static_assert((!std::is_convertible<Array&, Function*>::value), "");
static_assert((!std::is_convertible<Array&, Function* const>::value), "");
static_assert((!std::is_convertible<const Array&, Function*>::value), "");
static_assert((!std::is_convertible<const Array&, Function*const >::value), "");
static_assert((!std::is_convertible<Array&, Array>::value), "");
static_assert((!std::is_convertible<Array&, const Array>::value), "");
static_assert((!std::is_convertible<const Array&, Array>::value), "");
static_assert((!std::is_convertible<const Array&, const Array>::value), "");
static_assert(( std::is_convertible<Array&, Array&>::value), "");
static_assert(( std::is_convertible<Array&, const Array&>::value), "");
static_assert((!std::is_convertible<const Array&, Array&>::value), "");
static_assert(( std::is_convertible<const Array&, const Array&>::value), "");
static_assert((!std::is_convertible<Array&, char>::value), "");
static_assert((!std::is_convertible<Array&, const char>::value), "");
static_assert((!std::is_convertible<const Array&, char>::value), "");
static_assert((!std::is_convertible<const Array&, const char>::value), "");
static_assert((!std::is_convertible<Array&, char&>::value), "");
static_assert((!std::is_convertible<Array&, const char&>::value), "");
static_assert((!std::is_convertible<const Array&, char&>::value), "");
static_assert((!std::is_convertible<const Array&, const char&>::value), "");
static_assert(( std::is_convertible<Array&, char*>::value), "");
static_assert(( std::is_convertible<Array&, const char*>::value), "");
static_assert((!std::is_convertible<const Array&, char*>::value), "");
static_assert(( std::is_convertible<const Array&, const char*>::value), "");
}
{
static_assert((!std::is_convertible<char, void>::value), "");
static_assert((!std::is_convertible<const char, void>::value), "");
static_assert((!std::is_convertible<char, const void>::value), "");
static_assert((!std::is_convertible<const char, const void>::value), "");
static_assert((!std::is_convertible<char, Function>::value), "");
static_assert((!std::is_convertible<const char, Function>::value), "");
static_assert((!std::is_convertible<char, Function&>::value), "");
static_assert((!std::is_convertible<const char, Function&>::value), "");
static_assert((!std::is_convertible<char, Function*>::value), "");
static_assert((!std::is_convertible<char, Function* const>::value), "");
static_assert((!std::is_convertible<const char, Function*>::value), "");
static_assert((!std::is_convertible<const char, Function*const >::value), "");
static_assert((!std::is_convertible<char, Array>::value), "");
static_assert((!std::is_convertible<char, const Array>::value), "");
static_assert((!std::is_convertible<const char, Array>::value), "");
static_assert((!std::is_convertible<const char, const Array>::value), "");
static_assert((!std::is_convertible<char, Array&>::value), "");
static_assert((!std::is_convertible<char, const Array&>::value), "");
static_assert((!std::is_convertible<const char, Array&>::value), "");
static_assert((!std::is_convertible<const char, const Array&>::value), "");
static_assert(( std::is_convertible<char, char>::value), "");
static_assert(( std::is_convertible<char, const char>::value), "");
static_assert(( std::is_convertible<const char, char>::value), "");
static_assert(( std::is_convertible<const char, const char>::value), "");
static_assert((!std::is_convertible<char, char&>::value), "");
static_assert(( std::is_convertible<char, const char&>::value), "");
static_assert((!std::is_convertible<const char, char&>::value), "");
static_assert(( std::is_convertible<const char, const char&>::value), "");
static_assert((!std::is_convertible<char, char*>::value), "");
static_assert((!std::is_convertible<char, const char*>::value), "");
static_assert((!std::is_convertible<const char, char*>::value), "");
static_assert((!std::is_convertible<const char, const char*>::value), "");
}
{
static_assert((!std::is_convertible<char&, void>::value), "");
static_assert((!std::is_convertible<const char&, void>::value), "");
static_assert((!std::is_convertible<char&, const void>::value), "");
static_assert((!std::is_convertible<const char&, const void>::value), "");
static_assert((!std::is_convertible<char&, Function>::value), "");
static_assert((!std::is_convertible<const char&, Function>::value), "");
static_assert((!std::is_convertible<char&, Function&>::value), "");
static_assert((!std::is_convertible<const char&, Function&>::value), "");
static_assert((!std::is_convertible<char&, Function*>::value), "");
static_assert((!std::is_convertible<char&, Function* const>::value), "");
static_assert((!std::is_convertible<const char&, Function*>::value), "");
static_assert((!std::is_convertible<const char&, Function*const >::value), "");
static_assert((!std::is_convertible<char&, Array>::value), "");
static_assert((!std::is_convertible<char&, const Array>::value), "");
static_assert((!std::is_convertible<const char&, Array>::value), "");
static_assert((!std::is_convertible<const char&, const Array>::value), "");
static_assert((!std::is_convertible<char&, Array&>::value), "");
static_assert((!std::is_convertible<char&, const Array&>::value), "");
static_assert((!std::is_convertible<const char&, Array&>::value), "");
static_assert((!std::is_convertible<const char&, const Array&>::value), "");
static_assert(( std::is_convertible<char&, char>::value), "");
static_assert(( std::is_convertible<char&, const char>::value), "");
static_assert(( std::is_convertible<const char&, char>::value), "");
static_assert(( std::is_convertible<const char&, const char>::value), "");
static_assert(( std::is_convertible<char&, char&>::value), "");
static_assert(( std::is_convertible<char&, const char&>::value), "");
static_assert((!std::is_convertible<const char&, char&>::value), "");
static_assert(( std::is_convertible<const char&, const char&>::value), "");
static_assert((!std::is_convertible<char&, char*>::value), "");
static_assert((!std::is_convertible<char&, const char*>::value), "");
static_assert((!std::is_convertible<const char&, char*>::value), "");
static_assert((!std::is_convertible<const char&, const char*>::value), "");
}
{
static_assert((!std::is_convertible<char*, void>::value), "");
static_assert((!std::is_convertible<const char*, void>::value), "");
static_assert((!std::is_convertible<char*, const void>::value), "");
static_assert((!std::is_convertible<const char*, const void>::value), "");
static_assert((!std::is_convertible<char*, Function>::value), "");
static_assert((!std::is_convertible<const char*, Function>::value), "");
static_assert((!std::is_convertible<char*, Function&>::value), "");
static_assert((!std::is_convertible<const char*, Function&>::value), "");
static_assert((!std::is_convertible<char*, Function*>::value), "");
static_assert((!std::is_convertible<char*, Function* const>::value), "");
static_assert((!std::is_convertible<const char*, Function*>::value), "");
static_assert((!std::is_convertible<const char*, Function*const >::value), "");
static_assert((!std::is_convertible<char*, Array>::value), "");
static_assert((!std::is_convertible<char*, const Array>::value), "");
static_assert((!std::is_convertible<const char*, Array>::value), "");
static_assert((!std::is_convertible<const char*, const Array>::value), "");
static_assert((!std::is_convertible<char*, Array&>::value), "");
static_assert((!std::is_convertible<char*, const Array&>::value), "");
static_assert((!std::is_convertible<const char*, Array&>::value), "");
static_assert((!std::is_convertible<const char*, const Array&>::value), "");
static_assert((!std::is_convertible<char*, char>::value), "");
static_assert((!std::is_convertible<char*, const char>::value), "");
static_assert((!std::is_convertible<const char*, char>::value), "");
static_assert((!std::is_convertible<const char*, const char>::value), "");
static_assert((!std::is_convertible<char*, char&>::value), "");
static_assert((!std::is_convertible<char*, const char&>::value), "");
static_assert((!std::is_convertible<const char*, char&>::value), "");
static_assert((!std::is_convertible<const char*, const char&>::value), "");
static_assert(( std::is_convertible<char*, char*>::value), "");
static_assert(( std::is_convertible<char*, const char*>::value), "");
static_assert((!std::is_convertible<const char*, char*>::value), "");
static_assert(( std::is_convertible<const char*, const char*>::value), "");
}
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// is_convertible + +#include <type_traits> + +typedef void Function(); +typedef char Array[1]; + +int main() +{ + { + static_assert(( std::is_convertible<void, void>::value), ""); + static_assert(( std::is_convertible<const void, void>::value), ""); + static_assert(( std::is_convertible<void, const void>::value), ""); + static_assert(( std::is_convertible<const void, const void>::value), ""); + + static_assert((!std::is_convertible<void, Function>::value), ""); + static_assert((!std::is_convertible<const void, Function>::value), ""); + + static_assert((!std::is_convertible<void, Function&>::value), ""); + static_assert((!std::is_convertible<const void, Function&>::value), ""); + + static_assert((!std::is_convertible<void, Function*>::value), ""); + static_assert((!std::is_convertible<void, Function* const>::value), ""); + static_assert((!std::is_convertible<const void, Function*>::value), ""); + static_assert((!std::is_convertible<const void, Function*const >::value), ""); + + static_assert((!std::is_convertible<void, Array>::value), ""); + static_assert((!std::is_convertible<void, const Array>::value), ""); + static_assert((!std::is_convertible<const void, Array>::value), ""); + static_assert((!std::is_convertible<const void, const Array>::value), ""); + + static_assert((!std::is_convertible<void, Array&>::value), ""); + static_assert((!std::is_convertible<void, const Array&>::value), ""); + static_assert((!std::is_convertible<const void, Array&>::value), ""); + static_assert((!std::is_convertible<const void, const Array&>::value), ""); + + static_assert((!std::is_convertible<void, char>::value), ""); + static_assert((!std::is_convertible<void, const char>::value), ""); + static_assert((!std::is_convertible<const void, char>::value), ""); + static_assert((!std::is_convertible<const void, const char>::value), ""); + + static_assert((!std::is_convertible<void, char&>::value), ""); + static_assert((!std::is_convertible<void, const char&>::value), ""); + static_assert((!std::is_convertible<const void, char&>::value), ""); + static_assert((!std::is_convertible<const void, const char&>::value), ""); + + static_assert((!std::is_convertible<void, char*>::value), ""); + static_assert((!std::is_convertible<void, const char*>::value), ""); + static_assert((!std::is_convertible<const void, char*>::value), ""); + static_assert((!std::is_convertible<const void, const char*>::value), ""); + } + { + static_assert((!std::is_convertible<Function, void>::value), ""); + static_assert((!std::is_convertible<Function, const void>::value), ""); + + static_assert((!std::is_convertible<Function, Function>::value), ""); + + static_assert((!std::is_convertible<Function, Function&>::value), ""); + static_assert((!std::is_convertible<Function, Function&>::value), ""); + + static_assert(( std::is_convertible<Function, Function*>::value), ""); + static_assert(( std::is_convertible<Function, Function* const>::value), ""); + + static_assert((!std::is_convertible<Function, Array>::value), ""); + static_assert((!std::is_convertible<Function, const Array>::value), ""); + + static_assert((!std::is_convertible<Function, Array&>::value), ""); + static_assert((!std::is_convertible<Function, const Array&>::value), ""); + + static_assert((!std::is_convertible<Function, char>::value), ""); + static_assert((!std::is_convertible<Function, const char>::value), ""); + + static_assert((!std::is_convertible<Function, char&>::value), ""); + static_assert((!std::is_convertible<Function, const char&>::value), ""); + + static_assert((!std::is_convertible<Function, char*>::value), ""); + static_assert((!std::is_convertible<Function, const char*>::value), ""); + } + { + static_assert((!std::is_convertible<Function&, void>::value), ""); + static_assert((!std::is_convertible<Function&, const void>::value), ""); + + static_assert((!std::is_convertible<Function&, Function>::value), ""); + + static_assert(( std::is_convertible<Function&, Function&>::value), ""); + static_assert(( std::is_convertible<Function&, const Function&>::value), ""); + + static_assert(( std::is_convertible<Function&, Function*>::value), ""); + static_assert(( std::is_convertible<Function&, Function* const>::value), ""); + + static_assert((!std::is_convertible<Function&, Array>::value), ""); + static_assert((!std::is_convertible<Function&, const Array>::value), ""); + + static_assert((!std::is_convertible<Function&, Array&>::value), ""); + static_assert((!std::is_convertible<Function&, const Array&>::value), ""); + + static_assert((!std::is_convertible<Function&, char>::value), ""); + static_assert((!std::is_convertible<Function&, const char>::value), ""); + + static_assert((!std::is_convertible<Function&, char&>::value), ""); + static_assert((!std::is_convertible<Function&, const char&>::value), ""); + + static_assert((!std::is_convertible<Function&, char*>::value), ""); + static_assert((!std::is_convertible<Function&, const char*>::value), ""); + } + { + static_assert((!std::is_convertible<Function*, void>::value), ""); + static_assert((!std::is_convertible<Function*const, void>::value), ""); + static_assert((!std::is_convertible<Function*, const void>::value), ""); + static_assert((!std::is_convertible<Function*const, const void>::value), ""); + + static_assert((!std::is_convertible<Function*, Function>::value), ""); + static_assert((!std::is_convertible<Function*const, Function>::value), ""); + + static_assert((!std::is_convertible<Function*, Function&>::value), ""); + static_assert((!std::is_convertible<Function*const, Function&>::value), ""); + + static_assert(( std::is_convertible<Function*, Function*>::value), ""); + static_assert(( std::is_convertible<Function*, Function* const>::value), ""); + static_assert(( std::is_convertible<Function*const, Function*>::value), ""); + static_assert(( std::is_convertible<Function*const, Function*const >::value), ""); + + static_assert((!std::is_convertible<Function*, Array>::value), ""); + static_assert((!std::is_convertible<Function*, const Array>::value), ""); + static_assert((!std::is_convertible<Function*const, Array>::value), ""); + static_assert((!std::is_convertible<Function*const, const Array>::value), ""); + + static_assert((!std::is_convertible<Function*, Array&>::value), ""); + static_assert((!std::is_convertible<Function*, const Array&>::value), ""); + static_assert((!std::is_convertible<Function*const, Array&>::value), ""); + static_assert((!std::is_convertible<Function*const, const Array&>::value), ""); + + static_assert((!std::is_convertible<Function*, char>::value), ""); + static_assert((!std::is_convertible<Function*, const char>::value), ""); + static_assert((!std::is_convertible<Function*const, char>::value), ""); + static_assert((!std::is_convertible<Function*const, const char>::value), ""); + + static_assert((!std::is_convertible<Function*, char&>::value), ""); + static_assert((!std::is_convertible<Function*, const char&>::value), ""); + static_assert((!std::is_convertible<Function*const, char&>::value), ""); + static_assert((!std::is_convertible<Function*const, const char&>::value), ""); + + static_assert((!std::is_convertible<Function*, char*>::value), ""); + static_assert((!std::is_convertible<Function*, const char*>::value), ""); + static_assert((!std::is_convertible<Function*const, char*>::value), ""); + static_assert((!std::is_convertible<Function*const, const char*>::value), ""); + } + { + static_assert((!std::is_convertible<Array, void>::value), ""); + static_assert((!std::is_convertible<const Array, void>::value), ""); + static_assert((!std::is_convertible<Array, const void>::value), ""); + static_assert((!std::is_convertible<const Array, const void>::value), ""); + + static_assert((!std::is_convertible<Array, Function>::value), ""); + static_assert((!std::is_convertible<const Array, Function>::value), ""); + + static_assert((!std::is_convertible<Array, Function&>::value), ""); + static_assert((!std::is_convertible<const Array, Function&>::value), ""); + + static_assert((!std::is_convertible<Array, Function*>::value), ""); + static_assert((!std::is_convertible<Array, Function* const>::value), ""); + static_assert((!std::is_convertible<const Array, Function*>::value), ""); + static_assert((!std::is_convertible<const Array, Function*const >::value), ""); + + static_assert((!std::is_convertible<Array, Array>::value), ""); + static_assert((!std::is_convertible<Array, const Array>::value), ""); + static_assert((!std::is_convertible<const Array, Array>::value), ""); + static_assert((!std::is_convertible<const Array, const Array>::value), ""); + + static_assert((!std::is_convertible<Array, Array&>::value), ""); + static_assert(( std::is_convertible<Array, const Array&>::value), ""); + static_assert((!std::is_convertible<const Array, Array&>::value), ""); + static_assert((!std::is_convertible<const Array, const Array&>::value), ""); + + static_assert((!std::is_convertible<Array, char>::value), ""); + static_assert((!std::is_convertible<Array, const char>::value), ""); + static_assert((!std::is_convertible<const Array, char>::value), ""); + static_assert((!std::is_convertible<const Array, const char>::value), ""); + + static_assert((!std::is_convertible<Array, char&>::value), ""); + static_assert((!std::is_convertible<Array, const char&>::value), ""); + static_assert((!std::is_convertible<const Array, char&>::value), ""); + static_assert((!std::is_convertible<const Array, const char&>::value), ""); + + static_assert(( std::is_convertible<Array, char*>::value), ""); + static_assert(( std::is_convertible<Array, const char*>::value), ""); + static_assert((!std::is_convertible<const Array, char*>::value), ""); + static_assert(( std::is_convertible<const Array, const char*>::value), ""); + } + { + static_assert((!std::is_convertible<Array&, void>::value), ""); + static_assert((!std::is_convertible<const Array&, void>::value), ""); + static_assert((!std::is_convertible<Array&, const void>::value), ""); + static_assert((!std::is_convertible<const Array&, const void>::value), ""); + + static_assert((!std::is_convertible<Array&, Function>::value), ""); + static_assert((!std::is_convertible<const Array&, Function>::value), ""); + + static_assert((!std::is_convertible<Array&, Function&>::value), ""); + static_assert((!std::is_convertible<const Array&, Function&>::value), ""); + + static_assert((!std::is_convertible<Array&, Function*>::value), ""); + static_assert((!std::is_convertible<Array&, Function* const>::value), ""); + static_assert((!std::is_convertible<const Array&, Function*>::value), ""); + static_assert((!std::is_convertible<const Array&, Function*const >::value), ""); + + static_assert((!std::is_convertible<Array&, Array>::value), ""); + static_assert((!std::is_convertible<Array&, const Array>::value), ""); + static_assert((!std::is_convertible<const Array&, Array>::value), ""); + static_assert((!std::is_convertible<const Array&, const Array>::value), ""); + + static_assert(( std::is_convertible<Array&, Array&>::value), ""); + static_assert(( std::is_convertible<Array&, const Array&>::value), ""); + static_assert((!std::is_convertible<const Array&, Array&>::value), ""); + static_assert(( std::is_convertible<const Array&, const Array&>::value), ""); + + static_assert((!std::is_convertible<Array&, char>::value), ""); + static_assert((!std::is_convertible<Array&, const char>::value), ""); + static_assert((!std::is_convertible<const Array&, char>::value), ""); + static_assert((!std::is_convertible<const Array&, const char>::value), ""); + + static_assert((!std::is_convertible<Array&, char&>::value), ""); + static_assert((!std::is_convertible<Array&, const char&>::value), ""); + static_assert((!std::is_convertible<const Array&, char&>::value), ""); + static_assert((!std::is_convertible<const Array&, const char&>::value), ""); + + static_assert(( std::is_convertible<Array&, char*>::value), ""); + static_assert(( std::is_convertible<Array&, const char*>::value), ""); + static_assert((!std::is_convertible<const Array&, char*>::value), ""); + static_assert(( std::is_convertible<const Array&, const char*>::value), ""); + } + { + static_assert((!std::is_convertible<char, void>::value), ""); + static_assert((!std::is_convertible<const char, void>::value), ""); + static_assert((!std::is_convertible<char, const void>::value), ""); + static_assert((!std::is_convertible<const char, const void>::value), ""); + + static_assert((!std::is_convertible<char, Function>::value), ""); + static_assert((!std::is_convertible<const char, Function>::value), ""); + + static_assert((!std::is_convertible<char, Function&>::value), ""); + static_assert((!std::is_convertible<const char, Function&>::value), ""); + + static_assert((!std::is_convertible<char, Function*>::value), ""); + static_assert((!std::is_convertible<char, Function* const>::value), ""); + static_assert((!std::is_convertible<const char, Function*>::value), ""); + static_assert((!std::is_convertible<const char, Function*const >::value), ""); + + static_assert((!std::is_convertible<char, Array>::value), ""); + static_assert((!std::is_convertible<char, const Array>::value), ""); + static_assert((!std::is_convertible<const char, Array>::value), ""); + static_assert((!std::is_convertible<const char, const Array>::value), ""); + + static_assert((!std::is_convertible<char, Array&>::value), ""); + static_assert((!std::is_convertible<char, const Array&>::value), ""); + static_assert((!std::is_convertible<const char, Array&>::value), ""); + static_assert((!std::is_convertible<const char, const Array&>::value), ""); + + static_assert(( std::is_convertible<char, char>::value), ""); + static_assert(( std::is_convertible<char, const char>::value), ""); + static_assert(( std::is_convertible<const char, char>::value), ""); + static_assert(( std::is_convertible<const char, const char>::value), ""); + + static_assert((!std::is_convertible<char, char&>::value), ""); + static_assert(( std::is_convertible<char, const char&>::value), ""); + static_assert((!std::is_convertible<const char, char&>::value), ""); + static_assert(( std::is_convertible<const char, const char&>::value), ""); + + static_assert((!std::is_convertible<char, char*>::value), ""); + static_assert((!std::is_convertible<char, const char*>::value), ""); + static_assert((!std::is_convertible<const char, char*>::value), ""); + static_assert((!std::is_convertible<const char, const char*>::value), ""); + } + { + static_assert((!std::is_convertible<char&, void>::value), ""); + static_assert((!std::is_convertible<const char&, void>::value), ""); + static_assert((!std::is_convertible<char&, const void>::value), ""); + static_assert((!std::is_convertible<const char&, const void>::value), ""); + + static_assert((!std::is_convertible<char&, Function>::value), ""); + static_assert((!std::is_convertible<const char&, Function>::value), ""); + + static_assert((!std::is_convertible<char&, Function&>::value), ""); + static_assert((!std::is_convertible<const char&, Function&>::value), ""); + + static_assert((!std::is_convertible<char&, Function*>::value), ""); + static_assert((!std::is_convertible<char&, Function* const>::value), ""); + static_assert((!std::is_convertible<const char&, Function*>::value), ""); + static_assert((!std::is_convertible<const char&, Function*const >::value), ""); + + static_assert((!std::is_convertible<char&, Array>::value), ""); + static_assert((!std::is_convertible<char&, const Array>::value), ""); + static_assert((!std::is_convertible<const char&, Array>::value), ""); + static_assert((!std::is_convertible<const char&, const Array>::value), ""); + + static_assert((!std::is_convertible<char&, Array&>::value), ""); + static_assert((!std::is_convertible<char&, const Array&>::value), ""); + static_assert((!std::is_convertible<const char&, Array&>::value), ""); + static_assert((!std::is_convertible<const char&, const Array&>::value), ""); + + static_assert(( std::is_convertible<char&, char>::value), ""); + static_assert(( std::is_convertible<char&, const char>::value), ""); + static_assert(( std::is_convertible<const char&, char>::value), ""); + static_assert(( std::is_convertible<const char&, const char>::value), ""); + + static_assert(( std::is_convertible<char&, char&>::value), ""); + static_assert(( std::is_convertible<char&, const char&>::value), ""); + static_assert((!std::is_convertible<const char&, char&>::value), ""); + static_assert(( std::is_convertible<const char&, const char&>::value), ""); + + static_assert((!std::is_convertible<char&, char*>::value), ""); + static_assert((!std::is_convertible<char&, const char*>::value), ""); + static_assert((!std::is_convertible<const char&, char*>::value), ""); + static_assert((!std::is_convertible<const char&, const char*>::value), ""); + } + { + static_assert((!std::is_convertible<char*, void>::value), ""); + static_assert((!std::is_convertible<const char*, void>::value), ""); + static_assert((!std::is_convertible<char*, const void>::value), ""); + static_assert((!std::is_convertible<const char*, const void>::value), ""); + + static_assert((!std::is_convertible<char*, Function>::value), ""); + static_assert((!std::is_convertible<const char*, Function>::value), ""); + + static_assert((!std::is_convertible<char*, Function&>::value), ""); + static_assert((!std::is_convertible<const char*, Function&>::value), ""); + + static_assert((!std::is_convertible<char*, Function*>::value), ""); + static_assert((!std::is_convertible<char*, Function* const>::value), ""); + static_assert((!std::is_convertible<const char*, Function*>::value), ""); + static_assert((!std::is_convertible<const char*, Function*const >::value), ""); + + static_assert((!std::is_convertible<char*, Array>::value), ""); + static_assert((!std::is_convertible<char*, const Array>::value), ""); + static_assert((!std::is_convertible<const char*, Array>::value), ""); + static_assert((!std::is_convertible<const char*, const Array>::value), ""); + + static_assert((!std::is_convertible<char*, Array&>::value), ""); + static_assert((!std::is_convertible<char*, const Array&>::value), ""); + static_assert((!std::is_convertible<const char*, Array&>::value), ""); + static_assert((!std::is_convertible<const char*, const Array&>::value), ""); + + static_assert((!std::is_convertible<char*, char>::value), ""); + static_assert((!std::is_convertible<char*, const char>::value), ""); + static_assert((!std::is_convertible<const char*, char>::value), ""); + static_assert((!std::is_convertible<const char*, const char>::value), ""); + + static_assert((!std::is_convertible<char*, char&>::value), ""); + static_assert((!std::is_convertible<char*, const char&>::value), ""); + static_assert((!std::is_convertible<const char*, char&>::value), ""); + static_assert((!std::is_convertible<const char*, const char&>::value), ""); + + static_assert(( std::is_convertible<char*, char*>::value), ""); + static_assert(( std::is_convertible<char*, const char*>::value), ""); + static_assert((!std::is_convertible<const char*, char*>::value), ""); + static_assert(( std::is_convertible<const char*, const char*>::value), ""); + } +} diff --git a/libcxx/test/utilities/meta/meta.rel/is_same.pass.cpp b/libcxx/test/utilities/meta/meta.rel/is_same.pass.cpp index 8fa8e556d7c..e75a8d03768 100644 --- a/libcxx/test/utilities/meta/meta.rel/is_same.pass.cpp +++ b/libcxx/test/utilities/meta/meta.rel/is_same.pass.cpp @@ -1 +1,59 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// type_traits
// is_same
#include <type_traits>
template <class T, class U>
void test_is_same()
{
static_assert((std::is_same<T, U>::value), "");
static_assert((!std::is_same<const T, U>::value), "");
static_assert((!std::is_same<T, const U>::value), "");
static_assert((std::is_same<const T, const U>::value), "");
}
template <class T, class U>
void test_is_same_ref()
{
static_assert((std::is_same<T, U>::value), "");
static_assert((std::is_same<const T, U>::value), "");
static_assert((std::is_same<T, const U>::value), "");
static_assert((std::is_same<const T, const U>::value), "");
}
template <class T, class U>
void test_is_not_same()
{
static_assert((!std::is_same<T, U>::value), "");
}
class Class
{
public:
~Class();
};
int main()
{
test_is_same<int, int>();
test_is_same<void, void>();
test_is_same<Class, Class>();
test_is_same<int*, int*>();
test_is_same_ref<int&, int&>();
test_is_not_same<int, void>();
test_is_not_same<void, Class>();
test_is_not_same<Class, int*>();
test_is_not_same<int*, int&>();
test_is_not_same<int&, int>();
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// is_same + +#include <type_traits> + +template <class T, class U> +void test_is_same() +{ + static_assert((std::is_same<T, U>::value), ""); + static_assert((!std::is_same<const T, U>::value), ""); + static_assert((!std::is_same<T, const U>::value), ""); + static_assert((std::is_same<const T, const U>::value), ""); +} + +template <class T, class U> +void test_is_same_ref() +{ + static_assert((std::is_same<T, U>::value), ""); + static_assert((std::is_same<const T, U>::value), ""); + static_assert((std::is_same<T, const U>::value), ""); + static_assert((std::is_same<const T, const U>::value), ""); +} + +template <class T, class U> +void test_is_not_same() +{ + static_assert((!std::is_same<T, U>::value), ""); +} + +class Class +{ +public: + ~Class(); +}; + +int main() +{ + test_is_same<int, int>(); + test_is_same<void, void>(); + test_is_same<Class, Class>(); + test_is_same<int*, int*>(); + test_is_same_ref<int&, int&>(); + + test_is_not_same<int, void>(); + test_is_not_same<void, Class>(); + test_is_not_same<Class, int*>(); + test_is_not_same<int*, int&>(); + test_is_not_same<int&, int>(); +} diff --git a/libcxx/test/utilities/meta/meta.rqmts/nothing_to_do.pass.cpp b/libcxx/test/utilities/meta/meta.rqmts/nothing_to_do.pass.cpp index e8db90cbee0..b89f168e9c4 100644 --- a/libcxx/test/utilities/meta/meta.rqmts/nothing_to_do.pass.cpp +++ b/libcxx/test/utilities/meta/meta.rqmts/nothing_to_do.pass.cpp @@ -1 +1,12 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
int main()
{
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/libcxx/test/utilities/meta/meta.trans/meta.trans.arr/remove_all_extents.pass.cpp b/libcxx/test/utilities/meta/meta.trans/meta.trans.arr/remove_all_extents.pass.cpp index 51e5178cfd9..23b7646c3bb 100644 --- a/libcxx/test/utilities/meta/meta.trans/meta.trans.arr/remove_all_extents.pass.cpp +++ b/libcxx/test/utilities/meta/meta.trans/meta.trans.arr/remove_all_extents.pass.cpp @@ -1 +1,32 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// type_traits
// remove_all_extents
#include <type_traits>
enum Enum {zero, one_};
int main()
{
static_assert((std::is_same<std::remove_all_extents<int>::type, int>::value), "");
static_assert((std::is_same<std::remove_all_extents<const Enum>::type, const Enum>::value), "");
static_assert((std::is_same<std::remove_all_extents<int[]>::type, int>::value), "");
static_assert((std::is_same<std::remove_all_extents<const int[]>::type, const int>::value), "");
static_assert((std::is_same<std::remove_all_extents<int[3]>::type, int>::value), "");
static_assert((std::is_same<std::remove_all_extents<const int[3]>::type, const int>::value), "");
static_assert((std::is_same<std::remove_all_extents<int[][3]>::type, int>::value), "");
static_assert((std::is_same<std::remove_all_extents<const int[][3]>::type, const int>::value), "");
static_assert((std::is_same<std::remove_all_extents<int[2][3]>::type, int>::value), "");
static_assert((std::is_same<std::remove_all_extents<const int[2][3]>::type, const int>::value), "");
static_assert((std::is_same<std::remove_all_extents<int[1][2][3]>::type, int>::value), "");
static_assert((std::is_same<std::remove_all_extents<const int[1][2][3]>::type, const int>::value), "");
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// remove_all_extents + +#include <type_traits> + +enum Enum {zero, one_}; + +int main() +{ + static_assert((std::is_same<std::remove_all_extents<int>::type, int>::value), ""); + static_assert((std::is_same<std::remove_all_extents<const Enum>::type, const Enum>::value), ""); + static_assert((std::is_same<std::remove_all_extents<int[]>::type, int>::value), ""); + static_assert((std::is_same<std::remove_all_extents<const int[]>::type, const int>::value), ""); + static_assert((std::is_same<std::remove_all_extents<int[3]>::type, int>::value), ""); + static_assert((std::is_same<std::remove_all_extents<const int[3]>::type, const int>::value), ""); + static_assert((std::is_same<std::remove_all_extents<int[][3]>::type, int>::value), ""); + static_assert((std::is_same<std::remove_all_extents<const int[][3]>::type, const int>::value), ""); + static_assert((std::is_same<std::remove_all_extents<int[2][3]>::type, int>::value), ""); + static_assert((std::is_same<std::remove_all_extents<const int[2][3]>::type, const int>::value), ""); + static_assert((std::is_same<std::remove_all_extents<int[1][2][3]>::type, int>::value), ""); + static_assert((std::is_same<std::remove_all_extents<const int[1][2][3]>::type, const int>::value), ""); +} diff --git a/libcxx/test/utilities/meta/meta.trans/meta.trans.arr/remove_extent.pass.cpp b/libcxx/test/utilities/meta/meta.trans/meta.trans.arr/remove_extent.pass.cpp index d6592e88377..3f7d07a7466 100644 --- a/libcxx/test/utilities/meta/meta.trans/meta.trans.arr/remove_extent.pass.cpp +++ b/libcxx/test/utilities/meta/meta.trans/meta.trans.arr/remove_extent.pass.cpp @@ -1 +1,32 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// type_traits
// remove_extent
#include <type_traits>
enum Enum {zero, one_};
int main()
{
static_assert((std::is_same<std::remove_extent<int>::type, int>::value), "");
static_assert((std::is_same<std::remove_extent<const Enum>::type, const Enum>::value), "");
static_assert((std::is_same<std::remove_extent<int[]>::type, int>::value), "");
static_assert((std::is_same<std::remove_extent<const int[]>::type, const int>::value), "");
static_assert((std::is_same<std::remove_extent<int[3]>::type, int>::value), "");
static_assert((std::is_same<std::remove_extent<const int[3]>::type, const int>::value), "");
static_assert((std::is_same<std::remove_extent<int[][3]>::type, int[3]>::value), "");
static_assert((std::is_same<std::remove_extent<const int[][3]>::type, const int[3]>::value), "");
static_assert((std::is_same<std::remove_extent<int[2][3]>::type, int[3]>::value), "");
static_assert((std::is_same<std::remove_extent<const int[2][3]>::type, const int[3]>::value), "");
static_assert((std::is_same<std::remove_extent<int[1][2][3]>::type, int[2][3]>::value), "");
static_assert((std::is_same<std::remove_extent<const int[1][2][3]>::type, const int[2][3]>::value), "");
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// remove_extent + +#include <type_traits> + +enum Enum {zero, one_}; + +int main() +{ + static_assert((std::is_same<std::remove_extent<int>::type, int>::value), ""); + static_assert((std::is_same<std::remove_extent<const Enum>::type, const Enum>::value), ""); + static_assert((std::is_same<std::remove_extent<int[]>::type, int>::value), ""); + static_assert((std::is_same<std::remove_extent<const int[]>::type, const int>::value), ""); + static_assert((std::is_same<std::remove_extent<int[3]>::type, int>::value), ""); + static_assert((std::is_same<std::remove_extent<const int[3]>::type, const int>::value), ""); + static_assert((std::is_same<std::remove_extent<int[][3]>::type, int[3]>::value), ""); + static_assert((std::is_same<std::remove_extent<const int[][3]>::type, const int[3]>::value), ""); + static_assert((std::is_same<std::remove_extent<int[2][3]>::type, int[3]>::value), ""); + static_assert((std::is_same<std::remove_extent<const int[2][3]>::type, const int[3]>::value), ""); + static_assert((std::is_same<std::remove_extent<int[1][2][3]>::type, int[2][3]>::value), ""); + static_assert((std::is_same<std::remove_extent<const int[1][2][3]>::type, const int[2][3]>::value), ""); +} diff --git a/libcxx/test/utilities/meta/meta.trans/meta.trans.cv/add_const.pass.cpp b/libcxx/test/utilities/meta/meta.trans/meta.trans.cv/add_const.pass.cpp index 55767898c33..f9f20dfdf6c 100644 --- a/libcxx/test/utilities/meta/meta.trans/meta.trans.cv/add_const.pass.cpp +++ b/libcxx/test/utilities/meta/meta.trans/meta.trans.cv/add_const.pass.cpp @@ -1 +1,40 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// type_traits
// add_const
#include <type_traits>
template <class T, class U>
void test_add_const_imp()
{
static_assert((std::is_same<typename std::add_const<T>::type, const U>::value), "");
}
template <class T>
void test_add_const()
{
test_add_const_imp<T, const T>();
test_add_const_imp<const T, const T>();
test_add_const_imp<volatile T, volatile const T>();
test_add_const_imp<const volatile T, const volatile T>();
}
int main()
{
test_add_const<void>();
test_add_const<int>();
test_add_const<int[3]>();
test_add_const<int&>();
test_add_const<const int&>();
test_add_const<int*>();
test_add_const<const int*>();
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// add_const + +#include <type_traits> + +template <class T, class U> +void test_add_const_imp() +{ + static_assert((std::is_same<typename std::add_const<T>::type, const U>::value), ""); +} + +template <class T> +void test_add_const() +{ + test_add_const_imp<T, const T>(); + test_add_const_imp<const T, const T>(); + test_add_const_imp<volatile T, volatile const T>(); + test_add_const_imp<const volatile T, const volatile T>(); +} + +int main() +{ + test_add_const<void>(); + test_add_const<int>(); + test_add_const<int[3]>(); + test_add_const<int&>(); + test_add_const<const int&>(); + test_add_const<int*>(); + test_add_const<const int*>(); +} diff --git a/libcxx/test/utilities/meta/meta.trans/meta.trans.cv/add_cv.pass.cpp b/libcxx/test/utilities/meta/meta.trans/meta.trans.cv/add_cv.pass.cpp index 43f516eab71..ae87afb5f1d 100644 --- a/libcxx/test/utilities/meta/meta.trans/meta.trans.cv/add_cv.pass.cpp +++ b/libcxx/test/utilities/meta/meta.trans/meta.trans.cv/add_cv.pass.cpp @@ -1 +1,40 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// type_traits
// add_cv
#include <type_traits>
template <class T, class U>
void test_add_cv_imp()
{
static_assert((std::is_same<typename std::add_cv<T>::type, const volatile U>::value), "");
}
template <class T>
void test_add_cv()
{
test_add_cv_imp<T, const volatile T>();
test_add_cv_imp<const T, const volatile T>();
test_add_cv_imp<volatile T, volatile const T>();
test_add_cv_imp<const volatile T, const volatile T>();
}
int main()
{
test_add_cv<void>();
test_add_cv<int>();
test_add_cv<int[3]>();
test_add_cv<int&>();
test_add_cv<const int&>();
test_add_cv<int*>();
test_add_cv<const int*>();
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// add_cv + +#include <type_traits> + +template <class T, class U> +void test_add_cv_imp() +{ + static_assert((std::is_same<typename std::add_cv<T>::type, const volatile U>::value), ""); +} + +template <class T> +void test_add_cv() +{ + test_add_cv_imp<T, const volatile T>(); + test_add_cv_imp<const T, const volatile T>(); + test_add_cv_imp<volatile T, volatile const T>(); + test_add_cv_imp<const volatile T, const volatile T>(); +} + +int main() +{ + test_add_cv<void>(); + test_add_cv<int>(); + test_add_cv<int[3]>(); + test_add_cv<int&>(); + test_add_cv<const int&>(); + test_add_cv<int*>(); + test_add_cv<const int*>(); +} diff --git a/libcxx/test/utilities/meta/meta.trans/meta.trans.cv/add_volatile.pass.cpp b/libcxx/test/utilities/meta/meta.trans/meta.trans.cv/add_volatile.pass.cpp index cca30035925..fd82f953d30 100644 --- a/libcxx/test/utilities/meta/meta.trans/meta.trans.cv/add_volatile.pass.cpp +++ b/libcxx/test/utilities/meta/meta.trans/meta.trans.cv/add_volatile.pass.cpp @@ -1 +1,40 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// type_traits
// add_volatile
#include <type_traits>
template <class T, class U>
void test_add_volatile_imp()
{
static_assert((std::is_same<typename std::add_volatile<T>::type, volatile U>::value), "");
}
template <class T>
void test_add_volatile()
{
test_add_volatile_imp<T, volatile T>();
test_add_volatile_imp<const T, const volatile T>();
test_add_volatile_imp<volatile T, volatile T>();
test_add_volatile_imp<const volatile T, const volatile T>();
}
int main()
{
test_add_volatile<void>();
test_add_volatile<int>();
test_add_volatile<int[3]>();
test_add_volatile<int&>();
test_add_volatile<const int&>();
test_add_volatile<int*>();
test_add_volatile<const int*>();
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// add_volatile + +#include <type_traits> + +template <class T, class U> +void test_add_volatile_imp() +{ + static_assert((std::is_same<typename std::add_volatile<T>::type, volatile U>::value), ""); +} + +template <class T> +void test_add_volatile() +{ + test_add_volatile_imp<T, volatile T>(); + test_add_volatile_imp<const T, const volatile T>(); + test_add_volatile_imp<volatile T, volatile T>(); + test_add_volatile_imp<const volatile T, const volatile T>(); +} + +int main() +{ + test_add_volatile<void>(); + test_add_volatile<int>(); + test_add_volatile<int[3]>(); + test_add_volatile<int&>(); + test_add_volatile<const int&>(); + test_add_volatile<int*>(); + test_add_volatile<const int*>(); +} diff --git a/libcxx/test/utilities/meta/meta.trans/meta.trans.cv/remove_const.pass.cpp b/libcxx/test/utilities/meta/meta.trans/meta.trans.cv/remove_const.pass.cpp index 4ecfcb8930d..f49a2b7092a 100644 --- a/libcxx/test/utilities/meta/meta.trans/meta.trans.cv/remove_const.pass.cpp +++ b/libcxx/test/utilities/meta/meta.trans/meta.trans.cv/remove_const.pass.cpp @@ -1 +1,40 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// type_traits
// remove_const
#include <type_traits>
template <class T, class U>
void test_remove_const_imp()
{
static_assert((std::is_same<typename std::remove_const<T>::type, U>::value), "");
}
template <class T>
void test_remove_const()
{
test_remove_const_imp<T, T>();
test_remove_const_imp<const T, T>();
test_remove_const_imp<volatile T, volatile T>();
test_remove_const_imp<const volatile T, volatile T>();
}
int main()
{
test_remove_const<void>();
test_remove_const<int>();
test_remove_const<int[3]>();
test_remove_const<int&>();
test_remove_const<const int&>();
test_remove_const<int*>();
test_remove_const<const int*>();
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// remove_const + +#include <type_traits> + +template <class T, class U> +void test_remove_const_imp() +{ + static_assert((std::is_same<typename std::remove_const<T>::type, U>::value), ""); +} + +template <class T> +void test_remove_const() +{ + test_remove_const_imp<T, T>(); + test_remove_const_imp<const T, T>(); + test_remove_const_imp<volatile T, volatile T>(); + test_remove_const_imp<const volatile T, volatile T>(); +} + +int main() +{ + test_remove_const<void>(); + test_remove_const<int>(); + test_remove_const<int[3]>(); + test_remove_const<int&>(); + test_remove_const<const int&>(); + test_remove_const<int*>(); + test_remove_const<const int*>(); +} diff --git a/libcxx/test/utilities/meta/meta.trans/meta.trans.cv/remove_cv.pass.cpp b/libcxx/test/utilities/meta/meta.trans/meta.trans.cv/remove_cv.pass.cpp index fc5b36f4f68..137e093de30 100644 --- a/libcxx/test/utilities/meta/meta.trans/meta.trans.cv/remove_cv.pass.cpp +++ b/libcxx/test/utilities/meta/meta.trans/meta.trans.cv/remove_cv.pass.cpp @@ -1 +1,40 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// type_traits
// remove_cv
#include <type_traits>
template <class T, class U>
void test_remove_cv_imp()
{
static_assert((std::is_same<typename std::remove_cv<T>::type, U>::value), "");
}
template <class T>
void test_remove_cv()
{
test_remove_cv_imp<T, T>();
test_remove_cv_imp<const T, T>();
test_remove_cv_imp<volatile T, T>();
test_remove_cv_imp<const volatile T, T>();
}
int main()
{
test_remove_cv<void>();
test_remove_cv<int>();
test_remove_cv<int[3]>();
test_remove_cv<int&>();
test_remove_cv<const int&>();
test_remove_cv<int*>();
test_remove_cv<const int*>();
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// remove_cv + +#include <type_traits> + +template <class T, class U> +void test_remove_cv_imp() +{ + static_assert((std::is_same<typename std::remove_cv<T>::type, U>::value), ""); +} + +template <class T> +void test_remove_cv() +{ + test_remove_cv_imp<T, T>(); + test_remove_cv_imp<const T, T>(); + test_remove_cv_imp<volatile T, T>(); + test_remove_cv_imp<const volatile T, T>(); +} + +int main() +{ + test_remove_cv<void>(); + test_remove_cv<int>(); + test_remove_cv<int[3]>(); + test_remove_cv<int&>(); + test_remove_cv<const int&>(); + test_remove_cv<int*>(); + test_remove_cv<const int*>(); +} diff --git a/libcxx/test/utilities/meta/meta.trans/meta.trans.cv/remove_volatile.pass.cpp b/libcxx/test/utilities/meta/meta.trans/meta.trans.cv/remove_volatile.pass.cpp index 85d65213c08..7c829433488 100644 --- a/libcxx/test/utilities/meta/meta.trans/meta.trans.cv/remove_volatile.pass.cpp +++ b/libcxx/test/utilities/meta/meta.trans/meta.trans.cv/remove_volatile.pass.cpp @@ -1 +1,40 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// type_traits
// remove_volatile
#include <type_traits>
template <class T, class U>
void test_remove_volatile_imp()
{
static_assert((std::is_same<typename std::remove_volatile<T>::type, U>::value), "");
}
template <class T>
void test_remove_volatile()
{
test_remove_volatile_imp<T, T>();
test_remove_volatile_imp<const T, const T>();
test_remove_volatile_imp<volatile T, T>();
test_remove_volatile_imp<const volatile T, const T>();
}
int main()
{
test_remove_volatile<void>();
test_remove_volatile<int>();
test_remove_volatile<int[3]>();
test_remove_volatile<int&>();
test_remove_volatile<const int&>();
test_remove_volatile<int*>();
test_remove_volatile<volatile int*>();
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// remove_volatile + +#include <type_traits> + +template <class T, class U> +void test_remove_volatile_imp() +{ + static_assert((std::is_same<typename std::remove_volatile<T>::type, U>::value), ""); +} + +template <class T> +void test_remove_volatile() +{ + test_remove_volatile_imp<T, T>(); + test_remove_volatile_imp<const T, const T>(); + test_remove_volatile_imp<volatile T, T>(); + test_remove_volatile_imp<const volatile T, const T>(); +} + +int main() +{ + test_remove_volatile<void>(); + test_remove_volatile<int>(); + test_remove_volatile<int[3]>(); + test_remove_volatile<int&>(); + test_remove_volatile<const int&>(); + test_remove_volatile<int*>(); + test_remove_volatile<volatile int*>(); +} diff --git a/libcxx/test/utilities/meta/meta.trans/meta.trans.other/aligned_storage.pass.cpp b/libcxx/test/utilities/meta/meta.trans/meta.trans.other/aligned_storage.pass.cpp index 58be6e98024..55153de8efb 100644 --- a/libcxx/test/utilities/meta/meta.trans/meta.trans.other/aligned_storage.pass.cpp +++ b/libcxx/test/utilities/meta/meta.trans/meta.trans.other/aligned_storage.pass.cpp @@ -1 +1,123 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// type_traits
// aligned_storage
#include <type_traits>
int main()
{
{
typedef std::aligned_storage<10, 1 >::type T1;
static_assert(std::alignment_of<T1>::value == 1, "");
static_assert(sizeof(T1) == 10, "");
}
{
typedef std::aligned_storage<10, 2 >::type T1;
static_assert(std::alignment_of<T1>::value == 2, "");
static_assert(sizeof(T1) == 10, "");
}
{
typedef std::aligned_storage<10, 4 >::type T1;
static_assert(std::alignment_of<T1>::value == 4, "");
static_assert(sizeof(T1) == 12, "");
}
{
typedef std::aligned_storage<10, 8 >::type T1;
static_assert(std::alignment_of<T1>::value == 8, "");
static_assert(sizeof(T1) == 16, "");
}
{
typedef std::aligned_storage<10, 16 >::type T1;
static_assert(std::alignment_of<T1>::value == 16, "");
static_assert(sizeof(T1) == 16, "");
}
{
typedef std::aligned_storage<10, 32 >::type T1;
static_assert(std::alignment_of<T1>::value == 32, "");
static_assert(sizeof(T1) == 32, "");
}
{
typedef std::aligned_storage<20, 32 >::type T1;
static_assert(std::alignment_of<T1>::value == 32, "");
static_assert(sizeof(T1) == 32, "");
}
{
typedef std::aligned_storage<40, 32 >::type T1;
static_assert(std::alignment_of<T1>::value == 32, "");
static_assert(sizeof(T1) == 64, "");
}
{
typedef std::aligned_storage<12, 16 >::type T1;
static_assert(std::alignment_of<T1>::value == 16, "");
static_assert(sizeof(T1) == 16, "");
}
{
typedef std::aligned_storage<1>::type T1;
static_assert(std::alignment_of<T1>::value == 1, "");
static_assert(sizeof(T1) == 1, "");
}
{
typedef std::aligned_storage<2>::type T1;
static_assert(std::alignment_of<T1>::value == 2, "");
static_assert(sizeof(T1) == 2, "");
}
{
typedef std::aligned_storage<3>::type T1;
static_assert(std::alignment_of<T1>::value == 2, "");
static_assert(sizeof(T1) == 4, "");
}
{
typedef std::aligned_storage<4>::type T1;
static_assert(std::alignment_of<T1>::value == 4, "");
static_assert(sizeof(T1) == 4, "");
}
{
typedef std::aligned_storage<5>::type T1;
static_assert(std::alignment_of<T1>::value == 4, "");
static_assert(sizeof(T1) == 8, "");
}
{
typedef std::aligned_storage<7>::type T1;
static_assert(std::alignment_of<T1>::value == 4, "");
static_assert(sizeof(T1) == 8, "");
}
{
typedef std::aligned_storage<8>::type T1;
static_assert(std::alignment_of<T1>::value == (sizeof(long) == 4 ? 4 : 8), "");
static_assert(sizeof(T1) == 8, "");
}
{
typedef std::aligned_storage<9>::type T1;
static_assert(std::alignment_of<T1>::value == (sizeof(long) == 4 ? 4 : 8), "");
static_assert(sizeof(T1) == (sizeof(long) == 4 ? 12 : 16), "");
}
{
typedef std::aligned_storage<15>::type T1;
static_assert(std::alignment_of<T1>::value == (sizeof(long) == 4 ? 4 : 8), "");
static_assert(sizeof(T1) == 16, "");
}
{
typedef std::aligned_storage<16>::type T1;
static_assert(std::alignment_of<T1>::value == 16, "");
static_assert(sizeof(T1) == 16, "");
}
{
typedef std::aligned_storage<17>::type T1;
static_assert(std::alignment_of<T1>::value == 16, "");
static_assert(sizeof(T1) == 32, "");
}
{
typedef std::aligned_storage<10>::type T1;
static_assert(std::alignment_of<T1>::value == (sizeof(long) == 4 ? 4 : 8), "");
static_assert(sizeof(T1) == (sizeof(long) == 4 ? 12 : 16), "");
}
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// aligned_storage + +#include <type_traits> + +int main() +{ + { + typedef std::aligned_storage<10, 1 >::type T1; + static_assert(std::alignment_of<T1>::value == 1, ""); + static_assert(sizeof(T1) == 10, ""); + } + { + typedef std::aligned_storage<10, 2 >::type T1; + static_assert(std::alignment_of<T1>::value == 2, ""); + static_assert(sizeof(T1) == 10, ""); + } + { + typedef std::aligned_storage<10, 4 >::type T1; + static_assert(std::alignment_of<T1>::value == 4, ""); + static_assert(sizeof(T1) == 12, ""); + } + { + typedef std::aligned_storage<10, 8 >::type T1; + static_assert(std::alignment_of<T1>::value == 8, ""); + static_assert(sizeof(T1) == 16, ""); + } + { + typedef std::aligned_storage<10, 16 >::type T1; + static_assert(std::alignment_of<T1>::value == 16, ""); + static_assert(sizeof(T1) == 16, ""); + } + { + typedef std::aligned_storage<10, 32 >::type T1; + static_assert(std::alignment_of<T1>::value == 32, ""); + static_assert(sizeof(T1) == 32, ""); + } + { + typedef std::aligned_storage<20, 32 >::type T1; + static_assert(std::alignment_of<T1>::value == 32, ""); + static_assert(sizeof(T1) == 32, ""); + } + { + typedef std::aligned_storage<40, 32 >::type T1; + static_assert(std::alignment_of<T1>::value == 32, ""); + static_assert(sizeof(T1) == 64, ""); + } + { + typedef std::aligned_storage<12, 16 >::type T1; + static_assert(std::alignment_of<T1>::value == 16, ""); + static_assert(sizeof(T1) == 16, ""); + } + { + typedef std::aligned_storage<1>::type T1; + static_assert(std::alignment_of<T1>::value == 1, ""); + static_assert(sizeof(T1) == 1, ""); + } + { + typedef std::aligned_storage<2>::type T1; + static_assert(std::alignment_of<T1>::value == 2, ""); + static_assert(sizeof(T1) == 2, ""); + } + { + typedef std::aligned_storage<3>::type T1; + static_assert(std::alignment_of<T1>::value == 2, ""); + static_assert(sizeof(T1) == 4, ""); + } + { + typedef std::aligned_storage<4>::type T1; + static_assert(std::alignment_of<T1>::value == 4, ""); + static_assert(sizeof(T1) == 4, ""); + } + { + typedef std::aligned_storage<5>::type T1; + static_assert(std::alignment_of<T1>::value == 4, ""); + static_assert(sizeof(T1) == 8, ""); + } + { + typedef std::aligned_storage<7>::type T1; + static_assert(std::alignment_of<T1>::value == 4, ""); + static_assert(sizeof(T1) == 8, ""); + } + { + typedef std::aligned_storage<8>::type T1; + static_assert(std::alignment_of<T1>::value == (sizeof(long) == 4 ? 4 : 8), ""); + static_assert(sizeof(T1) == 8, ""); + } + { + typedef std::aligned_storage<9>::type T1; + static_assert(std::alignment_of<T1>::value == (sizeof(long) == 4 ? 4 : 8), ""); + static_assert(sizeof(T1) == (sizeof(long) == 4 ? 12 : 16), ""); + } + { + typedef std::aligned_storage<15>::type T1; + static_assert(std::alignment_of<T1>::value == (sizeof(long) == 4 ? 4 : 8), ""); + static_assert(sizeof(T1) == 16, ""); + } + { + typedef std::aligned_storage<16>::type T1; + static_assert(std::alignment_of<T1>::value == 16, ""); + static_assert(sizeof(T1) == 16, ""); + } + { + typedef std::aligned_storage<17>::type T1; + static_assert(std::alignment_of<T1>::value == 16, ""); + static_assert(sizeof(T1) == 32, ""); + } + { + typedef std::aligned_storage<10>::type T1; + static_assert(std::alignment_of<T1>::value == (sizeof(long) == 4 ? 4 : 8), ""); + static_assert(sizeof(T1) == (sizeof(long) == 4 ? 12 : 16), ""); + } +} diff --git a/libcxx/test/utilities/meta/meta.trans/meta.trans.other/common_type.pass.cpp b/libcxx/test/utilities/meta/meta.trans/meta.trans.other/common_type.pass.cpp index 460f734a7b2..cc9e6a9d120 100644 --- a/libcxx/test/utilities/meta/meta.trans/meta.trans.other/common_type.pass.cpp +++ b/libcxx/test/utilities/meta/meta.trans/meta.trans.other/common_type.pass.cpp @@ -1 +1,26 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// type_traits
// common_type
#include <type_traits>
int main()
{
static_assert((std::is_same<std::common_type<int>::type, int>::value), "");
static_assert((std::is_same<std::common_type<char>::type, char>::value), "");
static_assert((std::is_same<std::common_type<double, char>::type, double>::value), "");
static_assert((std::is_same<std::common_type<short, char>::type, int>::value), "");
static_assert((std::is_same<std::common_type<double, char, long long>::type, double>::value), "");
static_assert((std::is_same<std::common_type<unsigned, char, long long>::type, long long>::value), "");
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// common_type + +#include <type_traits> + +int main() +{ + static_assert((std::is_same<std::common_type<int>::type, int>::value), ""); + static_assert((std::is_same<std::common_type<char>::type, char>::value), ""); + + static_assert((std::is_same<std::common_type<double, char>::type, double>::value), ""); + static_assert((std::is_same<std::common_type<short, char>::type, int>::value), ""); + + static_assert((std::is_same<std::common_type<double, char, long long>::type, double>::value), ""); + static_assert((std::is_same<std::common_type<unsigned, char, long long>::type, long long>::value), ""); +} diff --git a/libcxx/test/utilities/meta/meta.trans/meta.trans.other/conditional.pass.cpp b/libcxx/test/utilities/meta/meta.trans/meta.trans.other/conditional.pass.cpp index c6317037a02..575814859f2 100644 --- a/libcxx/test/utilities/meta/meta.trans/meta.trans.other/conditional.pass.cpp +++ b/libcxx/test/utilities/meta/meta.trans/meta.trans.other/conditional.pass.cpp @@ -1 +1,20 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// type_traits
// conditional
#include <type_traits>
int main()
{
static_assert((std::is_same<std::conditional<true, char, int>::type, char>::value), "");
static_assert((std::is_same<std::conditional<false, char, int>::type, int>::value), "");
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// conditional + +#include <type_traits> + +int main() +{ + static_assert((std::is_same<std::conditional<true, char, int>::type, char>::value), ""); + static_assert((std::is_same<std::conditional<false, char, int>::type, int>::value), ""); +} diff --git a/libcxx/test/utilities/meta/meta.trans/meta.trans.other/decay.pass.cpp b/libcxx/test/utilities/meta/meta.trans/meta.trans.other/decay.pass.cpp index 6ed6da8f804..a1cc8ec18e6 100644 --- a/libcxx/test/utilities/meta/meta.trans/meta.trans.other/decay.pass.cpp +++ b/libcxx/test/utilities/meta/meta.trans/meta.trans.other/decay.pass.cpp @@ -1 +1,31 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// type_traits
// decay
#include <type_traits>
template <class T, class U>
void test_decay()
{
static_assert((std::is_same<typename std::decay<T>::type, U>::value), "");
}
int main()
{
test_decay<void, void>();
test_decay<int, int>();
test_decay<const volatile int, int>();
test_decay<int*, int*>();
test_decay<int[3], int*>();
test_decay<const int[3], const int*>();
test_decay<void(), void (*)()>();
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// decay + +#include <type_traits> + +template <class T, class U> +void test_decay() +{ + static_assert((std::is_same<typename std::decay<T>::type, U>::value), ""); +} + +int main() +{ + test_decay<void, void>(); + test_decay<int, int>(); + test_decay<const volatile int, int>(); + test_decay<int*, int*>(); + test_decay<int[3], int*>(); + test_decay<const int[3], const int*>(); + test_decay<void(), void (*)()>(); +} diff --git a/libcxx/test/utilities/meta/meta.trans/meta.trans.other/enable_if.fail.cpp b/libcxx/test/utilities/meta/meta.trans/meta.trans.other/enable_if.fail.cpp index c4d27dc6b8e..d3a37dad10e 100644 --- a/libcxx/test/utilities/meta/meta.trans/meta.trans.other/enable_if.fail.cpp +++ b/libcxx/test/utilities/meta/meta.trans/meta.trans.other/enable_if.fail.cpp @@ -1 +1,19 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// type_traits
// enable_if
#include <type_traits>
int main()
{
typedef std::enable_if<false>::type A;
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// enable_if + +#include <type_traits> + +int main() +{ + typedef std::enable_if<false>::type A; +} diff --git a/libcxx/test/utilities/meta/meta.trans/meta.trans.other/enable_if.pass.cpp b/libcxx/test/utilities/meta/meta.trans/meta.trans.other/enable_if.pass.cpp index 7cfdeeecfcb..f39719e2594 100644 --- a/libcxx/test/utilities/meta/meta.trans/meta.trans.other/enable_if.pass.cpp +++ b/libcxx/test/utilities/meta/meta.trans/meta.trans.other/enable_if.pass.cpp @@ -1 +1,20 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// type_traits
// enable_if
#include <type_traits>
int main()
{
static_assert((std::is_same<std::enable_if<true>::type, void>::value), "");
static_assert((std::is_same<std::enable_if<true, int>::type, int>::value), "");
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// enable_if + +#include <type_traits> + +int main() +{ + static_assert((std::is_same<std::enable_if<true>::type, void>::value), ""); + static_assert((std::is_same<std::enable_if<true, int>::type, int>::value), ""); +} diff --git a/libcxx/test/utilities/meta/meta.trans/meta.trans.other/result_of.pass.cpp b/libcxx/test/utilities/meta/meta.trans/meta.trans.other/result_of.pass.cpp index b1468de648a..b18b30b621b 100644 --- a/libcxx/test/utilities/meta/meta.trans/meta.trans.other/result_of.pass.cpp +++ b/libcxx/test/utilities/meta/meta.trans/meta.trans.other/result_of.pass.cpp @@ -1 +1,39 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <functional>
// result_of<Fn(ArgTypes...)>
#include <type_traits>
#include <memory>
typedef bool (&PF1)();
typedef short (*PF2)(long);
struct S
{
operator PF2() const;
double operator()(char, int&);
void calc(long) const;
char data_;
};
typedef void (S::*PMS)(long) const;
typedef char S::*PMD;
int main()
{
static_assert((std::is_same<std::result_of<S(int)>::type, short>::value), "Error!");
static_assert((std::is_same<std::result_of<S&(unsigned char, int&)>::type, double>::value), "Error!");
static_assert((std::is_same<std::result_of<PF1()>::type, bool>::value), "Error!");
// static_assert(std::is_same<std::result_of<PMS(std::unique_ptr<S>, int)>::type, void>::value, "Error!");
// static_assert(std::is_same<std::result_of<PMD(S)>::type, char&&>::value, "Error!");
// static_assert(std::is_same<std::result_of<PMD(const S*)>::type, const char&>::value, "Error!");
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// result_of<Fn(ArgTypes...)> + +#include <type_traits> +#include <memory> + +typedef bool (&PF1)(); +typedef short (*PF2)(long); + +struct S +{ + operator PF2() const; + double operator()(char, int&); + void calc(long) const; + char data_; +}; + +typedef void (S::*PMS)(long) const; +typedef char S::*PMD; + +int main() +{ + static_assert((std::is_same<std::result_of<S(int)>::type, short>::value), "Error!"); + static_assert((std::is_same<std::result_of<S&(unsigned char, int&)>::type, double>::value), "Error!"); + static_assert((std::is_same<std::result_of<PF1()>::type, bool>::value), "Error!"); +// static_assert(std::is_same<std::result_of<PMS(std::unique_ptr<S>, int)>::type, void>::value, "Error!"); +// static_assert(std::is_same<std::result_of<PMD(S)>::type, char&&>::value, "Error!"); +// static_assert(std::is_same<std::result_of<PMD(const S*)>::type, const char&>::value, "Error!"); +} diff --git a/libcxx/test/utilities/meta/meta.trans/meta.trans.other/underlying_type.pass.cpp b/libcxx/test/utilities/meta/meta.trans/meta.trans.other/underlying_type.pass.cpp index 128ca05adff..ba2b2bac724 100644 --- a/libcxx/test/utilities/meta/meta.trans/meta.trans.other/underlying_type.pass.cpp +++ b/libcxx/test/utilities/meta/meta.trans/meta.trans.other/underlying_type.pass.cpp @@ -1 +1,19 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// type_traits
// underlying_type
#include <type_traits>
int main()
{
#error underlying_type is not implemented
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// underlying_type + +#include <type_traits> + +int main() +{ +#error underlying_type is not implemented +} diff --git a/libcxx/test/utilities/meta/meta.trans/meta.trans.ptr/add_pointer.pass.cpp b/libcxx/test/utilities/meta/meta.trans/meta.trans.ptr/add_pointer.pass.cpp index ad43c439916..d601e85c184 100644 --- a/libcxx/test/utilities/meta/meta.trans/meta.trans.ptr/add_pointer.pass.cpp +++ b/libcxx/test/utilities/meta/meta.trans/meta.trans.ptr/add_pointer.pass.cpp @@ -1 +1,31 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// type_traits
// add_pointer
#include <type_traits>
template <class T, class U>
void test_add_pointer()
{
static_assert((std::is_same<typename std::add_pointer<T>::type, U>::value), "");
}
int main()
{
test_add_pointer<void, void*>();
test_add_pointer<int, int*>();
test_add_pointer<int[3], int(*)[3]>();
test_add_pointer<int&, int*>();
test_add_pointer<const int&, const int*>();
test_add_pointer<int*, int**>();
test_add_pointer<const int*, const int**>();
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// add_pointer + +#include <type_traits> + +template <class T, class U> +void test_add_pointer() +{ + static_assert((std::is_same<typename std::add_pointer<T>::type, U>::value), ""); +} + +int main() +{ + test_add_pointer<void, void*>(); + test_add_pointer<int, int*>(); + test_add_pointer<int[3], int(*)[3]>(); + test_add_pointer<int&, int*>(); + test_add_pointer<const int&, const int*>(); + test_add_pointer<int*, int**>(); + test_add_pointer<const int*, const int**>(); +} diff --git a/libcxx/test/utilities/meta/meta.trans/meta.trans.ptr/remove_pointer.pass.cpp b/libcxx/test/utilities/meta/meta.trans/meta.trans.ptr/remove_pointer.pass.cpp index 4b1b903e5cd..5156afc714b 100644 --- a/libcxx/test/utilities/meta/meta.trans/meta.trans.ptr/remove_pointer.pass.cpp +++ b/libcxx/test/utilities/meta/meta.trans/meta.trans.ptr/remove_pointer.pass.cpp @@ -1 +1,40 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// type_traits
// remove_pointer
#include <type_traits>
template <class T, class U>
void test_remove_pointer()
{
static_assert((std::is_same<typename std::remove_pointer<T>::type, U>::value), "");
}
int main()
{
test_remove_pointer<void, void>();
test_remove_pointer<int, int>();
test_remove_pointer<int[3], int[3]>();
test_remove_pointer<int*, int>();
test_remove_pointer<const int*, const int>();
test_remove_pointer<int**, int*>();
test_remove_pointer<int** const, int*>();
test_remove_pointer<int*const * , int* const>();
test_remove_pointer<const int** , const int*>();
test_remove_pointer<int&, int&>();
test_remove_pointer<const int&, const int&>();
test_remove_pointer<int(&)[3], int(&)[3]>();
test_remove_pointer<int(*)[3], int[3]>();
test_remove_pointer<int*&, int*&>();
test_remove_pointer<const int*&, const int*&>();
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// remove_pointer + +#include <type_traits> + +template <class T, class U> +void test_remove_pointer() +{ + static_assert((std::is_same<typename std::remove_pointer<T>::type, U>::value), ""); +} + +int main() +{ + test_remove_pointer<void, void>(); + test_remove_pointer<int, int>(); + test_remove_pointer<int[3], int[3]>(); + test_remove_pointer<int*, int>(); + test_remove_pointer<const int*, const int>(); + test_remove_pointer<int**, int*>(); + test_remove_pointer<int** const, int*>(); + test_remove_pointer<int*const * , int* const>(); + test_remove_pointer<const int** , const int*>(); + + test_remove_pointer<int&, int&>(); + test_remove_pointer<const int&, const int&>(); + test_remove_pointer<int(&)[3], int(&)[3]>(); + test_remove_pointer<int(*)[3], int[3]>(); + test_remove_pointer<int*&, int*&>(); + test_remove_pointer<const int*&, const int*&>(); +} diff --git a/libcxx/test/utilities/meta/meta.trans/meta.trans.ref/add_lvalue_ref.pass.cpp b/libcxx/test/utilities/meta/meta.trans/meta.trans.ref/add_lvalue_ref.pass.cpp index 5dfea669906..3bb92fc81e1 100644 --- a/libcxx/test/utilities/meta/meta.trans/meta.trans.ref/add_lvalue_ref.pass.cpp +++ b/libcxx/test/utilities/meta/meta.trans/meta.trans.ref/add_lvalue_ref.pass.cpp @@ -1 +1,31 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// type_traits
// add_lvalue_reference
#include <type_traits>
template <class T, class U>
void test_add_lvalue_reference()
{
static_assert((std::is_same<typename std::add_lvalue_reference<T>::type, U>::value), "");
}
int main()
{
test_add_lvalue_reference<void, void>();
test_add_lvalue_reference<int, int&>();
test_add_lvalue_reference<int[3], int(&)[3]>();
test_add_lvalue_reference<int&, int&>();
test_add_lvalue_reference<const int&, const int&>();
test_add_lvalue_reference<int*, int*&>();
test_add_lvalue_reference<const int*, const int*&>();
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// add_lvalue_reference + +#include <type_traits> + +template <class T, class U> +void test_add_lvalue_reference() +{ + static_assert((std::is_same<typename std::add_lvalue_reference<T>::type, U>::value), ""); +} + +int main() +{ + test_add_lvalue_reference<void, void>(); + test_add_lvalue_reference<int, int&>(); + test_add_lvalue_reference<int[3], int(&)[3]>(); + test_add_lvalue_reference<int&, int&>(); + test_add_lvalue_reference<const int&, const int&>(); + test_add_lvalue_reference<int*, int*&>(); + test_add_lvalue_reference<const int*, const int*&>(); +} diff --git a/libcxx/test/utilities/meta/meta.trans/meta.trans.ref/add_rvalue_ref.pass.cpp b/libcxx/test/utilities/meta/meta.trans/meta.trans.ref/add_rvalue_ref.pass.cpp index 0a86b53e5e1..cbfb7f4d75c 100644 --- a/libcxx/test/utilities/meta/meta.trans/meta.trans.ref/add_rvalue_ref.pass.cpp +++ b/libcxx/test/utilities/meta/meta.trans/meta.trans.ref/add_rvalue_ref.pass.cpp @@ -1 +1,37 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// type_traits
// add_rvalue_reference
#include <type_traits>
#ifdef _LIBCPP_MOVE
template <class T, class U>
void test_add_rvalue_reference()
{
static_assert((std::is_same<typename std::add_rvalue_reference<T>::type, U>::value), "");
}
#endif
int main()
{
#ifdef _LIBCPP_MOVE
test_add_rvalue_reference<void, void>();
test_add_rvalue_reference<int, int&&>();
test_add_rvalue_reference<int[3], int(&&)[3]>();
test_add_rvalue_reference<int&, int&>();
test_add_rvalue_reference<const int&, const int&>();
test_add_rvalue_reference<int*, int*&&>();
test_add_rvalue_reference<const int*, const int*&&>();
#endif
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// add_rvalue_reference + +#include <type_traits> + +#ifdef _LIBCPP_MOVE + +template <class T, class U> +void test_add_rvalue_reference() +{ + static_assert((std::is_same<typename std::add_rvalue_reference<T>::type, U>::value), ""); +} + +#endif // _LIBCPP_MOVE + +int main() +{ +#ifdef _LIBCPP_MOVE + test_add_rvalue_reference<void, void>(); + test_add_rvalue_reference<int, int&&>(); + test_add_rvalue_reference<int[3], int(&&)[3]>(); + test_add_rvalue_reference<int&, int&>(); + test_add_rvalue_reference<const int&, const int&>(); + test_add_rvalue_reference<int*, int*&&>(); + test_add_rvalue_reference<const int*, const int*&&>(); +#endif // _LIBCPP_MOVE +} diff --git a/libcxx/test/utilities/meta/meta.trans/meta.trans.ref/remove_ref.pass.cpp b/libcxx/test/utilities/meta/meta.trans/meta.trans.ref/remove_ref.pass.cpp index d36dd019b07..b42b0b504a3 100644 --- a/libcxx/test/utilities/meta/meta.trans/meta.trans.ref/remove_ref.pass.cpp +++ b/libcxx/test/utilities/meta/meta.trans/meta.trans.ref/remove_ref.pass.cpp @@ -1 +1,43 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// type_traits
// remove_reference
#include <type_traits>
template <class T, class U>
void test_remove_reference()
{
static_assert((std::is_same<typename std::remove_reference<T>::type, U>::value), "");
}
int main()
{
test_remove_reference<void, void>();
test_remove_reference<int, int>();
test_remove_reference<int[3], int[3]>();
test_remove_reference<int*, int*>();
test_remove_reference<const int*, const int*>();
test_remove_reference<int&, int>();
test_remove_reference<const int&, const int>();
test_remove_reference<int(&)[3], int[3]>();
test_remove_reference<int*&, int*>();
test_remove_reference<const int*&, const int*>();
#ifdef _LIBCPP_MOVE
test_remove_reference<int&&, int>();
test_remove_reference<const int&&, const int>();
test_remove_reference<int(&&)[3], int[3]>();
test_remove_reference<int*&&, int*>();
test_remove_reference<const int*&&, const int*>();
#endif
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// remove_reference + +#include <type_traits> + +template <class T, class U> +void test_remove_reference() +{ + static_assert((std::is_same<typename std::remove_reference<T>::type, U>::value), ""); +} + +int main() +{ + test_remove_reference<void, void>(); + test_remove_reference<int, int>(); + test_remove_reference<int[3], int[3]>(); + test_remove_reference<int*, int*>(); + test_remove_reference<const int*, const int*>(); + + test_remove_reference<int&, int>(); + test_remove_reference<const int&, const int>(); + test_remove_reference<int(&)[3], int[3]>(); + test_remove_reference<int*&, int*>(); + test_remove_reference<const int*&, const int*>(); + +#ifdef _LIBCPP_MOVE + test_remove_reference<int&&, int>(); + test_remove_reference<const int&&, const int>(); + test_remove_reference<int(&&)[3], int[3]>(); + test_remove_reference<int*&&, int*>(); + test_remove_reference<const int*&&, const int*>(); +#endif // _LIBCPP_MOVE +} diff --git a/libcxx/test/utilities/meta/meta.trans/meta.trans.sign/make_signed.pass.cpp b/libcxx/test/utilities/meta/meta.trans/meta.trans.sign/make_signed.pass.cpp index 3b87a835512..5d369daea49 100644 --- a/libcxx/test/utilities/meta/meta.trans/meta.trans.sign/make_signed.pass.cpp +++ b/libcxx/test/utilities/meta/meta.trans/meta.trans.sign/make_signed.pass.cpp @@ -1 +1,42 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// type_traits
// make_signed
#include <type_traits>
enum Enum {zero, one_};
enum BigEnum
{
bzero,
big = 0xFFFFFFFFFFFFFFFFULL
};
int main()
{
static_assert((std::is_same<std::make_signed<signed char>::type, signed char>::value), "");
static_assert((std::is_same<std::make_signed<unsigned char>::type, signed char>::value), "");
static_assert((std::is_same<std::make_signed<char>::type, signed char>::value), "");
static_assert((std::is_same<std::make_signed<short>::type, signed short>::value), "");
static_assert((std::is_same<std::make_signed<unsigned short>::type, signed short>::value), "");
static_assert((std::is_same<std::make_signed<int>::type, signed int>::value), "");
static_assert((std::is_same<std::make_signed<unsigned int>::type, signed int>::value), "");
static_assert((std::is_same<std::make_signed<long>::type, signed long>::value), "");
static_assert((std::is_same<std::make_signed<unsigned long>::type, long>::value), "");
static_assert((std::is_same<std::make_signed<long long>::type, signed long long>::value), "");
static_assert((std::is_same<std::make_signed<unsigned long long>::type, signed long long>::value), "");
static_assert((std::is_same<std::make_signed<wchar_t>::type, int>::value), "");
static_assert((std::is_same<std::make_signed<const wchar_t>::type, const int>::value), "");
static_assert((std::is_same<std::make_signed<const Enum>::type, const int>::value), "");
static_assert((std::is_same<std::make_signed<BigEnum>::type,
std::conditional<sizeof(long) == 4, long long, long>::type>::value), "");
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// make_signed + +#include <type_traits> + +enum Enum {zero, one_}; + +enum BigEnum +{ + bzero, + big = 0xFFFFFFFFFFFFFFFFULL +}; + +int main() +{ + static_assert((std::is_same<std::make_signed<signed char>::type, signed char>::value), ""); + static_assert((std::is_same<std::make_signed<unsigned char>::type, signed char>::value), ""); + static_assert((std::is_same<std::make_signed<char>::type, signed char>::value), ""); + static_assert((std::is_same<std::make_signed<short>::type, signed short>::value), ""); + static_assert((std::is_same<std::make_signed<unsigned short>::type, signed short>::value), ""); + static_assert((std::is_same<std::make_signed<int>::type, signed int>::value), ""); + static_assert((std::is_same<std::make_signed<unsigned int>::type, signed int>::value), ""); + static_assert((std::is_same<std::make_signed<long>::type, signed long>::value), ""); + static_assert((std::is_same<std::make_signed<unsigned long>::type, long>::value), ""); + static_assert((std::is_same<std::make_signed<long long>::type, signed long long>::value), ""); + static_assert((std::is_same<std::make_signed<unsigned long long>::type, signed long long>::value), ""); + static_assert((std::is_same<std::make_signed<wchar_t>::type, int>::value), ""); + static_assert((std::is_same<std::make_signed<const wchar_t>::type, const int>::value), ""); + static_assert((std::is_same<std::make_signed<const Enum>::type, const int>::value), ""); + static_assert((std::is_same<std::make_signed<BigEnum>::type, + std::conditional<sizeof(long) == 4, long long, long>::type>::value), ""); +} diff --git a/libcxx/test/utilities/meta/meta.trans/meta.trans.sign/make_unsigned.pass.cpp b/libcxx/test/utilities/meta/meta.trans/meta.trans.sign/make_unsigned.pass.cpp index d8bb4e33ef7..a029acb83ec 100644 --- a/libcxx/test/utilities/meta/meta.trans/meta.trans.sign/make_unsigned.pass.cpp +++ b/libcxx/test/utilities/meta/meta.trans/meta.trans.sign/make_unsigned.pass.cpp @@ -1 +1,42 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// type_traits
// make_unsigned
#include <type_traits>
enum Enum {zero, one_};
enum BigEnum
{
bzero,
big = 0xFFFFFFFFFFFFFFFFULL
};
int main()
{
static_assert((std::is_same<std::make_unsigned<signed char>::type, unsigned char>::value), "");
static_assert((std::is_same<std::make_unsigned<unsigned char>::type, unsigned char>::value), "");
static_assert((std::is_same<std::make_unsigned<char>::type, unsigned char>::value), "");
static_assert((std::is_same<std::make_unsigned<short>::type, unsigned short>::value), "");
static_assert((std::is_same<std::make_unsigned<unsigned short>::type, unsigned short>::value), "");
static_assert((std::is_same<std::make_unsigned<int>::type, unsigned int>::value), "");
static_assert((std::is_same<std::make_unsigned<unsigned int>::type, unsigned int>::value), "");
static_assert((std::is_same<std::make_unsigned<long>::type, unsigned long>::value), "");
static_assert((std::is_same<std::make_unsigned<unsigned long>::type, unsigned long>::value), "");
static_assert((std::is_same<std::make_unsigned<long long>::type, unsigned long long>::value), "");
static_assert((std::is_same<std::make_unsigned<unsigned long long>::type, unsigned long long>::value), "");
static_assert((std::is_same<std::make_unsigned<wchar_t>::type, unsigned int>::value), "");
static_assert((std::is_same<std::make_unsigned<const wchar_t>::type, const unsigned int>::value), "");
static_assert((std::is_same<std::make_unsigned<const Enum>::type, const unsigned int>::value), "");
static_assert((std::is_same<std::make_unsigned<BigEnum>::type,
std::conditional<sizeof(long) == 4, unsigned long long, unsigned long>::type>::value), "");
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// make_unsigned + +#include <type_traits> + +enum Enum {zero, one_}; + +enum BigEnum +{ + bzero, + big = 0xFFFFFFFFFFFFFFFFULL +}; + +int main() +{ + static_assert((std::is_same<std::make_unsigned<signed char>::type, unsigned char>::value), ""); + static_assert((std::is_same<std::make_unsigned<unsigned char>::type, unsigned char>::value), ""); + static_assert((std::is_same<std::make_unsigned<char>::type, unsigned char>::value), ""); + static_assert((std::is_same<std::make_unsigned<short>::type, unsigned short>::value), ""); + static_assert((std::is_same<std::make_unsigned<unsigned short>::type, unsigned short>::value), ""); + static_assert((std::is_same<std::make_unsigned<int>::type, unsigned int>::value), ""); + static_assert((std::is_same<std::make_unsigned<unsigned int>::type, unsigned int>::value), ""); + static_assert((std::is_same<std::make_unsigned<long>::type, unsigned long>::value), ""); + static_assert((std::is_same<std::make_unsigned<unsigned long>::type, unsigned long>::value), ""); + static_assert((std::is_same<std::make_unsigned<long long>::type, unsigned long long>::value), ""); + static_assert((std::is_same<std::make_unsigned<unsigned long long>::type, unsigned long long>::value), ""); + static_assert((std::is_same<std::make_unsigned<wchar_t>::type, unsigned int>::value), ""); + static_assert((std::is_same<std::make_unsigned<const wchar_t>::type, const unsigned int>::value), ""); + static_assert((std::is_same<std::make_unsigned<const Enum>::type, const unsigned int>::value), ""); + static_assert((std::is_same<std::make_unsigned<BigEnum>::type, + std::conditional<sizeof(long) == 4, unsigned long long, unsigned long>::type>::value), ""); +} diff --git a/libcxx/test/utilities/meta/meta.trans/nothing_to_do.pass.cpp b/libcxx/test/utilities/meta/meta.trans/nothing_to_do.pass.cpp index e8db90cbee0..b89f168e9c4 100644 --- a/libcxx/test/utilities/meta/meta.trans/nothing_to_do.pass.cpp +++ b/libcxx/test/utilities/meta/meta.trans/nothing_to_do.pass.cpp @@ -1 +1,12 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
int main()
{
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/libcxx/test/utilities/meta/meta.type.synop/nothing_to_do.pass.cpp b/libcxx/test/utilities/meta/meta.type.synop/nothing_to_do.pass.cpp index e8db90cbee0..b89f168e9c4 100644 --- a/libcxx/test/utilities/meta/meta.type.synop/nothing_to_do.pass.cpp +++ b/libcxx/test/utilities/meta/meta.type.synop/nothing_to_do.pass.cpp @@ -1 +1,12 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
int main()
{
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/libcxx/test/utilities/meta/meta.unary/meta.unary.cat/array.pass.cpp b/libcxx/test/utilities/meta/meta.unary/meta.unary.cat/array.pass.cpp index da1a68137d1..3eb16c215d5 100644 --- a/libcxx/test/utilities/meta/meta.unary/meta.unary.cat/array.pass.cpp +++ b/libcxx/test/utilities/meta/meta.unary/meta.unary.cat/array.pass.cpp @@ -1 +1,52 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// type_traits
// array
#include <type_traits>
template <class T>
void test_array_imp()
{
static_assert(!std::is_void<T>::value, "");
static_assert(!std::is_integral<T>::value, "");
static_assert(!std::is_floating_point<T>::value, "");
static_assert( std::is_array<T>::value, "");
static_assert(!std::is_pointer<T>::value, "");
static_assert(!std::is_lvalue_reference<T>::value, "");
static_assert(!std::is_rvalue_reference<T>::value, "");
static_assert(!std::is_member_object_pointer<T>::value, "");
static_assert(!std::is_member_function_pointer<T>::value, "");
static_assert(!std::is_enum<T>::value, "");
static_assert(!std::is_union<T>::value, "");
static_assert(!std::is_class<T>::value, "");
static_assert(!std::is_function<T>::value, "");
}
template <class T>
void test_array()
{
test_array_imp<T>();
test_array_imp<const T>();
test_array_imp<volatile T>();
test_array_imp<const volatile T>();
}
typedef char array[3];
typedef const char const_array[3];
typedef char incomplete_array[];
int main()
{
test_array<array>();
test_array<const_array>();
test_array<incomplete_array>();
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// array + +#include <type_traits> + +template <class T> +void test_array_imp() +{ + static_assert(!std::is_void<T>::value, ""); + static_assert(!std::is_integral<T>::value, ""); + static_assert(!std::is_floating_point<T>::value, ""); + static_assert( std::is_array<T>::value, ""); + static_assert(!std::is_pointer<T>::value, ""); + static_assert(!std::is_lvalue_reference<T>::value, ""); + static_assert(!std::is_rvalue_reference<T>::value, ""); + static_assert(!std::is_member_object_pointer<T>::value, ""); + static_assert(!std::is_member_function_pointer<T>::value, ""); + static_assert(!std::is_enum<T>::value, ""); + static_assert(!std::is_union<T>::value, ""); + static_assert(!std::is_class<T>::value, ""); + static_assert(!std::is_function<T>::value, ""); +} + +template <class T> +void test_array() +{ + test_array_imp<T>(); + test_array_imp<const T>(); + test_array_imp<volatile T>(); + test_array_imp<const volatile T>(); +} + +typedef char array[3]; +typedef const char const_array[3]; +typedef char incomplete_array[]; + +int main() +{ + test_array<array>(); + test_array<const_array>(); + test_array<incomplete_array>(); +} diff --git a/libcxx/test/utilities/meta/meta.unary/meta.unary.cat/class.pass.cpp b/libcxx/test/utilities/meta/meta.unary/meta.unary.cat/class.pass.cpp index fa604cf182e..3e6a9c08696 100644 --- a/libcxx/test/utilities/meta/meta.unary/meta.unary.cat/class.pass.cpp +++ b/libcxx/test/utilities/meta/meta.unary/meta.unary.cat/class.pass.cpp @@ -1 +1,52 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// type_traits
// class
#include <type_traits>
template <class T>
void test_class_imp()
{
static_assert(!std::is_void<T>::value, "");
static_assert(!std::is_integral<T>::value, "");
static_assert(!std::is_floating_point<T>::value, "");
static_assert(!std::is_array<T>::value, "");
static_assert(!std::is_pointer<T>::value, "");
static_assert(!std::is_lvalue_reference<T>::value, "");
static_assert(!std::is_rvalue_reference<T>::value, "");
static_assert(!std::is_member_object_pointer<T>::value, "");
static_assert(!std::is_member_function_pointer<T>::value, "");
static_assert(!std::is_enum<T>::value, "");
static_assert(!std::is_union<T>::value, "");
static_assert( std::is_class<T>::value, "");
static_assert(!std::is_function<T>::value, "");
}
template <class T>
void test_class()
{
test_class_imp<T>();
test_class_imp<const T>();
test_class_imp<volatile T>();
test_class_imp<const volatile T>();
}
class Class
{
int _;
double __;
};
int main()
{
test_class<Class>();
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// class + +#include <type_traits> + +template <class T> +void test_class_imp() +{ + static_assert(!std::is_void<T>::value, ""); + static_assert(!std::is_integral<T>::value, ""); + static_assert(!std::is_floating_point<T>::value, ""); + static_assert(!std::is_array<T>::value, ""); + static_assert(!std::is_pointer<T>::value, ""); + static_assert(!std::is_lvalue_reference<T>::value, ""); + static_assert(!std::is_rvalue_reference<T>::value, ""); + static_assert(!std::is_member_object_pointer<T>::value, ""); + static_assert(!std::is_member_function_pointer<T>::value, ""); + static_assert(!std::is_enum<T>::value, ""); + static_assert(!std::is_union<T>::value, ""); + static_assert( std::is_class<T>::value, ""); + static_assert(!std::is_function<T>::value, ""); +} + +template <class T> +void test_class() +{ + test_class_imp<T>(); + test_class_imp<const T>(); + test_class_imp<volatile T>(); + test_class_imp<const volatile T>(); +} + +class Class +{ + int _; + double __; +}; + +int main() +{ + test_class<Class>(); +} diff --git a/libcxx/test/utilities/meta/meta.unary/meta.unary.cat/enum.pass.cpp b/libcxx/test/utilities/meta/meta.unary/meta.unary.cat/enum.pass.cpp index b1a72f9f130..bdff0419fa8 100644 --- a/libcxx/test/utilities/meta/meta.unary/meta.unary.cat/enum.pass.cpp +++ b/libcxx/test/utilities/meta/meta.unary/meta.unary.cat/enum.pass.cpp @@ -1 +1,48 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// type_traits
// enum
#include <type_traits>
template <class T>
void test_enum_imp()
{
static_assert(!std::is_void<T>::value, "");
static_assert(!std::is_integral<T>::value, "");
static_assert(!std::is_floating_point<T>::value, "");
static_assert(!std::is_array<T>::value, "");
static_assert(!std::is_pointer<T>::value, "");
static_assert(!std::is_lvalue_reference<T>::value, "");
static_assert(!std::is_rvalue_reference<T>::value, "");
static_assert(!std::is_member_object_pointer<T>::value, "");
static_assert(!std::is_member_function_pointer<T>::value, "");
static_assert( std::is_enum<T>::value, "");
static_assert(!std::is_union<T>::value, "");
static_assert(!std::is_class<T>::value, "");
static_assert(!std::is_function<T>::value, "");
}
template <class T>
void test_enum()
{
test_enum_imp<T>();
test_enum_imp<const T>();
test_enum_imp<volatile T>();
test_enum_imp<const volatile T>();
}
enum Enum {zero, one};
int main()
{
test_enum<Enum>();
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// enum + +#include <type_traits> + +template <class T> +void test_enum_imp() +{ + static_assert(!std::is_void<T>::value, ""); + static_assert(!std::is_integral<T>::value, ""); + static_assert(!std::is_floating_point<T>::value, ""); + static_assert(!std::is_array<T>::value, ""); + static_assert(!std::is_pointer<T>::value, ""); + static_assert(!std::is_lvalue_reference<T>::value, ""); + static_assert(!std::is_rvalue_reference<T>::value, ""); + static_assert(!std::is_member_object_pointer<T>::value, ""); + static_assert(!std::is_member_function_pointer<T>::value, ""); + static_assert( std::is_enum<T>::value, ""); + static_assert(!std::is_union<T>::value, ""); + static_assert(!std::is_class<T>::value, ""); + static_assert(!std::is_function<T>::value, ""); +} + +template <class T> +void test_enum() +{ + test_enum_imp<T>(); + test_enum_imp<const T>(); + test_enum_imp<volatile T>(); + test_enum_imp<const volatile T>(); +} + +enum Enum {zero, one}; + +int main() +{ + test_enum<Enum>(); +} diff --git a/libcxx/test/utilities/meta/meta.unary/meta.unary.cat/floating_point.pass.cpp b/libcxx/test/utilities/meta/meta.unary/meta.unary.cat/floating_point.pass.cpp index bd5d03f449d..efff10aa52c 100644 --- a/libcxx/test/utilities/meta/meta.unary/meta.unary.cat/floating_point.pass.cpp +++ b/libcxx/test/utilities/meta/meta.unary/meta.unary.cat/floating_point.pass.cpp @@ -1 +1,48 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// type_traits
// floating_point
#include <type_traits>
template <class T>
void test_floating_point_imp()
{
static_assert(!std::is_void<T>::value, "");
static_assert(!std::is_integral<T>::value, "");
static_assert( std::is_floating_point<T>::value, "");
static_assert(!std::is_array<T>::value, "");
static_assert(!std::is_pointer<T>::value, "");
static_assert(!std::is_lvalue_reference<T>::value, "");
static_assert(!std::is_rvalue_reference<T>::value, "");
static_assert(!std::is_member_object_pointer<T>::value, "");
static_assert(!std::is_member_function_pointer<T>::value, "");
static_assert(!std::is_enum<T>::value, "");
static_assert(!std::is_union<T>::value, "");
static_assert(!std::is_class<T>::value, "");
static_assert(!std::is_function<T>::value, "");
}
template <class T>
void test_floating_point()
{
test_floating_point_imp<T>();
test_floating_point_imp<const T>();
test_floating_point_imp<volatile T>();
test_floating_point_imp<const volatile T>();
}
int main()
{
test_floating_point<float>();
test_floating_point<double>();
test_floating_point<long double>();
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// floating_point + +#include <type_traits> + +template <class T> +void test_floating_point_imp() +{ + static_assert(!std::is_void<T>::value, ""); + static_assert(!std::is_integral<T>::value, ""); + static_assert( std::is_floating_point<T>::value, ""); + static_assert(!std::is_array<T>::value, ""); + static_assert(!std::is_pointer<T>::value, ""); + static_assert(!std::is_lvalue_reference<T>::value, ""); + static_assert(!std::is_rvalue_reference<T>::value, ""); + static_assert(!std::is_member_object_pointer<T>::value, ""); + static_assert(!std::is_member_function_pointer<T>::value, ""); + static_assert(!std::is_enum<T>::value, ""); + static_assert(!std::is_union<T>::value, ""); + static_assert(!std::is_class<T>::value, ""); + static_assert(!std::is_function<T>::value, ""); +} + +template <class T> +void test_floating_point() +{ + test_floating_point_imp<T>(); + test_floating_point_imp<const T>(); + test_floating_point_imp<volatile T>(); + test_floating_point_imp<const volatile T>(); +} + +int main() +{ + test_floating_point<float>(); + test_floating_point<double>(); + test_floating_point<long double>(); +} diff --git a/libcxx/test/utilities/meta/meta.unary/meta.unary.cat/function.pass.cpp b/libcxx/test/utilities/meta/meta.unary/meta.unary.cat/function.pass.cpp index a3bab5b325a..ba5f5213f14 100644 --- a/libcxx/test/utilities/meta/meta.unary/meta.unary.cat/function.pass.cpp +++ b/libcxx/test/utilities/meta/meta.unary/meta.unary.cat/function.pass.cpp @@ -1 +1,49 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// type_traits
// function
#include <type_traits>
template <class T>
void test_function_imp()
{
static_assert(!std::is_void<T>::value, "");
static_assert(!std::is_integral<T>::value, "");
static_assert(!std::is_floating_point<T>::value, "");
static_assert(!std::is_array<T>::value, "");
static_assert(!std::is_pointer<T>::value, "");
static_assert(!std::is_lvalue_reference<T>::value, "");
static_assert(!std::is_rvalue_reference<T>::value, "");
static_assert(!std::is_member_object_pointer<T>::value, "");
static_assert(!std::is_member_function_pointer<T>::value, "");
static_assert(!std::is_enum<T>::value, "");
static_assert(!std::is_union<T>::value, "");
static_assert(!std::is_class<T>::value, "");
static_assert( std::is_function<T>::value, "");
}
template <class T>
void test_function()
{
test_function_imp<T>();
test_function_imp<const T>();
test_function_imp<volatile T>();
test_function_imp<const volatile T>();
}
int main()
{
test_function<void ()>();
test_function<void (int)>();
test_function<int (double)>();
test_function<int (double, char)>();
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// function + +#include <type_traits> + +template <class T> +void test_function_imp() +{ + static_assert(!std::is_void<T>::value, ""); + static_assert(!std::is_integral<T>::value, ""); + static_assert(!std::is_floating_point<T>::value, ""); + static_assert(!std::is_array<T>::value, ""); + static_assert(!std::is_pointer<T>::value, ""); + static_assert(!std::is_lvalue_reference<T>::value, ""); + static_assert(!std::is_rvalue_reference<T>::value, ""); + static_assert(!std::is_member_object_pointer<T>::value, ""); + static_assert(!std::is_member_function_pointer<T>::value, ""); + static_assert(!std::is_enum<T>::value, ""); + static_assert(!std::is_union<T>::value, ""); + static_assert(!std::is_class<T>::value, ""); + static_assert( std::is_function<T>::value, ""); +} + +template <class T> +void test_function() +{ + test_function_imp<T>(); + test_function_imp<const T>(); + test_function_imp<volatile T>(); + test_function_imp<const volatile T>(); +} + +int main() +{ + test_function<void ()>(); + test_function<void (int)>(); + test_function<int (double)>(); + test_function<int (double, char)>(); +} diff --git a/libcxx/test/utilities/meta/meta.unary/meta.unary.cat/integral.pass.cpp b/libcxx/test/utilities/meta/meta.unary/meta.unary.cat/integral.pass.cpp index a4c0cb427cf..ac300466729 100644 --- a/libcxx/test/utilities/meta/meta.unary/meta.unary.cat/integral.pass.cpp +++ b/libcxx/test/utilities/meta/meta.unary/meta.unary.cat/integral.pass.cpp @@ -1 +1,58 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// type_traits
// integral
#include <type_traits>
template <class T>
void test_integral_imp()
{
static_assert(!std::is_void<T>::value, "");
static_assert( std::is_integral<T>::value, "");
static_assert(!std::is_floating_point<T>::value, "");
static_assert(!std::is_array<T>::value, "");
static_assert(!std::is_pointer<T>::value, "");
static_assert(!std::is_lvalue_reference<T>::value, "");
static_assert(!std::is_rvalue_reference<T>::value, "");
static_assert(!std::is_member_object_pointer<T>::value, "");
static_assert(!std::is_member_function_pointer<T>::value, "");
static_assert(!std::is_enum<T>::value, "");
static_assert(!std::is_union<T>::value, "");
static_assert(!std::is_class<T>::value, "");
static_assert(!std::is_function<T>::value, "");
}
template <class T>
void test_integral()
{
test_integral_imp<T>();
test_integral_imp<const T>();
test_integral_imp<volatile T>();
test_integral_imp<const volatile T>();
}
int main()
{
test_integral<bool>();
test_integral<char>();
test_integral<signed char>();
test_integral<unsigned char>();
test_integral<wchar_t>();
test_integral<short>();
test_integral<unsigned short>();
test_integral<int>();
test_integral<unsigned int>();
test_integral<long>();
test_integral<unsigned long>();
test_integral<long long>();
test_integral<unsigned long long>();
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// integral + +#include <type_traits> + +template <class T> +void test_integral_imp() +{ + static_assert(!std::is_void<T>::value, ""); + static_assert( std::is_integral<T>::value, ""); + static_assert(!std::is_floating_point<T>::value, ""); + static_assert(!std::is_array<T>::value, ""); + static_assert(!std::is_pointer<T>::value, ""); + static_assert(!std::is_lvalue_reference<T>::value, ""); + static_assert(!std::is_rvalue_reference<T>::value, ""); + static_assert(!std::is_member_object_pointer<T>::value, ""); + static_assert(!std::is_member_function_pointer<T>::value, ""); + static_assert(!std::is_enum<T>::value, ""); + static_assert(!std::is_union<T>::value, ""); + static_assert(!std::is_class<T>::value, ""); + static_assert(!std::is_function<T>::value, ""); +} + +template <class T> +void test_integral() +{ + test_integral_imp<T>(); + test_integral_imp<const T>(); + test_integral_imp<volatile T>(); + test_integral_imp<const volatile T>(); +} + +int main() +{ + test_integral<bool>(); + test_integral<char>(); + test_integral<signed char>(); + test_integral<unsigned char>(); + test_integral<wchar_t>(); + test_integral<short>(); + test_integral<unsigned short>(); + test_integral<int>(); + test_integral<unsigned int>(); + test_integral<long>(); + test_integral<unsigned long>(); + test_integral<long long>(); + test_integral<unsigned long long>(); +} diff --git a/libcxx/test/utilities/meta/meta.unary/meta.unary.cat/lvalue_ref.pass.cpp b/libcxx/test/utilities/meta/meta.unary/meta.unary.cat/lvalue_ref.pass.cpp index 581a8aeb1c3..4b4dc2ed196 100644 --- a/libcxx/test/utilities/meta/meta.unary/meta.unary.cat/lvalue_ref.pass.cpp +++ b/libcxx/test/utilities/meta/meta.unary/meta.unary.cat/lvalue_ref.pass.cpp @@ -1 +1,38 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// type_traits
// lvalue_ref
#include <type_traits>
template <class T>
void test_lvalue_ref()
{
static_assert(!std::is_void<T>::value, "");
static_assert(!std::is_integral<T>::value, "");
static_assert(!std::is_floating_point<T>::value, "");
static_assert(!std::is_array<T>::value, "");
static_assert(!std::is_pointer<T>::value, "");
static_assert( std::is_lvalue_reference<T>::value, "");
static_assert(!std::is_rvalue_reference<T>::value, "");
static_assert(!std::is_member_object_pointer<T>::value, "");
static_assert(!std::is_member_function_pointer<T>::value, "");
static_assert(!std::is_enum<T>::value, "");
static_assert(!std::is_union<T>::value, "");
static_assert(!std::is_class<T>::value, "");
static_assert(!std::is_function<T>::value, "");
}
int main()
{
test_lvalue_ref<int&>();
test_lvalue_ref<const int&>();
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// lvalue_ref + +#include <type_traits> + +template <class T> +void test_lvalue_ref() +{ + static_assert(!std::is_void<T>::value, ""); + static_assert(!std::is_integral<T>::value, ""); + static_assert(!std::is_floating_point<T>::value, ""); + static_assert(!std::is_array<T>::value, ""); + static_assert(!std::is_pointer<T>::value, ""); + static_assert( std::is_lvalue_reference<T>::value, ""); + static_assert(!std::is_rvalue_reference<T>::value, ""); + static_assert(!std::is_member_object_pointer<T>::value, ""); + static_assert(!std::is_member_function_pointer<T>::value, ""); + static_assert(!std::is_enum<T>::value, ""); + static_assert(!std::is_union<T>::value, ""); + static_assert(!std::is_class<T>::value, ""); + static_assert(!std::is_function<T>::value, ""); +} + +int main() +{ + test_lvalue_ref<int&>(); + test_lvalue_ref<const int&>(); +} diff --git a/libcxx/test/utilities/meta/meta.unary/meta.unary.cat/member_function_pointer.pass.cpp b/libcxx/test/utilities/meta/meta.unary/meta.unary.cat/member_function_pointer.pass.cpp index 2a66fa0a967..914697400a9 100644 --- a/libcxx/test/utilities/meta/meta.unary/meta.unary.cat/member_function_pointer.pass.cpp +++ b/libcxx/test/utilities/meta/meta.unary/meta.unary.cat/member_function_pointer.pass.cpp @@ -1 +1,52 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// type_traits
// member_function_pointer
#include <type_traits>
template <class T>
void test_member_function_pointer_imp()
{
static_assert(!std::is_void<T>::value, "");
static_assert(!std::is_integral<T>::value, "");
static_assert(!std::is_floating_point<T>::value, "");
static_assert(!std::is_array<T>::value, "");
static_assert(!std::is_pointer<T>::value, "");
static_assert(!std::is_lvalue_reference<T>::value, "");
static_assert(!std::is_rvalue_reference<T>::value, "");
static_assert(!std::is_member_object_pointer<T>::value, "");
static_assert( std::is_member_function_pointer<T>::value, "");
static_assert(!std::is_enum<T>::value, "");
static_assert(!std::is_union<T>::value, "");
static_assert(!std::is_class<T>::value, "");
static_assert(!std::is_function<T>::value, "");
}
template <class T>
void test_member_function_pointer()
{
test_member_function_pointer_imp<T>();
test_member_function_pointer_imp<const T>();
test_member_function_pointer_imp<volatile T>();
test_member_function_pointer_imp<const volatile T>();
}
class Class
{
};
int main()
{
test_member_function_pointer<void (Class::*)()>();
test_member_function_pointer<void (Class::*)(int)>();
test_member_function_pointer<void (Class::*)(int, char)>();
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// member_function_pointer + +#include <type_traits> + +template <class T> +void test_member_function_pointer_imp() +{ + static_assert(!std::is_void<T>::value, ""); + static_assert(!std::is_integral<T>::value, ""); + static_assert(!std::is_floating_point<T>::value, ""); + static_assert(!std::is_array<T>::value, ""); + static_assert(!std::is_pointer<T>::value, ""); + static_assert(!std::is_lvalue_reference<T>::value, ""); + static_assert(!std::is_rvalue_reference<T>::value, ""); + static_assert(!std::is_member_object_pointer<T>::value, ""); + static_assert( std::is_member_function_pointer<T>::value, ""); + static_assert(!std::is_enum<T>::value, ""); + static_assert(!std::is_union<T>::value, ""); + static_assert(!std::is_class<T>::value, ""); + static_assert(!std::is_function<T>::value, ""); +} + +template <class T> +void test_member_function_pointer() +{ + test_member_function_pointer_imp<T>(); + test_member_function_pointer_imp<const T>(); + test_member_function_pointer_imp<volatile T>(); + test_member_function_pointer_imp<const volatile T>(); +} + +class Class +{ +}; + +int main() +{ + test_member_function_pointer<void (Class::*)()>(); + test_member_function_pointer<void (Class::*)(int)>(); + test_member_function_pointer<void (Class::*)(int, char)>(); +} diff --git a/libcxx/test/utilities/meta/meta.unary/meta.unary.cat/member_object_pointer.pass.cpp b/libcxx/test/utilities/meta/meta.unary/meta.unary.cat/member_object_pointer.pass.cpp index ed9eff866af..a768e9ec3cf 100644 --- a/libcxx/test/utilities/meta/meta.unary/meta.unary.cat/member_object_pointer.pass.cpp +++ b/libcxx/test/utilities/meta/meta.unary/meta.unary.cat/member_object_pointer.pass.cpp @@ -1 +1,50 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// type_traits
// member_object_pointer
#include <type_traits>
template <class T>
void test_member_object_pointer_imp()
{
static_assert(!std::is_void<T>::value, "");
static_assert(!std::is_integral<T>::value, "");
static_assert(!std::is_floating_point<T>::value, "");
static_assert(!std::is_array<T>::value, "");
static_assert(!std::is_pointer<T>::value, "");
static_assert(!std::is_lvalue_reference<T>::value, "");
static_assert(!std::is_rvalue_reference<T>::value, "");
static_assert( std::is_member_object_pointer<T>::value, "");
static_assert(!std::is_member_function_pointer<T>::value, "");
static_assert(!std::is_enum<T>::value, "");
static_assert(!std::is_union<T>::value, "");
static_assert(!std::is_class<T>::value, "");
static_assert(!std::is_function<T>::value, "");
}
template <class T>
void test_member_object_pointer()
{
test_member_object_pointer_imp<T>();
test_member_object_pointer_imp<const T>();
test_member_object_pointer_imp<volatile T>();
test_member_object_pointer_imp<const volatile T>();
}
class Class
{
};
int main()
{
test_member_object_pointer<int Class::*>();
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// member_object_pointer + +#include <type_traits> + +template <class T> +void test_member_object_pointer_imp() +{ + static_assert(!std::is_void<T>::value, ""); + static_assert(!std::is_integral<T>::value, ""); + static_assert(!std::is_floating_point<T>::value, ""); + static_assert(!std::is_array<T>::value, ""); + static_assert(!std::is_pointer<T>::value, ""); + static_assert(!std::is_lvalue_reference<T>::value, ""); + static_assert(!std::is_rvalue_reference<T>::value, ""); + static_assert( std::is_member_object_pointer<T>::value, ""); + static_assert(!std::is_member_function_pointer<T>::value, ""); + static_assert(!std::is_enum<T>::value, ""); + static_assert(!std::is_union<T>::value, ""); + static_assert(!std::is_class<T>::value, ""); + static_assert(!std::is_function<T>::value, ""); +} + +template <class T> +void test_member_object_pointer() +{ + test_member_object_pointer_imp<T>(); + test_member_object_pointer_imp<const T>(); + test_member_object_pointer_imp<volatile T>(); + test_member_object_pointer_imp<const volatile T>(); +} + +class Class +{ +}; + +int main() +{ + test_member_object_pointer<int Class::*>(); +} diff --git a/libcxx/test/utilities/meta/meta.unary/meta.unary.cat/pointer.pass.cpp b/libcxx/test/utilities/meta/meta.unary/meta.unary.cat/pointer.pass.cpp index 263e7388689..c74e9ea4314 100644 --- a/libcxx/test/utilities/meta/meta.unary/meta.unary.cat/pointer.pass.cpp +++ b/libcxx/test/utilities/meta/meta.unary/meta.unary.cat/pointer.pass.cpp @@ -1 +1,49 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// type_traits
// pointer
#include <type_traits>
template <class T>
void test_pointer_imp()
{
static_assert(!std::is_void<T>::value, "");
static_assert(!std::is_integral<T>::value, "");
static_assert(!std::is_floating_point<T>::value, "");
static_assert(!std::is_array<T>::value, "");
static_assert( std::is_pointer<T>::value, "");
static_assert(!std::is_lvalue_reference<T>::value, "");
static_assert(!std::is_rvalue_reference<T>::value, "");
static_assert(!std::is_member_object_pointer<T>::value, "");
static_assert(!std::is_member_function_pointer<T>::value, "");
static_assert(!std::is_enum<T>::value, "");
static_assert(!std::is_union<T>::value, "");
static_assert(!std::is_class<T>::value, "");
static_assert(!std::is_function<T>::value, "");
}
template <class T>
void test_pointer()
{
test_pointer_imp<T>();
test_pointer_imp<const T>();
test_pointer_imp<volatile T>();
test_pointer_imp<const volatile T>();
}
int main()
{
test_pointer<void*>();
test_pointer<int*>();
test_pointer<const int*>();
test_pointer<void (*)(int)>();
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// pointer + +#include <type_traits> + +template <class T> +void test_pointer_imp() +{ + static_assert(!std::is_void<T>::value, ""); + static_assert(!std::is_integral<T>::value, ""); + static_assert(!std::is_floating_point<T>::value, ""); + static_assert(!std::is_array<T>::value, ""); + static_assert( std::is_pointer<T>::value, ""); + static_assert(!std::is_lvalue_reference<T>::value, ""); + static_assert(!std::is_rvalue_reference<T>::value, ""); + static_assert(!std::is_member_object_pointer<T>::value, ""); + static_assert(!std::is_member_function_pointer<T>::value, ""); + static_assert(!std::is_enum<T>::value, ""); + static_assert(!std::is_union<T>::value, ""); + static_assert(!std::is_class<T>::value, ""); + static_assert(!std::is_function<T>::value, ""); +} + +template <class T> +void test_pointer() +{ + test_pointer_imp<T>(); + test_pointer_imp<const T>(); + test_pointer_imp<volatile T>(); + test_pointer_imp<const volatile T>(); +} + +int main() +{ + test_pointer<void*>(); + test_pointer<int*>(); + test_pointer<const int*>(); + test_pointer<void (*)(int)>(); +} diff --git a/libcxx/test/utilities/meta/meta.unary/meta.unary.cat/rvalue_ref.pass.cpp b/libcxx/test/utilities/meta/meta.unary/meta.unary.cat/rvalue_ref.pass.cpp index 91d7a6e0954..11600217ad9 100644 --- a/libcxx/test/utilities/meta/meta.unary/meta.unary.cat/rvalue_ref.pass.cpp +++ b/libcxx/test/utilities/meta/meta.unary/meta.unary.cat/rvalue_ref.pass.cpp @@ -1 +1,40 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// type_traits
// rvalue_ref
#include <type_traits>
template <class T>
void test_rvalue_ref()
{
static_assert(!std::is_void<T>::value, "");
static_assert(!std::is_integral<T>::value, "");
static_assert(!std::is_floating_point<T>::value, "");
static_assert(!std::is_array<T>::value, "");
static_assert(!std::is_pointer<T>::value, "");
static_assert(!std::is_lvalue_reference<T>::value, "");
static_assert( std::is_rvalue_reference<T>::value, "");
static_assert(!std::is_member_object_pointer<T>::value, "");
static_assert(!std::is_member_function_pointer<T>::value, "");
static_assert(!std::is_enum<T>::value, "");
static_assert(!std::is_union<T>::value, "");
static_assert(!std::is_class<T>::value, "");
static_assert(!std::is_function<T>::value, "");
}
int main()
{
#ifdef _LIBCPP_MOVE
test_rvalue_ref<int&&>();
test_rvalue_ref<const int&&>();
#endif
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// rvalue_ref + +#include <type_traits> + +template <class T> +void test_rvalue_ref() +{ + static_assert(!std::is_void<T>::value, ""); + static_assert(!std::is_integral<T>::value, ""); + static_assert(!std::is_floating_point<T>::value, ""); + static_assert(!std::is_array<T>::value, ""); + static_assert(!std::is_pointer<T>::value, ""); + static_assert(!std::is_lvalue_reference<T>::value, ""); + static_assert( std::is_rvalue_reference<T>::value, ""); + static_assert(!std::is_member_object_pointer<T>::value, ""); + static_assert(!std::is_member_function_pointer<T>::value, ""); + static_assert(!std::is_enum<T>::value, ""); + static_assert(!std::is_union<T>::value, ""); + static_assert(!std::is_class<T>::value, ""); + static_assert(!std::is_function<T>::value, ""); +} + +int main() +{ +#ifdef _LIBCPP_MOVE + test_rvalue_ref<int&&>(); + test_rvalue_ref<const int&&>(); +#endif // _LIBCPP_MOVE +} diff --git a/libcxx/test/utilities/meta/meta.unary/meta.unary.cat/union.pass.cpp b/libcxx/test/utilities/meta/meta.unary/meta.unary.cat/union.pass.cpp index 07c9729ff83..b386a8ae9b1 100644 --- a/libcxx/test/utilities/meta/meta.unary/meta.unary.cat/union.pass.cpp +++ b/libcxx/test/utilities/meta/meta.unary/meta.unary.cat/union.pass.cpp @@ -1 +1,52 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// type_traits
// union
#include <type_traits>
template <class T>
void test_union_imp()
{
static_assert(!std::is_void<T>::value, "");
static_assert(!std::is_integral<T>::value, "");
static_assert(!std::is_floating_point<T>::value, "");
static_assert(!std::is_array<T>::value, "");
static_assert(!std::is_pointer<T>::value, "");
static_assert(!std::is_lvalue_reference<T>::value, "");
static_assert(!std::is_rvalue_reference<T>::value, "");
static_assert(!std::is_member_object_pointer<T>::value, "");
static_assert(!std::is_member_function_pointer<T>::value, "");
static_assert(!std::is_enum<T>::value, "");
static_assert( std::is_union<T>::value, "");
static_assert(!std::is_class<T>::value, "");
static_assert(!std::is_function<T>::value, "");
}
template <class T>
void test_union()
{
test_union_imp<T>();
test_union_imp<const T>();
test_union_imp<volatile T>();
test_union_imp<const volatile T>();
}
union Union
{
int _;
double __;
};
int main()
{
test_union<Union>();
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// union + +#include <type_traits> + +template <class T> +void test_union_imp() +{ + static_assert(!std::is_void<T>::value, ""); + static_assert(!std::is_integral<T>::value, ""); + static_assert(!std::is_floating_point<T>::value, ""); + static_assert(!std::is_array<T>::value, ""); + static_assert(!std::is_pointer<T>::value, ""); + static_assert(!std::is_lvalue_reference<T>::value, ""); + static_assert(!std::is_rvalue_reference<T>::value, ""); + static_assert(!std::is_member_object_pointer<T>::value, ""); + static_assert(!std::is_member_function_pointer<T>::value, ""); + static_assert(!std::is_enum<T>::value, ""); + static_assert( std::is_union<T>::value, ""); + static_assert(!std::is_class<T>::value, ""); + static_assert(!std::is_function<T>::value, ""); +} + +template <class T> +void test_union() +{ + test_union_imp<T>(); + test_union_imp<const T>(); + test_union_imp<volatile T>(); + test_union_imp<const volatile T>(); +} + +union Union +{ + int _; + double __; +}; + +int main() +{ + test_union<Union>(); +} diff --git a/libcxx/test/utilities/meta/meta.unary/meta.unary.cat/void.pass.cpp b/libcxx/test/utilities/meta/meta.unary/meta.unary.cat/void.pass.cpp index cfcff70a923..49ecacced81 100644 --- a/libcxx/test/utilities/meta/meta.unary/meta.unary.cat/void.pass.cpp +++ b/libcxx/test/utilities/meta/meta.unary/meta.unary.cat/void.pass.cpp @@ -1 +1,46 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// type_traits
// void
#include <type_traits>
template <class T>
void test_void_imp()
{
static_assert( std::is_void<T>::value, "");
static_assert(!std::is_integral<T>::value, "");
static_assert(!std::is_floating_point<T>::value, "");
static_assert(!std::is_array<T>::value, "");
static_assert(!std::is_pointer<T>::value, "");
static_assert(!std::is_lvalue_reference<T>::value, "");
static_assert(!std::is_rvalue_reference<T>::value, "");
static_assert(!std::is_member_object_pointer<T>::value, "");
static_assert(!std::is_member_function_pointer<T>::value, "");
static_assert(!std::is_enum<T>::value, "");
static_assert(!std::is_union<T>::value, "");
static_assert(!std::is_class<T>::value, "");
static_assert(!std::is_function<T>::value, "");
}
template <class T>
void test_void()
{
test_void_imp<T>();
test_void_imp<const T>();
test_void_imp<volatile T>();
test_void_imp<const volatile T>();
}
int main()
{
test_void<void>();
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// void + +#include <type_traits> + +template <class T> +void test_void_imp() +{ + static_assert( std::is_void<T>::value, ""); + static_assert(!std::is_integral<T>::value, ""); + static_assert(!std::is_floating_point<T>::value, ""); + static_assert(!std::is_array<T>::value, ""); + static_assert(!std::is_pointer<T>::value, ""); + static_assert(!std::is_lvalue_reference<T>::value, ""); + static_assert(!std::is_rvalue_reference<T>::value, ""); + static_assert(!std::is_member_object_pointer<T>::value, ""); + static_assert(!std::is_member_function_pointer<T>::value, ""); + static_assert(!std::is_enum<T>::value, ""); + static_assert(!std::is_union<T>::value, ""); + static_assert(!std::is_class<T>::value, ""); + static_assert(!std::is_function<T>::value, ""); +} + +template <class T> +void test_void() +{ + test_void_imp<T>(); + test_void_imp<const T>(); + test_void_imp<volatile T>(); + test_void_imp<const volatile T>(); +} + +int main() +{ + test_void<void>(); +} diff --git a/libcxx/test/utilities/meta/meta.unary/meta.unary.comp/array.pass.cpp b/libcxx/test/utilities/meta/meta.unary/meta.unary.comp/array.pass.cpp index e521e45977d..80034227d41 100644 --- a/libcxx/test/utilities/meta/meta.unary/meta.unary.comp/array.pass.cpp +++ b/libcxx/test/utilities/meta/meta.unary/meta.unary.comp/array.pass.cpp @@ -1 +1,46 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// type_traits
// array
#include <type_traits>
template <class T>
void test_array_imp()
{
static_assert(!std::is_reference<T>::value, "");
static_assert(!std::is_arithmetic<T>::value, "");
static_assert(!std::is_fundamental<T>::value, "");
static_assert( std::is_object<T>::value, "");
static_assert(!std::is_scalar<T>::value, "");
static_assert( std::is_compound<T>::value, "");
static_assert(!std::is_member_pointer<T>::value, "");
}
template <class T>
void test_array()
{
test_array_imp<T>();
test_array_imp<const T>();
test_array_imp<volatile T>();
test_array_imp<const volatile T>();
}
typedef char array[3];
typedef const char const_array[3];
typedef char incomplete_array[];
int main()
{
test_array<array>();
test_array<const_array>();
test_array<incomplete_array>();
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// array + +#include <type_traits> + +template <class T> +void test_array_imp() +{ + static_assert(!std::is_reference<T>::value, ""); + static_assert(!std::is_arithmetic<T>::value, ""); + static_assert(!std::is_fundamental<T>::value, ""); + static_assert( std::is_object<T>::value, ""); + static_assert(!std::is_scalar<T>::value, ""); + static_assert( std::is_compound<T>::value, ""); + static_assert(!std::is_member_pointer<T>::value, ""); +} + +template <class T> +void test_array() +{ + test_array_imp<T>(); + test_array_imp<const T>(); + test_array_imp<volatile T>(); + test_array_imp<const volatile T>(); +} + +typedef char array[3]; +typedef const char const_array[3]; +typedef char incomplete_array[]; + +int main() +{ + test_array<array>(); + test_array<const_array>(); + test_array<incomplete_array>(); +} diff --git a/libcxx/test/utilities/meta/meta.unary/meta.unary.comp/class.pass.cpp b/libcxx/test/utilities/meta/meta.unary/meta.unary.comp/class.pass.cpp index 4ddf499d754..ca727b2dbf3 100644 --- a/libcxx/test/utilities/meta/meta.unary/meta.unary.comp/class.pass.cpp +++ b/libcxx/test/utilities/meta/meta.unary/meta.unary.comp/class.pass.cpp @@ -1 +1,46 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// type_traits
// class
#include <type_traits>
template <class T>
void test_class_imp()
{
static_assert(!std::is_reference<T>::value, "");
static_assert(!std::is_arithmetic<T>::value, "");
static_assert(!std::is_fundamental<T>::value, "");
static_assert( std::is_object<T>::value, "");
static_assert(!std::is_scalar<T>::value, "");
static_assert( std::is_compound<T>::value, "");
static_assert(!std::is_member_pointer<T>::value, "");
}
template <class T>
void test_class()
{
test_class_imp<T>();
test_class_imp<const T>();
test_class_imp<volatile T>();
test_class_imp<const volatile T>();
}
class Class
{
int _;
double __;
};
int main()
{
test_class<Class>();
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// class + +#include <type_traits> + +template <class T> +void test_class_imp() +{ + static_assert(!std::is_reference<T>::value, ""); + static_assert(!std::is_arithmetic<T>::value, ""); + static_assert(!std::is_fundamental<T>::value, ""); + static_assert( std::is_object<T>::value, ""); + static_assert(!std::is_scalar<T>::value, ""); + static_assert( std::is_compound<T>::value, ""); + static_assert(!std::is_member_pointer<T>::value, ""); +} + +template <class T> +void test_class() +{ + test_class_imp<T>(); + test_class_imp<const T>(); + test_class_imp<volatile T>(); + test_class_imp<const volatile T>(); +} + +class Class +{ + int _; + double __; +}; + +int main() +{ + test_class<Class>(); +} diff --git a/libcxx/test/utilities/meta/meta.unary/meta.unary.comp/enum.pass.cpp b/libcxx/test/utilities/meta/meta.unary/meta.unary.comp/enum.pass.cpp index cdd87e84c7e..9f0940db90b 100644 --- a/libcxx/test/utilities/meta/meta.unary/meta.unary.comp/enum.pass.cpp +++ b/libcxx/test/utilities/meta/meta.unary/meta.unary.comp/enum.pass.cpp @@ -1 +1,42 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// type_traits
// enum
#include <type_traits>
template <class T>
void test_enum_imp()
{
static_assert(!std::is_reference<T>::value, "");
static_assert(!std::is_arithmetic<T>::value, "");
static_assert(!std::is_fundamental<T>::value, "");
static_assert( std::is_object<T>::value, "");
static_assert( std::is_scalar<T>::value, "");
static_assert( std::is_compound<T>::value, "");
static_assert(!std::is_member_pointer<T>::value, "");
}
template <class T>
void test_enum()
{
test_enum_imp<T>();
test_enum_imp<const T>();
test_enum_imp<volatile T>();
test_enum_imp<const volatile T>();
}
enum Enum {zero, one};
int main()
{
test_enum<Enum>();
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// enum + +#include <type_traits> + +template <class T> +void test_enum_imp() +{ + static_assert(!std::is_reference<T>::value, ""); + static_assert(!std::is_arithmetic<T>::value, ""); + static_assert(!std::is_fundamental<T>::value, ""); + static_assert( std::is_object<T>::value, ""); + static_assert( std::is_scalar<T>::value, ""); + static_assert( std::is_compound<T>::value, ""); + static_assert(!std::is_member_pointer<T>::value, ""); +} + +template <class T> +void test_enum() +{ + test_enum_imp<T>(); + test_enum_imp<const T>(); + test_enum_imp<volatile T>(); + test_enum_imp<const volatile T>(); +} + +enum Enum {zero, one}; + +int main() +{ + test_enum<Enum>(); +} diff --git a/libcxx/test/utilities/meta/meta.unary/meta.unary.comp/floating_point.pass.cpp b/libcxx/test/utilities/meta/meta.unary/meta.unary.comp/floating_point.pass.cpp index d5d06eba72f..7d95a8a0dd1 100644 --- a/libcxx/test/utilities/meta/meta.unary/meta.unary.comp/floating_point.pass.cpp +++ b/libcxx/test/utilities/meta/meta.unary/meta.unary.comp/floating_point.pass.cpp @@ -1 +1,42 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// type_traits
// floating_point
#include <type_traits>
template <class T>
void test_floating_point_imp()
{
static_assert(!std::is_reference<T>::value, "");
static_assert( std::is_arithmetic<T>::value, "");
static_assert( std::is_fundamental<T>::value, "");
static_assert( std::is_object<T>::value, "");
static_assert( std::is_scalar<T>::value, "");
static_assert(!std::is_compound<T>::value, "");
static_assert(!std::is_member_pointer<T>::value, "");
}
template <class T>
void test_floating_point()
{
test_floating_point_imp<T>();
test_floating_point_imp<const T>();
test_floating_point_imp<volatile T>();
test_floating_point_imp<const volatile T>();
}
int main()
{
test_floating_point<float>();
test_floating_point<double>();
test_floating_point<long double>();
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// floating_point + +#include <type_traits> + +template <class T> +void test_floating_point_imp() +{ + static_assert(!std::is_reference<T>::value, ""); + static_assert( std::is_arithmetic<T>::value, ""); + static_assert( std::is_fundamental<T>::value, ""); + static_assert( std::is_object<T>::value, ""); + static_assert( std::is_scalar<T>::value, ""); + static_assert(!std::is_compound<T>::value, ""); + static_assert(!std::is_member_pointer<T>::value, ""); +} + +template <class T> +void test_floating_point() +{ + test_floating_point_imp<T>(); + test_floating_point_imp<const T>(); + test_floating_point_imp<volatile T>(); + test_floating_point_imp<const volatile T>(); +} + +int main() +{ + test_floating_point<float>(); + test_floating_point<double>(); + test_floating_point<long double>(); +} diff --git a/libcxx/test/utilities/meta/meta.unary/meta.unary.comp/function.pass.cpp b/libcxx/test/utilities/meta/meta.unary/meta.unary.comp/function.pass.cpp index f67fd8f3606..b4c4386f909 100644 --- a/libcxx/test/utilities/meta/meta.unary/meta.unary.comp/function.pass.cpp +++ b/libcxx/test/utilities/meta/meta.unary/meta.unary.comp/function.pass.cpp @@ -1 +1,43 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// type_traits
// function
#include <type_traits>
template <class T>
void test_function_imp()
{
static_assert(!std::is_reference<T>::value, "");
static_assert(!std::is_arithmetic<T>::value, "");
static_assert(!std::is_fundamental<T>::value, "");
static_assert(!std::is_object<T>::value, "");
static_assert(!std::is_scalar<T>::value, "");
static_assert( std::is_compound<T>::value, "");
static_assert(!std::is_member_pointer<T>::value, "");
}
template <class T>
void test_function()
{
test_function_imp<T>();
test_function_imp<const T>();
test_function_imp<volatile T>();
test_function_imp<const volatile T>();
}
int main()
{
test_function<void ()>();
test_function<void (int)>();
test_function<int (double)>();
test_function<int (double, char)>();
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// function + +#include <type_traits> + +template <class T> +void test_function_imp() +{ + static_assert(!std::is_reference<T>::value, ""); + static_assert(!std::is_arithmetic<T>::value, ""); + static_assert(!std::is_fundamental<T>::value, ""); + static_assert(!std::is_object<T>::value, ""); + static_assert(!std::is_scalar<T>::value, ""); + static_assert( std::is_compound<T>::value, ""); + static_assert(!std::is_member_pointer<T>::value, ""); +} + +template <class T> +void test_function() +{ + test_function_imp<T>(); + test_function_imp<const T>(); + test_function_imp<volatile T>(); + test_function_imp<const volatile T>(); +} + +int main() +{ + test_function<void ()>(); + test_function<void (int)>(); + test_function<int (double)>(); + test_function<int (double, char)>(); +} diff --git a/libcxx/test/utilities/meta/meta.unary/meta.unary.comp/integral.pass.cpp b/libcxx/test/utilities/meta/meta.unary/meta.unary.comp/integral.pass.cpp index 12c72ee5a6a..fdf374b2315 100644 --- a/libcxx/test/utilities/meta/meta.unary/meta.unary.comp/integral.pass.cpp +++ b/libcxx/test/utilities/meta/meta.unary/meta.unary.comp/integral.pass.cpp @@ -1 +1,52 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// type_traits
// integral
#include <type_traits>
template <class T>
void test_integral_imp()
{
static_assert(!std::is_reference<T>::value, "");
static_assert( std::is_arithmetic<T>::value, "");
static_assert( std::is_fundamental<T>::value, "");
static_assert( std::is_object<T>::value, "");
static_assert( std::is_scalar<T>::value, "");
static_assert(!std::is_compound<T>::value, "");
static_assert(!std::is_member_pointer<T>::value, "");
}
template <class T>
void test_integral()
{
test_integral_imp<T>();
test_integral_imp<const T>();
test_integral_imp<volatile T>();
test_integral_imp<const volatile T>();
}
int main()
{
test_integral<bool>();
test_integral<char>();
test_integral<signed char>();
test_integral<unsigned char>();
test_integral<wchar_t>();
test_integral<short>();
test_integral<unsigned short>();
test_integral<int>();
test_integral<unsigned int>();
test_integral<long>();
test_integral<unsigned long>();
test_integral<long long>();
test_integral<unsigned long long>();
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// integral + +#include <type_traits> + +template <class T> +void test_integral_imp() +{ + static_assert(!std::is_reference<T>::value, ""); + static_assert( std::is_arithmetic<T>::value, ""); + static_assert( std::is_fundamental<T>::value, ""); + static_assert( std::is_object<T>::value, ""); + static_assert( std::is_scalar<T>::value, ""); + static_assert(!std::is_compound<T>::value, ""); + static_assert(!std::is_member_pointer<T>::value, ""); +} + +template <class T> +void test_integral() +{ + test_integral_imp<T>(); + test_integral_imp<const T>(); + test_integral_imp<volatile T>(); + test_integral_imp<const volatile T>(); +} + +int main() +{ + test_integral<bool>(); + test_integral<char>(); + test_integral<signed char>(); + test_integral<unsigned char>(); + test_integral<wchar_t>(); + test_integral<short>(); + test_integral<unsigned short>(); + test_integral<int>(); + test_integral<unsigned int>(); + test_integral<long>(); + test_integral<unsigned long>(); + test_integral<long long>(); + test_integral<unsigned long long>(); +} diff --git a/libcxx/test/utilities/meta/meta.unary/meta.unary.comp/lvalue_ref.pass.cpp b/libcxx/test/utilities/meta/meta.unary/meta.unary.comp/lvalue_ref.pass.cpp index db749b0e8b8..8a4fdb7df08 100644 --- a/libcxx/test/utilities/meta/meta.unary/meta.unary.comp/lvalue_ref.pass.cpp +++ b/libcxx/test/utilities/meta/meta.unary/meta.unary.comp/lvalue_ref.pass.cpp @@ -1 +1,32 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// type_traits
// lvalue_ref
#include <type_traits>
template <class T>
void test_lvalue_ref()
{
static_assert( std::is_reference<T>::value, "");
static_assert(!std::is_arithmetic<T>::value, "");
static_assert(!std::is_fundamental<T>::value, "");
static_assert(!std::is_object<T>::value, "");
static_assert(!std::is_scalar<T>::value, "");
static_assert( std::is_compound<T>::value, "");
static_assert(!std::is_member_pointer<T>::value, "");
}
int main()
{
test_lvalue_ref<int&>();
test_lvalue_ref<const int&>();
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// lvalue_ref + +#include <type_traits> + +template <class T> +void test_lvalue_ref() +{ + static_assert( std::is_reference<T>::value, ""); + static_assert(!std::is_arithmetic<T>::value, ""); + static_assert(!std::is_fundamental<T>::value, ""); + static_assert(!std::is_object<T>::value, ""); + static_assert(!std::is_scalar<T>::value, ""); + static_assert( std::is_compound<T>::value, ""); + static_assert(!std::is_member_pointer<T>::value, ""); +} + +int main() +{ + test_lvalue_ref<int&>(); + test_lvalue_ref<const int&>(); +} diff --git a/libcxx/test/utilities/meta/meta.unary/meta.unary.comp/member_function_pointer.pass.cpp b/libcxx/test/utilities/meta/meta.unary/meta.unary.comp/member_function_pointer.pass.cpp index 9e8f15973f0..05c79be84ab 100644 --- a/libcxx/test/utilities/meta/meta.unary/meta.unary.comp/member_function_pointer.pass.cpp +++ b/libcxx/test/utilities/meta/meta.unary/meta.unary.comp/member_function_pointer.pass.cpp @@ -1 +1,46 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// type_traits
// member_function_pointer
#include <type_traits>
template <class T>
void test_member_function_pointer_imp()
{
static_assert(!std::is_reference<T>::value, "");
static_assert(!std::is_arithmetic<T>::value, "");
static_assert(!std::is_fundamental<T>::value, "");
static_assert( std::is_object<T>::value, "");
static_assert( std::is_scalar<T>::value, "");
static_assert( std::is_compound<T>::value, "");
static_assert( std::is_member_pointer<T>::value, "");
}
template <class T>
void test_member_function_pointer()
{
test_member_function_pointer_imp<T>();
test_member_function_pointer_imp<const T>();
test_member_function_pointer_imp<volatile T>();
test_member_function_pointer_imp<const volatile T>();
}
class Class
{
};
int main()
{
test_member_function_pointer<void (Class::*)()>();
test_member_function_pointer<void (Class::*)(int)>();
test_member_function_pointer<void (Class::*)(int, char)>();
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// member_function_pointer + +#include <type_traits> + +template <class T> +void test_member_function_pointer_imp() +{ + static_assert(!std::is_reference<T>::value, ""); + static_assert(!std::is_arithmetic<T>::value, ""); + static_assert(!std::is_fundamental<T>::value, ""); + static_assert( std::is_object<T>::value, ""); + static_assert( std::is_scalar<T>::value, ""); + static_assert( std::is_compound<T>::value, ""); + static_assert( std::is_member_pointer<T>::value, ""); +} + +template <class T> +void test_member_function_pointer() +{ + test_member_function_pointer_imp<T>(); + test_member_function_pointer_imp<const T>(); + test_member_function_pointer_imp<volatile T>(); + test_member_function_pointer_imp<const volatile T>(); +} + +class Class +{ +}; + +int main() +{ + test_member_function_pointer<void (Class::*)()>(); + test_member_function_pointer<void (Class::*)(int)>(); + test_member_function_pointer<void (Class::*)(int, char)>(); +} diff --git a/libcxx/test/utilities/meta/meta.unary/meta.unary.comp/member_object_pointer.pass.cpp b/libcxx/test/utilities/meta/meta.unary/meta.unary.comp/member_object_pointer.pass.cpp index 6af0606f02e..2ac24438258 100644 --- a/libcxx/test/utilities/meta/meta.unary/meta.unary.comp/member_object_pointer.pass.cpp +++ b/libcxx/test/utilities/meta/meta.unary/meta.unary.comp/member_object_pointer.pass.cpp @@ -1 +1,44 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// type_traits
// member_object_pointer
#include <type_traits>
template <class T>
void test_member_object_pointer_imp()
{
static_assert(!std::is_reference<T>::value, "");
static_assert(!std::is_arithmetic<T>::value, "");
static_assert(!std::is_fundamental<T>::value, "");
static_assert( std::is_object<T>::value, "");
static_assert( std::is_scalar<T>::value, "");
static_assert( std::is_compound<T>::value, "");
static_assert( std::is_member_pointer<T>::value, "");
}
template <class T>
void test_member_object_pointer()
{
test_member_object_pointer_imp<T>();
test_member_object_pointer_imp<const T>();
test_member_object_pointer_imp<volatile T>();
test_member_object_pointer_imp<const volatile T>();
}
class Class
{
};
int main()
{
test_member_object_pointer<int Class::*>();
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// member_object_pointer + +#include <type_traits> + +template <class T> +void test_member_object_pointer_imp() +{ + static_assert(!std::is_reference<T>::value, ""); + static_assert(!std::is_arithmetic<T>::value, ""); + static_assert(!std::is_fundamental<T>::value, ""); + static_assert( std::is_object<T>::value, ""); + static_assert( std::is_scalar<T>::value, ""); + static_assert( std::is_compound<T>::value, ""); + static_assert( std::is_member_pointer<T>::value, ""); +} + +template <class T> +void test_member_object_pointer() +{ + test_member_object_pointer_imp<T>(); + test_member_object_pointer_imp<const T>(); + test_member_object_pointer_imp<volatile T>(); + test_member_object_pointer_imp<const volatile T>(); +} + +class Class +{ +}; + +int main() +{ + test_member_object_pointer<int Class::*>(); +} diff --git a/libcxx/test/utilities/meta/meta.unary/meta.unary.comp/pointer.pass.cpp b/libcxx/test/utilities/meta/meta.unary/meta.unary.comp/pointer.pass.cpp index ccc936b13ce..4cc5ccf998c 100644 --- a/libcxx/test/utilities/meta/meta.unary/meta.unary.comp/pointer.pass.cpp +++ b/libcxx/test/utilities/meta/meta.unary/meta.unary.comp/pointer.pass.cpp @@ -1 +1,43 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// type_traits
// pointer
#include <type_traits>
template <class T>
void test_pointer_imp()
{
static_assert(!std::is_reference<T>::value, "");
static_assert(!std::is_arithmetic<T>::value, "");
static_assert(!std::is_fundamental<T>::value, "");
static_assert( std::is_object<T>::value, "");
static_assert( std::is_scalar<T>::value, "");
static_assert( std::is_compound<T>::value, "");
static_assert(!std::is_member_pointer<T>::value, "");
}
template <class T>
void test_pointer()
{
test_pointer_imp<T>();
test_pointer_imp<const T>();
test_pointer_imp<volatile T>();
test_pointer_imp<const volatile T>();
}
int main()
{
test_pointer<void*>();
test_pointer<int*>();
test_pointer<const int*>();
test_pointer<void (*)(int)>();
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// pointer + +#include <type_traits> + +template <class T> +void test_pointer_imp() +{ + static_assert(!std::is_reference<T>::value, ""); + static_assert(!std::is_arithmetic<T>::value, ""); + static_assert(!std::is_fundamental<T>::value, ""); + static_assert( std::is_object<T>::value, ""); + static_assert( std::is_scalar<T>::value, ""); + static_assert( std::is_compound<T>::value, ""); + static_assert(!std::is_member_pointer<T>::value, ""); +} + +template <class T> +void test_pointer() +{ + test_pointer_imp<T>(); + test_pointer_imp<const T>(); + test_pointer_imp<volatile T>(); + test_pointer_imp<const volatile T>(); +} + +int main() +{ + test_pointer<void*>(); + test_pointer<int*>(); + test_pointer<const int*>(); + test_pointer<void (*)(int)>(); +} diff --git a/libcxx/test/utilities/meta/meta.unary/meta.unary.comp/rvalue_ref.pass.cpp b/libcxx/test/utilities/meta/meta.unary/meta.unary.comp/rvalue_ref.pass.cpp index 7233ba99f3f..62f99781549 100644 --- a/libcxx/test/utilities/meta/meta.unary/meta.unary.comp/rvalue_ref.pass.cpp +++ b/libcxx/test/utilities/meta/meta.unary/meta.unary.comp/rvalue_ref.pass.cpp @@ -1 +1,34 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// type_traits
// rvalue_ref
#include <type_traits>
template <class T>
void test_rvalue_ref()
{
static_assert(std::is_reference<T>::value, "");
static_assert(!std::is_arithmetic<T>::value, "");
static_assert(!std::is_fundamental<T>::value, "");
static_assert(!std::is_object<T>::value, "");
static_assert(!std::is_scalar<T>::value, "");
static_assert( std::is_compound<T>::value, "");
static_assert(!std::is_member_pointer<T>::value, "");
}
int main()
{
#ifdef _LIBCPP_MOVE
test_rvalue_ref<int&&>();
test_rvalue_ref<const int&&>();
#endif
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// rvalue_ref + +#include <type_traits> + +template <class T> +void test_rvalue_ref() +{ + static_assert(std::is_reference<T>::value, ""); + static_assert(!std::is_arithmetic<T>::value, ""); + static_assert(!std::is_fundamental<T>::value, ""); + static_assert(!std::is_object<T>::value, ""); + static_assert(!std::is_scalar<T>::value, ""); + static_assert( std::is_compound<T>::value, ""); + static_assert(!std::is_member_pointer<T>::value, ""); +} + +int main() +{ +#ifdef _LIBCPP_MOVE + test_rvalue_ref<int&&>(); + test_rvalue_ref<const int&&>(); +#endif // _LIBCPP_MOVE +} diff --git a/libcxx/test/utilities/meta/meta.unary/meta.unary.comp/union.pass.cpp b/libcxx/test/utilities/meta/meta.unary/meta.unary.comp/union.pass.cpp index 8eb85706490..eeb073e963b 100644 --- a/libcxx/test/utilities/meta/meta.unary/meta.unary.comp/union.pass.cpp +++ b/libcxx/test/utilities/meta/meta.unary/meta.unary.comp/union.pass.cpp @@ -1 +1,46 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// type_traits
// union
#include <type_traits>
template <class T>
void test_union_imp()
{
static_assert(!std::is_reference<T>::value, "");
static_assert(!std::is_arithmetic<T>::value, "");
static_assert(!std::is_fundamental<T>::value, "");
static_assert( std::is_object<T>::value, "");
static_assert(!std::is_scalar<T>::value, "");
static_assert( std::is_compound<T>::value, "");
static_assert(!std::is_member_pointer<T>::value, "");
}
template <class T>
void test_union()
{
test_union_imp<T>();
test_union_imp<const T>();
test_union_imp<volatile T>();
test_union_imp<const volatile T>();
}
union Union
{
int _;
double __;
};
int main()
{
test_union<Union>();
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// union + +#include <type_traits> + +template <class T> +void test_union_imp() +{ + static_assert(!std::is_reference<T>::value, ""); + static_assert(!std::is_arithmetic<T>::value, ""); + static_assert(!std::is_fundamental<T>::value, ""); + static_assert( std::is_object<T>::value, ""); + static_assert(!std::is_scalar<T>::value, ""); + static_assert( std::is_compound<T>::value, ""); + static_assert(!std::is_member_pointer<T>::value, ""); +} + +template <class T> +void test_union() +{ + test_union_imp<T>(); + test_union_imp<const T>(); + test_union_imp<volatile T>(); + test_union_imp<const volatile T>(); +} + +union Union +{ + int _; + double __; +}; + +int main() +{ + test_union<Union>(); +} diff --git a/libcxx/test/utilities/meta/meta.unary/meta.unary.comp/void.pass.cpp b/libcxx/test/utilities/meta/meta.unary/meta.unary.comp/void.pass.cpp index 88c2fa8a0e7..9bebfba6dbe 100644 --- a/libcxx/test/utilities/meta/meta.unary/meta.unary.comp/void.pass.cpp +++ b/libcxx/test/utilities/meta/meta.unary/meta.unary.comp/void.pass.cpp @@ -1 +1,40 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// type_traits
// void
#include <type_traits>
template <class T>
void test_void_imp()
{
static_assert(!std::is_reference<T>::value, "");
static_assert(!std::is_arithmetic<T>::value, "");
static_assert( std::is_fundamental<T>::value, "");
static_assert(!std::is_object<T>::value, "");
static_assert(!std::is_scalar<T>::value, "");
static_assert(!std::is_compound<T>::value, "");
static_assert(!std::is_member_pointer<T>::value, "");
}
template <class T>
void test_void()
{
test_void_imp<T>();
test_void_imp<const T>();
test_void_imp<volatile T>();
test_void_imp<const volatile T>();
}
int main()
{
test_void<void>();
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// void + +#include <type_traits> + +template <class T> +void test_void_imp() +{ + static_assert(!std::is_reference<T>::value, ""); + static_assert(!std::is_arithmetic<T>::value, ""); + static_assert( std::is_fundamental<T>::value, ""); + static_assert(!std::is_object<T>::value, ""); + static_assert(!std::is_scalar<T>::value, ""); + static_assert(!std::is_compound<T>::value, ""); + static_assert(!std::is_member_pointer<T>::value, ""); +} + +template <class T> +void test_void() +{ + test_void_imp<T>(); + test_void_imp<const T>(); + test_void_imp<volatile T>(); + test_void_imp<const volatile T>(); +} + +int main() +{ + test_void<void>(); +} diff --git a/libcxx/test/utilities/meta/meta.unary/meta.unary.prop/alignment_of.pass.cpp b/libcxx/test/utilities/meta/meta.unary/meta.unary.prop/alignment_of.pass.cpp index 093ca33c98d..a277a3468fd 100644 --- a/libcxx/test/utilities/meta/meta.unary/meta.unary.prop/alignment_of.pass.cpp +++ b/libcxx/test/utilities/meta/meta.unary/meta.unary.prop/alignment_of.pass.cpp @@ -1 +1,42 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// type_traits
// alignment_of
#include <type_traits>
template <class T, unsigned A>
void test_alignment_of()
{
static_assert( std::alignment_of<T>::value == A, "");
static_assert( std::alignment_of<const T>::value == A, "");
static_assert( std::alignment_of<volatile T>::value == A, "");
static_assert( std::alignment_of<const volatile T>::value == A, "");
}
class Class
{
public:
~Class();
};
int main()
{
test_alignment_of<int&, sizeof(long) == 4 ? 4 : 8>();
test_alignment_of<Class, 1>();
test_alignment_of<int*, sizeof(long) == 4 ? 4 : 8>();
test_alignment_of<const int*, sizeof(long) == 4 ? 4 : 8>();
test_alignment_of<char[3], 1>();
test_alignment_of<int, 4>();
test_alignment_of<double, sizeof(long) == 4 ? 4 : 8>();
test_alignment_of<bool, 1>();
test_alignment_of<unsigned, 4>();
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// alignment_of + +#include <type_traits> + +template <class T, unsigned A> +void test_alignment_of() +{ + static_assert( std::alignment_of<T>::value == A, ""); + static_assert( std::alignment_of<const T>::value == A, ""); + static_assert( std::alignment_of<volatile T>::value == A, ""); + static_assert( std::alignment_of<const volatile T>::value == A, ""); +} + +class Class +{ +public: + ~Class(); +}; + +int main() +{ + test_alignment_of<int&, sizeof(long) == 4 ? 4 : 8>(); + test_alignment_of<Class, 1>(); + test_alignment_of<int*, sizeof(long) == 4 ? 4 : 8>(); + test_alignment_of<const int*, sizeof(long) == 4 ? 4 : 8>(); + test_alignment_of<char[3], 1>(); + test_alignment_of<int, 4>(); + test_alignment_of<double, sizeof(long) == 4 ? 4 : 8>(); + test_alignment_of<bool, 1>(); + test_alignment_of<unsigned, 4>(); +} diff --git a/libcxx/test/utilities/meta/meta.unary/meta.unary.prop/extent.pass.cpp b/libcxx/test/utilities/meta/meta.unary/meta.unary.prop/extent.pass.cpp index d149eb3d9d3..105217c21c3 100644 --- a/libcxx/test/utilities/meta/meta.unary/meta.unary.prop/extent.pass.cpp +++ b/libcxx/test/utilities/meta/meta.unary/meta.unary.prop/extent.pass.cpp @@ -1 +1,60 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// type_traits
// extent
#include <type_traits>
template <class T, unsigned A>
void test_extent()
{
static_assert((std::extent<T>::value == A), "");
static_assert((std::extent<const T>::value == A), "");
static_assert((std::extent<volatile T>::value == A), "");
static_assert((std::extent<const volatile T>::value == A), "");
}
template <class T, unsigned A>
void test_extent1()
{
static_assert((std::extent<T, 1>::value == A), "");
static_assert((std::extent<const T, 1>::value == A), "");
static_assert((std::extent<volatile T, 1>::value == A), "");
static_assert((std::extent<const volatile T, 1>::value == A), "");
}
class Class
{
public:
~Class();
};
int main()
{
test_extent<void, 0>();
test_extent<int&, 0>();
test_extent<Class, 0>();
test_extent<int*, 0>();
test_extent<const int*, 0>();
test_extent<int, 0>();
test_extent<double, 0>();
test_extent<bool, 0>();
test_extent<unsigned, 0>();
test_extent<int[2], 2>();
test_extent<int[2][4], 2>();
test_extent<int[][4], 0>();
test_extent1<int, 0>();
test_extent1<int[2], 0>();
test_extent1<int[2][4], 4>();
test_extent1<int[][4], 4>();
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// extent + +#include <type_traits> + +template <class T, unsigned A> +void test_extent() +{ + static_assert((std::extent<T>::value == A), ""); + static_assert((std::extent<const T>::value == A), ""); + static_assert((std::extent<volatile T>::value == A), ""); + static_assert((std::extent<const volatile T>::value == A), ""); +} + +template <class T, unsigned A> +void test_extent1() +{ + static_assert((std::extent<T, 1>::value == A), ""); + static_assert((std::extent<const T, 1>::value == A), ""); + static_assert((std::extent<volatile T, 1>::value == A), ""); + static_assert((std::extent<const volatile T, 1>::value == A), ""); +} + +class Class +{ +public: + ~Class(); +}; + +int main() +{ + test_extent<void, 0>(); + test_extent<int&, 0>(); + test_extent<Class, 0>(); + test_extent<int*, 0>(); + test_extent<const int*, 0>(); + test_extent<int, 0>(); + test_extent<double, 0>(); + test_extent<bool, 0>(); + test_extent<unsigned, 0>(); + + test_extent<int[2], 2>(); + test_extent<int[2][4], 2>(); + test_extent<int[][4], 0>(); + + test_extent1<int, 0>(); + test_extent1<int[2], 0>(); + test_extent1<int[2][4], 4>(); + test_extent1<int[][4], 4>(); +} diff --git a/libcxx/test/utilities/meta/meta.unary/meta.unary.prop/has_nothrow_copy_assign.pass.cpp b/libcxx/test/utilities/meta/meta.unary/meta.unary.prop/has_nothrow_copy_assign.pass.cpp index 31a5a7c1c1f..127e76290e0 100644 --- a/libcxx/test/utilities/meta/meta.unary/meta.unary.prop/has_nothrow_copy_assign.pass.cpp +++ b/libcxx/test/utilities/meta/meta.unary/meta.unary.prop/has_nothrow_copy_assign.pass.cpp @@ -1 +1,77 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// type_traits
// has_nothrow_copy_assign
#include <type_traits>
template <class T>
void test_has_nothrow_assign()
{
static_assert( std::has_nothrow_copy_assign<T>::value, "");
static_assert(!std::has_nothrow_copy_assign<const T>::value, "");
static_assert( std::has_nothrow_copy_assign<volatile T>::value, "");
static_assert(!std::has_nothrow_copy_assign<const volatile T>::value, "");
}
template <class T>
void test_has_not_nothrow_assign()
{
static_assert(!std::has_nothrow_copy_assign<T>::value, "");
static_assert(!std::has_nothrow_copy_assign<const T>::value, "");
static_assert(!std::has_nothrow_copy_assign<volatile T>::value, "");
static_assert(!std::has_nothrow_copy_assign<const volatile T>::value, "");
}
class Empty
{
};
class NotEmpty
{
virtual ~NotEmpty();
};
union Union {};
struct bit_zero
{
int : 0;
};
class Abstract
{
virtual ~Abstract() = 0;
};
struct A
{
A& operator=(const A&);
};
int main()
{
test_has_not_nothrow_assign<void>();
test_has_not_nothrow_assign<A>();
test_has_not_nothrow_assign<int&>();
test_has_nothrow_assign<Union>();
test_has_nothrow_assign<Abstract>();
test_has_nothrow_assign<Empty>();
test_has_nothrow_assign<int>();
test_has_nothrow_assign<double>();
test_has_nothrow_assign<int*>();
test_has_nothrow_assign<const int*>();
test_has_nothrow_assign<char[3]>();
test_has_nothrow_assign<char[3]>();
test_has_nothrow_assign<NotEmpty>();
test_has_nothrow_assign<bit_zero>();
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// has_nothrow_copy_assign + +#include <type_traits> + +template <class T> +void test_has_nothrow_assign() +{ + static_assert( std::has_nothrow_copy_assign<T>::value, ""); + static_assert(!std::has_nothrow_copy_assign<const T>::value, ""); + static_assert( std::has_nothrow_copy_assign<volatile T>::value, ""); + static_assert(!std::has_nothrow_copy_assign<const volatile T>::value, ""); +} + +template <class T> +void test_has_not_nothrow_assign() +{ + static_assert(!std::has_nothrow_copy_assign<T>::value, ""); + static_assert(!std::has_nothrow_copy_assign<const T>::value, ""); + static_assert(!std::has_nothrow_copy_assign<volatile T>::value, ""); + static_assert(!std::has_nothrow_copy_assign<const volatile T>::value, ""); +} + +class Empty +{ +}; + +class NotEmpty +{ + virtual ~NotEmpty(); +}; + +union Union {}; + +struct bit_zero +{ + int : 0; +}; + +class Abstract +{ + virtual ~Abstract() = 0; +}; + +struct A +{ + A& operator=(const A&); +}; + +int main() +{ + test_has_not_nothrow_assign<void>(); + test_has_not_nothrow_assign<A>(); + test_has_not_nothrow_assign<int&>(); + + test_has_nothrow_assign<Union>(); + test_has_nothrow_assign<Abstract>(); + test_has_nothrow_assign<Empty>(); + test_has_nothrow_assign<int>(); + test_has_nothrow_assign<double>(); + test_has_nothrow_assign<int*>(); + test_has_nothrow_assign<const int*>(); + test_has_nothrow_assign<char[3]>(); + test_has_nothrow_assign<char[3]>(); + test_has_nothrow_assign<NotEmpty>(); + test_has_nothrow_assign<bit_zero>(); +} diff --git a/libcxx/test/utilities/meta/meta.unary/meta.unary.prop/has_nothrow_copy_constructor.pass.cpp b/libcxx/test/utilities/meta/meta.unary/meta.unary.prop/has_nothrow_copy_constructor.pass.cpp index 1a9beaa5d77..1634dea8b64 100644 --- a/libcxx/test/utilities/meta/meta.unary/meta.unary.prop/has_nothrow_copy_constructor.pass.cpp +++ b/libcxx/test/utilities/meta/meta.unary/meta.unary.prop/has_nothrow_copy_constructor.pass.cpp @@ -1 +1,77 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// type_traits
// has_nothrow_copy_constructor
#include <type_traits>
template <class T>
void test_has_nothrow_copy_constructor()
{
static_assert( std::has_nothrow_copy_constructor<T>::value, "");
static_assert( std::has_nothrow_copy_constructor<const T>::value, "");
static_assert( std::has_nothrow_copy_constructor<volatile T>::value, "");
static_assert( std::has_nothrow_copy_constructor<const volatile T>::value, "");
}
template <class T>
void test_has_not_nothrow_copy_constructor()
{
static_assert(!std::has_nothrow_copy_constructor<T>::value, "");
static_assert(!std::has_nothrow_copy_constructor<const T>::value, "");
static_assert(!std::has_nothrow_copy_constructor<volatile T>::value, "");
static_assert(!std::has_nothrow_copy_constructor<const volatile T>::value, "");
}
class Empty
{
};
class NotEmpty
{
virtual ~NotEmpty();
};
union Union {};
struct bit_zero
{
int : 0;
};
class Abstract
{
virtual ~Abstract() = 0;
};
struct A
{
A(const A&);
};
int main()
{
test_has_not_nothrow_copy_constructor<void>();
test_has_not_nothrow_copy_constructor<A>();
test_has_not_nothrow_copy_constructor<int&>();
test_has_nothrow_copy_constructor<Union>();
test_has_nothrow_copy_constructor<Abstract>();
test_has_nothrow_copy_constructor<Empty>();
test_has_nothrow_copy_constructor<int>();
test_has_nothrow_copy_constructor<double>();
test_has_nothrow_copy_constructor<int*>();
test_has_nothrow_copy_constructor<const int*>();
test_has_nothrow_copy_constructor<char[3]>();
test_has_nothrow_copy_constructor<char[3]>();
test_has_nothrow_copy_constructor<NotEmpty>();
test_has_nothrow_copy_constructor<bit_zero>();
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// has_nothrow_copy_constructor + +#include <type_traits> + +template <class T> +void test_has_nothrow_copy_constructor() +{ + static_assert( std::has_nothrow_copy_constructor<T>::value, ""); + static_assert( std::has_nothrow_copy_constructor<const T>::value, ""); + static_assert( std::has_nothrow_copy_constructor<volatile T>::value, ""); + static_assert( std::has_nothrow_copy_constructor<const volatile T>::value, ""); +} + +template <class T> +void test_has_not_nothrow_copy_constructor() +{ + static_assert(!std::has_nothrow_copy_constructor<T>::value, ""); + static_assert(!std::has_nothrow_copy_constructor<const T>::value, ""); + static_assert(!std::has_nothrow_copy_constructor<volatile T>::value, ""); + static_assert(!std::has_nothrow_copy_constructor<const volatile T>::value, ""); +} + +class Empty +{ +}; + +class NotEmpty +{ + virtual ~NotEmpty(); +}; + +union Union {}; + +struct bit_zero +{ + int : 0; +}; + +class Abstract +{ + virtual ~Abstract() = 0; +}; + +struct A +{ + A(const A&); +}; + +int main() +{ + test_has_not_nothrow_copy_constructor<void>(); + test_has_not_nothrow_copy_constructor<A>(); + test_has_not_nothrow_copy_constructor<int&>(); + + test_has_nothrow_copy_constructor<Union>(); + test_has_nothrow_copy_constructor<Abstract>(); + test_has_nothrow_copy_constructor<Empty>(); + test_has_nothrow_copy_constructor<int>(); + test_has_nothrow_copy_constructor<double>(); + test_has_nothrow_copy_constructor<int*>(); + test_has_nothrow_copy_constructor<const int*>(); + test_has_nothrow_copy_constructor<char[3]>(); + test_has_nothrow_copy_constructor<char[3]>(); + test_has_nothrow_copy_constructor<NotEmpty>(); + test_has_nothrow_copy_constructor<bit_zero>(); +} diff --git a/libcxx/test/utilities/meta/meta.unary/meta.unary.prop/has_nothrow_default_constructor.pass.cpp b/libcxx/test/utilities/meta/meta.unary/meta.unary.prop/has_nothrow_default_constructor.pass.cpp index 2a4e81e5de4..cc4a4580930 100644 --- a/libcxx/test/utilities/meta/meta.unary/meta.unary.prop/has_nothrow_default_constructor.pass.cpp +++ b/libcxx/test/utilities/meta/meta.unary/meta.unary.prop/has_nothrow_default_constructor.pass.cpp @@ -1 +1,77 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// type_traits
// has_nothrow_default_constructor
#include <type_traits>
template <class T>
void test_has_nothrow_default_constructor()
{
static_assert( std::has_nothrow_default_constructor<T>::value, "");
static_assert( std::has_nothrow_default_constructor<const T>::value, "");
static_assert( std::has_nothrow_default_constructor<volatile T>::value, "");
static_assert( std::has_nothrow_default_constructor<const volatile T>::value, "");
}
template <class T>
void test_has_not_nothrow_default_constructor()
{
static_assert(!std::has_nothrow_default_constructor<T>::value, "");
static_assert(!std::has_nothrow_default_constructor<const T>::value, "");
static_assert(!std::has_nothrow_default_constructor<volatile T>::value, "");
static_assert(!std::has_nothrow_default_constructor<const volatile T>::value, "");
}
class Empty
{
};
class NotEmpty
{
virtual ~NotEmpty();
};
union Union {};
struct bit_zero
{
int : 0;
};
class Abstract
{
virtual ~Abstract() = 0;
};
struct A
{
A();
};
int main()
{
test_has_not_nothrow_default_constructor<void>();
test_has_not_nothrow_default_constructor<int&>();
test_has_not_nothrow_default_constructor<A>();
test_has_nothrow_default_constructor<Union>();
test_has_nothrow_default_constructor<Abstract>();
test_has_nothrow_default_constructor<Empty>();
test_has_nothrow_default_constructor<int>();
test_has_nothrow_default_constructor<double>();
test_has_nothrow_default_constructor<int*>();
test_has_nothrow_default_constructor<const int*>();
test_has_nothrow_default_constructor<char[3]>();
test_has_nothrow_default_constructor<char[3]>();
test_has_nothrow_default_constructor<NotEmpty>();
test_has_nothrow_default_constructor<bit_zero>();
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// has_nothrow_default_constructor + +#include <type_traits> + +template <class T> +void test_has_nothrow_default_constructor() +{ + static_assert( std::has_nothrow_default_constructor<T>::value, ""); + static_assert( std::has_nothrow_default_constructor<const T>::value, ""); + static_assert( std::has_nothrow_default_constructor<volatile T>::value, ""); + static_assert( std::has_nothrow_default_constructor<const volatile T>::value, ""); +} + +template <class T> +void test_has_not_nothrow_default_constructor() +{ + static_assert(!std::has_nothrow_default_constructor<T>::value, ""); + static_assert(!std::has_nothrow_default_constructor<const T>::value, ""); + static_assert(!std::has_nothrow_default_constructor<volatile T>::value, ""); + static_assert(!std::has_nothrow_default_constructor<const volatile T>::value, ""); +} + +class Empty +{ +}; + +class NotEmpty +{ + virtual ~NotEmpty(); +}; + +union Union {}; + +struct bit_zero +{ + int : 0; +}; + +class Abstract +{ + virtual ~Abstract() = 0; +}; + +struct A +{ + A(); +}; + +int main() +{ + test_has_not_nothrow_default_constructor<void>(); + test_has_not_nothrow_default_constructor<int&>(); + test_has_not_nothrow_default_constructor<A>(); + + test_has_nothrow_default_constructor<Union>(); + test_has_nothrow_default_constructor<Abstract>(); + test_has_nothrow_default_constructor<Empty>(); + test_has_nothrow_default_constructor<int>(); + test_has_nothrow_default_constructor<double>(); + test_has_nothrow_default_constructor<int*>(); + test_has_nothrow_default_constructor<const int*>(); + test_has_nothrow_default_constructor<char[3]>(); + test_has_nothrow_default_constructor<char[3]>(); + test_has_nothrow_default_constructor<NotEmpty>(); + test_has_nothrow_default_constructor<bit_zero>(); +} diff --git a/libcxx/test/utilities/meta/meta.unary/meta.unary.prop/has_trivial_copy_assign.pass.cpp b/libcxx/test/utilities/meta/meta.unary/meta.unary.prop/has_trivial_copy_assign.pass.cpp index 06419502736..762bd511479 100644 --- a/libcxx/test/utilities/meta/meta.unary/meta.unary.prop/has_trivial_copy_assign.pass.cpp +++ b/libcxx/test/utilities/meta/meta.unary/meta.unary.prop/has_trivial_copy_assign.pass.cpp @@ -1 +1,77 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// type_traits
// has_trivial_copy_assign
#include <type_traits>
template <class T>
void test_has_trivial_assign()
{
static_assert( std::has_trivial_copy_assign<T>::value, "");
static_assert(!std::has_trivial_copy_assign<const T>::value, "");
static_assert( std::has_trivial_copy_assign<volatile T>::value, "");
static_assert(!std::has_trivial_copy_assign<const volatile T>::value, "");
}
template <class T>
void test_has_not_trivial_assign()
{
static_assert(!std::has_trivial_copy_assign<T>::value, "");
static_assert(!std::has_trivial_copy_assign<const T>::value, "");
static_assert(!std::has_trivial_copy_assign<volatile T>::value, "");
static_assert(!std::has_trivial_copy_assign<const volatile T>::value, "");
}
class Empty
{
};
class NotEmpty
{
virtual ~NotEmpty();
};
union Union {};
struct bit_zero
{
int : 0;
};
class Abstract
{
virtual ~Abstract() = 0;
};
struct A
{
A& operator=(const A&);
};
int main()
{
test_has_not_trivial_assign<void>();
test_has_not_trivial_assign<A>();
test_has_not_trivial_assign<int&>();
test_has_trivial_assign<Union>();
test_has_trivial_assign<Abstract>();
test_has_trivial_assign<Empty>();
test_has_trivial_assign<int>();
test_has_trivial_assign<double>();
test_has_trivial_assign<int*>();
test_has_trivial_assign<const int*>();
test_has_trivial_assign<char[3]>();
test_has_trivial_assign<char[3]>();
test_has_trivial_assign<NotEmpty>();
test_has_trivial_assign<bit_zero>();
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// has_trivial_copy_assign + +#include <type_traits> + +template <class T> +void test_has_trivial_assign() +{ + static_assert( std::has_trivial_copy_assign<T>::value, ""); + static_assert(!std::has_trivial_copy_assign<const T>::value, ""); + static_assert( std::has_trivial_copy_assign<volatile T>::value, ""); + static_assert(!std::has_trivial_copy_assign<const volatile T>::value, ""); +} + +template <class T> +void test_has_not_trivial_assign() +{ + static_assert(!std::has_trivial_copy_assign<T>::value, ""); + static_assert(!std::has_trivial_copy_assign<const T>::value, ""); + static_assert(!std::has_trivial_copy_assign<volatile T>::value, ""); + static_assert(!std::has_trivial_copy_assign<const volatile T>::value, ""); +} + +class Empty +{ +}; + +class NotEmpty +{ + virtual ~NotEmpty(); +}; + +union Union {}; + +struct bit_zero +{ + int : 0; +}; + +class Abstract +{ + virtual ~Abstract() = 0; +}; + +struct A +{ + A& operator=(const A&); +}; + +int main() +{ + test_has_not_trivial_assign<void>(); + test_has_not_trivial_assign<A>(); + test_has_not_trivial_assign<int&>(); + + test_has_trivial_assign<Union>(); + test_has_trivial_assign<Abstract>(); + test_has_trivial_assign<Empty>(); + test_has_trivial_assign<int>(); + test_has_trivial_assign<double>(); + test_has_trivial_assign<int*>(); + test_has_trivial_assign<const int*>(); + test_has_trivial_assign<char[3]>(); + test_has_trivial_assign<char[3]>(); + test_has_trivial_assign<NotEmpty>(); + test_has_trivial_assign<bit_zero>(); +} diff --git a/libcxx/test/utilities/meta/meta.unary/meta.unary.prop/has_trivial_copy_constructor.pass.cpp b/libcxx/test/utilities/meta/meta.unary/meta.unary.prop/has_trivial_copy_constructor.pass.cpp index 711d9c3915a..c51b7726728 100644 --- a/libcxx/test/utilities/meta/meta.unary/meta.unary.prop/has_trivial_copy_constructor.pass.cpp +++ b/libcxx/test/utilities/meta/meta.unary/meta.unary.prop/has_trivial_copy_constructor.pass.cpp @@ -1 +1,77 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// type_traits
// has_trivial_copy_constructor
#include <type_traits>
template <class T>
void test_has_trivial_copy_constructor()
{
static_assert( std::has_trivial_copy_constructor<T>::value, "");
static_assert( std::has_trivial_copy_constructor<const T>::value, "");
static_assert( std::has_trivial_copy_constructor<volatile T>::value, "");
static_assert( std::has_trivial_copy_constructor<const volatile T>::value, "");
}
template <class T>
void test_has_not_trivial_copy_constructor()
{
static_assert(!std::has_trivial_copy_constructor<T>::value, "");
static_assert(!std::has_trivial_copy_constructor<const T>::value, "");
static_assert(!std::has_trivial_copy_constructor<volatile T>::value, "");
static_assert(!std::has_trivial_copy_constructor<const volatile T>::value, "");
}
class Empty
{
};
class NotEmpty
{
virtual ~NotEmpty();
};
union Union {};
struct bit_zero
{
int : 0;
};
class Abstract
{
virtual ~Abstract() = 0;
};
struct A
{
A(const A&);
};
int main()
{
test_has_not_trivial_copy_constructor<void>();
test_has_not_trivial_copy_constructor<A>();
test_has_not_trivial_copy_constructor<int&>();
test_has_trivial_copy_constructor<Union>();
test_has_trivial_copy_constructor<Abstract>();
test_has_trivial_copy_constructor<Empty>();
test_has_trivial_copy_constructor<int>();
test_has_trivial_copy_constructor<double>();
test_has_trivial_copy_constructor<int*>();
test_has_trivial_copy_constructor<const int*>();
test_has_trivial_copy_constructor<char[3]>();
test_has_trivial_copy_constructor<char[3]>();
test_has_trivial_copy_constructor<NotEmpty>();
test_has_trivial_copy_constructor<bit_zero>();
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// has_trivial_copy_constructor + +#include <type_traits> + +template <class T> +void test_has_trivial_copy_constructor() +{ + static_assert( std::has_trivial_copy_constructor<T>::value, ""); + static_assert( std::has_trivial_copy_constructor<const T>::value, ""); + static_assert( std::has_trivial_copy_constructor<volatile T>::value, ""); + static_assert( std::has_trivial_copy_constructor<const volatile T>::value, ""); +} + +template <class T> +void test_has_not_trivial_copy_constructor() +{ + static_assert(!std::has_trivial_copy_constructor<T>::value, ""); + static_assert(!std::has_trivial_copy_constructor<const T>::value, ""); + static_assert(!std::has_trivial_copy_constructor<volatile T>::value, ""); + static_assert(!std::has_trivial_copy_constructor<const volatile T>::value, ""); +} + +class Empty +{ +}; + +class NotEmpty +{ + virtual ~NotEmpty(); +}; + +union Union {}; + +struct bit_zero +{ + int : 0; +}; + +class Abstract +{ + virtual ~Abstract() = 0; +}; + +struct A +{ + A(const A&); +}; + +int main() +{ + test_has_not_trivial_copy_constructor<void>(); + test_has_not_trivial_copy_constructor<A>(); + test_has_not_trivial_copy_constructor<int&>(); + + test_has_trivial_copy_constructor<Union>(); + test_has_trivial_copy_constructor<Abstract>(); + test_has_trivial_copy_constructor<Empty>(); + test_has_trivial_copy_constructor<int>(); + test_has_trivial_copy_constructor<double>(); + test_has_trivial_copy_constructor<int*>(); + test_has_trivial_copy_constructor<const int*>(); + test_has_trivial_copy_constructor<char[3]>(); + test_has_trivial_copy_constructor<char[3]>(); + test_has_trivial_copy_constructor<NotEmpty>(); + test_has_trivial_copy_constructor<bit_zero>(); +} diff --git a/libcxx/test/utilities/meta/meta.unary/meta.unary.prop/has_trivial_default_constructor.pass.cpp b/libcxx/test/utilities/meta/meta.unary/meta.unary.prop/has_trivial_default_constructor.pass.cpp index 841fb37ec7c..cf20c8223f9 100644 --- a/libcxx/test/utilities/meta/meta.unary/meta.unary.prop/has_trivial_default_constructor.pass.cpp +++ b/libcxx/test/utilities/meta/meta.unary/meta.unary.prop/has_trivial_default_constructor.pass.cpp @@ -1 +1,77 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// type_traits
// has_trivial_default_constructor
#include <type_traits>
template <class T>
void test_has_trivial_default_constructor()
{
static_assert( std::has_trivial_default_constructor<T>::value, "");
static_assert( std::has_trivial_default_constructor<const T>::value, "");
static_assert( std::has_trivial_default_constructor<volatile T>::value, "");
static_assert( std::has_trivial_default_constructor<const volatile T>::value, "");
}
template <class T>
void test_has_not_trivial_default_constructor()
{
static_assert(!std::has_trivial_default_constructor<T>::value, "");
static_assert(!std::has_trivial_default_constructor<const T>::value, "");
static_assert(!std::has_trivial_default_constructor<volatile T>::value, "");
static_assert(!std::has_trivial_default_constructor<const volatile T>::value, "");
}
class Empty
{
};
class NotEmpty
{
virtual ~NotEmpty();
};
union Union {};
struct bit_zero
{
int : 0;
};
class Abstract
{
virtual ~Abstract() = 0;
};
struct A
{
A();
};
int main()
{
test_has_not_trivial_default_constructor<void>();
test_has_not_trivial_default_constructor<int&>();
test_has_not_trivial_default_constructor<A>();
test_has_trivial_default_constructor<Union>();
test_has_trivial_default_constructor<Abstract>();
test_has_trivial_default_constructor<Empty>();
test_has_trivial_default_constructor<int>();
test_has_trivial_default_constructor<double>();
test_has_trivial_default_constructor<int*>();
test_has_trivial_default_constructor<const int*>();
test_has_trivial_default_constructor<char[3]>();
test_has_trivial_default_constructor<char[3]>();
test_has_trivial_default_constructor<NotEmpty>();
test_has_trivial_default_constructor<bit_zero>();
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// has_trivial_default_constructor + +#include <type_traits> + +template <class T> +void test_has_trivial_default_constructor() +{ + static_assert( std::has_trivial_default_constructor<T>::value, ""); + static_assert( std::has_trivial_default_constructor<const T>::value, ""); + static_assert( std::has_trivial_default_constructor<volatile T>::value, ""); + static_assert( std::has_trivial_default_constructor<const volatile T>::value, ""); +} + +template <class T> +void test_has_not_trivial_default_constructor() +{ + static_assert(!std::has_trivial_default_constructor<T>::value, ""); + static_assert(!std::has_trivial_default_constructor<const T>::value, ""); + static_assert(!std::has_trivial_default_constructor<volatile T>::value, ""); + static_assert(!std::has_trivial_default_constructor<const volatile T>::value, ""); +} + +class Empty +{ +}; + +class NotEmpty +{ + virtual ~NotEmpty(); +}; + +union Union {}; + +struct bit_zero +{ + int : 0; +}; + +class Abstract +{ + virtual ~Abstract() = 0; +}; + +struct A +{ + A(); +}; + +int main() +{ + test_has_not_trivial_default_constructor<void>(); + test_has_not_trivial_default_constructor<int&>(); + test_has_not_trivial_default_constructor<A>(); + + test_has_trivial_default_constructor<Union>(); + test_has_trivial_default_constructor<Abstract>(); + test_has_trivial_default_constructor<Empty>(); + test_has_trivial_default_constructor<int>(); + test_has_trivial_default_constructor<double>(); + test_has_trivial_default_constructor<int*>(); + test_has_trivial_default_constructor<const int*>(); + test_has_trivial_default_constructor<char[3]>(); + test_has_trivial_default_constructor<char[3]>(); + test_has_trivial_default_constructor<NotEmpty>(); + test_has_trivial_default_constructor<bit_zero>(); +} diff --git a/libcxx/test/utilities/meta/meta.unary/meta.unary.prop/has_trivial_destructor.pass.cpp b/libcxx/test/utilities/meta/meta.unary/meta.unary.prop/has_trivial_destructor.pass.cpp index b0b09d9c8a9..37c278cebc0 100644 --- a/libcxx/test/utilities/meta/meta.unary/meta.unary.prop/has_trivial_destructor.pass.cpp +++ b/libcxx/test/utilities/meta/meta.unary/meta.unary.prop/has_trivial_destructor.pass.cpp @@ -1 +1,77 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// type_traits
// has_trivial_destructor
#include <type_traits>
template <class T>
void test_has_trivial_destructor()
{
static_assert( std::has_trivial_destructor<T>::value, "");
static_assert( std::has_trivial_destructor<const T>::value, "");
static_assert( std::has_trivial_destructor<volatile T>::value, "");
static_assert( std::has_trivial_destructor<const volatile T>::value, "");
}
template <class T>
void test_has_not_trivial_destructor()
{
static_assert(!std::has_trivial_destructor<T>::value, "");
static_assert(!std::has_trivial_destructor<const T>::value, "");
static_assert(!std::has_trivial_destructor<volatile T>::value, "");
static_assert(!std::has_trivial_destructor<const volatile T>::value, "");
}
class Empty
{
};
class NotEmpty
{
virtual ~NotEmpty();
};
union Union {};
struct bit_zero
{
int : 0;
};
class Abstract
{
virtual ~Abstract() = 0;
};
struct A
{
~A();
};
int main()
{
test_has_not_trivial_destructor<void>();
test_has_not_trivial_destructor<A>();
test_has_not_trivial_destructor<Abstract>();
test_has_not_trivial_destructor<NotEmpty>();
test_has_trivial_destructor<int&>();
test_has_trivial_destructor<Union>();
test_has_trivial_destructor<Empty>();
test_has_trivial_destructor<int>();
test_has_trivial_destructor<double>();
test_has_trivial_destructor<int*>();
test_has_trivial_destructor<const int*>();
test_has_trivial_destructor<char[3]>();
test_has_trivial_destructor<char[3]>();
test_has_trivial_destructor<bit_zero>();
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// has_trivial_destructor + +#include <type_traits> + +template <class T> +void test_has_trivial_destructor() +{ + static_assert( std::has_trivial_destructor<T>::value, ""); + static_assert( std::has_trivial_destructor<const T>::value, ""); + static_assert( std::has_trivial_destructor<volatile T>::value, ""); + static_assert( std::has_trivial_destructor<const volatile T>::value, ""); +} + +template <class T> +void test_has_not_trivial_destructor() +{ + static_assert(!std::has_trivial_destructor<T>::value, ""); + static_assert(!std::has_trivial_destructor<const T>::value, ""); + static_assert(!std::has_trivial_destructor<volatile T>::value, ""); + static_assert(!std::has_trivial_destructor<const volatile T>::value, ""); +} + +class Empty +{ +}; + +class NotEmpty +{ + virtual ~NotEmpty(); +}; + +union Union {}; + +struct bit_zero +{ + int : 0; +}; + +class Abstract +{ + virtual ~Abstract() = 0; +}; + +struct A +{ + ~A(); +}; + +int main() +{ + test_has_not_trivial_destructor<void>(); + test_has_not_trivial_destructor<A>(); + test_has_not_trivial_destructor<Abstract>(); + test_has_not_trivial_destructor<NotEmpty>(); + + test_has_trivial_destructor<int&>(); + test_has_trivial_destructor<Union>(); + test_has_trivial_destructor<Empty>(); + test_has_trivial_destructor<int>(); + test_has_trivial_destructor<double>(); + test_has_trivial_destructor<int*>(); + test_has_trivial_destructor<const int*>(); + test_has_trivial_destructor<char[3]>(); + test_has_trivial_destructor<char[3]>(); + test_has_trivial_destructor<bit_zero>(); +} diff --git a/libcxx/test/utilities/meta/meta.unary/meta.unary.prop/has_virtual_destructor.pass.cpp b/libcxx/test/utilities/meta/meta.unary/meta.unary.prop/has_virtual_destructor.pass.cpp index 05198ba130d..a9b38960443 100644 --- a/libcxx/test/utilities/meta/meta.unary/meta.unary.prop/has_virtual_destructor.pass.cpp +++ b/libcxx/test/utilities/meta/meta.unary/meta.unary.prop/has_virtual_destructor.pass.cpp @@ -1 +1,77 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// type_traits
// has_virtual_destructor
#include <type_traits>
template <class T>
void test_has_virtual_destructor()
{
static_assert( std::has_virtual_destructor<T>::value, "");
static_assert( std::has_virtual_destructor<const T>::value, "");
static_assert( std::has_virtual_destructor<volatile T>::value, "");
static_assert( std::has_virtual_destructor<const volatile T>::value, "");
}
template <class T>
void test_has_not_virtual_destructor()
{
static_assert(!std::has_virtual_destructor<T>::value, "");
static_assert(!std::has_virtual_destructor<const T>::value, "");
static_assert(!std::has_virtual_destructor<volatile T>::value, "");
static_assert(!std::has_virtual_destructor<const volatile T>::value, "");
}
class Empty
{
};
class NotEmpty
{
virtual ~NotEmpty();
};
union Union {};
struct bit_zero
{
int : 0;
};
class Abstract
{
virtual ~Abstract() = 0;
};
struct A
{
~A();
};
int main()
{
test_has_not_virtual_destructor<void>();
test_has_not_virtual_destructor<A>();
test_has_not_virtual_destructor<int&>();
test_has_not_virtual_destructor<Union>();
test_has_not_virtual_destructor<Empty>();
test_has_not_virtual_destructor<int>();
test_has_not_virtual_destructor<double>();
test_has_not_virtual_destructor<int*>();
test_has_not_virtual_destructor<const int*>();
test_has_not_virtual_destructor<char[3]>();
test_has_not_virtual_destructor<char[3]>();
test_has_not_virtual_destructor<bit_zero>();
test_has_virtual_destructor<Abstract>();
test_has_virtual_destructor<NotEmpty>();
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// has_virtual_destructor + +#include <type_traits> + +template <class T> +void test_has_virtual_destructor() +{ + static_assert( std::has_virtual_destructor<T>::value, ""); + static_assert( std::has_virtual_destructor<const T>::value, ""); + static_assert( std::has_virtual_destructor<volatile T>::value, ""); + static_assert( std::has_virtual_destructor<const volatile T>::value, ""); +} + +template <class T> +void test_has_not_virtual_destructor() +{ + static_assert(!std::has_virtual_destructor<T>::value, ""); + static_assert(!std::has_virtual_destructor<const T>::value, ""); + static_assert(!std::has_virtual_destructor<volatile T>::value, ""); + static_assert(!std::has_virtual_destructor<const volatile T>::value, ""); +} + +class Empty +{ +}; + +class NotEmpty +{ + virtual ~NotEmpty(); +}; + +union Union {}; + +struct bit_zero +{ + int : 0; +}; + +class Abstract +{ + virtual ~Abstract() = 0; +}; + +struct A +{ + ~A(); +}; + +int main() +{ + test_has_not_virtual_destructor<void>(); + test_has_not_virtual_destructor<A>(); + test_has_not_virtual_destructor<int&>(); + test_has_not_virtual_destructor<Union>(); + test_has_not_virtual_destructor<Empty>(); + test_has_not_virtual_destructor<int>(); + test_has_not_virtual_destructor<double>(); + test_has_not_virtual_destructor<int*>(); + test_has_not_virtual_destructor<const int*>(); + test_has_not_virtual_destructor<char[3]>(); + test_has_not_virtual_destructor<char[3]>(); + test_has_not_virtual_destructor<bit_zero>(); + + test_has_virtual_destructor<Abstract>(); + test_has_virtual_destructor<NotEmpty>(); +} diff --git a/libcxx/test/utilities/meta/meta.unary/meta.unary.prop/is_abstract.pass.cpp b/libcxx/test/utilities/meta/meta.unary/meta.unary.prop/is_abstract.pass.cpp index 583cbff8ffa..9be3d1dfe51 100644 --- a/libcxx/test/utilities/meta/meta.unary/meta.unary.prop/is_abstract.pass.cpp +++ b/libcxx/test/utilities/meta/meta.unary/meta.unary.prop/is_abstract.pass.cpp @@ -1 +1,71 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// type_traits
// is_abstract
#include <type_traits>
template <class T>
void test_is_abstract()
{
static_assert( std::is_abstract<T>::value, "");
static_assert( std::is_abstract<const T>::value, "");
static_assert( std::is_abstract<volatile T>::value, "");
static_assert( std::is_abstract<const volatile T>::value, "");
}
template <class T>
void test_is_not_abstract()
{
static_assert(!std::is_abstract<T>::value, "");
static_assert(!std::is_abstract<const T>::value, "");
static_assert(!std::is_abstract<volatile T>::value, "");
static_assert(!std::is_abstract<const volatile T>::value, "");
}
class Empty
{
};
class NotEmpty
{
virtual ~NotEmpty();
};
union Union {};
struct bit_zero
{
int : 0;
};
class Abstract
{
virtual ~Abstract() = 0;
};
int main()
{
test_is_not_abstract<void>();
test_is_not_abstract<int&>();
test_is_not_abstract<int>();
test_is_not_abstract<double>();
test_is_not_abstract<int*>();
test_is_not_abstract<const int*>();
test_is_not_abstract<char[3]>();
test_is_not_abstract<char[3]>();
test_is_not_abstract<Union>();
test_is_not_abstract<Empty>();
test_is_not_abstract<bit_zero>();
test_is_not_abstract<NotEmpty>();
test_is_abstract<Abstract>();
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// is_abstract + +#include <type_traits> + +template <class T> +void test_is_abstract() +{ + static_assert( std::is_abstract<T>::value, ""); + static_assert( std::is_abstract<const T>::value, ""); + static_assert( std::is_abstract<volatile T>::value, ""); + static_assert( std::is_abstract<const volatile T>::value, ""); +} + +template <class T> +void test_is_not_abstract() +{ + static_assert(!std::is_abstract<T>::value, ""); + static_assert(!std::is_abstract<const T>::value, ""); + static_assert(!std::is_abstract<volatile T>::value, ""); + static_assert(!std::is_abstract<const volatile T>::value, ""); +} + +class Empty +{ +}; + +class NotEmpty +{ + virtual ~NotEmpty(); +}; + +union Union {}; + +struct bit_zero +{ + int : 0; +}; + +class Abstract +{ + virtual ~Abstract() = 0; +}; + +int main() +{ + test_is_not_abstract<void>(); + test_is_not_abstract<int&>(); + test_is_not_abstract<int>(); + test_is_not_abstract<double>(); + test_is_not_abstract<int*>(); + test_is_not_abstract<const int*>(); + test_is_not_abstract<char[3]>(); + test_is_not_abstract<char[3]>(); + test_is_not_abstract<Union>(); + test_is_not_abstract<Empty>(); + test_is_not_abstract<bit_zero>(); + test_is_not_abstract<NotEmpty>(); + + test_is_abstract<Abstract>(); +} diff --git a/libcxx/test/utilities/meta/meta.unary/meta.unary.prop/is_const.pass.cpp b/libcxx/test/utilities/meta/meta.unary/meta.unary.prop/is_const.pass.cpp index c56b78ba519..7aeefa5686f 100644 --- a/libcxx/test/utilities/meta/meta.unary/meta.unary.prop/is_const.pass.cpp +++ b/libcxx/test/utilities/meta/meta.unary/meta.unary.prop/is_const.pass.cpp @@ -1 +1,37 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// type_traits
// is_const
#include <type_traits>
template <class T>
void test_is_const()
{
static_assert(!std::is_const<T>::value, "");
static_assert( std::is_const<const T>::value, "");
static_assert(!std::is_const<volatile T>::value, "");
static_assert( std::is_const<const volatile T>::value, "");
}
int main()
{
test_is_const<void>();
test_is_const<int>();
test_is_const<double>();
test_is_const<int*>();
test_is_const<const int*>();
test_is_const<char[3]>();
test_is_const<char[3]>();
static_assert(!std::is_const<int&>::value, "");
static_assert(!std::is_const<const int&>::value, "");
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// is_const + +#include <type_traits> + +template <class T> +void test_is_const() +{ + static_assert(!std::is_const<T>::value, ""); + static_assert( std::is_const<const T>::value, ""); + static_assert(!std::is_const<volatile T>::value, ""); + static_assert( std::is_const<const volatile T>::value, ""); +} + +int main() +{ + test_is_const<void>(); + test_is_const<int>(); + test_is_const<double>(); + test_is_const<int*>(); + test_is_const<const int*>(); + test_is_const<char[3]>(); + test_is_const<char[3]>(); + + static_assert(!std::is_const<int&>::value, ""); + static_assert(!std::is_const<const int&>::value, ""); +} diff --git a/libcxx/test/utilities/meta/meta.unary/meta.unary.prop/is_constructible.pass.cpp b/libcxx/test/utilities/meta/meta.unary/meta.unary.prop/is_constructible.pass.cpp index a4601fd9b6a..344ddcc03a1 100644 --- a/libcxx/test/utilities/meta/meta.unary/meta.unary.prop/is_constructible.pass.cpp +++ b/libcxx/test/utilities/meta/meta.unary/meta.unary.prop/is_constructible.pass.cpp @@ -1 +1,38 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// type_traits
// template <class T, class... Args>
// struct is_constructible;
#include <type_traits>
#ifndef _LIBCPP_HAS_NO_ADVANCED_SFINAE
struct A
{
explicit A(int);
A(int, double);
};
#endif
int main()
{
#ifndef _LIBCPP_HAS_NO_ADVANCED_SFINAE
static_assert((std::is_constructible<int>::value), "");
static_assert((std::is_constructible<int, const int>::value), "");
static_assert((std::is_constructible<A, int>::value), "");
static_assert((std::is_constructible<A, int, double>::value), "");
static_assert((!std::is_constructible<A>::value), "");
#endif
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// template <class T, class... Args> +// struct is_constructible; + +#include <type_traits> + +#ifndef _LIBCPP_HAS_NO_ADVANCED_SFINAE + +struct A +{ + explicit A(int); + A(int, double); +}; + +#endif // _LIBCPP_HAS_NO_ADVANCED_SFINAE + +int main() +{ +#ifndef _LIBCPP_HAS_NO_ADVANCED_SFINAE + + static_assert((std::is_constructible<int>::value), ""); + static_assert((std::is_constructible<int, const int>::value), ""); + static_assert((std::is_constructible<A, int>::value), ""); + static_assert((std::is_constructible<A, int, double>::value), ""); + static_assert((!std::is_constructible<A>::value), ""); + +#endif // _LIBCPP_HAS_NO_ADVANCED_SFINAE +} diff --git a/libcxx/test/utilities/meta/meta.unary/meta.unary.prop/is_empty.pass.cpp b/libcxx/test/utilities/meta/meta.unary/meta.unary.prop/is_empty.pass.cpp index e1dc14f7e70..1aebc0bcd65 100644 --- a/libcxx/test/utilities/meta/meta.unary/meta.unary.prop/is_empty.pass.cpp +++ b/libcxx/test/utilities/meta/meta.unary/meta.unary.prop/is_empty.pass.cpp @@ -1 +1,65 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// type_traits
// is_empty
#include <type_traits>
template <class T>
void test_is_empty()
{
static_assert( std::is_empty<T>::value, "");
static_assert( std::is_empty<const T>::value, "");
static_assert( std::is_empty<volatile T>::value, "");
static_assert( std::is_empty<const volatile T>::value, "");
}
template <class T>
void test_is_not_empty()
{
static_assert(!std::is_empty<T>::value, "");
static_assert(!std::is_empty<const T>::value, "");
static_assert(!std::is_empty<volatile T>::value, "");
static_assert(!std::is_empty<const volatile T>::value, "");
}
class Empty
{
};
class NotEmpty
{
virtual ~NotEmpty();
};
union Union {};
struct bit_zero
{
int : 0;
};
int main()
{
test_is_not_empty<void>();
test_is_not_empty<int&>();
test_is_not_empty<int>();
test_is_not_empty<double>();
test_is_not_empty<int*>();
test_is_not_empty<const int*>();
test_is_not_empty<char[3]>();
test_is_not_empty<char[3]>();
test_is_not_empty<Union>();
test_is_not_empty<NotEmpty>();
test_is_empty<Empty>();
test_is_empty<bit_zero>();
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// is_empty + +#include <type_traits> + +template <class T> +void test_is_empty() +{ + static_assert( std::is_empty<T>::value, ""); + static_assert( std::is_empty<const T>::value, ""); + static_assert( std::is_empty<volatile T>::value, ""); + static_assert( std::is_empty<const volatile T>::value, ""); +} + +template <class T> +void test_is_not_empty() +{ + static_assert(!std::is_empty<T>::value, ""); + static_assert(!std::is_empty<const T>::value, ""); + static_assert(!std::is_empty<volatile T>::value, ""); + static_assert(!std::is_empty<const volatile T>::value, ""); +} + +class Empty +{ +}; + +class NotEmpty +{ + virtual ~NotEmpty(); +}; + +union Union {}; + +struct bit_zero +{ + int : 0; +}; + +int main() +{ + test_is_not_empty<void>(); + test_is_not_empty<int&>(); + test_is_not_empty<int>(); + test_is_not_empty<double>(); + test_is_not_empty<int*>(); + test_is_not_empty<const int*>(); + test_is_not_empty<char[3]>(); + test_is_not_empty<char[3]>(); + test_is_not_empty<Union>(); + test_is_not_empty<NotEmpty>(); + + test_is_empty<Empty>(); + test_is_empty<bit_zero>(); +} diff --git a/libcxx/test/utilities/meta/meta.unary/meta.unary.prop/is_literal_type.pass.cpp b/libcxx/test/utilities/meta/meta.unary/meta.unary.prop/is_literal_type.pass.cpp index cbce73730c4..557206a3a39 100644 --- a/libcxx/test/utilities/meta/meta.unary/meta.unary.prop/is_literal_type.pass.cpp +++ b/libcxx/test/utilities/meta/meta.unary/meta.unary.prop/is_literal_type.pass.cpp @@ -1 +1,22 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// type_traits
// is_literal_type
#include <type_traits>
int main()
{
static_assert( std::is_literal_type<int>::value, "");
static_assert( std::is_literal_type<const int>::value, "");
static_assert(!std::is_literal_type<int&>::value, "");
static_assert(!std::is_literal_type<volatile int&>::value, "");
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// is_literal_type + +#include <type_traits> + +int main() +{ + static_assert( std::is_literal_type<int>::value, ""); + static_assert( std::is_literal_type<const int>::value, ""); + static_assert(!std::is_literal_type<int&>::value, ""); + static_assert(!std::is_literal_type<volatile int&>::value, ""); +} diff --git a/libcxx/test/utilities/meta/meta.unary/meta.unary.prop/is_nothrow_constructible.pass.cpp b/libcxx/test/utilities/meta/meta.unary/meta.unary.prop/is_nothrow_constructible.pass.cpp index 0974ee3aa33..57e176b7c17 100644 --- a/libcxx/test/utilities/meta/meta.unary/meta.unary.prop/is_nothrow_constructible.pass.cpp +++ b/libcxx/test/utilities/meta/meta.unary/meta.unary.prop/is_nothrow_constructible.pass.cpp @@ -1 +1,52 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// type_traits
// template <class T, class... Args>
// struct is_nothrow_constructible;
#include <type_traits>
#ifndef _LIBCPP_HAS_NO_VARIADICS
class Empty
{
};
class NotEmpty
{
virtual ~NotEmpty();
};
union Union {};
struct bit_zero
{
int : 0;
};
class Abstract
{
virtual ~Abstract() = 0;
};
struct A
{
A(const A&);
};
#endif
int main()
{
#ifndef _LIBCPP_HAS_NO_VARIADICS
static_assert((std::is_nothrow_constructible<int, const int>::value), "");
#endif
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// template <class T, class... Args> +// struct is_nothrow_constructible; + +#include <type_traits> + +#ifndef _LIBCPP_HAS_NO_VARIADICS + +class Empty +{ +}; + +class NotEmpty +{ + virtual ~NotEmpty(); +}; + +union Union {}; + +struct bit_zero +{ + int : 0; +}; + +class Abstract +{ + virtual ~Abstract() = 0; +}; + +struct A +{ + A(const A&); +}; + +#endif // _LIBCPP_HAS_NO_VARIADICS + +int main() +{ +#ifndef _LIBCPP_HAS_NO_VARIADICS + static_assert((std::is_nothrow_constructible<int, const int>::value), ""); +#endif +} diff --git a/libcxx/test/utilities/meta/meta.unary/meta.unary.prop/is_pod.pass.cpp b/libcxx/test/utilities/meta/meta.unary/meta.unary.prop/is_pod.pass.cpp index 8f783b0734a..a70d23ca15e 100644 --- a/libcxx/test/utilities/meta/meta.unary/meta.unary.prop/is_pod.pass.cpp +++ b/libcxx/test/utilities/meta/meta.unary/meta.unary.prop/is_pod.pass.cpp @@ -1 +1,52 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// type_traits
// is_pod
#include <type_traits>
template <class T>
void test_is_pod()
{
static_assert( std::is_pod<T>::value, "");
static_assert( std::is_pod<const T>::value, "");
static_assert( std::is_pod<volatile T>::value, "");
static_assert( std::is_pod<const volatile T>::value, "");
}
template <class T>
void test_is_not_pod()
{
static_assert(!std::is_pod<T>::value, "");
static_assert(!std::is_pod<const T>::value, "");
static_assert(!std::is_pod<volatile T>::value, "");
static_assert(!std::is_pod<const volatile T>::value, "");
}
class Class
{
public:
~Class();
};
int main()
{
test_is_not_pod<void>();
test_is_not_pod<int&>();
test_is_not_pod<Class>();
test_is_pod<int>();
test_is_pod<double>();
test_is_pod<int*>();
test_is_pod<const int*>();
test_is_pod<char[3]>();
test_is_pod<char[3]>();
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// is_pod + +#include <type_traits> + +template <class T> +void test_is_pod() +{ + static_assert( std::is_pod<T>::value, ""); + static_assert( std::is_pod<const T>::value, ""); + static_assert( std::is_pod<volatile T>::value, ""); + static_assert( std::is_pod<const volatile T>::value, ""); +} + +template <class T> +void test_is_not_pod() +{ + static_assert(!std::is_pod<T>::value, ""); + static_assert(!std::is_pod<const T>::value, ""); + static_assert(!std::is_pod<volatile T>::value, ""); + static_assert(!std::is_pod<const volatile T>::value, ""); +} + +class Class +{ +public: + ~Class(); +}; + +int main() +{ + test_is_not_pod<void>(); + test_is_not_pod<int&>(); + test_is_not_pod<Class>(); + + test_is_pod<int>(); + test_is_pod<double>(); + test_is_pod<int*>(); + test_is_pod<const int*>(); + test_is_pod<char[3]>(); + test_is_pod<char[3]>(); +} diff --git a/libcxx/test/utilities/meta/meta.unary/meta.unary.prop/is_polymorphic.pass.cpp b/libcxx/test/utilities/meta/meta.unary/meta.unary.prop/is_polymorphic.pass.cpp index 07004b9fa89..018478923a3 100644 --- a/libcxx/test/utilities/meta/meta.unary/meta.unary.prop/is_polymorphic.pass.cpp +++ b/libcxx/test/utilities/meta/meta.unary/meta.unary.prop/is_polymorphic.pass.cpp @@ -1 +1,71 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// type_traits
// is_polymorphic
#include <type_traits>
template <class T>
void test_is_polymorphic()
{
static_assert( std::is_polymorphic<T>::value, "");
static_assert( std::is_polymorphic<const T>::value, "");
static_assert( std::is_polymorphic<volatile T>::value, "");
static_assert( std::is_polymorphic<const volatile T>::value, "");
}
template <class T>
void test_is_not_polymorphic()
{
static_assert(!std::is_polymorphic<T>::value, "");
static_assert(!std::is_polymorphic<const T>::value, "");
static_assert(!std::is_polymorphic<volatile T>::value, "");
static_assert(!std::is_polymorphic<const volatile T>::value, "");
}
class Empty
{
};
class NotEmpty
{
virtual ~NotEmpty();
};
union Union {};
struct bit_zero
{
int : 0;
};
class Abstract
{
virtual ~Abstract() = 0;
};
int main()
{
test_is_not_polymorphic<void>();
test_is_not_polymorphic<int&>();
test_is_not_polymorphic<int>();
test_is_not_polymorphic<double>();
test_is_not_polymorphic<int*>();
test_is_not_polymorphic<const int*>();
test_is_not_polymorphic<char[3]>();
test_is_not_polymorphic<char[3]>();
test_is_not_polymorphic<Union>();
test_is_not_polymorphic<Empty>();
test_is_not_polymorphic<bit_zero>();
test_is_polymorphic<NotEmpty>();
test_is_polymorphic<Abstract>();
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// is_polymorphic + +#include <type_traits> + +template <class T> +void test_is_polymorphic() +{ + static_assert( std::is_polymorphic<T>::value, ""); + static_assert( std::is_polymorphic<const T>::value, ""); + static_assert( std::is_polymorphic<volatile T>::value, ""); + static_assert( std::is_polymorphic<const volatile T>::value, ""); +} + +template <class T> +void test_is_not_polymorphic() +{ + static_assert(!std::is_polymorphic<T>::value, ""); + static_assert(!std::is_polymorphic<const T>::value, ""); + static_assert(!std::is_polymorphic<volatile T>::value, ""); + static_assert(!std::is_polymorphic<const volatile T>::value, ""); +} + +class Empty +{ +}; + +class NotEmpty +{ + virtual ~NotEmpty(); +}; + +union Union {}; + +struct bit_zero +{ + int : 0; +}; + +class Abstract +{ + virtual ~Abstract() = 0; +}; + +int main() +{ + test_is_not_polymorphic<void>(); + test_is_not_polymorphic<int&>(); + test_is_not_polymorphic<int>(); + test_is_not_polymorphic<double>(); + test_is_not_polymorphic<int*>(); + test_is_not_polymorphic<const int*>(); + test_is_not_polymorphic<char[3]>(); + test_is_not_polymorphic<char[3]>(); + test_is_not_polymorphic<Union>(); + test_is_not_polymorphic<Empty>(); + test_is_not_polymorphic<bit_zero>(); + + test_is_polymorphic<NotEmpty>(); + test_is_polymorphic<Abstract>(); +} diff --git a/libcxx/test/utilities/meta/meta.unary/meta.unary.prop/is_signed.pass.cpp b/libcxx/test/utilities/meta/meta.unary/meta.unary.prop/is_signed.pass.cpp index 0416e3a96b6..10b8f4e0cce 100644 --- a/libcxx/test/utilities/meta/meta.unary/meta.unary.prop/is_signed.pass.cpp +++ b/libcxx/test/utilities/meta/meta.unary/meta.unary.prop/is_signed.pass.cpp @@ -1 +1,54 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// type_traits
// is_signed
#include <type_traits>
template <class T>
void test_is_signed()
{
static_assert( std::is_signed<T>::value, "");
static_assert( std::is_signed<const T>::value, "");
static_assert( std::is_signed<volatile T>::value, "");
static_assert( std::is_signed<const volatile T>::value, "");
}
template <class T>
void test_is_not_signed()
{
static_assert(!std::is_signed<T>::value, "");
static_assert(!std::is_signed<const T>::value, "");
static_assert(!std::is_signed<volatile T>::value, "");
static_assert(!std::is_signed<const volatile T>::value, "");
}
class Class
{
public:
~Class();
};
int main()
{
test_is_not_signed<void>();
test_is_not_signed<int&>();
test_is_not_signed<Class>();
test_is_not_signed<int*>();
test_is_not_signed<const int*>();
test_is_not_signed<char[3]>();
test_is_not_signed<char[3]>();
test_is_not_signed<bool>();
test_is_not_signed<unsigned>();
test_is_signed<int>();
test_is_signed<double>();
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// is_signed + +#include <type_traits> + +template <class T> +void test_is_signed() +{ + static_assert( std::is_signed<T>::value, ""); + static_assert( std::is_signed<const T>::value, ""); + static_assert( std::is_signed<volatile T>::value, ""); + static_assert( std::is_signed<const volatile T>::value, ""); +} + +template <class T> +void test_is_not_signed() +{ + static_assert(!std::is_signed<T>::value, ""); + static_assert(!std::is_signed<const T>::value, ""); + static_assert(!std::is_signed<volatile T>::value, ""); + static_assert(!std::is_signed<const volatile T>::value, ""); +} + +class Class +{ +public: + ~Class(); +}; + +int main() +{ + test_is_not_signed<void>(); + test_is_not_signed<int&>(); + test_is_not_signed<Class>(); + test_is_not_signed<int*>(); + test_is_not_signed<const int*>(); + test_is_not_signed<char[3]>(); + test_is_not_signed<char[3]>(); + test_is_not_signed<bool>(); + test_is_not_signed<unsigned>(); + + test_is_signed<int>(); + test_is_signed<double>(); +} diff --git a/libcxx/test/utilities/meta/meta.unary/meta.unary.prop/is_standard_layout.pass.cpp b/libcxx/test/utilities/meta/meta.unary/meta.unary.prop/is_standard_layout.pass.cpp index ede3b834a5f..7371adbe6bb 100644 --- a/libcxx/test/utilities/meta/meta.unary/meta.unary.prop/is_standard_layout.pass.cpp +++ b/libcxx/test/utilities/meta/meta.unary/meta.unary.prop/is_standard_layout.pass.cpp @@ -1 +1,21 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// type_traits
// is_standard_layout
#include <type_traits>
int main()
{
static_assert( std::is_standard_layout<int>::value, "");
static_assert(!std::is_standard_layout<int&>::value, "");
static_assert(!std::is_standard_layout<volatile int&>::value, "");
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// is_standard_layout + +#include <type_traits> + +int main() +{ + static_assert( std::is_standard_layout<int>::value, ""); + static_assert(!std::is_standard_layout<int&>::value, ""); + static_assert(!std::is_standard_layout<volatile int&>::value, ""); +} diff --git a/libcxx/test/utilities/meta/meta.unary/meta.unary.prop/is_trivial.pass.cpp b/libcxx/test/utilities/meta/meta.unary/meta.unary.prop/is_trivial.pass.cpp index 3a48ccab228..05262b6cf53 100644 --- a/libcxx/test/utilities/meta/meta.unary/meta.unary.prop/is_trivial.pass.cpp +++ b/libcxx/test/utilities/meta/meta.unary/meta.unary.prop/is_trivial.pass.cpp @@ -1 +1,21 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// type_traits
// is_trivial
#include <type_traits>
int main()
{
static_assert( std::is_trivial<int>::value, "");
static_assert(!std::is_trivial<int&>::value, "");
static_assert(!std::is_trivial<volatile int&>::value, "");
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// is_trivial + +#include <type_traits> + +int main() +{ + static_assert( std::is_trivial<int>::value, ""); + static_assert(!std::is_trivial<int&>::value, ""); + static_assert(!std::is_trivial<volatile int&>::value, ""); +} diff --git a/libcxx/test/utilities/meta/meta.unary/meta.unary.prop/is_trivialially_copyable.pass.cpp b/libcxx/test/utilities/meta/meta.unary/meta.unary.prop/is_trivialially_copyable.pass.cpp index b589c2b9291..4046dbbc30d 100644 --- a/libcxx/test/utilities/meta/meta.unary/meta.unary.prop/is_trivialially_copyable.pass.cpp +++ b/libcxx/test/utilities/meta/meta.unary/meta.unary.prop/is_trivialially_copyable.pass.cpp @@ -1 +1,37 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// type_traits
// is_trivially_copyable
#include <type_traits>
#include <cassert>
struct A
{
int i_;
};
struct B
{
int i_;
~B() {assert(i_ == 0);}
};
int main()
{
static_assert( std::is_trivially_copyable<int>::value, "");
static_assert( std::is_trivially_copyable<const int>::value, "");
static_assert(!std::is_trivially_copyable<int&>::value, "");
static_assert( std::is_trivially_copyable<A>::value, "");
static_assert( std::is_trivially_copyable<const A>::value, "");
static_assert(!std::is_trivially_copyable<const A&>::value, "");
static_assert(!std::is_trivially_copyable<B>::value, "");
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// is_trivially_copyable + +#include <type_traits> +#include <cassert> + +struct A +{ + int i_; +}; + +struct B +{ + int i_; + ~B() {assert(i_ == 0);} +}; + +int main() +{ + static_assert( std::is_trivially_copyable<int>::value, ""); + static_assert( std::is_trivially_copyable<const int>::value, ""); + static_assert(!std::is_trivially_copyable<int&>::value, ""); + static_assert( std::is_trivially_copyable<A>::value, ""); + static_assert( std::is_trivially_copyable<const A>::value, ""); + static_assert(!std::is_trivially_copyable<const A&>::value, ""); + static_assert(!std::is_trivially_copyable<B>::value, ""); +} diff --git a/libcxx/test/utilities/meta/meta.unary/meta.unary.prop/is_unsigned.pass.cpp b/libcxx/test/utilities/meta/meta.unary/meta.unary.prop/is_unsigned.pass.cpp index 9967cc4ab41..d5696feb828 100644 --- a/libcxx/test/utilities/meta/meta.unary/meta.unary.prop/is_unsigned.pass.cpp +++ b/libcxx/test/utilities/meta/meta.unary/meta.unary.prop/is_unsigned.pass.cpp @@ -1 +1,54 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// type_traits
// is_unsigned
#include <type_traits>
template <class T>
void test_is_unsigned()
{
static_assert( std::is_unsigned<T>::value, "");
static_assert( std::is_unsigned<const T>::value, "");
static_assert( std::is_unsigned<volatile T>::value, "");
static_assert( std::is_unsigned<const volatile T>::value, "");
}
template <class T>
void test_is_not_unsigned()
{
static_assert(!std::is_unsigned<T>::value, "");
static_assert(!std::is_unsigned<const T>::value, "");
static_assert(!std::is_unsigned<volatile T>::value, "");
static_assert(!std::is_unsigned<const volatile T>::value, "");
}
class Class
{
public:
~Class();
};
int main()
{
test_is_not_unsigned<void>();
test_is_not_unsigned<int&>();
test_is_not_unsigned<Class>();
test_is_not_unsigned<int*>();
test_is_not_unsigned<const int*>();
test_is_not_unsigned<char[3]>();
test_is_not_unsigned<char[3]>();
test_is_not_unsigned<int>();
test_is_not_unsigned<double>();
test_is_unsigned<bool>();
test_is_unsigned<unsigned>();
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// is_unsigned + +#include <type_traits> + +template <class T> +void test_is_unsigned() +{ + static_assert( std::is_unsigned<T>::value, ""); + static_assert( std::is_unsigned<const T>::value, ""); + static_assert( std::is_unsigned<volatile T>::value, ""); + static_assert( std::is_unsigned<const volatile T>::value, ""); +} + +template <class T> +void test_is_not_unsigned() +{ + static_assert(!std::is_unsigned<T>::value, ""); + static_assert(!std::is_unsigned<const T>::value, ""); + static_assert(!std::is_unsigned<volatile T>::value, ""); + static_assert(!std::is_unsigned<const volatile T>::value, ""); +} + +class Class +{ +public: + ~Class(); +}; + +int main() +{ + test_is_not_unsigned<void>(); + test_is_not_unsigned<int&>(); + test_is_not_unsigned<Class>(); + test_is_not_unsigned<int*>(); + test_is_not_unsigned<const int*>(); + test_is_not_unsigned<char[3]>(); + test_is_not_unsigned<char[3]>(); + test_is_not_unsigned<int>(); + test_is_not_unsigned<double>(); + + test_is_unsigned<bool>(); + test_is_unsigned<unsigned>(); +} diff --git a/libcxx/test/utilities/meta/meta.unary/meta.unary.prop/is_volatile.pass.cpp b/libcxx/test/utilities/meta/meta.unary/meta.unary.prop/is_volatile.pass.cpp index 00ff887e696..92a46bd9077 100644 --- a/libcxx/test/utilities/meta/meta.unary/meta.unary.prop/is_volatile.pass.cpp +++ b/libcxx/test/utilities/meta/meta.unary/meta.unary.prop/is_volatile.pass.cpp @@ -1 +1,37 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// type_traits
// is_volatile
#include <type_traits>
template <class T>
void test_is_volatile()
{
static_assert(!std::is_volatile<T>::value, "");
static_assert(!std::is_volatile<const T>::value, "");
static_assert( std::is_volatile<volatile T>::value, "");
static_assert( std::is_volatile<const volatile T>::value, "");
}
int main()
{
test_is_volatile<void>();
test_is_volatile<int>();
test_is_volatile<double>();
test_is_volatile<int*>();
test_is_volatile<const int*>();
test_is_volatile<char[3]>();
test_is_volatile<char[3]>();
static_assert(!std::is_volatile<int&>::value, "");
static_assert(!std::is_volatile<volatile int&>::value, "");
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// is_volatile + +#include <type_traits> + +template <class T> +void test_is_volatile() +{ + static_assert(!std::is_volatile<T>::value, ""); + static_assert(!std::is_volatile<const T>::value, ""); + static_assert( std::is_volatile<volatile T>::value, ""); + static_assert( std::is_volatile<const volatile T>::value, ""); +} + +int main() +{ + test_is_volatile<void>(); + test_is_volatile<int>(); + test_is_volatile<double>(); + test_is_volatile<int*>(); + test_is_volatile<const int*>(); + test_is_volatile<char[3]>(); + test_is_volatile<char[3]>(); + + static_assert(!std::is_volatile<int&>::value, ""); + static_assert(!std::is_volatile<volatile int&>::value, ""); +} diff --git a/libcxx/test/utilities/meta/meta.unary/meta.unary.prop/rank.pass.cpp b/libcxx/test/utilities/meta/meta.unary/meta.unary.prop/rank.pass.cpp index 0cd61f685f0..d2e4702e886 100644 --- a/libcxx/test/utilities/meta/meta.unary/meta.unary.prop/rank.pass.cpp +++ b/libcxx/test/utilities/meta/meta.unary/meta.unary.prop/rank.pass.cpp @@ -1 +1,46 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// type_traits
// rank
#include <type_traits>
template <class T, unsigned A>
void test_rank()
{
static_assert( std::rank<T>::value == A, "");
static_assert( std::rank<const T>::value == A, "");
static_assert( std::rank<volatile T>::value == A, "");
static_assert( std::rank<const volatile T>::value == A, "");
}
class Class
{
public:
~Class();
};
int main()
{
test_rank<void, 0>();
test_rank<int&, 0>();
test_rank<Class, 0>();
test_rank<int*, 0>();
test_rank<const int*, 0>();
test_rank<int, 0>();
test_rank<double, 0>();
test_rank<bool, 0>();
test_rank<unsigned, 0>();
test_rank<char[3], 1>();
test_rank<char[][3], 2>();
test_rank<char[][4][3], 3>();
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// rank + +#include <type_traits> + +template <class T, unsigned A> +void test_rank() +{ + static_assert( std::rank<T>::value == A, ""); + static_assert( std::rank<const T>::value == A, ""); + static_assert( std::rank<volatile T>::value == A, ""); + static_assert( std::rank<const volatile T>::value == A, ""); +} + +class Class +{ +public: + ~Class(); +}; + +int main() +{ + test_rank<void, 0>(); + test_rank<int&, 0>(); + test_rank<Class, 0>(); + test_rank<int*, 0>(); + test_rank<const int*, 0>(); + test_rank<int, 0>(); + test_rank<double, 0>(); + test_rank<bool, 0>(); + test_rank<unsigned, 0>(); + + test_rank<char[3], 1>(); + test_rank<char[][3], 2>(); + test_rank<char[][4][3], 3>(); +} diff --git a/libcxx/test/utilities/meta/meta.unary/nothing_to_do.pass.cpp b/libcxx/test/utilities/meta/meta.unary/nothing_to_do.pass.cpp index e8db90cbee0..b89f168e9c4 100644 --- a/libcxx/test/utilities/meta/meta.unary/nothing_to_do.pass.cpp +++ b/libcxx/test/utilities/meta/meta.unary/nothing_to_do.pass.cpp @@ -1 +1,12 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
int main()
{
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/libcxx/test/utilities/meta/version.pass.cpp b/libcxx/test/utilities/meta/version.pass.cpp index 513d4080a53..9aa7c8c096f 100644 --- a/libcxx/test/utilities/meta/version.pass.cpp +++ b/libcxx/test/utilities/meta/version.pass.cpp @@ -1 +1,20 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <type_traits>
#include <type_traits>
#ifndef _LIBCPP_VERSION
#error _LIBCPP_VERSION not defined
#endif
int main()
{
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <type_traits> + +#include <type_traits> + +#ifndef _LIBCPP_VERSION +#error _LIBCPP_VERSION not defined +#endif + +int main() +{ +} diff --git a/libcxx/test/utilities/nothing_to_do.pass.cpp b/libcxx/test/utilities/nothing_to_do.pass.cpp index e8db90cbee0..b89f168e9c4 100644 --- a/libcxx/test/utilities/nothing_to_do.pass.cpp +++ b/libcxx/test/utilities/nothing_to_do.pass.cpp @@ -1 +1,12 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
int main()
{
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/libcxx/test/utilities/ratio/ratio.arithmetic/ratio_add.fail.cpp b/libcxx/test/utilities/ratio/ratio.arithmetic/ratio_add.fail.cpp index 4b88d7ca1af..17d7a900d66 100644 --- a/libcxx/test/utilities/ratio/ratio.arithmetic/ratio_add.fail.cpp +++ b/libcxx/test/utilities/ratio/ratio.arithmetic/ratio_add.fail.cpp @@ -1 +1,19 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// test ratio_add
#include <ratio>
int main()
{
typedef std::ratio<0x7FFFFFFFFFFFFFFFLL, 1> R1;
typedef std::ratio<1, 1> R2;
typedef std::ratio_add<R1, R2>::type R;
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// test ratio_add + +#include <ratio> + +int main() +{ + typedef std::ratio<0x7FFFFFFFFFFFFFFFLL, 1> R1; + typedef std::ratio<1, 1> R2; + typedef std::ratio_add<R1, R2>::type R; +} diff --git a/libcxx/test/utilities/ratio/ratio.arithmetic/ratio_add.pass.cpp b/libcxx/test/utilities/ratio/ratio.arithmetic/ratio_add.pass.cpp index 8ab8ad98527..e69f11f43cd 100644 --- a/libcxx/test/utilities/ratio/ratio.arithmetic/ratio_add.pass.cpp +++ b/libcxx/test/utilities/ratio/ratio.arithmetic/ratio_add.pass.cpp @@ -1 +1,58 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// test ratio_add
#include <ratio>
int main()
{
{
typedef std::ratio<1, 1> R1;
typedef std::ratio<1, 1> R2;
typedef std::ratio_add<R1, R2>::type R;
static_assert(R::num == 2 && R::den == 1, "");
}
{
typedef std::ratio<1, 2> R1;
typedef std::ratio<1, 1> R2;
typedef std::ratio_add<R1, R2>::type R;
static_assert(R::num == 3 && R::den == 2, "");
}
{
typedef std::ratio<-1, 2> R1;
typedef std::ratio<1, 1> R2;
typedef std::ratio_add<R1, R2>::type R;
static_assert(R::num == 1 && R::den == 2, "");
}
{
typedef std::ratio<1, -2> R1;
typedef std::ratio<1, 1> R2;
typedef std::ratio_add<R1, R2>::type R;
static_assert(R::num == 1 && R::den == 2, "");
}
{
typedef std::ratio<1, 2> R1;
typedef std::ratio<-1, 1> R2;
typedef std::ratio_add<R1, R2>::type R;
static_assert(R::num == -1 && R::den == 2, "");
}
{
typedef std::ratio<1, 2> R1;
typedef std::ratio<1, -1> R2;
typedef std::ratio_add<R1, R2>::type R;
static_assert(R::num == -1 && R::den == 2, "");
}
{
typedef std::ratio<56987354, 467584654> R1;
typedef std::ratio<544668, 22145> R2;
typedef std::ratio_add<R1, R2>::type R;
static_assert(R::num == 127970191639601LL && R::den == 5177331081415LL, "");
}
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// test ratio_add + +#include <ratio> + +int main() +{ + { + typedef std::ratio<1, 1> R1; + typedef std::ratio<1, 1> R2; + typedef std::ratio_add<R1, R2>::type R; + static_assert(R::num == 2 && R::den == 1, ""); + } + { + typedef std::ratio<1, 2> R1; + typedef std::ratio<1, 1> R2; + typedef std::ratio_add<R1, R2>::type R; + static_assert(R::num == 3 && R::den == 2, ""); + } + { + typedef std::ratio<-1, 2> R1; + typedef std::ratio<1, 1> R2; + typedef std::ratio_add<R1, R2>::type R; + static_assert(R::num == 1 && R::den == 2, ""); + } + { + typedef std::ratio<1, -2> R1; + typedef std::ratio<1, 1> R2; + typedef std::ratio_add<R1, R2>::type R; + static_assert(R::num == 1 && R::den == 2, ""); + } + { + typedef std::ratio<1, 2> R1; + typedef std::ratio<-1, 1> R2; + typedef std::ratio_add<R1, R2>::type R; + static_assert(R::num == -1 && R::den == 2, ""); + } + { + typedef std::ratio<1, 2> R1; + typedef std::ratio<1, -1> R2; + typedef std::ratio_add<R1, R2>::type R; + static_assert(R::num == -1 && R::den == 2, ""); + } + { + typedef std::ratio<56987354, 467584654> R1; + typedef std::ratio<544668, 22145> R2; + typedef std::ratio_add<R1, R2>::type R; + static_assert(R::num == 127970191639601LL && R::den == 5177331081415LL, ""); + } +} diff --git a/libcxx/test/utilities/ratio/ratio.arithmetic/ratio_divide.fail.cpp b/libcxx/test/utilities/ratio/ratio.arithmetic/ratio_divide.fail.cpp index 6058f7cdb9e..69acec1f889 100644 --- a/libcxx/test/utilities/ratio/ratio.arithmetic/ratio_divide.fail.cpp +++ b/libcxx/test/utilities/ratio/ratio.arithmetic/ratio_divide.fail.cpp @@ -1 +1,19 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// test ratio_divide
#include <ratio>
int main()
{
typedef std::ratio<0x7FFFFFFFFFFFFFFFLL, 1> R1;
typedef std::ratio<1, 2> R2;
typedef std::ratio_divide<R1, R2>::type R;
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// test ratio_divide + +#include <ratio> + +int main() +{ + typedef std::ratio<0x7FFFFFFFFFFFFFFFLL, 1> R1; + typedef std::ratio<1, 2> R2; + typedef std::ratio_divide<R1, R2>::type R; +} diff --git a/libcxx/test/utilities/ratio/ratio.arithmetic/ratio_divide.pass.cpp b/libcxx/test/utilities/ratio/ratio.arithmetic/ratio_divide.pass.cpp index 79623e67498..2e7b312570e 100644 --- a/libcxx/test/utilities/ratio/ratio.arithmetic/ratio_divide.pass.cpp +++ b/libcxx/test/utilities/ratio/ratio.arithmetic/ratio_divide.pass.cpp @@ -1 +1,58 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// test ratio_divide
#include <ratio>
int main()
{
{
typedef std::ratio<1, 1> R1;
typedef std::ratio<1, 1> R2;
typedef std::ratio_divide<R1, R2>::type R;
static_assert(R::num == 1 && R::den == 1, "");
}
{
typedef std::ratio<1, 2> R1;
typedef std::ratio<1, 1> R2;
typedef std::ratio_divide<R1, R2>::type R;
static_assert(R::num == 1 && R::den == 2, "");
}
{
typedef std::ratio<-1, 2> R1;
typedef std::ratio<1, 1> R2;
typedef std::ratio_divide<R1, R2>::type R;
static_assert(R::num == -1 && R::den == 2, "");
}
{
typedef std::ratio<1, -2> R1;
typedef std::ratio<1, 1> R2;
typedef std::ratio_divide<R1, R2>::type R;
static_assert(R::num == -1 && R::den == 2, "");
}
{
typedef std::ratio<1, 2> R1;
typedef std::ratio<-1, 1> R2;
typedef std::ratio_divide<R1, R2>::type R;
static_assert(R::num == -1 && R::den == 2, "");
}
{
typedef std::ratio<1, 2> R1;
typedef std::ratio<1, -1> R2;
typedef std::ratio_divide<R1, R2>::type R;
static_assert(R::num == -1 && R::den == 2, "");
}
{
typedef std::ratio<56987354, 467584654> R1;
typedef std::ratio<544668, 22145> R2;
typedef std::ratio_divide<R1, R2>::type R;
static_assert(R::num == 630992477165LL && R::den == 127339199162436LL, "");
}
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// test ratio_divide + +#include <ratio> + +int main() +{ + { + typedef std::ratio<1, 1> R1; + typedef std::ratio<1, 1> R2; + typedef std::ratio_divide<R1, R2>::type R; + static_assert(R::num == 1 && R::den == 1, ""); + } + { + typedef std::ratio<1, 2> R1; + typedef std::ratio<1, 1> R2; + typedef std::ratio_divide<R1, R2>::type R; + static_assert(R::num == 1 && R::den == 2, ""); + } + { + typedef std::ratio<-1, 2> R1; + typedef std::ratio<1, 1> R2; + typedef std::ratio_divide<R1, R2>::type R; + static_assert(R::num == -1 && R::den == 2, ""); + } + { + typedef std::ratio<1, -2> R1; + typedef std::ratio<1, 1> R2; + typedef std::ratio_divide<R1, R2>::type R; + static_assert(R::num == -1 && R::den == 2, ""); + } + { + typedef std::ratio<1, 2> R1; + typedef std::ratio<-1, 1> R2; + typedef std::ratio_divide<R1, R2>::type R; + static_assert(R::num == -1 && R::den == 2, ""); + } + { + typedef std::ratio<1, 2> R1; + typedef std::ratio<1, -1> R2; + typedef std::ratio_divide<R1, R2>::type R; + static_assert(R::num == -1 && R::den == 2, ""); + } + { + typedef std::ratio<56987354, 467584654> R1; + typedef std::ratio<544668, 22145> R2; + typedef std::ratio_divide<R1, R2>::type R; + static_assert(R::num == 630992477165LL && R::den == 127339199162436LL, ""); + } +} diff --git a/libcxx/test/utilities/ratio/ratio.arithmetic/ratio_multiply.fail.cpp b/libcxx/test/utilities/ratio/ratio.arithmetic/ratio_multiply.fail.cpp index 04e7683d18d..98031002ca4 100644 --- a/libcxx/test/utilities/ratio/ratio.arithmetic/ratio_multiply.fail.cpp +++ b/libcxx/test/utilities/ratio/ratio.arithmetic/ratio_multiply.fail.cpp @@ -1 +1,19 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// test ratio_multiply
#include <ratio>
int main()
{
typedef std::ratio<0x7FFFFFFFFFFFFFFFLL, 1> R1;
typedef std::ratio<2, 1> R2;
typedef std::ratio_multiply<R1, R2>::type R;
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// test ratio_multiply + +#include <ratio> + +int main() +{ + typedef std::ratio<0x7FFFFFFFFFFFFFFFLL, 1> R1; + typedef std::ratio<2, 1> R2; + typedef std::ratio_multiply<R1, R2>::type R; +} diff --git a/libcxx/test/utilities/ratio/ratio.arithmetic/ratio_multiply.pass.cpp b/libcxx/test/utilities/ratio/ratio.arithmetic/ratio_multiply.pass.cpp index b4b3f6a725e..24d980a117e 100644 --- a/libcxx/test/utilities/ratio/ratio.arithmetic/ratio_multiply.pass.cpp +++ b/libcxx/test/utilities/ratio/ratio.arithmetic/ratio_multiply.pass.cpp @@ -1 +1,58 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// test ratio_multiply
#include <ratio>
int main()
{
{
typedef std::ratio<1, 1> R1;
typedef std::ratio<1, 1> R2;
typedef std::ratio_multiply<R1, R2>::type R;
static_assert(R::num == 1 && R::den == 1, "");
}
{
typedef std::ratio<1, 2> R1;
typedef std::ratio<1, 1> R2;
typedef std::ratio_multiply<R1, R2>::type R;
static_assert(R::num == 1 && R::den == 2, "");
}
{
typedef std::ratio<-1, 2> R1;
typedef std::ratio<1, 1> R2;
typedef std::ratio_multiply<R1, R2>::type R;
static_assert(R::num == -1 && R::den == 2, "");
}
{
typedef std::ratio<1, -2> R1;
typedef std::ratio<1, 1> R2;
typedef std::ratio_multiply<R1, R2>::type R;
static_assert(R::num == -1 && R::den == 2, "");
}
{
typedef std::ratio<1, 2> R1;
typedef std::ratio<-1, 1> R2;
typedef std::ratio_multiply<R1, R2>::type R;
static_assert(R::num == -1 && R::den == 2, "");
}
{
typedef std::ratio<1, 2> R1;
typedef std::ratio<1, -1> R2;
typedef std::ratio_multiply<R1, R2>::type R;
static_assert(R::num == -1 && R::den == 2, "");
}
{
typedef std::ratio<56987354, 467584654> R1;
typedef std::ratio<544668, 22145> R2;
typedef std::ratio_multiply<R1, R2>::type R;
static_assert(R::num == 15519594064236LL && R::den == 5177331081415LL, "");
}
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// test ratio_multiply + +#include <ratio> + +int main() +{ + { + typedef std::ratio<1, 1> R1; + typedef std::ratio<1, 1> R2; + typedef std::ratio_multiply<R1, R2>::type R; + static_assert(R::num == 1 && R::den == 1, ""); + } + { + typedef std::ratio<1, 2> R1; + typedef std::ratio<1, 1> R2; + typedef std::ratio_multiply<R1, R2>::type R; + static_assert(R::num == 1 && R::den == 2, ""); + } + { + typedef std::ratio<-1, 2> R1; + typedef std::ratio<1, 1> R2; + typedef std::ratio_multiply<R1, R2>::type R; + static_assert(R::num == -1 && R::den == 2, ""); + } + { + typedef std::ratio<1, -2> R1; + typedef std::ratio<1, 1> R2; + typedef std::ratio_multiply<R1, R2>::type R; + static_assert(R::num == -1 && R::den == 2, ""); + } + { + typedef std::ratio<1, 2> R1; + typedef std::ratio<-1, 1> R2; + typedef std::ratio_multiply<R1, R2>::type R; + static_assert(R::num == -1 && R::den == 2, ""); + } + { + typedef std::ratio<1, 2> R1; + typedef std::ratio<1, -1> R2; + typedef std::ratio_multiply<R1, R2>::type R; + static_assert(R::num == -1 && R::den == 2, ""); + } + { + typedef std::ratio<56987354, 467584654> R1; + typedef std::ratio<544668, 22145> R2; + typedef std::ratio_multiply<R1, R2>::type R; + static_assert(R::num == 15519594064236LL && R::den == 5177331081415LL, ""); + } +} diff --git a/libcxx/test/utilities/ratio/ratio.arithmetic/ratio_subtract.fail.cpp b/libcxx/test/utilities/ratio/ratio.arithmetic/ratio_subtract.fail.cpp index 7d03fb7a694..8b5ea5d2d32 100644 --- a/libcxx/test/utilities/ratio/ratio.arithmetic/ratio_subtract.fail.cpp +++ b/libcxx/test/utilities/ratio/ratio.arithmetic/ratio_subtract.fail.cpp @@ -1 +1,19 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// test ratio_subtract
#include <ratio>
int main()
{
typedef std::ratio<-0x7FFFFFFFFFFFFFFFLL, 1> R1;
typedef std::ratio<1, 1> R2;
typedef std::ratio_subtract<R1, R2>::type R;
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// test ratio_subtract + +#include <ratio> + +int main() +{ + typedef std::ratio<-0x7FFFFFFFFFFFFFFFLL, 1> R1; + typedef std::ratio<1, 1> R2; + typedef std::ratio_subtract<R1, R2>::type R; +} diff --git a/libcxx/test/utilities/ratio/ratio.arithmetic/ratio_subtract.pass.cpp b/libcxx/test/utilities/ratio/ratio.arithmetic/ratio_subtract.pass.cpp index 3068ecaf997..11e53d1f84f 100644 --- a/libcxx/test/utilities/ratio/ratio.arithmetic/ratio_subtract.pass.cpp +++ b/libcxx/test/utilities/ratio/ratio.arithmetic/ratio_subtract.pass.cpp @@ -1 +1,58 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// test ratio_subtract
#include <ratio>
int main()
{
{
typedef std::ratio<1, 1> R1;
typedef std::ratio<1, 1> R2;
typedef std::ratio_subtract<R1, R2>::type R;
static_assert(R::num == 0 && R::den == 1, "");
}
{
typedef std::ratio<1, 2> R1;
typedef std::ratio<1, 1> R2;
typedef std::ratio_subtract<R1, R2>::type R;
static_assert(R::num == -1 && R::den == 2, "");
}
{
typedef std::ratio<-1, 2> R1;
typedef std::ratio<1, 1> R2;
typedef std::ratio_subtract<R1, R2>::type R;
static_assert(R::num == -3 && R::den == 2, "");
}
{
typedef std::ratio<1, -2> R1;
typedef std::ratio<1, 1> R2;
typedef std::ratio_subtract<R1, R2>::type R;
static_assert(R::num == -3 && R::den == 2, "");
}
{
typedef std::ratio<1, 2> R1;
typedef std::ratio<-1, 1> R2;
typedef std::ratio_subtract<R1, R2>::type R;
static_assert(R::num == 3 && R::den == 2, "");
}
{
typedef std::ratio<1, 2> R1;
typedef std::ratio<1, -1> R2;
typedef std::ratio_subtract<R1, R2>::type R;
static_assert(R::num == 3 && R::den == 2, "");
}
{
typedef std::ratio<56987354, 467584654> R1;
typedef std::ratio<544668, 22145> R2;
typedef std::ratio_subtract<R1, R2>::type R;
static_assert(R::num == -126708206685271LL && R::den == 5177331081415LL, "");
}
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// test ratio_subtract + +#include <ratio> + +int main() +{ + { + typedef std::ratio<1, 1> R1; + typedef std::ratio<1, 1> R2; + typedef std::ratio_subtract<R1, R2>::type R; + static_assert(R::num == 0 && R::den == 1, ""); + } + { + typedef std::ratio<1, 2> R1; + typedef std::ratio<1, 1> R2; + typedef std::ratio_subtract<R1, R2>::type R; + static_assert(R::num == -1 && R::den == 2, ""); + } + { + typedef std::ratio<-1, 2> R1; + typedef std::ratio<1, 1> R2; + typedef std::ratio_subtract<R1, R2>::type R; + static_assert(R::num == -3 && R::den == 2, ""); + } + { + typedef std::ratio<1, -2> R1; + typedef std::ratio<1, 1> R2; + typedef std::ratio_subtract<R1, R2>::type R; + static_assert(R::num == -3 && R::den == 2, ""); + } + { + typedef std::ratio<1, 2> R1; + typedef std::ratio<-1, 1> R2; + typedef std::ratio_subtract<R1, R2>::type R; + static_assert(R::num == 3 && R::den == 2, ""); + } + { + typedef std::ratio<1, 2> R1; + typedef std::ratio<1, -1> R2; + typedef std::ratio_subtract<R1, R2>::type R; + static_assert(R::num == 3 && R::den == 2, ""); + } + { + typedef std::ratio<56987354, 467584654> R1; + typedef std::ratio<544668, 22145> R2; + typedef std::ratio_subtract<R1, R2>::type R; + static_assert(R::num == -126708206685271LL && R::den == 5177331081415LL, ""); + } +} diff --git a/libcxx/test/utilities/ratio/ratio.comparison/ratio_equal.pass.cpp b/libcxx/test/utilities/ratio/ratio.comparison/ratio_equal.pass.cpp index 7f77c02b4cf..8a78294bc2a 100644 --- a/libcxx/test/utilities/ratio/ratio.comparison/ratio_equal.pass.cpp +++ b/libcxx/test/utilities/ratio/ratio.comparison/ratio_equal.pass.cpp @@ -1 +1,56 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// test ratio_equal
#include <ratio>
int main()
{
{
typedef std::ratio<1, 1> R1;
typedef std::ratio<1, 1> R2;
static_assert((std::ratio_equal<R1, R2>::value), "");
}
{
typedef std::ratio<0x7FFFFFFFFFFFFFFFLL, 1> R1;
typedef std::ratio<0x7FFFFFFFFFFFFFFFLL, 1> R2;
static_assert((std::ratio_equal<R1, R2>::value), "");
}
{
typedef std::ratio<-0x7FFFFFFFFFFFFFFFLL, 1> R1;
typedef std::ratio<-0x7FFFFFFFFFFFFFFFLL, 1> R2;
static_assert((std::ratio_equal<R1, R2>::value), "");
}
{
typedef std::ratio<1, 0x7FFFFFFFFFFFFFFFLL> R1;
typedef std::ratio<1, 0x7FFFFFFFFFFFFFFFLL> R2;
static_assert((std::ratio_equal<R1, R2>::value), "");
}
{
typedef std::ratio<1, 1> R1;
typedef std::ratio<1, -1> R2;
static_assert((!std::ratio_equal<R1, R2>::value), "");
}
{
typedef std::ratio<0x7FFFFFFFFFFFFFFFLL, 1> R1;
typedef std::ratio<-0x7FFFFFFFFFFFFFFFLL, 1> R2;
static_assert((!std::ratio_equal<R1, R2>::value), "");
}
{
typedef std::ratio<-0x7FFFFFFFFFFFFFFFLL, 1> R1;
typedef std::ratio<0x7FFFFFFFFFFFFFFFLL, 1> R2;
static_assert((!std::ratio_equal<R1, R2>::value), "");
}
{
typedef std::ratio<1, 0x7FFFFFFFFFFFFFFFLL> R1;
typedef std::ratio<1, -0x7FFFFFFFFFFFFFFFLL> R2;
static_assert((!std::ratio_equal<R1, R2>::value), "");
}
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// test ratio_equal + +#include <ratio> + +int main() +{ + { + typedef std::ratio<1, 1> R1; + typedef std::ratio<1, 1> R2; + static_assert((std::ratio_equal<R1, R2>::value), ""); + } + { + typedef std::ratio<0x7FFFFFFFFFFFFFFFLL, 1> R1; + typedef std::ratio<0x7FFFFFFFFFFFFFFFLL, 1> R2; + static_assert((std::ratio_equal<R1, R2>::value), ""); + } + { + typedef std::ratio<-0x7FFFFFFFFFFFFFFFLL, 1> R1; + typedef std::ratio<-0x7FFFFFFFFFFFFFFFLL, 1> R2; + static_assert((std::ratio_equal<R1, R2>::value), ""); + } + { + typedef std::ratio<1, 0x7FFFFFFFFFFFFFFFLL> R1; + typedef std::ratio<1, 0x7FFFFFFFFFFFFFFFLL> R2; + static_assert((std::ratio_equal<R1, R2>::value), ""); + } + { + typedef std::ratio<1, 1> R1; + typedef std::ratio<1, -1> R2; + static_assert((!std::ratio_equal<R1, R2>::value), ""); + } + { + typedef std::ratio<0x7FFFFFFFFFFFFFFFLL, 1> R1; + typedef std::ratio<-0x7FFFFFFFFFFFFFFFLL, 1> R2; + static_assert((!std::ratio_equal<R1, R2>::value), ""); + } + { + typedef std::ratio<-0x7FFFFFFFFFFFFFFFLL, 1> R1; + typedef std::ratio<0x7FFFFFFFFFFFFFFFLL, 1> R2; + static_assert((!std::ratio_equal<R1, R2>::value), ""); + } + { + typedef std::ratio<1, 0x7FFFFFFFFFFFFFFFLL> R1; + typedef std::ratio<1, -0x7FFFFFFFFFFFFFFFLL> R2; + static_assert((!std::ratio_equal<R1, R2>::value), ""); + } +} diff --git a/libcxx/test/utilities/ratio/ratio.comparison/ratio_greater.pass.cpp b/libcxx/test/utilities/ratio/ratio.comparison/ratio_greater.pass.cpp index 5f75f19dc5d..662f38444b2 100644 --- a/libcxx/test/utilities/ratio/ratio.comparison/ratio_greater.pass.cpp +++ b/libcxx/test/utilities/ratio/ratio.comparison/ratio_greater.pass.cpp @@ -1 +1,56 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// test ratio_greater
#include <ratio>
int main()
{
{
typedef std::ratio<1, 1> R1;
typedef std::ratio<1, 1> R2;
static_assert((!std::ratio_greater<R1, R2>::value), "");
}
{
typedef std::ratio<0x7FFFFFFFFFFFFFFFLL, 1> R1;
typedef std::ratio<0x7FFFFFFFFFFFFFFFLL, 1> R2;
static_assert((!std::ratio_greater<R1, R2>::value), "");
}
{
typedef std::ratio<-0x7FFFFFFFFFFFFFFFLL, 1> R1;
typedef std::ratio<-0x7FFFFFFFFFFFFFFFLL, 1> R2;
static_assert((!std::ratio_greater<R1, R2>::value), "");
}
{
typedef std::ratio<1, 0x7FFFFFFFFFFFFFFFLL> R1;
typedef std::ratio<1, 0x7FFFFFFFFFFFFFFFLL> R2;
static_assert((!std::ratio_greater<R1, R2>::value), "");
}
{
typedef std::ratio<1, 1> R1;
typedef std::ratio<1, -1> R2;
static_assert((std::ratio_greater<R1, R2>::value), "");
}
{
typedef std::ratio<0x7FFFFFFFFFFFFFFFLL, 1> R1;
typedef std::ratio<-0x7FFFFFFFFFFFFFFFLL, 1> R2;
static_assert((std::ratio_greater<R1, R2>::value), "");
}
{
typedef std::ratio<-0x7FFFFFFFFFFFFFFFLL, 1> R1;
typedef std::ratio<0x7FFFFFFFFFFFFFFFLL, 1> R2;
static_assert((!std::ratio_greater<R1, R2>::value), "");
}
{
typedef std::ratio<1, 0x7FFFFFFFFFFFFFFFLL> R1;
typedef std::ratio<1, -0x7FFFFFFFFFFFFFFFLL> R2;
static_assert((std::ratio_greater<R1, R2>::value), "");
}
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// test ratio_greater + +#include <ratio> + +int main() +{ + { + typedef std::ratio<1, 1> R1; + typedef std::ratio<1, 1> R2; + static_assert((!std::ratio_greater<R1, R2>::value), ""); + } + { + typedef std::ratio<0x7FFFFFFFFFFFFFFFLL, 1> R1; + typedef std::ratio<0x7FFFFFFFFFFFFFFFLL, 1> R2; + static_assert((!std::ratio_greater<R1, R2>::value), ""); + } + { + typedef std::ratio<-0x7FFFFFFFFFFFFFFFLL, 1> R1; + typedef std::ratio<-0x7FFFFFFFFFFFFFFFLL, 1> R2; + static_assert((!std::ratio_greater<R1, R2>::value), ""); + } + { + typedef std::ratio<1, 0x7FFFFFFFFFFFFFFFLL> R1; + typedef std::ratio<1, 0x7FFFFFFFFFFFFFFFLL> R2; + static_assert((!std::ratio_greater<R1, R2>::value), ""); + } + { + typedef std::ratio<1, 1> R1; + typedef std::ratio<1, -1> R2; + static_assert((std::ratio_greater<R1, R2>::value), ""); + } + { + typedef std::ratio<0x7FFFFFFFFFFFFFFFLL, 1> R1; + typedef std::ratio<-0x7FFFFFFFFFFFFFFFLL, 1> R2; + static_assert((std::ratio_greater<R1, R2>::value), ""); + } + { + typedef std::ratio<-0x7FFFFFFFFFFFFFFFLL, 1> R1; + typedef std::ratio<0x7FFFFFFFFFFFFFFFLL, 1> R2; + static_assert((!std::ratio_greater<R1, R2>::value), ""); + } + { + typedef std::ratio<1, 0x7FFFFFFFFFFFFFFFLL> R1; + typedef std::ratio<1, -0x7FFFFFFFFFFFFFFFLL> R2; + static_assert((std::ratio_greater<R1, R2>::value), ""); + } +} diff --git a/libcxx/test/utilities/ratio/ratio.comparison/ratio_greater_equal.pass.cpp b/libcxx/test/utilities/ratio/ratio.comparison/ratio_greater_equal.pass.cpp index 05533cfa7ac..1720294bb71 100644 --- a/libcxx/test/utilities/ratio/ratio.comparison/ratio_greater_equal.pass.cpp +++ b/libcxx/test/utilities/ratio/ratio.comparison/ratio_greater_equal.pass.cpp @@ -1 +1,56 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// test ratio_greater_equal
#include <ratio>
int main()
{
{
typedef std::ratio<1, 1> R1;
typedef std::ratio<1, 1> R2;
static_assert((std::ratio_greater_equal<R1, R2>::value), "");
}
{
typedef std::ratio<0x7FFFFFFFFFFFFFFFLL, 1> R1;
typedef std::ratio<0x7FFFFFFFFFFFFFFFLL, 1> R2;
static_assert((std::ratio_greater_equal<R1, R2>::value), "");
}
{
typedef std::ratio<-0x7FFFFFFFFFFFFFFFLL, 1> R1;
typedef std::ratio<-0x7FFFFFFFFFFFFFFFLL, 1> R2;
static_assert((std::ratio_greater_equal<R1, R2>::value), "");
}
{
typedef std::ratio<1, 0x7FFFFFFFFFFFFFFFLL> R1;
typedef std::ratio<1, 0x7FFFFFFFFFFFFFFFLL> R2;
static_assert((std::ratio_greater_equal<R1, R2>::value), "");
}
{
typedef std::ratio<1, 1> R1;
typedef std::ratio<1, -1> R2;
static_assert((std::ratio_greater_equal<R1, R2>::value), "");
}
{
typedef std::ratio<0x7FFFFFFFFFFFFFFFLL, 1> R1;
typedef std::ratio<-0x7FFFFFFFFFFFFFFFLL, 1> R2;
static_assert((std::ratio_greater_equal<R1, R2>::value), "");
}
{
typedef std::ratio<-0x7FFFFFFFFFFFFFFFLL, 1> R1;
typedef std::ratio<0x7FFFFFFFFFFFFFFFLL, 1> R2;
static_assert((!std::ratio_greater_equal<R1, R2>::value), "");
}
{
typedef std::ratio<1, 0x7FFFFFFFFFFFFFFFLL> R1;
typedef std::ratio<1, -0x7FFFFFFFFFFFFFFFLL> R2;
static_assert((std::ratio_greater_equal<R1, R2>::value), "");
}
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// test ratio_greater_equal + +#include <ratio> + +int main() +{ + { + typedef std::ratio<1, 1> R1; + typedef std::ratio<1, 1> R2; + static_assert((std::ratio_greater_equal<R1, R2>::value), ""); + } + { + typedef std::ratio<0x7FFFFFFFFFFFFFFFLL, 1> R1; + typedef std::ratio<0x7FFFFFFFFFFFFFFFLL, 1> R2; + static_assert((std::ratio_greater_equal<R1, R2>::value), ""); + } + { + typedef std::ratio<-0x7FFFFFFFFFFFFFFFLL, 1> R1; + typedef std::ratio<-0x7FFFFFFFFFFFFFFFLL, 1> R2; + static_assert((std::ratio_greater_equal<R1, R2>::value), ""); + } + { + typedef std::ratio<1, 0x7FFFFFFFFFFFFFFFLL> R1; + typedef std::ratio<1, 0x7FFFFFFFFFFFFFFFLL> R2; + static_assert((std::ratio_greater_equal<R1, R2>::value), ""); + } + { + typedef std::ratio<1, 1> R1; + typedef std::ratio<1, -1> R2; + static_assert((std::ratio_greater_equal<R1, R2>::value), ""); + } + { + typedef std::ratio<0x7FFFFFFFFFFFFFFFLL, 1> R1; + typedef std::ratio<-0x7FFFFFFFFFFFFFFFLL, 1> R2; + static_assert((std::ratio_greater_equal<R1, R2>::value), ""); + } + { + typedef std::ratio<-0x7FFFFFFFFFFFFFFFLL, 1> R1; + typedef std::ratio<0x7FFFFFFFFFFFFFFFLL, 1> R2; + static_assert((!std::ratio_greater_equal<R1, R2>::value), ""); + } + { + typedef std::ratio<1, 0x7FFFFFFFFFFFFFFFLL> R1; + typedef std::ratio<1, -0x7FFFFFFFFFFFFFFFLL> R2; + static_assert((std::ratio_greater_equal<R1, R2>::value), ""); + } +} diff --git a/libcxx/test/utilities/ratio/ratio.comparison/ratio_less.pass.cpp b/libcxx/test/utilities/ratio/ratio.comparison/ratio_less.pass.cpp index 0b264d840df..2cc8b960ea3 100644 --- a/libcxx/test/utilities/ratio/ratio.comparison/ratio_less.pass.cpp +++ b/libcxx/test/utilities/ratio/ratio.comparison/ratio_less.pass.cpp @@ -1 +1,86 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// test ratio_less
#include <ratio>
int main()
{
{
typedef std::ratio<1, 1> R1;
typedef std::ratio<1, 1> R2;
static_assert((!std::ratio_less<R1, R2>::value), "");
}
{
typedef std::ratio<0x7FFFFFFFFFFFFFFFLL, 1> R1;
typedef std::ratio<0x7FFFFFFFFFFFFFFFLL, 1> R2;
static_assert((!std::ratio_less<R1, R2>::value), "");
}
{
typedef std::ratio<-0x7FFFFFFFFFFFFFFFLL, 1> R1;
typedef std::ratio<-0x7FFFFFFFFFFFFFFFLL, 1> R2;
static_assert((!std::ratio_less<R1, R2>::value), "");
}
{
typedef std::ratio<1, 0x7FFFFFFFFFFFFFFFLL> R1;
typedef std::ratio<1, 0x7FFFFFFFFFFFFFFFLL> R2;
static_assert((!std::ratio_less<R1, R2>::value), "");
}
{
typedef std::ratio<1, 1> R1;
typedef std::ratio<1, -1> R2;
static_assert((!std::ratio_less<R1, R2>::value), "");
}
{
typedef std::ratio<0x7FFFFFFFFFFFFFFFLL, 1> R1;
typedef std::ratio<-0x7FFFFFFFFFFFFFFFLL, 1> R2;
static_assert((!std::ratio_less<R1, R2>::value), "");
}
{
typedef std::ratio<-0x7FFFFFFFFFFFFFFFLL, 1> R1;
typedef std::ratio<0x7FFFFFFFFFFFFFFFLL, 1> R2;
static_assert((std::ratio_less<R1, R2>::value), "");
}
{
typedef std::ratio<1, 0x7FFFFFFFFFFFFFFFLL> R1;
typedef std::ratio<1, -0x7FFFFFFFFFFFFFFFLL> R2;
static_assert((!std::ratio_less<R1, R2>::value), "");
}
{
typedef std::ratio<0x7FFFFFFFFFFFFFFFLL, 0x7FFFFFFFFFFFFFFELL> R1;
typedef std::ratio<0x7FFFFFFFFFFFFFFDLL, 0x7FFFFFFFFFFFFFFCLL> R2;
static_assert((std::ratio_less<R1, R2>::value), "");
}
{
typedef std::ratio<0x7FFFFFFFFFFFFFFDLL, 0x7FFFFFFFFFFFFFFCLL> R1;
typedef std::ratio<0x7FFFFFFFFFFFFFFFLL, 0x7FFFFFFFFFFFFFFELL> R2;
static_assert((!std::ratio_less<R1, R2>::value), "");
}
{
typedef std::ratio<-0x7FFFFFFFFFFFFFFDLL, 0x7FFFFFFFFFFFFFFCLL> R1;
typedef std::ratio<-0x7FFFFFFFFFFFFFFFLL, 0x7FFFFFFFFFFFFFFELL> R2;
static_assert((std::ratio_less<R1, R2>::value), "");
}
{
typedef std::ratio<0x7FFFFFFFFFFFFFFFLL, 0x7FFFFFFFFFFFFFFELL> R1;
typedef std::ratio<0x7FFFFFFFFFFFFFFELL, 0x7FFFFFFFFFFFFFFDLL> R2;
static_assert((std::ratio_less<R1, R2>::value), "");
}
{
typedef std::ratio<641981, 1339063> R1;
typedef std::ratio<1291640, 2694141LL> R2;
static_assert((!std::ratio_less<R1, R2>::value), "");
}
{
typedef std::ratio<1291640, 2694141LL> R1;
typedef std::ratio<641981, 1339063> R2;
static_assert((std::ratio_less<R1, R2>::value), "");
}
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// test ratio_less + +#include <ratio> + +int main() +{ + { + typedef std::ratio<1, 1> R1; + typedef std::ratio<1, 1> R2; + static_assert((!std::ratio_less<R1, R2>::value), ""); + } + { + typedef std::ratio<0x7FFFFFFFFFFFFFFFLL, 1> R1; + typedef std::ratio<0x7FFFFFFFFFFFFFFFLL, 1> R2; + static_assert((!std::ratio_less<R1, R2>::value), ""); + } + { + typedef std::ratio<-0x7FFFFFFFFFFFFFFFLL, 1> R1; + typedef std::ratio<-0x7FFFFFFFFFFFFFFFLL, 1> R2; + static_assert((!std::ratio_less<R1, R2>::value), ""); + } + { + typedef std::ratio<1, 0x7FFFFFFFFFFFFFFFLL> R1; + typedef std::ratio<1, 0x7FFFFFFFFFFFFFFFLL> R2; + static_assert((!std::ratio_less<R1, R2>::value), ""); + } + { + typedef std::ratio<1, 1> R1; + typedef std::ratio<1, -1> R2; + static_assert((!std::ratio_less<R1, R2>::value), ""); + } + { + typedef std::ratio<0x7FFFFFFFFFFFFFFFLL, 1> R1; + typedef std::ratio<-0x7FFFFFFFFFFFFFFFLL, 1> R2; + static_assert((!std::ratio_less<R1, R2>::value), ""); + } + { + typedef std::ratio<-0x7FFFFFFFFFFFFFFFLL, 1> R1; + typedef std::ratio<0x7FFFFFFFFFFFFFFFLL, 1> R2; + static_assert((std::ratio_less<R1, R2>::value), ""); + } + { + typedef std::ratio<1, 0x7FFFFFFFFFFFFFFFLL> R1; + typedef std::ratio<1, -0x7FFFFFFFFFFFFFFFLL> R2; + static_assert((!std::ratio_less<R1, R2>::value), ""); + } + { + typedef std::ratio<0x7FFFFFFFFFFFFFFFLL, 0x7FFFFFFFFFFFFFFELL> R1; + typedef std::ratio<0x7FFFFFFFFFFFFFFDLL, 0x7FFFFFFFFFFFFFFCLL> R2; + static_assert((std::ratio_less<R1, R2>::value), ""); + } + { + typedef std::ratio<0x7FFFFFFFFFFFFFFDLL, 0x7FFFFFFFFFFFFFFCLL> R1; + typedef std::ratio<0x7FFFFFFFFFFFFFFFLL, 0x7FFFFFFFFFFFFFFELL> R2; + static_assert((!std::ratio_less<R1, R2>::value), ""); + } + { + typedef std::ratio<-0x7FFFFFFFFFFFFFFDLL, 0x7FFFFFFFFFFFFFFCLL> R1; + typedef std::ratio<-0x7FFFFFFFFFFFFFFFLL, 0x7FFFFFFFFFFFFFFELL> R2; + static_assert((std::ratio_less<R1, R2>::value), ""); + } + { + typedef std::ratio<0x7FFFFFFFFFFFFFFFLL, 0x7FFFFFFFFFFFFFFELL> R1; + typedef std::ratio<0x7FFFFFFFFFFFFFFELL, 0x7FFFFFFFFFFFFFFDLL> R2; + static_assert((std::ratio_less<R1, R2>::value), ""); + } + { + typedef std::ratio<641981, 1339063> R1; + typedef std::ratio<1291640, 2694141LL> R2; + static_assert((!std::ratio_less<R1, R2>::value), ""); + } + { + typedef std::ratio<1291640, 2694141LL> R1; + typedef std::ratio<641981, 1339063> R2; + static_assert((std::ratio_less<R1, R2>::value), ""); + } +} diff --git a/libcxx/test/utilities/ratio/ratio.comparison/ratio_less_equal.pass.cpp b/libcxx/test/utilities/ratio/ratio.comparison/ratio_less_equal.pass.cpp index 3db02068ab3..d84a4065667 100644 --- a/libcxx/test/utilities/ratio/ratio.comparison/ratio_less_equal.pass.cpp +++ b/libcxx/test/utilities/ratio/ratio.comparison/ratio_less_equal.pass.cpp @@ -1 +1,56 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// test ratio_less_equal
#include <ratio>
int main()
{
{
typedef std::ratio<1, 1> R1;
typedef std::ratio<1, 1> R2;
static_assert((std::ratio_less_equal<R1, R2>::value), "");
}
{
typedef std::ratio<0x7FFFFFFFFFFFFFFFLL, 1> R1;
typedef std::ratio<0x7FFFFFFFFFFFFFFFLL, 1> R2;
static_assert((std::ratio_less_equal<R1, R2>::value), "");
}
{
typedef std::ratio<-0x7FFFFFFFFFFFFFFFLL, 1> R1;
typedef std::ratio<-0x7FFFFFFFFFFFFFFFLL, 1> R2;
static_assert((std::ratio_less_equal<R1, R2>::value), "");
}
{
typedef std::ratio<1, 0x7FFFFFFFFFFFFFFFLL> R1;
typedef std::ratio<1, 0x7FFFFFFFFFFFFFFFLL> R2;
static_assert((std::ratio_less_equal<R1, R2>::value), "");
}
{
typedef std::ratio<1, 1> R1;
typedef std::ratio<1, -1> R2;
static_assert((!std::ratio_less_equal<R1, R2>::value), "");
}
{
typedef std::ratio<0x7FFFFFFFFFFFFFFFLL, 1> R1;
typedef std::ratio<-0x7FFFFFFFFFFFFFFFLL, 1> R2;
static_assert((!std::ratio_less_equal<R1, R2>::value), "");
}
{
typedef std::ratio<-0x7FFFFFFFFFFFFFFFLL, 1> R1;
typedef std::ratio<0x7FFFFFFFFFFFFFFFLL, 1> R2;
static_assert((std::ratio_less_equal<R1, R2>::value), "");
}
{
typedef std::ratio<1, 0x7FFFFFFFFFFFFFFFLL> R1;
typedef std::ratio<1, -0x7FFFFFFFFFFFFFFFLL> R2;
static_assert((!std::ratio_less_equal<R1, R2>::value), "");
}
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// test ratio_less_equal + +#include <ratio> + +int main() +{ + { + typedef std::ratio<1, 1> R1; + typedef std::ratio<1, 1> R2; + static_assert((std::ratio_less_equal<R1, R2>::value), ""); + } + { + typedef std::ratio<0x7FFFFFFFFFFFFFFFLL, 1> R1; + typedef std::ratio<0x7FFFFFFFFFFFFFFFLL, 1> R2; + static_assert((std::ratio_less_equal<R1, R2>::value), ""); + } + { + typedef std::ratio<-0x7FFFFFFFFFFFFFFFLL, 1> R1; + typedef std::ratio<-0x7FFFFFFFFFFFFFFFLL, 1> R2; + static_assert((std::ratio_less_equal<R1, R2>::value), ""); + } + { + typedef std::ratio<1, 0x7FFFFFFFFFFFFFFFLL> R1; + typedef std::ratio<1, 0x7FFFFFFFFFFFFFFFLL> R2; + static_assert((std::ratio_less_equal<R1, R2>::value), ""); + } + { + typedef std::ratio<1, 1> R1; + typedef std::ratio<1, -1> R2; + static_assert((!std::ratio_less_equal<R1, R2>::value), ""); + } + { + typedef std::ratio<0x7FFFFFFFFFFFFFFFLL, 1> R1; + typedef std::ratio<-0x7FFFFFFFFFFFFFFFLL, 1> R2; + static_assert((!std::ratio_less_equal<R1, R2>::value), ""); + } + { + typedef std::ratio<-0x7FFFFFFFFFFFFFFFLL, 1> R1; + typedef std::ratio<0x7FFFFFFFFFFFFFFFLL, 1> R2; + static_assert((std::ratio_less_equal<R1, R2>::value), ""); + } + { + typedef std::ratio<1, 0x7FFFFFFFFFFFFFFFLL> R1; + typedef std::ratio<1, -0x7FFFFFFFFFFFFFFFLL> R2; + static_assert((!std::ratio_less_equal<R1, R2>::value), ""); + } +} diff --git a/libcxx/test/utilities/ratio/ratio.comparison/ratio_not_equal.pass.cpp b/libcxx/test/utilities/ratio/ratio.comparison/ratio_not_equal.pass.cpp index fa35cef7046..0bf77dac1bc 100644 --- a/libcxx/test/utilities/ratio/ratio.comparison/ratio_not_equal.pass.cpp +++ b/libcxx/test/utilities/ratio/ratio.comparison/ratio_not_equal.pass.cpp @@ -1 +1,56 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// test ratio_not_equal
#include <ratio>
int main()
{
{
typedef std::ratio<1, 1> R1;
typedef std::ratio<1, 1> R2;
static_assert((!std::ratio_not_equal<R1, R2>::value), "");
}
{
typedef std::ratio<0x7FFFFFFFFFFFFFFFLL, 1> R1;
typedef std::ratio<0x7FFFFFFFFFFFFFFFLL, 1> R2;
static_assert((!std::ratio_not_equal<R1, R2>::value), "");
}
{
typedef std::ratio<-0x7FFFFFFFFFFFFFFFLL, 1> R1;
typedef std::ratio<-0x7FFFFFFFFFFFFFFFLL, 1> R2;
static_assert((!std::ratio_not_equal<R1, R2>::value), "");
}
{
typedef std::ratio<1, 0x7FFFFFFFFFFFFFFFLL> R1;
typedef std::ratio<1, 0x7FFFFFFFFFFFFFFFLL> R2;
static_assert((!std::ratio_not_equal<R1, R2>::value), "");
}
{
typedef std::ratio<1, 1> R1;
typedef std::ratio<1, -1> R2;
static_assert((std::ratio_not_equal<R1, R2>::value), "");
}
{
typedef std::ratio<0x7FFFFFFFFFFFFFFFLL, 1> R1;
typedef std::ratio<-0x7FFFFFFFFFFFFFFFLL, 1> R2;
static_assert((std::ratio_not_equal<R1, R2>::value), "");
}
{
typedef std::ratio<-0x7FFFFFFFFFFFFFFFLL, 1> R1;
typedef std::ratio<0x7FFFFFFFFFFFFFFFLL, 1> R2;
static_assert((std::ratio_not_equal<R1, R2>::value), "");
}
{
typedef std::ratio<1, 0x7FFFFFFFFFFFFFFFLL> R1;
typedef std::ratio<1, -0x7FFFFFFFFFFFFFFFLL> R2;
static_assert((std::ratio_not_equal<R1, R2>::value), "");
}
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// test ratio_not_equal + +#include <ratio> + +int main() +{ + { + typedef std::ratio<1, 1> R1; + typedef std::ratio<1, 1> R2; + static_assert((!std::ratio_not_equal<R1, R2>::value), ""); + } + { + typedef std::ratio<0x7FFFFFFFFFFFFFFFLL, 1> R1; + typedef std::ratio<0x7FFFFFFFFFFFFFFFLL, 1> R2; + static_assert((!std::ratio_not_equal<R1, R2>::value), ""); + } + { + typedef std::ratio<-0x7FFFFFFFFFFFFFFFLL, 1> R1; + typedef std::ratio<-0x7FFFFFFFFFFFFFFFLL, 1> R2; + static_assert((!std::ratio_not_equal<R1, R2>::value), ""); + } + { + typedef std::ratio<1, 0x7FFFFFFFFFFFFFFFLL> R1; + typedef std::ratio<1, 0x7FFFFFFFFFFFFFFFLL> R2; + static_assert((!std::ratio_not_equal<R1, R2>::value), ""); + } + { + typedef std::ratio<1, 1> R1; + typedef std::ratio<1, -1> R2; + static_assert((std::ratio_not_equal<R1, R2>::value), ""); + } + { + typedef std::ratio<0x7FFFFFFFFFFFFFFFLL, 1> R1; + typedef std::ratio<-0x7FFFFFFFFFFFFFFFLL, 1> R2; + static_assert((std::ratio_not_equal<R1, R2>::value), ""); + } + { + typedef std::ratio<-0x7FFFFFFFFFFFFFFFLL, 1> R1; + typedef std::ratio<0x7FFFFFFFFFFFFFFFLL, 1> R2; + static_assert((std::ratio_not_equal<R1, R2>::value), ""); + } + { + typedef std::ratio<1, 0x7FFFFFFFFFFFFFFFLL> R1; + typedef std::ratio<1, -0x7FFFFFFFFFFFFFFFLL> R2; + static_assert((std::ratio_not_equal<R1, R2>::value), ""); + } +} diff --git a/libcxx/test/utilities/ratio/ratio.ratio/ratio.pass.cpp b/libcxx/test/utilities/ratio/ratio.ratio/ratio.pass.cpp index c2c8166fbe8..36d7965edfe 100644 --- a/libcxx/test/utilities/ratio/ratio.ratio/ratio.pass.cpp +++ b/libcxx/test/utilities/ratio/ratio.ratio/ratio.pass.cpp @@ -1 +1,44 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// test ratio: The static data members num and den shall have thcommon
// divisor of the absolute values of N and D:
#include <ratio>
template <long long N, long long D, long long eN, long long eD>
void test()
{
static_assert((std::ratio<N, D>::num == eN), "");
static_assert((std::ratio<N, D>::den == eD), "");
}
int main()
{
test<1, 1, 1, 1>();
test<1, 10, 1, 10>();
test<10, 10, 1, 1>();
test<10, 1, 10, 1>();
test<12, 4, 3, 1>();
test<12, -4, -3, 1>();
test<-12, 4, -3, 1>();
test<-12, -4, 3, 1>();
test<4, 12, 1, 3>();
test<4, -12, -1, 3>();
test<-4, 12, -1, 3>();
test<-4, -12, 1, 3>();
test<222, 333, 2, 3>();
test<222, -333, -2, 3>();
test<-222, 333, -2, 3>();
test<-222, -333, 2, 3>();
test<0x7FFFFFFFFFFFFFFFLL, 127, 72624976668147841LL, 1>();
test<-0x7FFFFFFFFFFFFFFFLL, 127, -72624976668147841LL, 1>();
test<0x7FFFFFFFFFFFFFFFLL, -127, -72624976668147841LL, 1>();
test<-0x7FFFFFFFFFFFFFFFLL, -127, 72624976668147841LL, 1>();
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// test ratio: The static data members num and den shall have thcommon +// divisor of the absolute values of N and D: + +#include <ratio> + +template <long long N, long long D, long long eN, long long eD> +void test() +{ + static_assert((std::ratio<N, D>::num == eN), ""); + static_assert((std::ratio<N, D>::den == eD), ""); +} + +int main() +{ + test<1, 1, 1, 1>(); + test<1, 10, 1, 10>(); + test<10, 10, 1, 1>(); + test<10, 1, 10, 1>(); + test<12, 4, 3, 1>(); + test<12, -4, -3, 1>(); + test<-12, 4, -3, 1>(); + test<-12, -4, 3, 1>(); + test<4, 12, 1, 3>(); + test<4, -12, -1, 3>(); + test<-4, 12, -1, 3>(); + test<-4, -12, 1, 3>(); + test<222, 333, 2, 3>(); + test<222, -333, -2, 3>(); + test<-222, 333, -2, 3>(); + test<-222, -333, 2, 3>(); + test<0x7FFFFFFFFFFFFFFFLL, 127, 72624976668147841LL, 1>(); + test<-0x7FFFFFFFFFFFFFFFLL, 127, -72624976668147841LL, 1>(); + test<0x7FFFFFFFFFFFFFFFLL, -127, -72624976668147841LL, 1>(); + test<-0x7FFFFFFFFFFFFFFFLL, -127, 72624976668147841LL, 1>(); +} diff --git a/libcxx/test/utilities/ratio/ratio.ratio/ratio1.fail.cpp b/libcxx/test/utilities/ratio/ratio.ratio/ratio1.fail.cpp index f3d12d2a0e7..4860ce9d72a 100644 --- a/libcxx/test/utilities/ratio/ratio.ratio/ratio1.fail.cpp +++ b/libcxx/test/utilities/ratio/ratio.ratio/ratio1.fail.cpp @@ -1 +1,18 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// test ratio: The template argument D shall not be zero
#include <ratio>
#include <cstdint>
int main()
{
const std::intmax_t t1 = std::ratio<1, 0>::num;
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// test ratio: The template argument D shall not be zero + +#include <ratio> +#include <cstdint> + +int main() +{ + const std::intmax_t t1 = std::ratio<1, 0>::num; +} diff --git a/libcxx/test/utilities/ratio/ratio.ratio/ratio2.fail.cpp b/libcxx/test/utilities/ratio/ratio.ratio/ratio2.fail.cpp index e371ed9d064..e854aca4aab 100644 --- a/libcxx/test/utilities/ratio/ratio.ratio/ratio2.fail.cpp +++ b/libcxx/test/utilities/ratio/ratio.ratio/ratio2.fail.cpp @@ -1 +1,19 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// test ratio: the absolute values of the template arguments N and D
// shall be representable by type intmax_t.
#include <ratio>
#include <cstdint>
int main()
{
const std::intmax_t t1 = std::ratio<0x8000000000000000ULL, 1>::num;
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// test ratio: the absolute values of the template arguments N and D +// shall be representable by type intmax_t. + +#include <ratio> +#include <cstdint> + +int main() +{ + const std::intmax_t t1 = std::ratio<0x8000000000000000ULL, 1>::num; +} diff --git a/libcxx/test/utilities/ratio/ratio.ratio/ratio3.fail.cpp b/libcxx/test/utilities/ratio/ratio.ratio/ratio3.fail.cpp index 36097d023b2..56616cf951c 100644 --- a/libcxx/test/utilities/ratio/ratio.ratio/ratio3.fail.cpp +++ b/libcxx/test/utilities/ratio/ratio.ratio/ratio3.fail.cpp @@ -1 +1,19 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// test ratio: the absolute values of the template arguments N and D
// shall be representable by type intmax_t.
#include <ratio>
#include <cstdint>
int main()
{
const std::intmax_t t1 = std::ratio<1, 0x8000000000000000ULL>::num;
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// test ratio: the absolute values of the template arguments N and D +// shall be representable by type intmax_t. + +#include <ratio> +#include <cstdint> + +int main() +{ + const std::intmax_t t1 = std::ratio<1, 0x8000000000000000ULL>::num; +} diff --git a/libcxx/test/utilities/ratio/ratio.si/nothing_to_do.pass.cpp b/libcxx/test/utilities/ratio/ratio.si/nothing_to_do.pass.cpp index e8db90cbee0..b89f168e9c4 100644 --- a/libcxx/test/utilities/ratio/ratio.si/nothing_to_do.pass.cpp +++ b/libcxx/test/utilities/ratio/ratio.si/nothing_to_do.pass.cpp @@ -1 +1,12 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
int main()
{
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/libcxx/test/utilities/ratio/typedefs.pass.cpp b/libcxx/test/utilities/ratio/typedefs.pass.cpp index 83ef47ec2e2..adbe0afd937 100644 --- a/libcxx/test/utilities/ratio/typedefs.pass.cpp +++ b/libcxx/test/utilities/ratio/typedefs.pass.cpp @@ -1 +1,32 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// test ratio typedef's
#include <ratio>
int main()
{
static_assert(std::atto::num == 1 && std::atto::den == 1000000000000000000ULL, "");
static_assert(std::femto::num == 1 && std::femto::den == 1000000000000000ULL, "");
static_assert(std::pico::num == 1 && std::pico::den == 1000000000000ULL, "");
static_assert(std::nano::num == 1 && std::nano::den == 1000000000ULL, "");
static_assert(std::micro::num == 1 && std::micro::den == 1000000ULL, "");
static_assert(std::milli::num == 1 && std::milli::den == 1000ULL, "");
static_assert(std::centi::num == 1 && std::centi::den == 100ULL, "");
static_assert(std::deci::num == 1 && std::deci::den == 10ULL, "");
static_assert(std::deca::num == 10ULL && std::deca::den == 1, "");
static_assert(std::hecto::num == 100ULL && std::hecto::den == 1, "");
static_assert(std::kilo::num == 1000ULL && std::kilo::den == 1, "");
static_assert(std::mega::num == 1000000ULL && std::mega::den == 1, "");
static_assert(std::giga::num == 1000000000ULL && std::giga::den == 1, "");
static_assert(std::tera::num == 1000000000000ULL && std::tera::den == 1, "");
static_assert(std::peta::num == 1000000000000000ULL && std::peta::den == 1, "");
static_assert(std::exa::num == 1000000000000000000ULL && std::exa::den == 1, "");
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// test ratio typedef's + +#include <ratio> + +int main() +{ + static_assert(std::atto::num == 1 && std::atto::den == 1000000000000000000ULL, ""); + static_assert(std::femto::num == 1 && std::femto::den == 1000000000000000ULL, ""); + static_assert(std::pico::num == 1 && std::pico::den == 1000000000000ULL, ""); + static_assert(std::nano::num == 1 && std::nano::den == 1000000000ULL, ""); + static_assert(std::micro::num == 1 && std::micro::den == 1000000ULL, ""); + static_assert(std::milli::num == 1 && std::milli::den == 1000ULL, ""); + static_assert(std::centi::num == 1 && std::centi::den == 100ULL, ""); + static_assert(std::deci::num == 1 && std::deci::den == 10ULL, ""); + static_assert(std::deca::num == 10ULL && std::deca::den == 1, ""); + static_assert(std::hecto::num == 100ULL && std::hecto::den == 1, ""); + static_assert(std::kilo::num == 1000ULL && std::kilo::den == 1, ""); + static_assert(std::mega::num == 1000000ULL && std::mega::den == 1, ""); + static_assert(std::giga::num == 1000000000ULL && std::giga::den == 1, ""); + static_assert(std::tera::num == 1000000000000ULL && std::tera::den == 1, ""); + static_assert(std::peta::num == 1000000000000000ULL && std::peta::den == 1, ""); + static_assert(std::exa::num == 1000000000000000000ULL && std::exa::den == 1, ""); +} diff --git a/libcxx/test/utilities/ratio/version.pass.cpp b/libcxx/test/utilities/ratio/version.pass.cpp index 1d6b9e4c938..48d3133bfab 100644 --- a/libcxx/test/utilities/ratio/version.pass.cpp +++ b/libcxx/test/utilities/ratio/version.pass.cpp @@ -1 +1,20 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <ratio>
#include <ratio>
#ifndef _LIBCPP_VERSION
#error _LIBCPP_VERSION not defined
#endif
int main()
{
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <ratio> + +#include <ratio> + +#ifndef _LIBCPP_VERSION +#error _LIBCPP_VERSION not defined +#endif + +int main() +{ +} diff --git a/libcxx/test/utilities/template.bitset/bitset.cons/char_ptr_ctor.pass.cpp b/libcxx/test/utilities/template.bitset/bitset.cons/char_ptr_ctor.pass.cpp index e446fc00704..c928bd0568c 100644 --- a/libcxx/test/utilities/template.bitset/bitset.cons/char_ptr_ctor.pass.cpp +++ b/libcxx/test/utilities/template.bitset/bitset.cons/char_ptr_ctor.pass.cpp @@ -1 +1,51 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// test bitset(const char *str);
#include <bitset>
#include <cassert>
template <std::size_t N>
void test_char_pointer_ctor()
{
{
try
{
std::bitset<N> v("xxx1010101010xxxx");
assert(false);
}
catch (std::invalid_argument&)
{
}
}
{
const char str[] ="1010101010";
std::bitset<N> v(str);
std::size_t M = std::min<std::size_t>(N, 10);
for (std::size_t i = 0; i < M; ++i)
assert(v[i] == (str[M - 1 - i] == '1'));
for (std::size_t i = 10; i < N; ++i)
assert(v[i] == false);
}
}
int main()
{
test_char_pointer_ctor<0>();
test_char_pointer_ctor<1>();
test_char_pointer_ctor<31>();
test_char_pointer_ctor<32>();
test_char_pointer_ctor<33>();
test_char_pointer_ctor<63>();
test_char_pointer_ctor<64>();
test_char_pointer_ctor<65>();
test_char_pointer_ctor<1000>();
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// test bitset(const char *str); + +#include <bitset> +#include <cassert> + +template <std::size_t N> +void test_char_pointer_ctor() +{ + { + try + { + std::bitset<N> v("xxx1010101010xxxx"); + assert(false); + } + catch (std::invalid_argument&) + { + } + } + + { + const char str[] ="1010101010"; + std::bitset<N> v(str); + std::size_t M = std::min<std::size_t>(N, 10); + for (std::size_t i = 0; i < M; ++i) + assert(v[i] == (str[M - 1 - i] == '1')); + for (std::size_t i = 10; i < N; ++i) + assert(v[i] == false); + } +} + +int main() +{ + test_char_pointer_ctor<0>(); + test_char_pointer_ctor<1>(); + test_char_pointer_ctor<31>(); + test_char_pointer_ctor<32>(); + test_char_pointer_ctor<33>(); + test_char_pointer_ctor<63>(); + test_char_pointer_ctor<64>(); + test_char_pointer_ctor<65>(); + test_char_pointer_ctor<1000>(); +} diff --git a/libcxx/test/utilities/template.bitset/bitset.cons/default.pass.cpp b/libcxx/test/utilities/template.bitset/bitset.cons/default.pass.cpp index e0abc516e15..571e6f0500e 100644 --- a/libcxx/test/utilities/template.bitset/bitset.cons/default.pass.cpp +++ b/libcxx/test/utilities/template.bitset/bitset.cons/default.pass.cpp @@ -1 +1,37 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// test default ctor
#include <bitset>
#include <cassert>
template <std::size_t N>
void test_default_ctor()
{
{
std::bitset<N> v1;
assert(v1.size() == N);
for (std::size_t i = 0; i < N; ++i)
assert(v1[i] == false);
}
}
int main()
{
test_default_ctor<0>();
test_default_ctor<1>();
test_default_ctor<31>();
test_default_ctor<32>();
test_default_ctor<33>();
test_default_ctor<63>();
test_default_ctor<64>();
test_default_ctor<65>();
test_default_ctor<1000>();
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// test default ctor + +#include <bitset> +#include <cassert> + +template <std::size_t N> +void test_default_ctor() +{ + { + std::bitset<N> v1; + assert(v1.size() == N); + for (std::size_t i = 0; i < N; ++i) + assert(v1[i] == false); + } +} + +int main() +{ + test_default_ctor<0>(); + test_default_ctor<1>(); + test_default_ctor<31>(); + test_default_ctor<32>(); + test_default_ctor<33>(); + test_default_ctor<63>(); + test_default_ctor<64>(); + test_default_ctor<65>(); + test_default_ctor<1000>(); +} diff --git a/libcxx/test/utilities/template.bitset/bitset.cons/string_ctor.pass.cpp b/libcxx/test/utilities/template.bitset/bitset.cons/string_ctor.pass.cpp index 800dfc6db3e..acf719c8041 100644 --- a/libcxx/test/utilities/template.bitset/bitset.cons/string_ctor.pass.cpp +++ b/libcxx/test/utilities/template.bitset/bitset.cons/string_ctor.pass.cpp @@ -1 +1,86 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// test bitset(string, pos, n, zero, one);
#include <bitset>
#include <cassert>
template <std::size_t N>
void test_string_ctor()
{
{
try
{
std::string str("xxx1010101010xxxx");
std::bitset<N> v(str, str.size()+1, 10);
assert(false);
}
catch (std::out_of_range&)
{
}
}
{
try
{
std::string str("xxx1010101010xxxx");
std::bitset<N> v(str, 2, 10);
assert(false);
}
catch (std::invalid_argument&)
{
}
}
{
std::string str("xxx1010101010xxxx");
std::bitset<N> v(str, 3, 10);
std::size_t M = std::min<std::size_t>(N, 10);
for (std::size_t i = 0; i < M; ++i)
assert(v[i] == (str[3 + M - 1 - i] == '1'));
for (std::size_t i = 10; i < N; ++i)
assert(v[i] == false);
}
{
try
{
std::string str("xxxbababababaxxxx");
std::bitset<N> v(str, 2, 10, 'a', 'b');
assert(false);
}
catch (std::invalid_argument&)
{
}
}
{
std::string str("xxxbababababaxxxx");
std::bitset<N> v(str, 3, 10, 'a', 'b');
std::size_t M = std::min<std::size_t>(N, 10);
for (std::size_t i = 0; i < M; ++i)
assert(v[i] == (str[3 + M - 1 - i] == 'b'));
for (std::size_t i = 10; i < N; ++i)
assert(v[i] == false);
}
}
int main()
{
test_string_ctor<0>();
test_string_ctor<1>();
test_string_ctor<31>();
test_string_ctor<32>();
test_string_ctor<33>();
test_string_ctor<63>();
test_string_ctor<64>();
test_string_ctor<65>();
test_string_ctor<1000>();
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// test bitset(string, pos, n, zero, one); + +#include <bitset> +#include <cassert> + +template <std::size_t N> +void test_string_ctor() +{ + { + try + { + std::string str("xxx1010101010xxxx"); + std::bitset<N> v(str, str.size()+1, 10); + assert(false); + } + catch (std::out_of_range&) + { + } + } + + { + try + { + std::string str("xxx1010101010xxxx"); + std::bitset<N> v(str, 2, 10); + assert(false); + } + catch (std::invalid_argument&) + { + } + } + + { + std::string str("xxx1010101010xxxx"); + std::bitset<N> v(str, 3, 10); + std::size_t M = std::min<std::size_t>(N, 10); + for (std::size_t i = 0; i < M; ++i) + assert(v[i] == (str[3 + M - 1 - i] == '1')); + for (std::size_t i = 10; i < N; ++i) + assert(v[i] == false); + } + + { + try + { + std::string str("xxxbababababaxxxx"); + std::bitset<N> v(str, 2, 10, 'a', 'b'); + assert(false); + } + catch (std::invalid_argument&) + { + } + } + + { + std::string str("xxxbababababaxxxx"); + std::bitset<N> v(str, 3, 10, 'a', 'b'); + std::size_t M = std::min<std::size_t>(N, 10); + for (std::size_t i = 0; i < M; ++i) + assert(v[i] == (str[3 + M - 1 - i] == 'b')); + for (std::size_t i = 10; i < N; ++i) + assert(v[i] == false); + } +} + +int main() +{ + test_string_ctor<0>(); + test_string_ctor<1>(); + test_string_ctor<31>(); + test_string_ctor<32>(); + test_string_ctor<33>(); + test_string_ctor<63>(); + test_string_ctor<64>(); + test_string_ctor<65>(); + test_string_ctor<1000>(); +} diff --git a/libcxx/test/utilities/template.bitset/bitset.cons/ull_ctor.pass.cpp b/libcxx/test/utilities/template.bitset/bitset.cons/ull_ctor.pass.cpp index 6e20abd489e..e5763e31844 100644 --- a/libcxx/test/utilities/template.bitset/bitset.cons/ull_ctor.pass.cpp +++ b/libcxx/test/utilities/template.bitset/bitset.cons/ull_ctor.pass.cpp @@ -1 +1,40 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// test bitset(unsigned long long val);
#include <bitset>
#include <cassert>
template <std::size_t N>
void test_val_ctor()
{
{
std::bitset<N> v(0xAAAAAAAAAAAAAAAAULL);
assert(v.size() == N);
unsigned M = std::min<std::size_t>(N, 64);
for (std::size_t i = 0; i < M; ++i)
assert(v[i] == (i & 1));
for (std::size_t i = M; i < N; ++i)
assert(v[i] == false);
}
}
int main()
{
test_val_ctor<0>();
test_val_ctor<1>();
test_val_ctor<31>();
test_val_ctor<32>();
test_val_ctor<33>();
test_val_ctor<63>();
test_val_ctor<64>();
test_val_ctor<65>();
test_val_ctor<1000>();
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// test bitset(unsigned long long val); + +#include <bitset> +#include <cassert> + +template <std::size_t N> +void test_val_ctor() +{ + { + std::bitset<N> v(0xAAAAAAAAAAAAAAAAULL); + assert(v.size() == N); + unsigned M = std::min<std::size_t>(N, 64); + for (std::size_t i = 0; i < M; ++i) + assert(v[i] == (i & 1)); + for (std::size_t i = M; i < N; ++i) + assert(v[i] == false); + } +} + +int main() +{ + test_val_ctor<0>(); + test_val_ctor<1>(); + test_val_ctor<31>(); + test_val_ctor<32>(); + test_val_ctor<33>(); + test_val_ctor<63>(); + test_val_ctor<64>(); + test_val_ctor<65>(); + test_val_ctor<1000>(); +} diff --git a/libcxx/test/utilities/template.bitset/bitset.members/all.pass.cpp b/libcxx/test/utilities/template.bitset/bitset.members/all.pass.cpp index fbe6447b075..04ad5cefb5b 100644 --- a/libcxx/test/utilities/template.bitset/bitset.members/all.pass.cpp +++ b/libcxx/test/utilities/template.bitset/bitset.members/all.pass.cpp @@ -1 +1,41 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// test bool all() const;
#include <bitset>
#include <cassert>
template <std::size_t N>
void test_all()
{
std::bitset<N> v;
v.reset();
assert(v.all() == (N == 0));
v.set();
assert(v.all() == true);
if (N > 1)
{
v[N/2] = false;
assert(v.all() == false);
}
}
int main()
{
test_all<0>();
test_all<1>();
test_all<31>();
test_all<32>();
test_all<33>();
test_all<63>();
test_all<64>();
test_all<65>();
test_all<1000>();
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// test bool all() const; + +#include <bitset> +#include <cassert> + +template <std::size_t N> +void test_all() +{ + std::bitset<N> v; + v.reset(); + assert(v.all() == (N == 0)); + v.set(); + assert(v.all() == true); + if (N > 1) + { + v[N/2] = false; + assert(v.all() == false); + } +} + +int main() +{ + test_all<0>(); + test_all<1>(); + test_all<31>(); + test_all<32>(); + test_all<33>(); + test_all<63>(); + test_all<64>(); + test_all<65>(); + test_all<1000>(); +} diff --git a/libcxx/test/utilities/template.bitset/bitset.members/any.pass.cpp b/libcxx/test/utilities/template.bitset/bitset.members/any.pass.cpp index 40cd0067bc6..e685b3735bd 100644 --- a/libcxx/test/utilities/template.bitset/bitset.members/any.pass.cpp +++ b/libcxx/test/utilities/template.bitset/bitset.members/any.pass.cpp @@ -1 +1,44 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// test bool any() const;
#include <bitset>
#include <cassert>
template <std::size_t N>
void test_any()
{
std::bitset<N> v;
v.reset();
assert(v.any() == false);
v.set();
assert(v.any() == (N != 0));
if (N > 1)
{
v[N/2] = false;
assert(v.any() == true);
v.reset();
v[N/2] = true;
assert(v.any() == true);
}
}
int main()
{
test_any<0>();
test_any<1>();
test_any<31>();
test_any<32>();
test_any<33>();
test_any<63>();
test_any<64>();
test_any<65>();
test_any<1000>();
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// test bool any() const; + +#include <bitset> +#include <cassert> + +template <std::size_t N> +void test_any() +{ + std::bitset<N> v; + v.reset(); + assert(v.any() == false); + v.set(); + assert(v.any() == (N != 0)); + if (N > 1) + { + v[N/2] = false; + assert(v.any() == true); + v.reset(); + v[N/2] = true; + assert(v.any() == true); + } +} + +int main() +{ + test_any<0>(); + test_any<1>(); + test_any<31>(); + test_any<32>(); + test_any<33>(); + test_any<63>(); + test_any<64>(); + test_any<65>(); + test_any<1000>(); +} diff --git a/libcxx/test/utilities/template.bitset/bitset.members/count.pass.cpp b/libcxx/test/utilities/template.bitset/bitset.members/count.pass.cpp index 8b5a727361a..82222dfb4de 100644 --- a/libcxx/test/utilities/template.bitset/bitset.members/count.pass.cpp +++ b/libcxx/test/utilities/template.bitset/bitset.members/count.pass.cpp @@ -1 +1,49 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// test size_t count() const;
#include <bitset>
#include <cstdlib>
#include <cassert>
template <std::size_t N>
std::bitset<N>
make_bitset()
{
std::bitset<N> v;
for (std::size_t i = 0; i < N; ++i)
v[i] = static_cast<bool>(std::rand() & 1);
return v;
}
template <std::size_t N>
void test_count()
{
const std::bitset<N> v = make_bitset<N>();
std::size_t c1 = v.count();
std::size_t c2 = 0;
for (std::size_t i = 0; i < N; ++i)
if (v[i])
++c2;
assert(c1 == c2);
}
int main()
{
test_count<0>();
test_count<1>();
test_count<31>();
test_count<32>();
test_count<33>();
test_count<63>();
test_count<64>();
test_count<65>();
test_count<1000>();
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// test size_t count() const; + +#include <bitset> +#include <cstdlib> +#include <cassert> + +template <std::size_t N> +std::bitset<N> +make_bitset() +{ + std::bitset<N> v; + for (std::size_t i = 0; i < N; ++i) + v[i] = static_cast<bool>(std::rand() & 1); + return v; +} + +template <std::size_t N> +void test_count() +{ + const std::bitset<N> v = make_bitset<N>(); + std::size_t c1 = v.count(); + std::size_t c2 = 0; + for (std::size_t i = 0; i < N; ++i) + if (v[i]) + ++c2; + assert(c1 == c2); +} + +int main() +{ + test_count<0>(); + test_count<1>(); + test_count<31>(); + test_count<32>(); + test_count<33>(); + test_count<63>(); + test_count<64>(); + test_count<65>(); + test_count<1000>(); +} diff --git a/libcxx/test/utilities/template.bitset/bitset.members/flip_all.pass.cpp b/libcxx/test/utilities/template.bitset/bitset.members/flip_all.pass.cpp index 790d0b22cd9..85b255d443f 100644 --- a/libcxx/test/utilities/template.bitset/bitset.members/flip_all.pass.cpp +++ b/libcxx/test/utilities/template.bitset/bitset.members/flip_all.pass.cpp @@ -1 +1,47 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// test bitset<N>& flip();
#include <bitset>
#include <cstdlib>
#include <cassert>
template <std::size_t N>
std::bitset<N>
make_bitset()
{
std::bitset<N> v;
for (std::size_t i = 0; i < N; ++i)
v[i] = static_cast<bool>(std::rand() & 1);
return v;
}
template <std::size_t N>
void test_flip_all()
{
std::bitset<N> v1 = make_bitset<N>();
std::bitset<N> v2 = v1;
v2.flip();
for (std::size_t i = 0; i < N; ++i)
assert(v2[i] == ~v1[i]);
}
int main()
{
test_flip_all<0>();
test_flip_all<1>();
test_flip_all<31>();
test_flip_all<32>();
test_flip_all<33>();
test_flip_all<63>();
test_flip_all<64>();
test_flip_all<65>();
test_flip_all<1000>();
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// test bitset<N>& flip(); + +#include <bitset> +#include <cstdlib> +#include <cassert> + +template <std::size_t N> +std::bitset<N> +make_bitset() +{ + std::bitset<N> v; + for (std::size_t i = 0; i < N; ++i) + v[i] = static_cast<bool>(std::rand() & 1); + return v; +} + +template <std::size_t N> +void test_flip_all() +{ + std::bitset<N> v1 = make_bitset<N>(); + std::bitset<N> v2 = v1; + v2.flip(); + for (std::size_t i = 0; i < N; ++i) + assert(v2[i] == ~v1[i]); +} + +int main() +{ + test_flip_all<0>(); + test_flip_all<1>(); + test_flip_all<31>(); + test_flip_all<32>(); + test_flip_all<33>(); + test_flip_all<63>(); + test_flip_all<64>(); + test_flip_all<65>(); + test_flip_all<1000>(); +} diff --git a/libcxx/test/utilities/template.bitset/bitset.members/flip_one.pass.cpp b/libcxx/test/utilities/template.bitset/bitset.members/flip_one.pass.cpp index 10e1b7dbe4d..1754ee867a7 100644 --- a/libcxx/test/utilities/template.bitset/bitset.members/flip_one.pass.cpp +++ b/libcxx/test/utilities/template.bitset/bitset.members/flip_one.pass.cpp @@ -1 +1,58 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// test bitset<N>& flip(size_t pos);
#include <bitset>
#include <cstdlib>
#include <cassert>
template <std::size_t N>
std::bitset<N>
make_bitset()
{
std::bitset<N> v;
for (std::size_t i = 0; i < N; ++i)
v[i] = static_cast<bool>(std::rand() & 1);
return v;
}
template <std::size_t N>
void test_flip_one()
{
std::bitset<N> v = make_bitset<N>();
try
{
v.flip(50);
bool b = v[50];
if (50 >= v.size())
assert(false);
assert(v[50] == b);
v.flip(50);
assert(v[50] != b);
v.flip(50);
assert(v[50] == b);
}
catch (std::out_of_range&)
{
}
}
int main()
{
test_flip_one<0>();
test_flip_one<1>();
test_flip_one<31>();
test_flip_one<32>();
test_flip_one<33>();
test_flip_one<63>();
test_flip_one<64>();
test_flip_one<65>();
test_flip_one<1000>();
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// test bitset<N>& flip(size_t pos); + +#include <bitset> +#include <cstdlib> +#include <cassert> + +template <std::size_t N> +std::bitset<N> +make_bitset() +{ + std::bitset<N> v; + for (std::size_t i = 0; i < N; ++i) + v[i] = static_cast<bool>(std::rand() & 1); + return v; +} + +template <std::size_t N> +void test_flip_one() +{ + std::bitset<N> v = make_bitset<N>(); + try + { + v.flip(50); + bool b = v[50]; + if (50 >= v.size()) + assert(false); + assert(v[50] == b); + v.flip(50); + assert(v[50] != b); + v.flip(50); + assert(v[50] == b); + } + catch (std::out_of_range&) + { + } +} + +int main() +{ + test_flip_one<0>(); + test_flip_one<1>(); + test_flip_one<31>(); + test_flip_one<32>(); + test_flip_one<33>(); + test_flip_one<63>(); + test_flip_one<64>(); + test_flip_one<65>(); + test_flip_one<1000>(); +} diff --git a/libcxx/test/utilities/template.bitset/bitset.members/index.pass.cpp b/libcxx/test/utilities/template.bitset/bitset.members/index.pass.cpp index b18489037eb..c346a3fb00d 100644 --- a/libcxx/test/utilities/template.bitset/bitset.members/index.pass.cpp +++ b/libcxx/test/utilities/template.bitset/bitset.members/index.pass.cpp @@ -1 +1,65 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// test bitset<N>::reference operator[](size_t pos);
#include <bitset>
#include <cstdlib>
#include <cassert>
template <std::size_t N>
std::bitset<N>
make_bitset()
{
std::bitset<N> v;
for (std::size_t i = 0; i < N; ++i)
v[i] = static_cast<bool>(std::rand() & 1);
return v;
}
template <std::size_t N>
void test_index_const()
{
std::bitset<N> v1 = make_bitset<N>();
if (N > 0)
{
assert(v1[N/2] == v1.test(N/2));
typename std::bitset<N>::reference r = v1[N/2];
assert(r == v1.test(N/2));
typename std::bitset<N>::reference r2 = v1[N/2];
r = r2;
assert(r == v1.test(N/2));
r = false;
assert(r == false);
assert(v1.test(N/2) == false);
r = true;
assert(r == true);
assert(v1.test(N/2) == true);
bool b = ~r;
assert(r == true);
assert(v1.test(N/2) == true);
assert(b == false);
r.flip();
assert(r == false);
assert(v1.test(N/2) == false);
}
}
int main()
{
test_index_const<0>();
test_index_const<1>();
test_index_const<31>();
test_index_const<32>();
test_index_const<33>();
test_index_const<63>();
test_index_const<64>();
test_index_const<65>();
test_index_const<1000>();
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// test bitset<N>::reference operator[](size_t pos); + +#include <bitset> +#include <cstdlib> +#include <cassert> + +template <std::size_t N> +std::bitset<N> +make_bitset() +{ + std::bitset<N> v; + for (std::size_t i = 0; i < N; ++i) + v[i] = static_cast<bool>(std::rand() & 1); + return v; +} + +template <std::size_t N> +void test_index_const() +{ + std::bitset<N> v1 = make_bitset<N>(); + if (N > 0) + { + assert(v1[N/2] == v1.test(N/2)); + typename std::bitset<N>::reference r = v1[N/2]; + assert(r == v1.test(N/2)); + typename std::bitset<N>::reference r2 = v1[N/2]; + r = r2; + assert(r == v1.test(N/2)); + r = false; + assert(r == false); + assert(v1.test(N/2) == false); + r = true; + assert(r == true); + assert(v1.test(N/2) == true); + bool b = ~r; + assert(r == true); + assert(v1.test(N/2) == true); + assert(b == false); + r.flip(); + assert(r == false); + assert(v1.test(N/2) == false); + } +} + +int main() +{ + test_index_const<0>(); + test_index_const<1>(); + test_index_const<31>(); + test_index_const<32>(); + test_index_const<33>(); + test_index_const<63>(); + test_index_const<64>(); + test_index_const<65>(); + test_index_const<1000>(); +} diff --git a/libcxx/test/utilities/template.bitset/bitset.members/index_const.pass.cpp b/libcxx/test/utilities/template.bitset/bitset.members/index_const.pass.cpp index 60973a275a8..3d4d1e8223e 100644 --- a/libcxx/test/utilities/template.bitset/bitset.members/index_const.pass.cpp +++ b/libcxx/test/utilities/template.bitset/bitset.members/index_const.pass.cpp @@ -1 +1,47 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// test constexpr bool operator[](size_t pos) const;
#include <bitset>
#include <cstdlib>
#include <cassert>
template <std::size_t N>
std::bitset<N>
make_bitset()
{
std::bitset<N> v;
for (std::size_t i = 0; i < N; ++i)
v[i] = static_cast<bool>(std::rand() & 1);
return v;
}
template <std::size_t N>
void test_index_const()
{
const std::bitset<N> v1 = make_bitset<N>();
if (N > 0)
{
assert(v1[N/2] == v1.test(N/2));
}
}
int main()
{
test_index_const<0>();
test_index_const<1>();
test_index_const<31>();
test_index_const<32>();
test_index_const<33>();
test_index_const<63>();
test_index_const<64>();
test_index_const<65>();
test_index_const<1000>();
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// test constexpr bool operator[](size_t pos) const; + +#include <bitset> +#include <cstdlib> +#include <cassert> + +template <std::size_t N> +std::bitset<N> +make_bitset() +{ + std::bitset<N> v; + for (std::size_t i = 0; i < N; ++i) + v[i] = static_cast<bool>(std::rand() & 1); + return v; +} + +template <std::size_t N> +void test_index_const() +{ + const std::bitset<N> v1 = make_bitset<N>(); + if (N > 0) + { + assert(v1[N/2] == v1.test(N/2)); + } +} + +int main() +{ + test_index_const<0>(); + test_index_const<1>(); + test_index_const<31>(); + test_index_const<32>(); + test_index_const<33>(); + test_index_const<63>(); + test_index_const<64>(); + test_index_const<65>(); + test_index_const<1000>(); +} diff --git a/libcxx/test/utilities/template.bitset/bitset.members/left_shift.pass.cpp b/libcxx/test/utilities/template.bitset/bitset.members/left_shift.pass.cpp index b1d373187e4..f19987c018c 100644 --- a/libcxx/test/utilities/template.bitset/bitset.members/left_shift.pass.cpp +++ b/libcxx/test/utilities/template.bitset/bitset.members/left_shift.pass.cpp @@ -1 +1,48 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// test bitset<N> operator<<(size_t pos) const;
#include <bitset>
#include <cstdlib>
#include <cassert>
template <std::size_t N>
std::bitset<N>
make_bitset()
{
std::bitset<N> v;
for (std::size_t i = 0; i < N; ++i)
v[i] = static_cast<bool>(std::rand() & 1);
return v;
}
template <std::size_t N>
void test_left_shift()
{
for (std::size_t s = 0; s <= N+1; ++s)
{
std::bitset<N> v1 = make_bitset<N>();
std::bitset<N> v2 = v1;
assert((v1 <<= s) == (v2 << s));
}
}
int main()
{
test_left_shift<0>();
test_left_shift<1>();
test_left_shift<31>();
test_left_shift<32>();
test_left_shift<33>();
test_left_shift<63>();
test_left_shift<64>();
test_left_shift<65>();
test_left_shift<1000>();
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// test bitset<N> operator<<(size_t pos) const; + +#include <bitset> +#include <cstdlib> +#include <cassert> + +template <std::size_t N> +std::bitset<N> +make_bitset() +{ + std::bitset<N> v; + for (std::size_t i = 0; i < N; ++i) + v[i] = static_cast<bool>(std::rand() & 1); + return v; +} + +template <std::size_t N> +void test_left_shift() +{ + for (std::size_t s = 0; s <= N+1; ++s) + { + std::bitset<N> v1 = make_bitset<N>(); + std::bitset<N> v2 = v1; + assert((v1 <<= s) == (v2 << s)); + } +} + +int main() +{ + test_left_shift<0>(); + test_left_shift<1>(); + test_left_shift<31>(); + test_left_shift<32>(); + test_left_shift<33>(); + test_left_shift<63>(); + test_left_shift<64>(); + test_left_shift<65>(); + test_left_shift<1000>(); +} diff --git a/libcxx/test/utilities/template.bitset/bitset.members/left_shift_eq.pass.cpp b/libcxx/test/utilities/template.bitset/bitset.members/left_shift_eq.pass.cpp index 8ea0981c525..340921db5d0 100644 --- a/libcxx/test/utilities/template.bitset/bitset.members/left_shift_eq.pass.cpp +++ b/libcxx/test/utilities/template.bitset/bitset.members/left_shift_eq.pass.cpp @@ -1 +1,53 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// test bitset<N>& operator<<=(size_t pos);
#include <bitset>
#include <cstdlib>
#include <cassert>
template <std::size_t N>
std::bitset<N>
make_bitset()
{
std::bitset<N> v;
for (std::size_t i = 0; i < N; ++i)
v[i] = static_cast<bool>(std::rand() & 1);
return v;
}
template <std::size_t N>
void test_left_shift()
{
for (std::size_t s = 0; s <= N+1; ++s)
{
std::bitset<N> v1 = make_bitset<N>();
std::bitset<N> v2 = v1;
v1 <<= s;
for (std::size_t i = 0; i < N; ++i)
if (i < s)
assert(v1[i] == 0);
else
assert(v1[i] == v2[i-s]);
}
}
int main()
{
test_left_shift<0>();
test_left_shift<1>();
test_left_shift<31>();
test_left_shift<32>();
test_left_shift<33>();
test_left_shift<63>();
test_left_shift<64>();
test_left_shift<65>();
test_left_shift<1000>();
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// test bitset<N>& operator<<=(size_t pos); + +#include <bitset> +#include <cstdlib> +#include <cassert> + +template <std::size_t N> +std::bitset<N> +make_bitset() +{ + std::bitset<N> v; + for (std::size_t i = 0; i < N; ++i) + v[i] = static_cast<bool>(std::rand() & 1); + return v; +} + +template <std::size_t N> +void test_left_shift() +{ + for (std::size_t s = 0; s <= N+1; ++s) + { + std::bitset<N> v1 = make_bitset<N>(); + std::bitset<N> v2 = v1; + v1 <<= s; + for (std::size_t i = 0; i < N; ++i) + if (i < s) + assert(v1[i] == 0); + else + assert(v1[i] == v2[i-s]); + } +} + +int main() +{ + test_left_shift<0>(); + test_left_shift<1>(); + test_left_shift<31>(); + test_left_shift<32>(); + test_left_shift<33>(); + test_left_shift<63>(); + test_left_shift<64>(); + test_left_shift<65>(); + test_left_shift<1000>(); +} diff --git a/libcxx/test/utilities/template.bitset/bitset.members/none.pass.cpp b/libcxx/test/utilities/template.bitset/bitset.members/none.pass.cpp index abba3fd54f0..5270a5a3320 100644 --- a/libcxx/test/utilities/template.bitset/bitset.members/none.pass.cpp +++ b/libcxx/test/utilities/template.bitset/bitset.members/none.pass.cpp @@ -1 +1,44 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// test bool none() const;
#include <bitset>
#include <cassert>
template <std::size_t N>
void test_none()
{
std::bitset<N> v;
v.reset();
assert(v.none() == true);
v.set();
assert(v.none() == (N == 0));
if (N > 1)
{
v[N/2] = false;
assert(v.none() == false);
v.reset();
v[N/2] = true;
assert(v.none() == false);
}
}
int main()
{
test_none<0>();
test_none<1>();
test_none<31>();
test_none<32>();
test_none<33>();
test_none<63>();
test_none<64>();
test_none<65>();
test_none<1000>();
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// test bool none() const; + +#include <bitset> +#include <cassert> + +template <std::size_t N> +void test_none() +{ + std::bitset<N> v; + v.reset(); + assert(v.none() == true); + v.set(); + assert(v.none() == (N == 0)); + if (N > 1) + { + v[N/2] = false; + assert(v.none() == false); + v.reset(); + v[N/2] = true; + assert(v.none() == false); + } +} + +int main() +{ + test_none<0>(); + test_none<1>(); + test_none<31>(); + test_none<32>(); + test_none<33>(); + test_none<63>(); + test_none<64>(); + test_none<65>(); + test_none<1000>(); +} diff --git a/libcxx/test/utilities/template.bitset/bitset.members/not_all.pass.cpp b/libcxx/test/utilities/template.bitset/bitset.members/not_all.pass.cpp index edaeac67305..7b30564f1f2 100644 --- a/libcxx/test/utilities/template.bitset/bitset.members/not_all.pass.cpp +++ b/libcxx/test/utilities/template.bitset/bitset.members/not_all.pass.cpp @@ -1 +1,46 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// test bitset<N> operator~() const;
#include <bitset>
#include <cstdlib>
#include <cassert>
template <std::size_t N>
std::bitset<N>
make_bitset()
{
std::bitset<N> v;
for (std::size_t i = 0; i < N; ++i)
v[i] = static_cast<bool>(std::rand() & 1);
return v;
}
template <std::size_t N>
void test_not_all()
{
std::bitset<N> v1 = make_bitset<N>();
std::bitset<N> v2 = ~v1;
for (std::size_t i = 0; i < N; ++i)
assert(v2[i] == ~v1[i]);
}
int main()
{
test_not_all<0>();
test_not_all<1>();
test_not_all<31>();
test_not_all<32>();
test_not_all<33>();
test_not_all<63>();
test_not_all<64>();
test_not_all<65>();
test_not_all<1000>();
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// test bitset<N> operator~() const; + +#include <bitset> +#include <cstdlib> +#include <cassert> + +template <std::size_t N> +std::bitset<N> +make_bitset() +{ + std::bitset<N> v; + for (std::size_t i = 0; i < N; ++i) + v[i] = static_cast<bool>(std::rand() & 1); + return v; +} + +template <std::size_t N> +void test_not_all() +{ + std::bitset<N> v1 = make_bitset<N>(); + std::bitset<N> v2 = ~v1; + for (std::size_t i = 0; i < N; ++i) + assert(v2[i] == ~v1[i]); +} + +int main() +{ + test_not_all<0>(); + test_not_all<1>(); + test_not_all<31>(); + test_not_all<32>(); + test_not_all<33>(); + test_not_all<63>(); + test_not_all<64>(); + test_not_all<65>(); + test_not_all<1000>(); +} diff --git a/libcxx/test/utilities/template.bitset/bitset.members/op_and_eq.pass.cpp b/libcxx/test/utilities/template.bitset/bitset.members/op_and_eq.pass.cpp index 420443ea3ac..d1c878dd75c 100644 --- a/libcxx/test/utilities/template.bitset/bitset.members/op_and_eq.pass.cpp +++ b/libcxx/test/utilities/template.bitset/bitset.members/op_and_eq.pass.cpp @@ -1 +1,48 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// test bitset<N>& operator&=(const bitset<N>& rhs);
#include <bitset>
#include <cstdlib>
#include <cassert>
template <std::size_t N>
std::bitset<N>
make_bitset()
{
std::bitset<N> v;
for (std::size_t i = 0; i < N; ++i)
v[i] = static_cast<bool>(std::rand() & 1);
return v;
}
template <std::size_t N>
void test_op_and_eq()
{
std::bitset<N> v1 = make_bitset<N>();
std::bitset<N> v2 = make_bitset<N>();
std::bitset<N> v3 = v1;
v1 &= v2;
for (std::size_t i = 0; i < N; ++i)
assert(v1[i] == (v3[i] && v2[i]));
}
int main()
{
test_op_and_eq<0>();
test_op_and_eq<1>();
test_op_and_eq<31>();
test_op_and_eq<32>();
test_op_and_eq<33>();
test_op_and_eq<63>();
test_op_and_eq<64>();
test_op_and_eq<65>();
test_op_and_eq<1000>();
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// test bitset<N>& operator&=(const bitset<N>& rhs); + +#include <bitset> +#include <cstdlib> +#include <cassert> + +template <std::size_t N> +std::bitset<N> +make_bitset() +{ + std::bitset<N> v; + for (std::size_t i = 0; i < N; ++i) + v[i] = static_cast<bool>(std::rand() & 1); + return v; +} + +template <std::size_t N> +void test_op_and_eq() +{ + std::bitset<N> v1 = make_bitset<N>(); + std::bitset<N> v2 = make_bitset<N>(); + std::bitset<N> v3 = v1; + v1 &= v2; + for (std::size_t i = 0; i < N; ++i) + assert(v1[i] == (v3[i] && v2[i])); +} + +int main() +{ + test_op_and_eq<0>(); + test_op_and_eq<1>(); + test_op_and_eq<31>(); + test_op_and_eq<32>(); + test_op_and_eq<33>(); + test_op_and_eq<63>(); + test_op_and_eq<64>(); + test_op_and_eq<65>(); + test_op_and_eq<1000>(); +} diff --git a/libcxx/test/utilities/template.bitset/bitset.members/op_eq_eq.pass.cpp b/libcxx/test/utilities/template.bitset/bitset.members/op_eq_eq.pass.cpp index beac3d31c77..4d37de6b9f2 100644 --- a/libcxx/test/utilities/template.bitset/bitset.members/op_eq_eq.pass.cpp +++ b/libcxx/test/utilities/template.bitset/bitset.members/op_eq_eq.pass.cpp @@ -1 +1,53 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// test:
// bool operator==(const bitset<N>& rhs) const;
// bool operator!=(const bitset<N>& rhs) const;
#include <bitset>
#include <cstdlib>
#include <cassert>
template <std::size_t N>
std::bitset<N>
make_bitset()
{
std::bitset<N> v;
for (std::size_t i = 0; i < N; ++i)
v[i] = static_cast<bool>(std::rand() & 1);
return v;
}
template <std::size_t N>
void test_equality()
{
const std::bitset<N> v1 = make_bitset<N>();
std::bitset<N> v2 = v1;
assert(v1 == v2);
if (N > 0)
{
v2[N/2].flip();
assert(v1 != v2);
}
}
int main()
{
test_equality<0>();
test_equality<1>();
test_equality<31>();
test_equality<32>();
test_equality<33>();
test_equality<63>();
test_equality<64>();
test_equality<65>();
test_equality<1000>();
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// test: + +// bool operator==(const bitset<N>& rhs) const; +// bool operator!=(const bitset<N>& rhs) const; + +#include <bitset> +#include <cstdlib> +#include <cassert> + +template <std::size_t N> +std::bitset<N> +make_bitset() +{ + std::bitset<N> v; + for (std::size_t i = 0; i < N; ++i) + v[i] = static_cast<bool>(std::rand() & 1); + return v; +} + +template <std::size_t N> +void test_equality() +{ + const std::bitset<N> v1 = make_bitset<N>(); + std::bitset<N> v2 = v1; + assert(v1 == v2); + if (N > 0) + { + v2[N/2].flip(); + assert(v1 != v2); + } +} + +int main() +{ + test_equality<0>(); + test_equality<1>(); + test_equality<31>(); + test_equality<32>(); + test_equality<33>(); + test_equality<63>(); + test_equality<64>(); + test_equality<65>(); + test_equality<1000>(); +} diff --git a/libcxx/test/utilities/template.bitset/bitset.members/op_or_eq.pass.cpp b/libcxx/test/utilities/template.bitset/bitset.members/op_or_eq.pass.cpp index 6de4b037693..041e2dd7ec0 100644 --- a/libcxx/test/utilities/template.bitset/bitset.members/op_or_eq.pass.cpp +++ b/libcxx/test/utilities/template.bitset/bitset.members/op_or_eq.pass.cpp @@ -1 +1,48 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// test bitset<N>& operator|=(const bitset<N>& rhs);
#include <bitset>
#include <cstdlib>
#include <cassert>
template <std::size_t N>
std::bitset<N>
make_bitset()
{
std::bitset<N> v;
for (std::size_t i = 0; i < N; ++i)
v[i] = static_cast<bool>(std::rand() & 1);
return v;
}
template <std::size_t N>
void test_op_or_eq()
{
std::bitset<N> v1 = make_bitset<N>();
std::bitset<N> v2 = make_bitset<N>();
std::bitset<N> v3 = v1;
v1 |= v2;
for (std::size_t i = 0; i < N; ++i)
assert(v1[i] == (v3[i] || v2[i]));
}
int main()
{
test_op_or_eq<0>();
test_op_or_eq<1>();
test_op_or_eq<31>();
test_op_or_eq<32>();
test_op_or_eq<33>();
test_op_or_eq<63>();
test_op_or_eq<64>();
test_op_or_eq<65>();
test_op_or_eq<1000>();
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// test bitset<N>& operator|=(const bitset<N>& rhs); + +#include <bitset> +#include <cstdlib> +#include <cassert> + +template <std::size_t N> +std::bitset<N> +make_bitset() +{ + std::bitset<N> v; + for (std::size_t i = 0; i < N; ++i) + v[i] = static_cast<bool>(std::rand() & 1); + return v; +} + +template <std::size_t N> +void test_op_or_eq() +{ + std::bitset<N> v1 = make_bitset<N>(); + std::bitset<N> v2 = make_bitset<N>(); + std::bitset<N> v3 = v1; + v1 |= v2; + for (std::size_t i = 0; i < N; ++i) + assert(v1[i] == (v3[i] || v2[i])); +} + +int main() +{ + test_op_or_eq<0>(); + test_op_or_eq<1>(); + test_op_or_eq<31>(); + test_op_or_eq<32>(); + test_op_or_eq<33>(); + test_op_or_eq<63>(); + test_op_or_eq<64>(); + test_op_or_eq<65>(); + test_op_or_eq<1000>(); +} diff --git a/libcxx/test/utilities/template.bitset/bitset.members/op_xor_eq.pass.cpp b/libcxx/test/utilities/template.bitset/bitset.members/op_xor_eq.pass.cpp index b02e5cd5d00..4ebc187a503 100644 --- a/libcxx/test/utilities/template.bitset/bitset.members/op_xor_eq.pass.cpp +++ b/libcxx/test/utilities/template.bitset/bitset.members/op_xor_eq.pass.cpp @@ -1 +1,48 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// test bitset<N>& operator^=(const bitset<N>& rhs);
#include <bitset>
#include <cstdlib>
#include <cassert>
template <std::size_t N>
std::bitset<N>
make_bitset()
{
std::bitset<N> v;
for (std::size_t i = 0; i < N; ++i)
v[i] = static_cast<bool>(std::rand() & 1);
return v;
}
template <std::size_t N>
void test_op_xor_eq()
{
std::bitset<N> v1 = make_bitset<N>();
std::bitset<N> v2 = make_bitset<N>();
std::bitset<N> v3 = v1;
v1 ^= v2;
for (std::size_t i = 0; i < N; ++i)
assert(v1[i] == (v3[i] != v2[i]));
}
int main()
{
test_op_xor_eq<0>();
test_op_xor_eq<1>();
test_op_xor_eq<31>();
test_op_xor_eq<32>();
test_op_xor_eq<33>();
test_op_xor_eq<63>();
test_op_xor_eq<64>();
test_op_xor_eq<65>();
test_op_xor_eq<1000>();
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// test bitset<N>& operator^=(const bitset<N>& rhs); + +#include <bitset> +#include <cstdlib> +#include <cassert> + +template <std::size_t N> +std::bitset<N> +make_bitset() +{ + std::bitset<N> v; + for (std::size_t i = 0; i < N; ++i) + v[i] = static_cast<bool>(std::rand() & 1); + return v; +} + +template <std::size_t N> +void test_op_xor_eq() +{ + std::bitset<N> v1 = make_bitset<N>(); + std::bitset<N> v2 = make_bitset<N>(); + std::bitset<N> v3 = v1; + v1 ^= v2; + for (std::size_t i = 0; i < N; ++i) + assert(v1[i] == (v3[i] != v2[i])); +} + +int main() +{ + test_op_xor_eq<0>(); + test_op_xor_eq<1>(); + test_op_xor_eq<31>(); + test_op_xor_eq<32>(); + test_op_xor_eq<33>(); + test_op_xor_eq<63>(); + test_op_xor_eq<64>(); + test_op_xor_eq<65>(); + test_op_xor_eq<1000>(); +} diff --git a/libcxx/test/utilities/template.bitset/bitset.members/reset_all.pass.cpp b/libcxx/test/utilities/template.bitset/bitset.members/reset_all.pass.cpp index 0d8695bd089..3d3d9a2fbbc 100644 --- a/libcxx/test/utilities/template.bitset/bitset.members/reset_all.pass.cpp +++ b/libcxx/test/utilities/template.bitset/bitset.members/reset_all.pass.cpp @@ -1 +1,36 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// test bitset<N>& reset();
#include <bitset>
#include <cassert>
template <std::size_t N>
void test_reset_all()
{
std::bitset<N> v;
v.set();
v.reset();
for (std::size_t i = 0; i < N; ++i)
assert(!v[i]);
}
int main()
{
test_reset_all<0>();
test_reset_all<1>();
test_reset_all<31>();
test_reset_all<32>();
test_reset_all<33>();
test_reset_all<63>();
test_reset_all<64>();
test_reset_all<65>();
test_reset_all<1000>();
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// test bitset<N>& reset(); + +#include <bitset> +#include <cassert> + +template <std::size_t N> +void test_reset_all() +{ + std::bitset<N> v; + v.set(); + v.reset(); + for (std::size_t i = 0; i < N; ++i) + assert(!v[i]); +} + +int main() +{ + test_reset_all<0>(); + test_reset_all<1>(); + test_reset_all<31>(); + test_reset_all<32>(); + test_reset_all<33>(); + test_reset_all<63>(); + test_reset_all<64>(); + test_reset_all<65>(); + test_reset_all<1000>(); +} diff --git a/libcxx/test/utilities/template.bitset/bitset.members/reset_one.pass.cpp b/libcxx/test/utilities/template.bitset/bitset.members/reset_one.pass.cpp index 61c1410c007..b37d2fa3da8 100644 --- a/libcxx/test/utilities/template.bitset/bitset.members/reset_one.pass.cpp +++ b/libcxx/test/utilities/template.bitset/bitset.members/reset_one.pass.cpp @@ -1 +1,47 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// test bitset<N>& reset(size_t pos);
#include <bitset>
#include <cassert>
template <std::size_t N>
void test_reset_one()
{
std::bitset<N> v;
try
{
v.set();
v.reset(50);
if (50 >= v.size())
assert(false);
for (unsigned i = 0; i < v.size(); ++i)
if (i == 50)
assert(!v[i]);
else
assert(v[i]);
}
catch (std::out_of_range&)
{
}
}
int main()
{
test_reset_one<0>();
test_reset_one<1>();
test_reset_one<31>();
test_reset_one<32>();
test_reset_one<33>();
test_reset_one<63>();
test_reset_one<64>();
test_reset_one<65>();
test_reset_one<1000>();
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// test bitset<N>& reset(size_t pos); + +#include <bitset> +#include <cassert> + +template <std::size_t N> +void test_reset_one() +{ + std::bitset<N> v; + try + { + v.set(); + v.reset(50); + if (50 >= v.size()) + assert(false); + for (unsigned i = 0; i < v.size(); ++i) + if (i == 50) + assert(!v[i]); + else + assert(v[i]); + } + catch (std::out_of_range&) + { + } +} + +int main() +{ + test_reset_one<0>(); + test_reset_one<1>(); + test_reset_one<31>(); + test_reset_one<32>(); + test_reset_one<33>(); + test_reset_one<63>(); + test_reset_one<64>(); + test_reset_one<65>(); + test_reset_one<1000>(); +} diff --git a/libcxx/test/utilities/template.bitset/bitset.members/right_shift.pass.cpp b/libcxx/test/utilities/template.bitset/bitset.members/right_shift.pass.cpp index 4c48638ed38..817adabe8e3 100644 --- a/libcxx/test/utilities/template.bitset/bitset.members/right_shift.pass.cpp +++ b/libcxx/test/utilities/template.bitset/bitset.members/right_shift.pass.cpp @@ -1 +1,48 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// test bitset<N> operator>>(size_t pos) const;
#include <bitset>
#include <cstdlib>
#include <cassert>
template <std::size_t N>
std::bitset<N>
make_bitset()
{
std::bitset<N> v;
for (std::size_t i = 0; i < N; ++i)
v[i] = static_cast<bool>(std::rand() & 1);
return v;
}
template <std::size_t N>
void test_right_shift()
{
for (std::size_t s = 0; s <= N+1; ++s)
{
std::bitset<N> v1 = make_bitset<N>();
std::bitset<N> v2 = v1;
assert((v1 >>= s) == (v2 >> s));
}
}
int main()
{
test_right_shift<0>();
test_right_shift<1>();
test_right_shift<31>();
test_right_shift<32>();
test_right_shift<33>();
test_right_shift<63>();
test_right_shift<64>();
test_right_shift<65>();
test_right_shift<1000>();
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// test bitset<N> operator>>(size_t pos) const; + +#include <bitset> +#include <cstdlib> +#include <cassert> + +template <std::size_t N> +std::bitset<N> +make_bitset() +{ + std::bitset<N> v; + for (std::size_t i = 0; i < N; ++i) + v[i] = static_cast<bool>(std::rand() & 1); + return v; +} + +template <std::size_t N> +void test_right_shift() +{ + for (std::size_t s = 0; s <= N+1; ++s) + { + std::bitset<N> v1 = make_bitset<N>(); + std::bitset<N> v2 = v1; + assert((v1 >>= s) == (v2 >> s)); + } +} + +int main() +{ + test_right_shift<0>(); + test_right_shift<1>(); + test_right_shift<31>(); + test_right_shift<32>(); + test_right_shift<33>(); + test_right_shift<63>(); + test_right_shift<64>(); + test_right_shift<65>(); + test_right_shift<1000>(); +} diff --git a/libcxx/test/utilities/template.bitset/bitset.members/right_shift_eq.pass.cpp b/libcxx/test/utilities/template.bitset/bitset.members/right_shift_eq.pass.cpp index 71f3347961b..8171a782547 100644 --- a/libcxx/test/utilities/template.bitset/bitset.members/right_shift_eq.pass.cpp +++ b/libcxx/test/utilities/template.bitset/bitset.members/right_shift_eq.pass.cpp @@ -1 +1,53 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// test bitset<N>& operator<<=(size_t pos);
#include <bitset>
#include <cstdlib>
#include <cassert>
template <std::size_t N>
std::bitset<N>
make_bitset()
{
std::bitset<N> v;
for (std::size_t i = 0; i < N; ++i)
v[i] = static_cast<bool>(std::rand() & 1);
return v;
}
template <std::size_t N>
void test_right_shift()
{
for (std::size_t s = 0; s <= N+1; ++s)
{
std::bitset<N> v1 = make_bitset<N>();
std::bitset<N> v2 = v1;
v1 >>= s;
for (std::size_t i = 0; i < N; ++i)
if (i + s < N)
assert(v1[i] == v2[i + s]);
else
assert(v1[i] == 0);
}
}
int main()
{
test_right_shift<0>();
test_right_shift<1>();
test_right_shift<31>();
test_right_shift<32>();
test_right_shift<33>();
test_right_shift<63>();
test_right_shift<64>();
test_right_shift<65>();
test_right_shift<1000>();
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// test bitset<N>& operator<<=(size_t pos); + +#include <bitset> +#include <cstdlib> +#include <cassert> + +template <std::size_t N> +std::bitset<N> +make_bitset() +{ + std::bitset<N> v; + for (std::size_t i = 0; i < N; ++i) + v[i] = static_cast<bool>(std::rand() & 1); + return v; +} + +template <std::size_t N> +void test_right_shift() +{ + for (std::size_t s = 0; s <= N+1; ++s) + { + std::bitset<N> v1 = make_bitset<N>(); + std::bitset<N> v2 = v1; + v1 >>= s; + for (std::size_t i = 0; i < N; ++i) + if (i + s < N) + assert(v1[i] == v2[i + s]); + else + assert(v1[i] == 0); + } +} + +int main() +{ + test_right_shift<0>(); + test_right_shift<1>(); + test_right_shift<31>(); + test_right_shift<32>(); + test_right_shift<33>(); + test_right_shift<63>(); + test_right_shift<64>(); + test_right_shift<65>(); + test_right_shift<1000>(); +} diff --git a/libcxx/test/utilities/template.bitset/bitset.members/set_all.pass.cpp b/libcxx/test/utilities/template.bitset/bitset.members/set_all.pass.cpp index 289eae31622..97e58b1f761 100644 --- a/libcxx/test/utilities/template.bitset/bitset.members/set_all.pass.cpp +++ b/libcxx/test/utilities/template.bitset/bitset.members/set_all.pass.cpp @@ -1 +1,35 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// test bitset<N>& set();
#include <bitset>
#include <cassert>
template <std::size_t N>
void test_set_all()
{
std::bitset<N> v;
v.set();
for (std::size_t i = 0; i < N; ++i)
assert(v[i]);
}
int main()
{
test_set_all<0>();
test_set_all<1>();
test_set_all<31>();
test_set_all<32>();
test_set_all<33>();
test_set_all<63>();
test_set_all<64>();
test_set_all<65>();
test_set_all<1000>();
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// test bitset<N>& set(); + +#include <bitset> +#include <cassert> + +template <std::size_t N> +void test_set_all() +{ + std::bitset<N> v; + v.set(); + for (std::size_t i = 0; i < N; ++i) + assert(v[i]); +} + +int main() +{ + test_set_all<0>(); + test_set_all<1>(); + test_set_all<31>(); + test_set_all<32>(); + test_set_all<33>(); + test_set_all<63>(); + test_set_all<64>(); + test_set_all<65>(); + test_set_all<1000>(); +} diff --git a/libcxx/test/utilities/template.bitset/bitset.members/set_one.pass.cpp b/libcxx/test/utilities/template.bitset/bitset.members/set_one.pass.cpp index 899b2f4cfb8..869a5ca6a5c 100644 --- a/libcxx/test/utilities/template.bitset/bitset.members/set_one.pass.cpp +++ b/libcxx/test/utilities/template.bitset/bitset.members/set_one.pass.cpp @@ -1 +1,52 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// test bitset<N>& set(size_t pos, bool val = true);
#include <bitset>
#include <cassert>
template <std::size_t N>
void test_set_one()
{
std::bitset<N> v;
try
{
v.set(50);
if (50 >= v.size())
assert(false);
assert(v[50]);
}
catch (std::out_of_range&)
{
}
try
{
v.set(50, false);
if (50 >= v.size())
assert(false);
assert(!v[50]);
}
catch (std::out_of_range&)
{
}
}
int main()
{
test_set_one<0>();
test_set_one<1>();
test_set_one<31>();
test_set_one<32>();
test_set_one<33>();
test_set_one<63>();
test_set_one<64>();
test_set_one<65>();
test_set_one<1000>();
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// test bitset<N>& set(size_t pos, bool val = true); + +#include <bitset> +#include <cassert> + +template <std::size_t N> +void test_set_one() +{ + std::bitset<N> v; + try + { + v.set(50); + if (50 >= v.size()) + assert(false); + assert(v[50]); + } + catch (std::out_of_range&) + { + } + try + { + v.set(50, false); + if (50 >= v.size()) + assert(false); + assert(!v[50]); + } + catch (std::out_of_range&) + { + } +} + +int main() +{ + test_set_one<0>(); + test_set_one<1>(); + test_set_one<31>(); + test_set_one<32>(); + test_set_one<33>(); + test_set_one<63>(); + test_set_one<64>(); + test_set_one<65>(); + test_set_one<1000>(); +} diff --git a/libcxx/test/utilities/template.bitset/bitset.members/size.pass.cpp b/libcxx/test/utilities/template.bitset/bitset.members/size.pass.cpp index 9109d2a2c0f..641f9d672f4 100644 --- a/libcxx/test/utilities/template.bitset/bitset.members/size.pass.cpp +++ b/libcxx/test/utilities/template.bitset/bitset.members/size.pass.cpp @@ -1 +1,33 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// test size_t count() const;
#include <bitset>
#include <cassert>
template <std::size_t N>
void test_size()
{
const std::bitset<N> v;
assert(v.size() == N);
}
int main()
{
test_size<0>();
test_size<1>();
test_size<31>();
test_size<32>();
test_size<33>();
test_size<63>();
test_size<64>();
test_size<65>();
test_size<1000>();
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// test size_t count() const; + +#include <bitset> +#include <cassert> + +template <std::size_t N> +void test_size() +{ + const std::bitset<N> v; + assert(v.size() == N); +} + +int main() +{ + test_size<0>(); + test_size<1>(); + test_size<31>(); + test_size<32>(); + test_size<33>(); + test_size<63>(); + test_size<64>(); + test_size<65>(); + test_size<1000>(); +} diff --git a/libcxx/test/utilities/template.bitset/bitset.members/test.pass.cpp b/libcxx/test/utilities/template.bitset/bitset.members/test.pass.cpp index 530cc1d9fe6..e2f0d39f02f 100644 --- a/libcxx/test/utilities/template.bitset/bitset.members/test.pass.cpp +++ b/libcxx/test/utilities/template.bitset/bitset.members/test.pass.cpp @@ -1 +1,53 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// test constexpr bool test(size_t pos) const;
#include <bitset>
#include <cstdlib>
#include <cassert>
template <std::size_t N>
std::bitset<N>
make_bitset()
{
std::bitset<N> v;
for (std::size_t i = 0; i < N; ++i)
v[i] = static_cast<bool>(std::rand() & 1);
return v;
}
template <std::size_t N>
void test_test()
{
const std::bitset<N> v1 = make_bitset<N>();
try
{
bool b = v1.test(50);
if (50 >= v1.size())
assert(false);
assert(b == v1[50]);
}
catch (std::out_of_range&)
{
}
}
int main()
{
test_test<0>();
test_test<1>();
test_test<31>();
test_test<32>();
test_test<33>();
test_test<63>();
test_test<64>();
test_test<65>();
test_test<1000>();
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// test constexpr bool test(size_t pos) const; + +#include <bitset> +#include <cstdlib> +#include <cassert> + +template <std::size_t N> +std::bitset<N> +make_bitset() +{ + std::bitset<N> v; + for (std::size_t i = 0; i < N; ++i) + v[i] = static_cast<bool>(std::rand() & 1); + return v; +} + +template <std::size_t N> +void test_test() +{ + const std::bitset<N> v1 = make_bitset<N>(); + try + { + bool b = v1.test(50); + if (50 >= v1.size()) + assert(false); + assert(b == v1[50]); + } + catch (std::out_of_range&) + { + } +} + +int main() +{ + test_test<0>(); + test_test<1>(); + test_test<31>(); + test_test<32>(); + test_test<33>(); + test_test<63>(); + test_test<64>(); + test_test<65>(); + test_test<1000>(); +} diff --git a/libcxx/test/utilities/template.bitset/bitset.members/to_string.pass.cpp b/libcxx/test/utilities/template.bitset/bitset.members/to_string.pass.cpp index a44877902b3..eebe8d1e23e 100644 --- a/libcxx/test/utilities/template.bitset/bitset.members/to_string.pass.cpp +++ b/libcxx/test/utilities/template.bitset/bitset.members/to_string.pass.cpp @@ -1 +1,160 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// test:
// template <class charT, class traits, class Allocator>
// basic_string<charT, traits, Allocator>
// to_string(charT zero = charT('0'), charT one = charT('1')) const;
//
// template <class charT, class traits>
// basic_string<charT, traits, allocator<charT> > to_string() const;
//
// template <class charT>
// basic_string<charT, char_traits<charT>, allocator<charT> > to_string() const;
//
// basic_string<char, char_traits<char>, allocator<char> > to_string() const;
#include <bitset>
#include <string>
#include <cstdlib>
#include <cassert>
template <std::size_t N>
std::bitset<N>
make_bitset()
{
std::bitset<N> v;
for (std::size_t i = 0; i < N; ++i)
v[i] = static_cast<bool>(std::rand() & 1);
return v;
}
template <std::size_t N>
void test_to_string()
{
{
std::bitset<N> v = make_bitset<N>();
{
std::wstring s = v.template to_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >();
for (std::size_t i = 0; i < N; ++i)
if (v[i])
assert(s[N - 1 - i] == '1');
else
assert(s[N - 1 - i] == '0');
}
{
std::wstring s = v.template to_string<wchar_t, std::char_traits<wchar_t> >();
for (std::size_t i = 0; i < N; ++i)
if (v[i])
assert(s[N - 1 - i] == '1');
else
assert(s[N - 1 - i] == '0');
}
{
std::string s = v.template to_string<char>();
for (std::size_t i = 0; i < N; ++i)
if (v[i])
assert(s[N - 1 - i] == '1');
else
assert(s[N - 1 - i] == '0');
}
{
std::string s = v.to_string();
for (std::size_t i = 0; i < N; ++i)
if (v[i])
assert(s[N - 1 - i] == '1');
else
assert(s[N - 1 - i] == '0');
}
}
{
std::bitset<N> v = make_bitset<N>();
{
std::wstring s = v.template to_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >('0');
for (std::size_t i = 0; i < N; ++i)
if (v[i])
assert(s[N - 1 - i] == '1');
else
assert(s[N - 1 - i] == '0');
}
{
std::wstring s = v.template to_string<wchar_t, std::char_traits<wchar_t> >('0');
for (std::size_t i = 0; i < N; ++i)
if (v[i])
assert(s[N - 1 - i] == '1');
else
assert(s[N - 1 - i] == '0');
}
{
std::string s = v.template to_string<char>('0');
for (std::size_t i = 0; i < N; ++i)
if (v[i])
assert(s[N - 1 - i] == '1');
else
assert(s[N - 1 - i] == '0');
}
{
std::string s = v.to_string('0');
for (std::size_t i = 0; i < N; ++i)
if (v[i])
assert(s[N - 1 - i] == '1');
else
assert(s[N - 1 - i] == '0');
}
}
{
std::bitset<N> v = make_bitset<N>();
{
std::wstring s = v.template to_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >('0', '1');
for (std::size_t i = 0; i < N; ++i)
if (v[i])
assert(s[N - 1 - i] == '1');
else
assert(s[N - 1 - i] == '0');
}
{
std::wstring s = v.template to_string<wchar_t, std::char_traits<wchar_t> >('0', '1');
for (std::size_t i = 0; i < N; ++i)
if (v[i])
assert(s[N - 1 - i] == '1');
else
assert(s[N - 1 - i] == '0');
}
{
std::string s = v.template to_string<char>('0', '1');
for (std::size_t i = 0; i < N; ++i)
if (v[i])
assert(s[N - 1 - i] == '1');
else
assert(s[N - 1 - i] == '0');
}
{
std::string s = v.to_string('0', '1');
for (std::size_t i = 0; i < N; ++i)
if (v[i])
assert(s[N - 1 - i] == '1');
else
assert(s[N - 1 - i] == '0');
}
}
}
int main()
{
test_to_string<0>();
test_to_string<1>();
test_to_string<31>();
test_to_string<32>();
test_to_string<33>();
test_to_string<63>();
test_to_string<64>();
test_to_string<65>();
test_to_string<1000>();
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// test: + +// template <class charT, class traits, class Allocator> +// basic_string<charT, traits, Allocator> +// to_string(charT zero = charT('0'), charT one = charT('1')) const; +// +// template <class charT, class traits> +// basic_string<charT, traits, allocator<charT> > to_string() const; +// +// template <class charT> +// basic_string<charT, char_traits<charT>, allocator<charT> > to_string() const; +// +// basic_string<char, char_traits<char>, allocator<char> > to_string() const; + +#include <bitset> +#include <string> +#include <cstdlib> +#include <cassert> + +template <std::size_t N> +std::bitset<N> +make_bitset() +{ + std::bitset<N> v; + for (std::size_t i = 0; i < N; ++i) + v[i] = static_cast<bool>(std::rand() & 1); + return v; +} + +template <std::size_t N> +void test_to_string() +{ +{ + std::bitset<N> v = make_bitset<N>(); + { + std::wstring s = v.template to_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >(); + for (std::size_t i = 0; i < N; ++i) + if (v[i]) + assert(s[N - 1 - i] == '1'); + else + assert(s[N - 1 - i] == '0'); + } + { + std::wstring s = v.template to_string<wchar_t, std::char_traits<wchar_t> >(); + for (std::size_t i = 0; i < N; ++i) + if (v[i]) + assert(s[N - 1 - i] == '1'); + else + assert(s[N - 1 - i] == '0'); + } + { + std::string s = v.template to_string<char>(); + for (std::size_t i = 0; i < N; ++i) + if (v[i]) + assert(s[N - 1 - i] == '1'); + else + assert(s[N - 1 - i] == '0'); + } + { + std::string s = v.to_string(); + for (std::size_t i = 0; i < N; ++i) + if (v[i]) + assert(s[N - 1 - i] == '1'); + else + assert(s[N - 1 - i] == '0'); + } +} +{ + std::bitset<N> v = make_bitset<N>(); + { + std::wstring s = v.template to_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >('0'); + for (std::size_t i = 0; i < N; ++i) + if (v[i]) + assert(s[N - 1 - i] == '1'); + else + assert(s[N - 1 - i] == '0'); + } + { + std::wstring s = v.template to_string<wchar_t, std::char_traits<wchar_t> >('0'); + for (std::size_t i = 0; i < N; ++i) + if (v[i]) + assert(s[N - 1 - i] == '1'); + else + assert(s[N - 1 - i] == '0'); + } + { + std::string s = v.template to_string<char>('0'); + for (std::size_t i = 0; i < N; ++i) + if (v[i]) + assert(s[N - 1 - i] == '1'); + else + assert(s[N - 1 - i] == '0'); + } + { + std::string s = v.to_string('0'); + for (std::size_t i = 0; i < N; ++i) + if (v[i]) + assert(s[N - 1 - i] == '1'); + else + assert(s[N - 1 - i] == '0'); + } +} +{ + std::bitset<N> v = make_bitset<N>(); + { + std::wstring s = v.template to_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >('0', '1'); + for (std::size_t i = 0; i < N; ++i) + if (v[i]) + assert(s[N - 1 - i] == '1'); + else + assert(s[N - 1 - i] == '0'); + } + { + std::wstring s = v.template to_string<wchar_t, std::char_traits<wchar_t> >('0', '1'); + for (std::size_t i = 0; i < N; ++i) + if (v[i]) + assert(s[N - 1 - i] == '1'); + else + assert(s[N - 1 - i] == '0'); + } + { + std::string s = v.template to_string<char>('0', '1'); + for (std::size_t i = 0; i < N; ++i) + if (v[i]) + assert(s[N - 1 - i] == '1'); + else + assert(s[N - 1 - i] == '0'); + } + { + std::string s = v.to_string('0', '1'); + for (std::size_t i = 0; i < N; ++i) + if (v[i]) + assert(s[N - 1 - i] == '1'); + else + assert(s[N - 1 - i] == '0'); + } +} +} + +int main() +{ + test_to_string<0>(); + test_to_string<1>(); + test_to_string<31>(); + test_to_string<32>(); + test_to_string<33>(); + test_to_string<63>(); + test_to_string<64>(); + test_to_string<65>(); + test_to_string<1000>(); +} diff --git a/libcxx/test/utilities/template.bitset/bitset.members/to_ullong.pass.cpp b/libcxx/test/utilities/template.bitset/bitset.members/to_ullong.pass.cpp index 0fbf212e82e..4b9b5cbda1f 100644 --- a/libcxx/test/utilities/template.bitset/bitset.members/to_ullong.pass.cpp +++ b/libcxx/test/utilities/template.bitset/bitset.members/to_ullong.pass.cpp @@ -1 +1,50 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// test unsigned long long to_ullong() const;
#include <bitset>
#include <algorithm>
#include <climits>
#include <cassert>
template <std::size_t N>
void test_to_ullong()
{
const std::size_t M = sizeof(unsigned long long) * CHAR_BIT < N ? sizeof(unsigned long long) * CHAR_BIT : N;
const std::size_t X = M == 0 ? sizeof(unsigned long long) * CHAR_BIT - 1 : sizeof(unsigned long long) * CHAR_BIT - M;
const unsigned long long max = M == 0 ? 0 : (unsigned long long)(-1) >> X;
unsigned long long tests[] = {0,
std::min<unsigned long long>(1, max),
std::min<unsigned long long>(2, max),
std::min<unsigned long long>(3, max),
std::min(max, max-3),
std::min(max, max-2),
std::min(max, max-1),
max};
for (std::size_t i = 0; i < sizeof(tests)/sizeof(tests[0]); ++i)
{
unsigned long long j = tests[i];
std::bitset<N> v(j);
assert(j == v.to_ullong());
}
}
int main()
{
test_to_ullong<0>();
test_to_ullong<1>();
test_to_ullong<31>();
test_to_ullong<32>();
test_to_ullong<33>();
test_to_ullong<63>();
test_to_ullong<64>();
test_to_ullong<65>();
test_to_ullong<1000>();
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// test unsigned long long to_ullong() const; + +#include <bitset> +#include <algorithm> +#include <climits> +#include <cassert> + +template <std::size_t N> +void test_to_ullong() +{ + const std::size_t M = sizeof(unsigned long long) * CHAR_BIT < N ? sizeof(unsigned long long) * CHAR_BIT : N; + const std::size_t X = M == 0 ? sizeof(unsigned long long) * CHAR_BIT - 1 : sizeof(unsigned long long) * CHAR_BIT - M; + const unsigned long long max = M == 0 ? 0 : (unsigned long long)(-1) >> X; + unsigned long long tests[] = {0, + std::min<unsigned long long>(1, max), + std::min<unsigned long long>(2, max), + std::min<unsigned long long>(3, max), + std::min(max, max-3), + std::min(max, max-2), + std::min(max, max-1), + max}; + for (std::size_t i = 0; i < sizeof(tests)/sizeof(tests[0]); ++i) + { + unsigned long long j = tests[i]; + std::bitset<N> v(j); + assert(j == v.to_ullong()); + } +} + +int main() +{ + test_to_ullong<0>(); + test_to_ullong<1>(); + test_to_ullong<31>(); + test_to_ullong<32>(); + test_to_ullong<33>(); + test_to_ullong<63>(); + test_to_ullong<64>(); + test_to_ullong<65>(); + test_to_ullong<1000>(); +} diff --git a/libcxx/test/utilities/template.bitset/bitset.members/to_ulong.pass.cpp b/libcxx/test/utilities/template.bitset/bitset.members/to_ulong.pass.cpp index da5f163362b..050b3f798ee 100644 --- a/libcxx/test/utilities/template.bitset/bitset.members/to_ulong.pass.cpp +++ b/libcxx/test/utilities/template.bitset/bitset.members/to_ulong.pass.cpp @@ -1 +1,50 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// test unsigned long to_ulong() const;
#include <bitset>
#include <algorithm>
#include <climits>
#include <cassert>
template <std::size_t N>
void test_to_ulong()
{
const std::size_t M = sizeof(unsigned long) * CHAR_BIT < N ? sizeof(unsigned long) * CHAR_BIT : N;
const std::size_t X = M == 0 ? sizeof(unsigned long) * CHAR_BIT - 1 : sizeof(unsigned long) * CHAR_BIT - M;
const std::size_t max = M == 0 ? 0 : std::size_t(-1) >> X;
std::size_t tests[] = {0,
std::min<std::size_t>(1, max),
std::min<std::size_t>(2, max),
std::min<std::size_t>(3, max),
std::min(max, max-3),
std::min(max, max-2),
std::min(max, max-1),
max};
for (std::size_t i = 0; i < sizeof(tests)/sizeof(tests[0]); ++i)
{
std::size_t j = tests[i];
std::bitset<N> v(j);
assert(j == v.to_ulong());
}
}
int main()
{
test_to_ulong<0>();
test_to_ulong<1>();
test_to_ulong<31>();
test_to_ulong<32>();
test_to_ulong<33>();
test_to_ulong<63>();
test_to_ulong<64>();
test_to_ulong<65>();
test_to_ulong<1000>();
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// test unsigned long to_ulong() const; + +#include <bitset> +#include <algorithm> +#include <climits> +#include <cassert> + +template <std::size_t N> +void test_to_ulong() +{ + const std::size_t M = sizeof(unsigned long) * CHAR_BIT < N ? sizeof(unsigned long) * CHAR_BIT : N; + const std::size_t X = M == 0 ? sizeof(unsigned long) * CHAR_BIT - 1 : sizeof(unsigned long) * CHAR_BIT - M; + const std::size_t max = M == 0 ? 0 : std::size_t(-1) >> X; + std::size_t tests[] = {0, + std::min<std::size_t>(1, max), + std::min<std::size_t>(2, max), + std::min<std::size_t>(3, max), + std::min(max, max-3), + std::min(max, max-2), + std::min(max, max-1), + max}; + for (std::size_t i = 0; i < sizeof(tests)/sizeof(tests[0]); ++i) + { + std::size_t j = tests[i]; + std::bitset<N> v(j); + assert(j == v.to_ulong()); + } +} + +int main() +{ + test_to_ulong<0>(); + test_to_ulong<1>(); + test_to_ulong<31>(); + test_to_ulong<32>(); + test_to_ulong<33>(); + test_to_ulong<63>(); + test_to_ulong<64>(); + test_to_ulong<65>(); + test_to_ulong<1000>(); +} diff --git a/libcxx/test/utilities/template.bitset/bitset.operators/op_and.pass.cpp b/libcxx/test/utilities/template.bitset/bitset.operators/op_and.pass.cpp index a27b55bdbd9..437f8c47e01 100644 --- a/libcxx/test/utilities/template.bitset/bitset.operators/op_and.pass.cpp +++ b/libcxx/test/utilities/template.bitset/bitset.operators/op_and.pass.cpp @@ -1 +1,46 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// test bitset<N> operator&(const bitset<N>& lhs, const bitset<N>& rhs);
#include <bitset>
#include <cstdlib>
#include <cassert>
template <std::size_t N>
std::bitset<N>
make_bitset()
{
std::bitset<N> v;
for (std::size_t i = 0; i < N; ++i)
v[i] = static_cast<bool>(std::rand() & 1);
return v;
}
template <std::size_t N>
void test_op_and()
{
std::bitset<N> v1 = make_bitset<N>();
std::bitset<N> v2 = make_bitset<N>();
std::bitset<N> v3 = v1;
assert((v1 & v2) == (v3 &= v2));;
}
int main()
{
test_op_and<0>();
test_op_and<1>();
test_op_and<31>();
test_op_and<32>();
test_op_and<33>();
test_op_and<63>();
test_op_and<64>();
test_op_and<65>();
test_op_and<1000>();
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// test bitset<N> operator&(const bitset<N>& lhs, const bitset<N>& rhs); + +#include <bitset> +#include <cstdlib> +#include <cassert> + +template <std::size_t N> +std::bitset<N> +make_bitset() +{ + std::bitset<N> v; + for (std::size_t i = 0; i < N; ++i) + v[i] = static_cast<bool>(std::rand() & 1); + return v; +} + +template <std::size_t N> +void test_op_and() +{ + std::bitset<N> v1 = make_bitset<N>(); + std::bitset<N> v2 = make_bitset<N>(); + std::bitset<N> v3 = v1; + assert((v1 & v2) == (v3 &= v2));; +} + +int main() +{ + test_op_and<0>(); + test_op_and<1>(); + test_op_and<31>(); + test_op_and<32>(); + test_op_and<33>(); + test_op_and<63>(); + test_op_and<64>(); + test_op_and<65>(); + test_op_and<1000>(); +} diff --git a/libcxx/test/utilities/template.bitset/bitset.operators/op_not.pass.cpp b/libcxx/test/utilities/template.bitset/bitset.operators/op_not.pass.cpp index e4b20fd9a95..5d4196ed43a 100644 --- a/libcxx/test/utilities/template.bitset/bitset.operators/op_not.pass.cpp +++ b/libcxx/test/utilities/template.bitset/bitset.operators/op_not.pass.cpp @@ -1 +1,46 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// test bitset<N> operator^(const bitset<N>& lhs, const bitset<N>& rhs);
#include <bitset>
#include <cstdlib>
#include <cassert>
template <std::size_t N>
std::bitset<N>
make_bitset()
{
std::bitset<N> v;
for (std::size_t i = 0; i < N; ++i)
v[i] = static_cast<bool>(std::rand() & 1);
return v;
}
template <std::size_t N>
void test_op_not()
{
std::bitset<N> v1 = make_bitset<N>();
std::bitset<N> v2 = make_bitset<N>();
std::bitset<N> v3 = v1;
assert((v1 ^ v2) == (v3 ^= v2));;
}
int main()
{
test_op_not<0>();
test_op_not<1>();
test_op_not<31>();
test_op_not<32>();
test_op_not<33>();
test_op_not<63>();
test_op_not<64>();
test_op_not<65>();
test_op_not<1000>();
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// test bitset<N> operator^(const bitset<N>& lhs, const bitset<N>& rhs); + +#include <bitset> +#include <cstdlib> +#include <cassert> + +template <std::size_t N> +std::bitset<N> +make_bitset() +{ + std::bitset<N> v; + for (std::size_t i = 0; i < N; ++i) + v[i] = static_cast<bool>(std::rand() & 1); + return v; +} + +template <std::size_t N> +void test_op_not() +{ + std::bitset<N> v1 = make_bitset<N>(); + std::bitset<N> v2 = make_bitset<N>(); + std::bitset<N> v3 = v1; + assert((v1 ^ v2) == (v3 ^= v2));; +} + +int main() +{ + test_op_not<0>(); + test_op_not<1>(); + test_op_not<31>(); + test_op_not<32>(); + test_op_not<33>(); + test_op_not<63>(); + test_op_not<64>(); + test_op_not<65>(); + test_op_not<1000>(); +} diff --git a/libcxx/test/utilities/template.bitset/bitset.operators/op_or.pass.cpp b/libcxx/test/utilities/template.bitset/bitset.operators/op_or.pass.cpp index 573ab8e6e0a..56667140a70 100644 --- a/libcxx/test/utilities/template.bitset/bitset.operators/op_or.pass.cpp +++ b/libcxx/test/utilities/template.bitset/bitset.operators/op_or.pass.cpp @@ -1 +1,46 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// test bitset<N> operator|(const bitset<N>& lhs, const bitset<N>& rhs);
#include <bitset>
#include <cstdlib>
#include <cassert>
template <std::size_t N>
std::bitset<N>
make_bitset()
{
std::bitset<N> v;
for (std::size_t i = 0; i < N; ++i)
v[i] = static_cast<bool>(std::rand() & 1);
return v;
}
template <std::size_t N>
void test_op_or()
{
std::bitset<N> v1 = make_bitset<N>();
std::bitset<N> v2 = make_bitset<N>();
std::bitset<N> v3 = v1;
assert((v1 | v2) == (v3 |= v2));;
}
int main()
{
test_op_or<0>();
test_op_or<1>();
test_op_or<31>();
test_op_or<32>();
test_op_or<33>();
test_op_or<63>();
test_op_or<64>();
test_op_or<65>();
test_op_or<1000>();
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// test bitset<N> operator|(const bitset<N>& lhs, const bitset<N>& rhs); + +#include <bitset> +#include <cstdlib> +#include <cassert> + +template <std::size_t N> +std::bitset<N> +make_bitset() +{ + std::bitset<N> v; + for (std::size_t i = 0; i < N; ++i) + v[i] = static_cast<bool>(std::rand() & 1); + return v; +} + +template <std::size_t N> +void test_op_or() +{ + std::bitset<N> v1 = make_bitset<N>(); + std::bitset<N> v2 = make_bitset<N>(); + std::bitset<N> v3 = v1; + assert((v1 | v2) == (v3 |= v2));; +} + +int main() +{ + test_op_or<0>(); + test_op_or<1>(); + test_op_or<31>(); + test_op_or<32>(); + test_op_or<33>(); + test_op_or<63>(); + test_op_or<64>(); + test_op_or<65>(); + test_op_or<1000>(); +} diff --git a/libcxx/test/utilities/template.bitset/bitset.operators/stream_in.pass.cpp b/libcxx/test/utilities/template.bitset/bitset.operators/stream_in.pass.cpp index b18007e41b6..edd2fd85577 100644 --- a/libcxx/test/utilities/template.bitset/bitset.operators/stream_in.pass.cpp +++ b/libcxx/test/utilities/template.bitset/bitset.operators/stream_in.pass.cpp @@ -1 +1,26 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// test:
// template <class charT, class traits, size_t N>
// basic_ostream<charT, traits>&
// operator<<(basic_ostream<charT, traits>& os, const bitset<N>& x);
#include <bitset>
#include <sstream>
#include <cassert>
int main()
{
std::istringstream in("01011010");
std::bitset<8> b;
in >> b;
assert(b.to_ulong() == 0x5A);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// test: + +// template <class charT, class traits, size_t N> +// basic_ostream<charT, traits>& +// operator<<(basic_ostream<charT, traits>& os, const bitset<N>& x); + +#include <bitset> +#include <sstream> +#include <cassert> + +int main() +{ + std::istringstream in("01011010"); + std::bitset<8> b; + in >> b; + assert(b.to_ulong() == 0x5A); +} diff --git a/libcxx/test/utilities/template.bitset/bitset.operators/stream_out.pass.cpp b/libcxx/test/utilities/template.bitset/bitset.operators/stream_out.pass.cpp index 41486d9b4fe..5ebf87f3570 100644 --- a/libcxx/test/utilities/template.bitset/bitset.operators/stream_out.pass.cpp +++ b/libcxx/test/utilities/template.bitset/bitset.operators/stream_out.pass.cpp @@ -1 +1,26 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// test:
// template <class charT, class traits, size_t N>
// basic_istream<charT, traits>&
// operator>>(basic_istream<charT, traits>& is, bitset<N>& x);
#include <bitset>
#include <sstream>
#include <cassert>
int main()
{
std::ostringstream os;
std::bitset<8> b(0x5A);
os << b;
assert(os.str() == "01011010");
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// test: + +// template <class charT, class traits, size_t N> +// basic_istream<charT, traits>& +// operator>>(basic_istream<charT, traits>& is, bitset<N>& x); + +#include <bitset> +#include <sstream> +#include <cassert> + +int main() +{ + std::ostringstream os; + std::bitset<8> b(0x5A); + os << b; + assert(os.str() == "01011010"); +} diff --git a/libcxx/test/utilities/template.bitset/includes.pass.cpp b/libcxx/test/utilities/template.bitset/includes.pass.cpp index 4812424b6dc..19baadca705 100644 --- a/libcxx/test/utilities/template.bitset/includes.pass.cpp +++ b/libcxx/test/utilities/template.bitset/includes.pass.cpp @@ -1 +1,32 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// test that <bitset> includes <cstddef>, <string>, <stdexcept> and <iosfwd>
#include <bitset>
#ifndef _LIBCPP_CSTDDEF
#error <cstddef> has not been included
#endif
#ifndef _LIBCPP_STRING
#error <string> has not been included
#endif
#ifndef _LIBCPP_STDEXCEPT
#error <stdexcept> has not been included
#endif
#ifndef _LIBCPP_IOSFWD
#error <iosfwd> has not been included
#endif
int main()
{
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// test that <bitset> includes <cstddef>, <string>, <stdexcept> and <iosfwd> + +#include <bitset> + +#ifndef _LIBCPP_CSTDDEF +#error <cstddef> has not been included +#endif + +#ifndef _LIBCPP_STRING +#error <string> has not been included +#endif + +#ifndef _LIBCPP_STDEXCEPT +#error <stdexcept> has not been included +#endif + +#ifndef _LIBCPP_IOSFWD +#error <iosfwd> has not been included +#endif + +int main() +{ +} diff --git a/libcxx/test/utilities/template.bitset/version.pass.cpp b/libcxx/test/utilities/template.bitset/version.pass.cpp index 37f3671f2d8..5b6511fd0a3 100644 --- a/libcxx/test/utilities/template.bitset/version.pass.cpp +++ b/libcxx/test/utilities/template.bitset/version.pass.cpp @@ -1 +1,20 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <bitset>
#include <bitset>
#ifndef _LIBCPP_VERSION
#error _LIBCPP_VERSION not defined
#endif
int main()
{
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <bitset> + +#include <bitset> + +#ifndef _LIBCPP_VERSION +#error _LIBCPP_VERSION not defined +#endif + +int main() +{ +} diff --git a/libcxx/test/utilities/time/clock.h b/libcxx/test/utilities/time/clock.h index d5f4c02cc2f..8490188aca7 100644 --- a/libcxx/test/utilities/time/clock.h +++ b/libcxx/test/utilities/time/clock.h @@ -14,4 +14,4 @@ class Clock static time_point now(); }; -#endif +#endif // CLOCK_H diff --git a/libcxx/test/utilities/time/hours.pass.cpp b/libcxx/test/utilities/time/hours.pass.cpp index f76fdf007d2..387089f8f59 100644 --- a/libcxx/test/utilities/time/hours.pass.cpp +++ b/libcxx/test/utilities/time/hours.pass.cpp @@ -1 +1,27 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <chrono>
// typedef duration<signed integral type of at least 23 bits, ratio<3600>> hours;
#include <chrono>
#include <type_traits>
#include <limits>
int main()
{
typedef std::chrono::hours D;
typedef D::rep Rep;
typedef D::period Period;
static_assert(std::is_signed<Rep>::value, "");
static_assert(std::is_integral<Rep>::value, "");
static_assert(std::numeric_limits<Rep>::digits >= 22, "");
static_assert((std::is_same<Period, std::ratio<3600> >::value), "");
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// typedef duration<signed integral type of at least 23 bits, ratio<3600>> hours; + +#include <chrono> +#include <type_traits> +#include <limits> + +int main() +{ + typedef std::chrono::hours D; + typedef D::rep Rep; + typedef D::period Period; + static_assert(std::is_signed<Rep>::value, ""); + static_assert(std::is_integral<Rep>::value, ""); + static_assert(std::numeric_limits<Rep>::digits >= 22, ""); + static_assert((std::is_same<Period, std::ratio<3600> >::value), ""); +} diff --git a/libcxx/test/utilities/time/microseconds.pass.cpp b/libcxx/test/utilities/time/microseconds.pass.cpp index f04a2de5df5..368d4127335 100644 --- a/libcxx/test/utilities/time/microseconds.pass.cpp +++ b/libcxx/test/utilities/time/microseconds.pass.cpp @@ -1 +1,27 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <chrono>
// typedef duration<signed integral type of at least 55 bits, micro> microseconds;
#include <chrono>
#include <type_traits>
#include <limits>
int main()
{
typedef std::chrono::microseconds D;
typedef D::rep Rep;
typedef D::period Period;
static_assert(std::is_signed<Rep>::value, "");
static_assert(std::is_integral<Rep>::value, "");
static_assert(std::numeric_limits<Rep>::digits >= 54, "");
static_assert((std::is_same<Period, std::micro>::value), "");
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// typedef duration<signed integral type of at least 55 bits, micro> microseconds; + +#include <chrono> +#include <type_traits> +#include <limits> + +int main() +{ + typedef std::chrono::microseconds D; + typedef D::rep Rep; + typedef D::period Period; + static_assert(std::is_signed<Rep>::value, ""); + static_assert(std::is_integral<Rep>::value, ""); + static_assert(std::numeric_limits<Rep>::digits >= 54, ""); + static_assert((std::is_same<Period, std::micro>::value), ""); +} diff --git a/libcxx/test/utilities/time/milliseconds.pass.cpp b/libcxx/test/utilities/time/milliseconds.pass.cpp index 6002fa028cb..8c147d9f09e 100644 --- a/libcxx/test/utilities/time/milliseconds.pass.cpp +++ b/libcxx/test/utilities/time/milliseconds.pass.cpp @@ -1 +1,27 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <chrono>
// typedef duration<signed integral type of at least 45 bits, milli> milliseconds;
#include <chrono>
#include <type_traits>
#include <limits>
int main()
{
typedef std::chrono::milliseconds D;
typedef D::rep Rep;
typedef D::period Period;
static_assert(std::is_signed<Rep>::value, "");
static_assert(std::is_integral<Rep>::value, "");
static_assert(std::numeric_limits<Rep>::digits >= 44, "");
static_assert((std::is_same<Period, std::milli>::value), "");
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// typedef duration<signed integral type of at least 45 bits, milli> milliseconds; + +#include <chrono> +#include <type_traits> +#include <limits> + +int main() +{ + typedef std::chrono::milliseconds D; + typedef D::rep Rep; + typedef D::period Period; + static_assert(std::is_signed<Rep>::value, ""); + static_assert(std::is_integral<Rep>::value, ""); + static_assert(std::numeric_limits<Rep>::digits >= 44, ""); + static_assert((std::is_same<Period, std::milli>::value), ""); +} diff --git a/libcxx/test/utilities/time/minutes.pass.cpp b/libcxx/test/utilities/time/minutes.pass.cpp index afa1b320b5c..96589947654 100644 --- a/libcxx/test/utilities/time/minutes.pass.cpp +++ b/libcxx/test/utilities/time/minutes.pass.cpp @@ -1 +1,27 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <chrono>
// typedef duration<signed integral type of at least 29 bits, ratio< 60>> minutes;
#include <chrono>
#include <type_traits>
#include <limits>
int main()
{
typedef std::chrono::minutes D;
typedef D::rep Rep;
typedef D::period Period;
static_assert(std::is_signed<Rep>::value, "");
static_assert(std::is_integral<Rep>::value, "");
static_assert(std::numeric_limits<Rep>::digits >= 28, "");
static_assert((std::is_same<Period, std::ratio<60> >::value), "");
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// typedef duration<signed integral type of at least 29 bits, ratio< 60>> minutes; + +#include <chrono> +#include <type_traits> +#include <limits> + +int main() +{ + typedef std::chrono::minutes D; + typedef D::rep Rep; + typedef D::period Period; + static_assert(std::is_signed<Rep>::value, ""); + static_assert(std::is_integral<Rep>::value, ""); + static_assert(std::numeric_limits<Rep>::digits >= 28, ""); + static_assert((std::is_same<Period, std::ratio<60> >::value), ""); +} diff --git a/libcxx/test/utilities/time/nanoseconds.pass.cpp b/libcxx/test/utilities/time/nanoseconds.pass.cpp index 929bd9a15ec..a5eb803f537 100644 --- a/libcxx/test/utilities/time/nanoseconds.pass.cpp +++ b/libcxx/test/utilities/time/nanoseconds.pass.cpp @@ -1 +1,27 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <chrono>
// typedef duration<signed integral type of at least 64 bits, nano> nanoseconds;
#include <chrono>
#include <type_traits>
#include <limits>
int main()
{
typedef std::chrono::nanoseconds D;
typedef D::rep Rep;
typedef D::period Period;
static_assert(std::is_signed<Rep>::value, "");
static_assert(std::is_integral<Rep>::value, "");
static_assert(std::numeric_limits<Rep>::digits >= 63, "");
static_assert((std::is_same<Period, std::nano>::value), "");
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// typedef duration<signed integral type of at least 64 bits, nano> nanoseconds; + +#include <chrono> +#include <type_traits> +#include <limits> + +int main() +{ + typedef std::chrono::nanoseconds D; + typedef D::rep Rep; + typedef D::period Period; + static_assert(std::is_signed<Rep>::value, ""); + static_assert(std::is_integral<Rep>::value, ""); + static_assert(std::numeric_limits<Rep>::digits >= 63, ""); + static_assert((std::is_same<Period, std::nano>::value), ""); +} diff --git a/libcxx/test/utilities/time/rep.h b/libcxx/test/utilities/time/rep.h index fa949fe2e08..ea4db2d3f21 100644 --- a/libcxx/test/utilities/time/rep.h +++ b/libcxx/test/utilities/time/rep.h @@ -15,4 +15,4 @@ public: Rep& operator/=(Rep x) {data_ /= x.data_; return *this;} }; -#endif +#endif // REP_H diff --git a/libcxx/test/utilities/time/seconds.pass.cpp b/libcxx/test/utilities/time/seconds.pass.cpp index 0022b56a719..d9948bc5b08 100644 --- a/libcxx/test/utilities/time/seconds.pass.cpp +++ b/libcxx/test/utilities/time/seconds.pass.cpp @@ -1 +1,27 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <chrono>
// typedef duration<signed integral type of at least 35 bits > seconds;
#include <chrono>
#include <type_traits>
#include <limits>
int main()
{
typedef std::chrono::seconds D;
typedef D::rep Rep;
typedef D::period Period;
static_assert(std::is_signed<Rep>::value, "");
static_assert(std::is_integral<Rep>::value, "");
static_assert(std::numeric_limits<Rep>::digits >= 34, "");
static_assert((std::is_same<Period, std::ratio<1> >::value), "");
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// typedef duration<signed integral type of at least 35 bits > seconds; + +#include <chrono> +#include <type_traits> +#include <limits> + +int main() +{ + typedef std::chrono::seconds D; + typedef D::rep Rep; + typedef D::period Period; + static_assert(std::is_signed<Rep>::value, ""); + static_assert(std::is_integral<Rep>::value, ""); + static_assert(std::numeric_limits<Rep>::digits >= 34, ""); + static_assert((std::is_same<Period, std::ratio<1> >::value), ""); +} diff --git a/libcxx/test/utilities/time/time.clock.req/nothing_to_do.pass.cpp b/libcxx/test/utilities/time/time.clock.req/nothing_to_do.pass.cpp index e8db90cbee0..b89f168e9c4 100644 --- a/libcxx/test/utilities/time/time.clock.req/nothing_to_do.pass.cpp +++ b/libcxx/test/utilities/time/time.clock.req/nothing_to_do.pass.cpp @@ -1 +1,12 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
int main()
{
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/libcxx/test/utilities/time/time.clock/nothing_to_do.pass.cpp b/libcxx/test/utilities/time/time.clock/nothing_to_do.pass.cpp index e8db90cbee0..b89f168e9c4 100644 --- a/libcxx/test/utilities/time/time.clock/nothing_to_do.pass.cpp +++ b/libcxx/test/utilities/time/time.clock/nothing_to_do.pass.cpp @@ -1 +1,12 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
int main()
{
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/libcxx/test/utilities/time/time.clock/time.clock.hires/consistency.pass.cpp b/libcxx/test/utilities/time/time.clock/time.clock.hires/consistency.pass.cpp index 5ad13d0b65f..50923a9f3b0 100644 --- a/libcxx/test/utilities/time/time.clock/time.clock.hires/consistency.pass.cpp +++ b/libcxx/test/utilities/time/time.clock/time.clock.hires/consistency.pass.cpp @@ -1 +1,25 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <chrono>
// high_resolution_clock
// check clock invariants
#include <chrono>
int main()
{
typedef std::chrono::high_resolution_clock C;
static_assert((std::is_same<C::rep, C::duration::rep>::value), "");
static_assert((std::is_same<C::period, C::duration::period>::value), "");
static_assert((std::is_same<C::duration, C::time_point::duration>::value), "");
static_assert(C::is_monotonic || !C::is_monotonic, "");
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// high_resolution_clock + +// check clock invariants + +#include <chrono> + +int main() +{ + typedef std::chrono::high_resolution_clock C; + static_assert((std::is_same<C::rep, C::duration::rep>::value), ""); + static_assert((std::is_same<C::period, C::duration::period>::value), ""); + static_assert((std::is_same<C::duration, C::time_point::duration>::value), ""); + static_assert(C::is_monotonic || !C::is_monotonic, ""); +} diff --git a/libcxx/test/utilities/time/time.clock/time.clock.hires/now.pass.cpp b/libcxx/test/utilities/time/time.clock/time.clock.hires/now.pass.cpp index d98e07310f6..a0a917bc8a6 100644 --- a/libcxx/test/utilities/time/time.clock/time.clock.hires/now.pass.cpp +++ b/libcxx/test/utilities/time/time.clock/time.clock.hires/now.pass.cpp @@ -1 +1,22 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <chrono>
// high_resolution_clock
// static time_point now();
#include <chrono>
int main()
{
typedef std::chrono::high_resolution_clock C;
C::time_point t1 = C::now();
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// high_resolution_clock + +// static time_point now(); + +#include <chrono> + +int main() +{ + typedef std::chrono::high_resolution_clock C; + C::time_point t1 = C::now(); +} diff --git a/libcxx/test/utilities/time/time.clock/time.clock.monotonic/consistency.pass.cpp b/libcxx/test/utilities/time/time.clock/time.clock.monotonic/consistency.pass.cpp index 63690ff6b57..ac661240e30 100644 --- a/libcxx/test/utilities/time/time.clock/time.clock.monotonic/consistency.pass.cpp +++ b/libcxx/test/utilities/time/time.clock/time.clock.monotonic/consistency.pass.cpp @@ -1 +1,25 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <chrono>
// monotonic_clock
// check clock invariants
#include <chrono>
int main()
{
typedef std::chrono::monotonic_clock C;
static_assert((std::is_same<C::rep, C::duration::rep>::value), "");
static_assert((std::is_same<C::period, C::duration::period>::value), "");
static_assert((std::is_same<C::duration, C::time_point::duration>::value), "");
static_assert(C::is_monotonic, "");
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// monotonic_clock + +// check clock invariants + +#include <chrono> + +int main() +{ + typedef std::chrono::monotonic_clock C; + static_assert((std::is_same<C::rep, C::duration::rep>::value), ""); + static_assert((std::is_same<C::period, C::duration::period>::value), ""); + static_assert((std::is_same<C::duration, C::time_point::duration>::value), ""); + static_assert(C::is_monotonic, ""); +} diff --git a/libcxx/test/utilities/time/time.clock/time.clock.monotonic/now.pass.cpp b/libcxx/test/utilities/time/time.clock/time.clock.monotonic/now.pass.cpp index 994e9375027..0cb141222de 100644 --- a/libcxx/test/utilities/time/time.clock/time.clock.monotonic/now.pass.cpp +++ b/libcxx/test/utilities/time/time.clock/time.clock.monotonic/now.pass.cpp @@ -1 +1,25 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <chrono>
// monotonic_clock
// static time_point now();
#include <chrono>
#include <cassert>
int main()
{
typedef std::chrono::monotonic_clock C;
C::time_point t1 = C::now();
C::time_point t2 = C::now();
assert(t2 >= t1);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// monotonic_clock + +// static time_point now(); + +#include <chrono> +#include <cassert> + +int main() +{ + typedef std::chrono::monotonic_clock C; + C::time_point t1 = C::now(); + C::time_point t2 = C::now(); + assert(t2 >= t1); +} diff --git a/libcxx/test/utilities/time/time.clock/time.clock.system/consistency.pass.cpp b/libcxx/test/utilities/time/time.clock/time.clock.system/consistency.pass.cpp index f1b43e62664..915504a56bd 100644 --- a/libcxx/test/utilities/time/time.clock/time.clock.system/consistency.pass.cpp +++ b/libcxx/test/utilities/time/time.clock/time.clock.system/consistency.pass.cpp @@ -1 +1,26 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <chrono>
// system_clock
// check clock invariants
#include <chrono>
int main()
{
typedef std::chrono::system_clock C;
static_assert((std::is_same<C::rep, C::duration::rep>::value), "");
static_assert((std::is_same<C::period, C::duration::period>::value), "");
static_assert((std::is_same<C::duration, C::time_point::duration>::value), "");
static_assert((std::is_same<C::time_point::clock, C>::value), "");
static_assert((C::is_monotonic || !C::is_monotonic), "");
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// system_clock + +// check clock invariants + +#include <chrono> + +int main() +{ + typedef std::chrono::system_clock C; + static_assert((std::is_same<C::rep, C::duration::rep>::value), ""); + static_assert((std::is_same<C::period, C::duration::period>::value), ""); + static_assert((std::is_same<C::duration, C::time_point::duration>::value), ""); + static_assert((std::is_same<C::time_point::clock, C>::value), ""); + static_assert((C::is_monotonic || !C::is_monotonic), ""); +} diff --git a/libcxx/test/utilities/time/time.clock/time.clock.system/from_time_t.pass.cpp b/libcxx/test/utilities/time/time.clock/time.clock.system/from_time_t.pass.cpp index 9b44a1084e1..4404445993a 100644 --- a/libcxx/test/utilities/time/time.clock/time.clock.system/from_time_t.pass.cpp +++ b/libcxx/test/utilities/time/time.clock/time.clock.system/from_time_t.pass.cpp @@ -1 +1,23 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <chrono>
// system_clock
// static time_point from_time_t(time_t t);
#include <chrono>
#include <ctime>
int main()
{
typedef std::chrono::system_clock C;
C::time_point t1 = C::from_time_t(C::to_time_t(C::now()));
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// system_clock + +// static time_point from_time_t(time_t t); + +#include <chrono> +#include <ctime> + +int main() +{ + typedef std::chrono::system_clock C; + C::time_point t1 = C::from_time_t(C::to_time_t(C::now())); +} diff --git a/libcxx/test/utilities/time/time.clock/time.clock.system/now.pass.cpp b/libcxx/test/utilities/time/time.clock/time.clock.system/now.pass.cpp index a4739568040..ef6cb055ae5 100644 --- a/libcxx/test/utilities/time/time.clock/time.clock.system/now.pass.cpp +++ b/libcxx/test/utilities/time/time.clock/time.clock.system/now.pass.cpp @@ -1 +1,22 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <chrono>
// system_clock
// static time_point now();
#include <chrono>
int main()
{
typedef std::chrono::system_clock C;
C::time_point t1 = C::now();
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// system_clock + +// static time_point now(); + +#include <chrono> + +int main() +{ + typedef std::chrono::system_clock C; + C::time_point t1 = C::now(); +} diff --git a/libcxx/test/utilities/time/time.clock/time.clock.system/rep_signed.pass.cpp b/libcxx/test/utilities/time/time.clock/time.clock.system/rep_signed.pass.cpp index d9b574e5341..f971c90afd1 100644 --- a/libcxx/test/utilities/time/time.clock/time.clock.system/rep_signed.pass.cpp +++ b/libcxx/test/utilities/time/time.clock/time.clock.system/rep_signed.pass.cpp @@ -1 +1,23 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <chrono>
// system_clock
// rep should be signed
#include <chrono>
#include <cassert>
int main()
{
assert(std::chrono::system_clock::duration::min() <
std::chrono::system_clock::duration::zero());
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// system_clock + +// rep should be signed + +#include <chrono> +#include <cassert> + +int main() +{ + assert(std::chrono::system_clock::duration::min() < + std::chrono::system_clock::duration::zero()); +} diff --git a/libcxx/test/utilities/time/time.clock/time.clock.system/to_time_t.pass.cpp b/libcxx/test/utilities/time/time.clock/time.clock.system/to_time_t.pass.cpp index f87bd84d727..c307cbe315e 100644 --- a/libcxx/test/utilities/time/time.clock/time.clock.system/to_time_t.pass.cpp +++ b/libcxx/test/utilities/time/time.clock/time.clock.system/to_time_t.pass.cpp @@ -1 +1,23 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <chrono>
// system_clock
// time_t to_time_t(const time_point& t);
#include <chrono>
#include <ctime>
int main()
{
typedef std::chrono::system_clock C;
std::time_t t1 = C::to_time_t(C::now());
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// system_clock + +// time_t to_time_t(const time_point& t); + +#include <chrono> +#include <ctime> + +int main() +{ + typedef std::chrono::system_clock C; + std::time_t t1 = C::to_time_t(C::now()); +} diff --git a/libcxx/test/utilities/time/time.duration/default_ratio.pass.cpp b/libcxx/test/utilities/time/time.duration/default_ratio.pass.cpp index 2d323049616..2e20acfc490 100644 --- a/libcxx/test/utilities/time/time.duration/default_ratio.pass.cpp +++ b/libcxx/test/utilities/time/time.duration/default_ratio.pass.cpp @@ -1 +1,26 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <chrono>
// duration
// Test default template arg:
// template <class Rep, class Period = ratio<1>>
// class duration;
#include <chrono>
#include <type_traits>
int main()
{
static_assert((std::is_same<std::chrono::duration<int, std::ratio<1> >,
std::chrono::duration<int> >::value), "");
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// Test default template arg: + +// template <class Rep, class Period = ratio<1>> +// class duration; + +#include <chrono> +#include <type_traits> + +int main() +{ + static_assert((std::is_same<std::chrono::duration<int, std::ratio<1> >, + std::chrono::duration<int> >::value), ""); +} diff --git a/libcxx/test/utilities/time/time.duration/duration.fail.cpp b/libcxx/test/utilities/time/time.duration/duration.fail.cpp index 11a157d3e58..2a879cbf3fa 100644 --- a/libcxx/test/utilities/time/time.duration/duration.fail.cpp +++ b/libcxx/test/utilities/time/time.duration/duration.fail.cpp @@ -1 +1,23 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <chrono>
// duration
// If a program instantiates duration with a duration type for the template
// argument Rep a diagnostic is required.
#include <chrono>
int main()
{
typedef std::chrono::duration<std::chrono::milliseconds> D;
D d;
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// If a program instantiates duration with a duration type for the template +// argument Rep a diagnostic is required. + +#include <chrono> + +int main() +{ + typedef std::chrono::duration<std::chrono::milliseconds> D; + D d; +} diff --git a/libcxx/test/utilities/time/time.duration/positive_num.fail.cpp b/libcxx/test/utilities/time/time.duration/positive_num.fail.cpp index afb51a5a1fa..430bf0ac728 100644 --- a/libcxx/test/utilities/time/time.duration/positive_num.fail.cpp +++ b/libcxx/test/utilities/time/time.duration/positive_num.fail.cpp @@ -1 +1,22 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <chrono>
// duration
// Period::num shall be positive, diagnostic required.
#include <chrono>
int main()
{
typedef std::chrono::duration<int, std::ratio<5, -1> > D;
D d;
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// Period::num shall be positive, diagnostic required. + +#include <chrono> + +int main() +{ + typedef std::chrono::duration<int, std::ratio<5, -1> > D; + D d; +} diff --git a/libcxx/test/utilities/time/time.duration/ratio.fail.cpp b/libcxx/test/utilities/time/time.duration/ratio.fail.cpp index e3e104ebf0e..44039e4c233 100644 --- a/libcxx/test/utilities/time/time.duration/ratio.fail.cpp +++ b/libcxx/test/utilities/time/time.duration/ratio.fail.cpp @@ -1 +1,30 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <chrono>
// duration
// Period shall be a specialization of ratio, diagnostic required.
#include <chrono>
template <int N, int D = 1>
class Ratio
{
public:
static const int num = N;
static const int den = D;
};
int main()
{
typedef std::chrono::duration<int, Ratio<1> > D;
D d;
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// Period shall be a specialization of ratio, diagnostic required. + +#include <chrono> + +template <int N, int D = 1> +class Ratio +{ +public: + static const int num = N; + static const int den = D; +}; + +int main() +{ + typedef std::chrono::duration<int, Ratio<1> > D; + D d; +} diff --git a/libcxx/test/utilities/time/time.duration/time.duration.arithmetic/op_++.pass.cpp b/libcxx/test/utilities/time/time.duration/time.duration.arithmetic/op_++.pass.cpp index beaa5cb5f13..41f24dc71db 100644 --- a/libcxx/test/utilities/time/time.duration/time.duration.arithmetic/op_++.pass.cpp +++ b/libcxx/test/utilities/time/time.duration/time.duration.arithmetic/op_++.pass.cpp @@ -1 +1,25 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <chrono>
// duration
// duration& operator++();
#include <chrono>
#include <cassert>
int main()
{
std::chrono::hours h(3);
std::chrono::hours& href = ++h;
assert(&href == &h);
assert(h.count() == 4);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// duration& operator++(); + +#include <chrono> +#include <cassert> + +int main() +{ + std::chrono::hours h(3); + std::chrono::hours& href = ++h; + assert(&href == &h); + assert(h.count() == 4); +} diff --git a/libcxx/test/utilities/time/time.duration/time.duration.arithmetic/op_++int.pass.cpp b/libcxx/test/utilities/time/time.duration/time.duration.arithmetic/op_++int.pass.cpp index 129c0efd712..c596a7eab2b 100644 --- a/libcxx/test/utilities/time/time.duration/time.duration.arithmetic/op_++int.pass.cpp +++ b/libcxx/test/utilities/time/time.duration/time.duration.arithmetic/op_++int.pass.cpp @@ -1 +1,25 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <chrono>
// duration
// duration operator++(int);
#include <chrono>
#include <cassert>
int main()
{
std::chrono::hours h(3);
std::chrono::hours h2 = h++;
assert(h.count() == 4);
assert(h2.count() == 3);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// duration operator++(int); + +#include <chrono> +#include <cassert> + +int main() +{ + std::chrono::hours h(3); + std::chrono::hours h2 = h++; + assert(h.count() == 4); + assert(h2.count() == 3); +} diff --git a/libcxx/test/utilities/time/time.duration/time.duration.arithmetic/op_+.pass.cpp b/libcxx/test/utilities/time/time.duration/time.duration.arithmetic/op_+.pass.cpp index 667b1959f2b..27d11cabbee 100644 --- a/libcxx/test/utilities/time/time.duration/time.duration.arithmetic/op_+.pass.cpp +++ b/libcxx/test/utilities/time/time.duration/time.duration.arithmetic/op_+.pass.cpp @@ -1 +1,24 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <chrono>
// duration
// duration operator+() const;
#include <chrono>
#include <cassert>
int main()
{
const std::chrono::minutes m(3);
std::chrono::minutes m2 = +m;
assert(m.count() == m2.count());
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// duration operator+() const; + +#include <chrono> +#include <cassert> + +int main() +{ + const std::chrono::minutes m(3); + std::chrono::minutes m2 = +m; + assert(m.count() == m2.count()); +} diff --git a/libcxx/test/utilities/time/time.duration/time.duration.arithmetic/op_+=.pass.cpp b/libcxx/test/utilities/time/time.duration/time.duration.arithmetic/op_+=.pass.cpp index 244de3c8e83..5038ab75d3c 100644 --- a/libcxx/test/utilities/time/time.duration/time.duration.arithmetic/op_+=.pass.cpp +++ b/libcxx/test/utilities/time/time.duration/time.duration.arithmetic/op_+=.pass.cpp @@ -1 +1,26 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <chrono>
// duration
// duration& operator+=(const duration& d);
#include <chrono>
#include <cassert>
int main()
{
std::chrono::seconds s(3);
s += std::chrono::seconds(2);
assert(s.count() == 5);
s += std::chrono::minutes(2);
assert(s.count() == 125);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// duration& operator+=(const duration& d); + +#include <chrono> +#include <cassert> + +int main() +{ + std::chrono::seconds s(3); + s += std::chrono::seconds(2); + assert(s.count() == 5); + s += std::chrono::minutes(2); + assert(s.count() == 125); +} diff --git a/libcxx/test/utilities/time/time.duration/time.duration.arithmetic/op_--.pass.cpp b/libcxx/test/utilities/time/time.duration/time.duration.arithmetic/op_--.pass.cpp index cb60a618cb4..9966f063ce0 100644 --- a/libcxx/test/utilities/time/time.duration/time.duration.arithmetic/op_--.pass.cpp +++ b/libcxx/test/utilities/time/time.duration/time.duration.arithmetic/op_--.pass.cpp @@ -1 +1,25 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <chrono>
// duration
// duration& operator--();
#include <chrono>
#include <cassert>
int main()
{
std::chrono::hours h(3);
std::chrono::hours& href = --h;
assert(&href == &h);
assert(h.count() == 2);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// duration& operator--(); + +#include <chrono> +#include <cassert> + +int main() +{ + std::chrono::hours h(3); + std::chrono::hours& href = --h; + assert(&href == &h); + assert(h.count() == 2); +} diff --git a/libcxx/test/utilities/time/time.duration/time.duration.arithmetic/op_--int.pass.cpp b/libcxx/test/utilities/time/time.duration/time.duration.arithmetic/op_--int.pass.cpp index 6b88ddfdc4c..bbed446d850 100644 --- a/libcxx/test/utilities/time/time.duration/time.duration.arithmetic/op_--int.pass.cpp +++ b/libcxx/test/utilities/time/time.duration/time.duration.arithmetic/op_--int.pass.cpp @@ -1 +1,25 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <chrono>
// duration
// duration operator--(int);
#include <chrono>
#include <cassert>
int main()
{
std::chrono::hours h(3);
std::chrono::hours h2 = h--;
assert(h.count() == 2);
assert(h2.count() == 3);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// duration operator--(int); + +#include <chrono> +#include <cassert> + +int main() +{ + std::chrono::hours h(3); + std::chrono::hours h2 = h--; + assert(h.count() == 2); + assert(h2.count() == 3); +} diff --git a/libcxx/test/utilities/time/time.duration/time.duration.arithmetic/op_-.pass.cpp b/libcxx/test/utilities/time/time.duration/time.duration.arithmetic/op_-.pass.cpp index 8ea6e46e363..0148dc77eb1 100644 --- a/libcxx/test/utilities/time/time.duration/time.duration.arithmetic/op_-.pass.cpp +++ b/libcxx/test/utilities/time/time.duration/time.duration.arithmetic/op_-.pass.cpp @@ -1 +1,24 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <chrono>
// duration
// duration operator-() const;
#include <chrono>
#include <cassert>
int main()
{
const std::chrono::minutes m(3);
std::chrono::minutes m2 = -m;
assert(m2.count() == -m.count());
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// duration operator-() const; + +#include <chrono> +#include <cassert> + +int main() +{ + const std::chrono::minutes m(3); + std::chrono::minutes m2 = -m; + assert(m2.count() == -m.count()); +} diff --git a/libcxx/test/utilities/time/time.duration/time.duration.arithmetic/op_-=.pass.cpp b/libcxx/test/utilities/time/time.duration/time.duration.arithmetic/op_-=.pass.cpp index 87ce32c93aa..eab4d7007c6 100644 --- a/libcxx/test/utilities/time/time.duration/time.duration.arithmetic/op_-=.pass.cpp +++ b/libcxx/test/utilities/time/time.duration/time.duration.arithmetic/op_-=.pass.cpp @@ -1 +1,26 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <chrono>
// duration
// duration& operator-=(const duration& d);
#include <chrono>
#include <cassert>
int main()
{
std::chrono::seconds s(3);
s -= std::chrono::seconds(2);
assert(s.count() == 1);
s -= std::chrono::minutes(2);
assert(s.count() == -119);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// duration& operator-=(const duration& d); + +#include <chrono> +#include <cassert> + +int main() +{ + std::chrono::seconds s(3); + s -= std::chrono::seconds(2); + assert(s.count() == 1); + s -= std::chrono::minutes(2); + assert(s.count() == -119); +} diff --git a/libcxx/test/utilities/time/time.duration/time.duration.arithmetic/op_divide=.pass.cpp b/libcxx/test/utilities/time/time.duration/time.duration.arithmetic/op_divide=.pass.cpp index 3371c392dc2..0490ab4efb7 100644 --- a/libcxx/test/utilities/time/time.duration/time.duration.arithmetic/op_divide=.pass.cpp +++ b/libcxx/test/utilities/time/time.duration/time.duration.arithmetic/op_divide=.pass.cpp @@ -1 +1,24 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <chrono>
// duration
// duration& operator/=(const rep& rhs);
#include <chrono>
#include <cassert>
int main()
{
std::chrono::nanoseconds ns(15);
ns /= 5;
assert(ns.count() == 3);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// duration& operator/=(const rep& rhs); + +#include <chrono> +#include <cassert> + +int main() +{ + std::chrono::nanoseconds ns(15); + ns /= 5; + assert(ns.count() == 3); +} diff --git a/libcxx/test/utilities/time/time.duration/time.duration.arithmetic/op_mod=duration.pass.cpp b/libcxx/test/utilities/time/time.duration/time.duration.arithmetic/op_mod=duration.pass.cpp index 953e778a981..f1e0c8690b5 100644 --- a/libcxx/test/utilities/time/time.duration/time.duration.arithmetic/op_mod=duration.pass.cpp +++ b/libcxx/test/utilities/time/time.duration/time.duration.arithmetic/op_mod=duration.pass.cpp @@ -1 +1,27 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <chrono>
// duration
// duration& operator%=(const duration& rhs)
#include <chrono>
#include <cassert>
int main()
{
std::chrono::microseconds us(11);
std::chrono::microseconds us2(3);
us %= us2;
assert(us.count() == 2);
us %= std::chrono::milliseconds(3);
assert(us.count() == 2);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// duration& operator%=(const duration& rhs) + +#include <chrono> +#include <cassert> + +int main() +{ + std::chrono::microseconds us(11); + std::chrono::microseconds us2(3); + us %= us2; + assert(us.count() == 2); + us %= std::chrono::milliseconds(3); + assert(us.count() == 2); +} diff --git a/libcxx/test/utilities/time/time.duration/time.duration.arithmetic/op_mod=rep.pass.cpp b/libcxx/test/utilities/time/time.duration/time.duration.arithmetic/op_mod=rep.pass.cpp index ab7d7ca82fd..5449aecd396 100644 --- a/libcxx/test/utilities/time/time.duration/time.duration.arithmetic/op_mod=rep.pass.cpp +++ b/libcxx/test/utilities/time/time.duration/time.duration.arithmetic/op_mod=rep.pass.cpp @@ -1 +1,24 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <chrono>
// duration
// duration& operator%=(const rep& rhs)
#include <chrono>
#include <cassert>
int main()
{
std::chrono::microseconds us(11);
us %= 3;
assert(us.count() == 2);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// duration& operator%=(const rep& rhs) + +#include <chrono> +#include <cassert> + +int main() +{ + std::chrono::microseconds us(11); + us %= 3; + assert(us.count() == 2); +} diff --git a/libcxx/test/utilities/time/time.duration/time.duration.arithmetic/op_times=.pass.cpp b/libcxx/test/utilities/time/time.duration/time.duration.arithmetic/op_times=.pass.cpp index 869eb7fcb6f..e04887082fe 100644 --- a/libcxx/test/utilities/time/time.duration/time.duration.arithmetic/op_times=.pass.cpp +++ b/libcxx/test/utilities/time/time.duration/time.duration.arithmetic/op_times=.pass.cpp @@ -1 +1,24 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <chrono>
// duration
// duration& operator*=(const rep& rhs);
#include <chrono>
#include <cassert>
int main()
{
std::chrono::nanoseconds ns(3);
ns *= 5;
assert(ns.count() == 15);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// duration& operator*=(const rep& rhs); + +#include <chrono> +#include <cassert> + +int main() +{ + std::chrono::nanoseconds ns(3); + ns *= 5; + assert(ns.count() == 15); +} diff --git a/libcxx/test/utilities/time/time.duration/time.duration.cast/duration_cast.pass.cpp b/libcxx/test/utilities/time/time.duration/time.duration.cast/duration_cast.pass.cpp index acc41bb1aaf..7c5758f249a 100644 --- a/libcxx/test/utilities/time/time.duration/time.duration.cast/duration_cast.pass.cpp +++ b/libcxx/test/utilities/time/time.duration/time.duration.cast/duration_cast.pass.cpp @@ -1 +1,43 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <chrono>
// duration
// template <class ToDuration, class Rep, class Period>
// ToDuration
// duration_cast(const duration<Rep, Period>& d);
#include <chrono>
#include <type_traits>
#include <cassert>
template <class ToDuration, class FromDuration>
void
test(const FromDuration& f, const ToDuration& d)
{
typedef decltype(std::chrono::duration_cast<ToDuration>(f)) R;
static_assert((std::is_same<R, ToDuration>::value), "");
assert(std::chrono::duration_cast<ToDuration>(f) == d);
}
int main()
{
test(std::chrono::milliseconds(7265000), std::chrono::hours(2));
test(std::chrono::milliseconds(7265000), std::chrono::minutes(121));
test(std::chrono::milliseconds(7265000), std::chrono::seconds(7265));
test(std::chrono::milliseconds(7265000), std::chrono::milliseconds(7265000));
test(std::chrono::milliseconds(7265000), std::chrono::microseconds(7265000000LL));
test(std::chrono::milliseconds(7265000), std::chrono::nanoseconds(7265000000000LL));
test(std::chrono::milliseconds(7265000),
std::chrono::duration<double, std::ratio<3600> >(7265./3600));
test(std::chrono::duration<int, std::ratio<2, 3> >(9),
std::chrono::duration<int, std::ratio<3, 5> >(10));
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// template <class ToDuration, class Rep, class Period> +// ToDuration +// duration_cast(const duration<Rep, Period>& d); + +#include <chrono> +#include <type_traits> +#include <cassert> + +template <class ToDuration, class FromDuration> +void +test(const FromDuration& f, const ToDuration& d) +{ + typedef decltype(std::chrono::duration_cast<ToDuration>(f)) R; + static_assert((std::is_same<R, ToDuration>::value), ""); + assert(std::chrono::duration_cast<ToDuration>(f) == d); +} + +int main() +{ + test(std::chrono::milliseconds(7265000), std::chrono::hours(2)); + test(std::chrono::milliseconds(7265000), std::chrono::minutes(121)); + test(std::chrono::milliseconds(7265000), std::chrono::seconds(7265)); + test(std::chrono::milliseconds(7265000), std::chrono::milliseconds(7265000)); + test(std::chrono::milliseconds(7265000), std::chrono::microseconds(7265000000LL)); + test(std::chrono::milliseconds(7265000), std::chrono::nanoseconds(7265000000000LL)); + test(std::chrono::milliseconds(7265000), + std::chrono::duration<double, std::ratio<3600> >(7265./3600)); + test(std::chrono::duration<int, std::ratio<2, 3> >(9), + std::chrono::duration<int, std::ratio<3, 5> >(10)); +} diff --git a/libcxx/test/utilities/time/time.duration/time.duration.cast/toduration.fail.cpp b/libcxx/test/utilities/time/time.duration/time.duration.cast/toduration.fail.cpp index d90502cba4b..bbf7be5cb04 100644 --- a/libcxx/test/utilities/time/time.duration/time.duration.cast/toduration.fail.cpp +++ b/libcxx/test/utilities/time/time.duration/time.duration.cast/toduration.fail.cpp @@ -1 +1,25 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <chrono>
// duration
// template <class ToDuration, class Rep, class Period>
// ToDuration
// duration_cast(const duration<Rep, Period>& d);
// ToDuration shall be an instantiation of duration.
#include <chrono>
int main()
{
std::chrono::duration_cast<int>(std::chrono::milliseconds(3));
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// template <class ToDuration, class Rep, class Period> +// ToDuration +// duration_cast(const duration<Rep, Period>& d); + +// ToDuration shall be an instantiation of duration. + +#include <chrono> + +int main() +{ + std::chrono::duration_cast<int>(std::chrono::milliseconds(3)); +} diff --git a/libcxx/test/utilities/time/time.duration/time.duration.comparisons/op_equal.pass.cpp b/libcxx/test/utilities/time/time.duration/time.duration.comparisons/op_equal.pass.cpp index 86d23704954..c850e2b33ca 100644 --- a/libcxx/test/utilities/time/time.duration/time.duration.comparisons/op_equal.pass.cpp +++ b/libcxx/test/utilities/time/time.duration/time.duration.comparisons/op_equal.pass.cpp @@ -1 +1,69 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <chrono>
// duration
// template <class Rep1, class Period1, class Rep2, class Period2>
// bool
// operator==(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
// template <class Rep1, class Period1, class Rep2, class Period2>
// bool
// operator!=(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
#include <chrono>
#include <cassert>
int main()
{
{
std::chrono::seconds s1(3);
std::chrono::seconds s2(3);
assert(s1 == s2);
assert(!(s1 != s2));
}
{
std::chrono::seconds s1(3);
std::chrono::seconds s2(4);
assert(!(s1 == s2));
assert(s1 != s2);
}
{
std::chrono::milliseconds s1(3);
std::chrono::microseconds s2(3000);
assert(s1 == s2);
assert(!(s1 != s2));
}
{
std::chrono::milliseconds s1(3);
std::chrono::microseconds s2(4000);
assert(!(s1 == s2));
assert(s1 != s2);
}
{
std::chrono::duration<int, std::ratio<2, 3> > s1(9);
std::chrono::duration<int, std::ratio<3, 5> > s2(10);
assert(s1 == s2);
assert(!(s1 != s2));
}
{
std::chrono::duration<int, std::ratio<2, 3> > s1(10);
std::chrono::duration<int, std::ratio<3, 5> > s2(9);
assert(!(s1 == s2));
assert(s1 != s2);
}
{
std::chrono::duration<int, std::ratio<2, 3> > s1(9);
std::chrono::duration<double, std::ratio<3, 5> > s2(10);
assert(s1 == s2);
assert(!(s1 != s2));
}
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// template <class Rep1, class Period1, class Rep2, class Period2> +// bool +// operator==(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs); + +// template <class Rep1, class Period1, class Rep2, class Period2> +// bool +// operator!=(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs); + +#include <chrono> +#include <cassert> + +int main() +{ + { + std::chrono::seconds s1(3); + std::chrono::seconds s2(3); + assert(s1 == s2); + assert(!(s1 != s2)); + } + { + std::chrono::seconds s1(3); + std::chrono::seconds s2(4); + assert(!(s1 == s2)); + assert(s1 != s2); + } + { + std::chrono::milliseconds s1(3); + std::chrono::microseconds s2(3000); + assert(s1 == s2); + assert(!(s1 != s2)); + } + { + std::chrono::milliseconds s1(3); + std::chrono::microseconds s2(4000); + assert(!(s1 == s2)); + assert(s1 != s2); + } + { + std::chrono::duration<int, std::ratio<2, 3> > s1(9); + std::chrono::duration<int, std::ratio<3, 5> > s2(10); + assert(s1 == s2); + assert(!(s1 != s2)); + } + { + std::chrono::duration<int, std::ratio<2, 3> > s1(10); + std::chrono::duration<int, std::ratio<3, 5> > s2(9); + assert(!(s1 == s2)); + assert(s1 != s2); + } + { + std::chrono::duration<int, std::ratio<2, 3> > s1(9); + std::chrono::duration<double, std::ratio<3, 5> > s2(10); + assert(s1 == s2); + assert(!(s1 != s2)); + } +} diff --git a/libcxx/test/utilities/time/time.duration/time.duration.comparisons/op_less.pass.cpp b/libcxx/test/utilities/time/time.duration/time.duration.comparisons/op_less.pass.cpp index 5d447115da5..cfb86338b10 100644 --- a/libcxx/test/utilities/time/time.duration/time.duration.comparisons/op_less.pass.cpp +++ b/libcxx/test/utilities/time/time.duration/time.duration.comparisons/op_less.pass.cpp @@ -1 +1,91 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <chrono>
// duration
// template <class Rep1, class Period1, class Rep2, class Period2>
// bool
// operator< (const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
// template <class Rep1, class Period1, class Rep2, class Period2>
// bool
// operator> (const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
// template <class Rep1, class Period1, class Rep2, class Period2>
// bool
// operator<=(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
// template <class Rep1, class Period1, class Rep2, class Period2>
// bool
// operator>=(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
#include <chrono>
#include <cassert>
int main()
{
{
std::chrono::seconds s1(3);
std::chrono::seconds s2(3);
assert(!(s1 < s2));
assert(!(s1 > s2));
assert( (s1 <= s2));
assert( (s1 >= s2));
}
{
std::chrono::seconds s1(3);
std::chrono::seconds s2(4);
assert( (s1 < s2));
assert(!(s1 > s2));
assert( (s1 <= s2));
assert(!(s1 >= s2));
}
{
std::chrono::milliseconds s1(3);
std::chrono::microseconds s2(3000);
assert(!(s1 < s2));
assert(!(s1 > s2));
assert( (s1 <= s2));
assert( (s1 >= s2));
}
{
std::chrono::milliseconds s1(3);
std::chrono::microseconds s2(4000);
assert( (s1 < s2));
assert(!(s1 > s2));
assert( (s1 <= s2));
assert(!(s1 >= s2));
}
{
std::chrono::duration<int, std::ratio<2, 3> > s1(9);
std::chrono::duration<int, std::ratio<3, 5> > s2(10);
assert(!(s1 < s2));
assert(!(s1 > s2));
assert( (s1 <= s2));
assert( (s1 >= s2));
}
{
std::chrono::duration<int, std::ratio<2, 3> > s1(10);
std::chrono::duration<int, std::ratio<3, 5> > s2(9);
assert(!(s1 < s2));
assert( (s1 > s2));
assert(!(s1 <= s2));
assert( (s1 >= s2));
}
{
std::chrono::duration<int, std::ratio<2, 3> > s1(9);
std::chrono::duration<double, std::ratio<3, 5> > s2(10);
assert(!(s1 < s2));
assert(!(s1 > s2));
assert( (s1 <= s2));
assert( (s1 >= s2));
}
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// template <class Rep1, class Period1, class Rep2, class Period2> +// bool +// operator< (const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs); + +// template <class Rep1, class Period1, class Rep2, class Period2> +// bool +// operator> (const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs); + +// template <class Rep1, class Period1, class Rep2, class Period2> +// bool +// operator<=(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs); + +// template <class Rep1, class Period1, class Rep2, class Period2> +// bool +// operator>=(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs); + +#include <chrono> +#include <cassert> + +int main() +{ + { + std::chrono::seconds s1(3); + std::chrono::seconds s2(3); + assert(!(s1 < s2)); + assert(!(s1 > s2)); + assert( (s1 <= s2)); + assert( (s1 >= s2)); + } + { + std::chrono::seconds s1(3); + std::chrono::seconds s2(4); + assert( (s1 < s2)); + assert(!(s1 > s2)); + assert( (s1 <= s2)); + assert(!(s1 >= s2)); + } + { + std::chrono::milliseconds s1(3); + std::chrono::microseconds s2(3000); + assert(!(s1 < s2)); + assert(!(s1 > s2)); + assert( (s1 <= s2)); + assert( (s1 >= s2)); + } + { + std::chrono::milliseconds s1(3); + std::chrono::microseconds s2(4000); + assert( (s1 < s2)); + assert(!(s1 > s2)); + assert( (s1 <= s2)); + assert(!(s1 >= s2)); + } + { + std::chrono::duration<int, std::ratio<2, 3> > s1(9); + std::chrono::duration<int, std::ratio<3, 5> > s2(10); + assert(!(s1 < s2)); + assert(!(s1 > s2)); + assert( (s1 <= s2)); + assert( (s1 >= s2)); + } + { + std::chrono::duration<int, std::ratio<2, 3> > s1(10); + std::chrono::duration<int, std::ratio<3, 5> > s2(9); + assert(!(s1 < s2)); + assert( (s1 > s2)); + assert(!(s1 <= s2)); + assert( (s1 >= s2)); + } + { + std::chrono::duration<int, std::ratio<2, 3> > s1(9); + std::chrono::duration<double, std::ratio<3, 5> > s2(10); + assert(!(s1 < s2)); + assert(!(s1 > s2)); + assert( (s1 <= s2)); + assert( (s1 >= s2)); + } +} diff --git a/libcxx/test/utilities/time/time.duration/time.duration.cons/convert_exact.pass.cpp b/libcxx/test/utilities/time/time.duration/time.duration.cons/convert_exact.pass.cpp index 356fd1bd8e3..9639ad2b902 100644 --- a/libcxx/test/utilities/time/time.duration/time.duration.cons/convert_exact.pass.cpp +++ b/libcxx/test/utilities/time/time.duration/time.duration.cons/convert_exact.pass.cpp @@ -1 +1,27 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <chrono>
// duration
// template <class Rep2, class Period2>
// duration(const duration<Rep2, Period2>& d);
// exact conversions allowed for integral reps
#include <chrono>
#include <cassert>
int main()
{
std::chrono::milliseconds ms(1);
std::chrono::microseconds us = ms;
assert(us.count() == 1000);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// template <class Rep2, class Period2> +// duration(const duration<Rep2, Period2>& d); + +// exact conversions allowed for integral reps + +#include <chrono> +#include <cassert> + +int main() +{ + std::chrono::milliseconds ms(1); + std::chrono::microseconds us = ms; + assert(us.count() == 1000); +} diff --git a/libcxx/test/utilities/time/time.duration/time.duration.cons/convert_float_to_int.fail.cpp b/libcxx/test/utilities/time/time.duration/time.duration.cons/convert_float_to_int.fail.cpp index 5d53a39d594..056096a66b0 100644 --- a/libcxx/test/utilities/time/time.duration/time.duration.cons/convert_float_to_int.fail.cpp +++ b/libcxx/test/utilities/time/time.duration/time.duration.cons/convert_float_to_int.fail.cpp @@ -1 +1,25 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <chrono>
// duration
// template <class Rep2, class Period2>
// duration(const duration<Rep2, Period2>& d);
// conversions from floating point to integral durations disallowed
#include <chrono>
int main()
{
std::chrono::duration<double> d;
std::chrono::duration<int> i = d;
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// template <class Rep2, class Period2> +// duration(const duration<Rep2, Period2>& d); + +// conversions from floating point to integral durations disallowed + +#include <chrono> + +int main() +{ + std::chrono::duration<double> d; + std::chrono::duration<int> i = d; +} diff --git a/libcxx/test/utilities/time/time.duration/time.duration.cons/convert_inexact.fail.cpp b/libcxx/test/utilities/time/time.duration/time.duration.cons/convert_inexact.fail.cpp index 1e87931a01d..692da387770 100644 --- a/libcxx/test/utilities/time/time.duration/time.duration.cons/convert_inexact.fail.cpp +++ b/libcxx/test/utilities/time/time.duration/time.duration.cons/convert_inexact.fail.cpp @@ -1 +1,25 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <chrono>
// duration
// template <class Rep2, class Period2>
// duration(const duration<Rep2, Period2>& d);
// inexact conversions disallowed for integral reps
#include <chrono>
int main()
{
std::chrono::microseconds us(1);
std::chrono::milliseconds ms = us;
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// template <class Rep2, class Period2> +// duration(const duration<Rep2, Period2>& d); + +// inexact conversions disallowed for integral reps + +#include <chrono> + +int main() +{ + std::chrono::microseconds us(1); + std::chrono::milliseconds ms = us; +} diff --git a/libcxx/test/utilities/time/time.duration/time.duration.cons/convert_inexact.pass.cpp b/libcxx/test/utilities/time/time.duration/time.duration.cons/convert_inexact.pass.cpp index 1359be9c0eb..39f281a026e 100644 --- a/libcxx/test/utilities/time/time.duration/time.duration.cons/convert_inexact.pass.cpp +++ b/libcxx/test/utilities/time/time.duration/time.duration.cons/convert_inexact.pass.cpp @@ -1 +1,27 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <chrono>
// duration
// template <class Rep2, class Period2>
// duration(const duration<Rep2, Period2>& d);
// inexact conversions allowed for floating point reps
#include <chrono>
#include <cassert>
int main()
{
std::chrono::duration<double, std::micro> us(1);
std::chrono::duration<double, std::milli> ms = us;
assert(ms.count() == 1./1000);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// template <class Rep2, class Period2> +// duration(const duration<Rep2, Period2>& d); + +// inexact conversions allowed for floating point reps + +#include <chrono> +#include <cassert> + +int main() +{ + std::chrono::duration<double, std::micro> us(1); + std::chrono::duration<double, std::milli> ms = us; + assert(ms.count() == 1./1000); +} diff --git a/libcxx/test/utilities/time/time.duration/time.duration.cons/convert_int_to_float.pass.cpp b/libcxx/test/utilities/time/time.duration/time.duration.cons/convert_int_to_float.pass.cpp index 32328cac805..a69c3543c2d 100644 --- a/libcxx/test/utilities/time/time.duration/time.duration.cons/convert_int_to_float.pass.cpp +++ b/libcxx/test/utilities/time/time.duration/time.duration.cons/convert_int_to_float.pass.cpp @@ -1 +1,27 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <chrono>
// duration
// template <class Rep2, class Period2>
// duration(const duration<Rep2, Period2>& d);
// conversions from integral to floating point durations allowed
#include <chrono>
#include <cassert>
int main()
{
std::chrono::duration<int> i(3);
std::chrono::duration<int> d = i;
assert(d.count() == 3);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// template <class Rep2, class Period2> +// duration(const duration<Rep2, Period2>& d); + +// conversions from integral to floating point durations allowed + +#include <chrono> +#include <cassert> + +int main() +{ + std::chrono::duration<int> i(3); + std::chrono::duration<int> d = i; + assert(d.count() == 3); +} diff --git a/libcxx/test/utilities/time/time.duration/time.duration.cons/default.pass.cpp b/libcxx/test/utilities/time/time.duration/time.duration.cons/default.pass.cpp index 1d86be2ecac..917c4cc744c 100644 --- a/libcxx/test/utilities/time/time.duration/time.duration.cons/default.pass.cpp +++ b/libcxx/test/utilities/time/time.duration/time.duration.cons/default.pass.cpp @@ -1 +1,34 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <chrono>
// duration
// duration() = default;
// Rep must be default initialized, not initialized with 0
#include <chrono>
#include <cassert>
#include "../../rep.h"
template <class D>
void
test()
{
D d;
assert(d.count() == typename D::rep());
}
int main()
{
test<std::chrono::duration<Rep> >();
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// duration() = default; + +// Rep must be default initialized, not initialized with 0 + +#include <chrono> +#include <cassert> + +#include "../../rep.h" + +template <class D> +void +test() +{ + D d; + assert(d.count() == typename D::rep()); +} + +int main() +{ + test<std::chrono::duration<Rep> >(); +} diff --git a/libcxx/test/utilities/time/time.duration/time.duration.cons/rep.pass.cpp b/libcxx/test/utilities/time/time.duration/time.duration.cons/rep.pass.cpp index 7538605d073..59bbd6e1946 100644 --- a/libcxx/test/utilities/time/time.duration/time.duration.cons/rep.pass.cpp +++ b/libcxx/test/utilities/time/time.duration/time.duration.cons/rep.pass.cpp @@ -1 +1,36 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <chrono>
// duration
// template <class Rep2>
// explicit duration(const Rep2& r);
#include <chrono>
#include <cassert>
#include "../../rep.h"
template <class D, class R>
void
test(R r)
{
D d(r);
assert(d.count() == r);
}
int main()
{
test<std::chrono::duration<int> >(5);
test<std::chrono::duration<int, std::ratio<3, 2> > >(5);
test<std::chrono::duration<Rep, std::ratio<3, 2> > >(Rep(3));
test<std::chrono::duration<double, std::ratio<2, 3> > >(5.5);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// template <class Rep2> +// explicit duration(const Rep2& r); + +#include <chrono> +#include <cassert> + +#include "../../rep.h" + +template <class D, class R> +void +test(R r) +{ + D d(r); + assert(d.count() == r); +} + +int main() +{ + test<std::chrono::duration<int> >(5); + test<std::chrono::duration<int, std::ratio<3, 2> > >(5); + test<std::chrono::duration<Rep, std::ratio<3, 2> > >(Rep(3)); + test<std::chrono::duration<double, std::ratio<2, 3> > >(5.5); +} diff --git a/libcxx/test/utilities/time/time.duration/time.duration.cons/rep01.fail.cpp b/libcxx/test/utilities/time/time.duration/time.duration.cons/rep01.fail.cpp index da9d886c249..b0d20e1e1a6 100644 --- a/libcxx/test/utilities/time/time.duration/time.duration.cons/rep01.fail.cpp +++ b/libcxx/test/utilities/time/time.duration/time.duration.cons/rep01.fail.cpp @@ -1 +1,26 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <chrono>
// duration
// template <class Rep2>
// explicit duration(const Rep2& r);
// test for explicit
#include <chrono>
#include "../../rep.h"
int main()
{
std::chrono::duration<int> d = 1;
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// template <class Rep2> +// explicit duration(const Rep2& r); + +// test for explicit + +#include <chrono> + +#include "../../rep.h" + +int main() +{ + std::chrono::duration<int> d = 1; +} diff --git a/libcxx/test/utilities/time/time.duration/time.duration.cons/rep02.fail.cpp b/libcxx/test/utilities/time/time.duration/time.duration.cons/rep02.fail.cpp index 17d532cbadb..72bd7678858 100644 --- a/libcxx/test/utilities/time/time.duration/time.duration.cons/rep02.fail.cpp +++ b/libcxx/test/utilities/time/time.duration/time.duration.cons/rep02.fail.cpp @@ -1 +1,26 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <chrono>
// duration
// template <class Rep2>
// explicit duration(const Rep2& r);
// Rep2 shall be implicitly convertible to rep
#include <chrono>
#include "../../rep.h"
int main()
{
std::chrono::duration<Rep> d(1);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// template <class Rep2> +// explicit duration(const Rep2& r); + +// Rep2 shall be implicitly convertible to rep + +#include <chrono> + +#include "../../rep.h" + +int main() +{ + std::chrono::duration<Rep> d(1); +} diff --git a/libcxx/test/utilities/time/time.duration/time.duration.cons/rep02.pass.cpp b/libcxx/test/utilities/time/time.duration/time.duration.cons/rep02.pass.cpp index 38844c7811c..c25f04a96c9 100644 --- a/libcxx/test/utilities/time/time.duration/time.duration.cons/rep02.pass.cpp +++ b/libcxx/test/utilities/time/time.duration/time.duration.cons/rep02.pass.cpp @@ -1 +1,26 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <chrono>
// duration
// template <class Rep2>
// explicit duration(const Rep2& r);
// construct double with int
#include <chrono>
#include <cassert>
int main()
{
std::chrono::duration<double> d(5);
assert(d.count() == 5);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// template <class Rep2> +// explicit duration(const Rep2& r); + +// construct double with int + +#include <chrono> +#include <cassert> + +int main() +{ + std::chrono::duration<double> d(5); + assert(d.count() == 5); +} diff --git a/libcxx/test/utilities/time/time.duration/time.duration.cons/rep03.fail.cpp b/libcxx/test/utilities/time/time.duration/time.duration.cons/rep03.fail.cpp index fb6c83a1d3d..9fa9bdeb8c7 100644 --- a/libcxx/test/utilities/time/time.duration/time.duration.cons/rep03.fail.cpp +++ b/libcxx/test/utilities/time/time.duration/time.duration.cons/rep03.fail.cpp @@ -1 +1,24 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <chrono>
// duration
// template <class Rep2>
// explicit duration(const Rep2& r);
// treat_as_floating_point<Rep2>::value shall be false
#include <chrono>
int main()
{
std::chrono::duration<int> d(1.);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// template <class Rep2> +// explicit duration(const Rep2& r); + +// treat_as_floating_point<Rep2>::value shall be false + +#include <chrono> + +int main() +{ + std::chrono::duration<int> d(1.); +} diff --git a/libcxx/test/utilities/time/time.duration/time.duration.nonmember/op_+.pass.cpp b/libcxx/test/utilities/time/time.duration/time.duration.nonmember/op_+.pass.cpp index 168e7a0437a..94605b2d4ca 100644 --- a/libcxx/test/utilities/time/time.duration/time.duration.nonmember/op_+.pass.cpp +++ b/libcxx/test/utilities/time/time.duration/time.duration.nonmember/op_+.pass.cpp @@ -1 +1,47 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <chrono>
// duration
// template <class Rep1, class Period1, class Rep2, class Period2>
// typename common_type<duration<Rep1, Period1>, duration<Rep2, Period2>>::type
// operator+(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
#include <chrono>
#include <cassert>
int main()
{
{
std::chrono::seconds s1(3);
std::chrono::seconds s2(5);
std::chrono::seconds r = s1 + s2;
assert(r.count() == 8);
}
{
std::chrono::seconds s1(3);
std::chrono::microseconds s2(5);
std::chrono::microseconds r = s1 + s2;
assert(r.count() == 3000005);
}
{
std::chrono::duration<int, std::ratio<2, 3> > s1(3);
std::chrono::duration<int, std::ratio<3, 5> > s2(5);
std::chrono::duration<int, std::ratio<1, 15> > r = s1 + s2;
assert(r.count() == 75);
}
{
std::chrono::duration<int, std::ratio<2, 3> > s1(3);
std::chrono::duration<double, std::ratio<3, 5> > s2(5);
std::chrono::duration<double, std::ratio<1, 15> > r = s1 + s2;
assert(r.count() == 75);
}
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// template <class Rep1, class Period1, class Rep2, class Period2> +// typename common_type<duration<Rep1, Period1>, duration<Rep2, Period2>>::type +// operator+(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs); + +#include <chrono> +#include <cassert> + +int main() +{ + { + std::chrono::seconds s1(3); + std::chrono::seconds s2(5); + std::chrono::seconds r = s1 + s2; + assert(r.count() == 8); + } + { + std::chrono::seconds s1(3); + std::chrono::microseconds s2(5); + std::chrono::microseconds r = s1 + s2; + assert(r.count() == 3000005); + } + { + std::chrono::duration<int, std::ratio<2, 3> > s1(3); + std::chrono::duration<int, std::ratio<3, 5> > s2(5); + std::chrono::duration<int, std::ratio<1, 15> > r = s1 + s2; + assert(r.count() == 75); + } + { + std::chrono::duration<int, std::ratio<2, 3> > s1(3); + std::chrono::duration<double, std::ratio<3, 5> > s2(5); + std::chrono::duration<double, std::ratio<1, 15> > r = s1 + s2; + assert(r.count() == 75); + } +} diff --git a/libcxx/test/utilities/time/time.duration/time.duration.nonmember/op_-.pass.cpp b/libcxx/test/utilities/time/time.duration/time.duration.nonmember/op_-.pass.cpp index 918f62d5d20..56329ee0c5f 100644 --- a/libcxx/test/utilities/time/time.duration/time.duration.nonmember/op_-.pass.cpp +++ b/libcxx/test/utilities/time/time.duration/time.duration.nonmember/op_-.pass.cpp @@ -1 +1,47 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <chrono>
// duration
// template <class Rep1, class Period1, class Rep2, class Period2>
// typename common_type<duration<Rep1, Period1>, duration<Rep2, Period2>>::type
// operator-(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
#include <chrono>
#include <cassert>
int main()
{
{
std::chrono::seconds s1(3);
std::chrono::seconds s2(5);
std::chrono::seconds r = s1 - s2;
assert(r.count() == -2);
}
{
std::chrono::seconds s1(3);
std::chrono::microseconds s2(5);
std::chrono::microseconds r = s1 - s2;
assert(r.count() == 2999995);
}
{
std::chrono::duration<int, std::ratio<2, 3> > s1(3);
std::chrono::duration<int, std::ratio<3, 5> > s2(5);
std::chrono::duration<int, std::ratio<1, 15> > r = s1 - s2;
assert(r.count() == -15);
}
{
std::chrono::duration<int, std::ratio<2, 3> > s1(3);
std::chrono::duration<double, std::ratio<3, 5> > s2(5);
std::chrono::duration<double, std::ratio<1, 15> > r = s1 - s2;
assert(r.count() == -15);
}
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// template <class Rep1, class Period1, class Rep2, class Period2> +// typename common_type<duration<Rep1, Period1>, duration<Rep2, Period2>>::type +// operator-(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs); + +#include <chrono> +#include <cassert> + +int main() +{ + { + std::chrono::seconds s1(3); + std::chrono::seconds s2(5); + std::chrono::seconds r = s1 - s2; + assert(r.count() == -2); + } + { + std::chrono::seconds s1(3); + std::chrono::microseconds s2(5); + std::chrono::microseconds r = s1 - s2; + assert(r.count() == 2999995); + } + { + std::chrono::duration<int, std::ratio<2, 3> > s1(3); + std::chrono::duration<int, std::ratio<3, 5> > s2(5); + std::chrono::duration<int, std::ratio<1, 15> > r = s1 - s2; + assert(r.count() == -15); + } + { + std::chrono::duration<int, std::ratio<2, 3> > s1(3); + std::chrono::duration<double, std::ratio<3, 5> > s2(5); + std::chrono::duration<double, std::ratio<1, 15> > r = s1 - s2; + assert(r.count() == -15); + } +} diff --git a/libcxx/test/utilities/time/time.duration/time.duration.nonmember/op_divide_duration.pass.cpp b/libcxx/test/utilities/time/time.duration/time.duration.nonmember/op_divide_duration.pass.cpp index 4ad5961fc8a..af50271e6ae 100644 --- a/libcxx/test/utilities/time/time.duration/time.duration.nonmember/op_divide_duration.pass.cpp +++ b/libcxx/test/utilities/time/time.duration/time.duration.nonmember/op_divide_duration.pass.cpp @@ -1 +1,43 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <chrono>
// duration
// template <class Rep1, class Period1, class Rep2, class Period2>
// typename common_type<Rep1, Rep2>::type
// operator/(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
#include <chrono>
#include <cassert>
int main()
{
{
std::chrono::nanoseconds ns1(15);
std::chrono::nanoseconds ns2(5);
assert(ns1 / ns2 == 3);
}
{
std::chrono::microseconds us1(15);
std::chrono::nanoseconds ns2(5);
assert(us1 / ns2 == 3000);
}
{
std::chrono::duration<int, std::ratio<2, 3> > s1(30);
std::chrono::duration<int, std::ratio<3, 5> > s2(5);
assert(s1 / s2 == 6);
}
{
std::chrono::duration<int, std::ratio<2, 3> > s1(30);
std::chrono::duration<double, std::ratio<3, 5> > s2(5);
assert(s1 / s2 == 20./3);
}
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// template <class Rep1, class Period1, class Rep2, class Period2> +// typename common_type<Rep1, Rep2>::type +// operator/(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs); + +#include <chrono> +#include <cassert> + +int main() +{ + { + std::chrono::nanoseconds ns1(15); + std::chrono::nanoseconds ns2(5); + assert(ns1 / ns2 == 3); + } + { + std::chrono::microseconds us1(15); + std::chrono::nanoseconds ns2(5); + assert(us1 / ns2 == 3000); + } + { + std::chrono::duration<int, std::ratio<2, 3> > s1(30); + std::chrono::duration<int, std::ratio<3, 5> > s2(5); + assert(s1 / s2 == 6); + } + { + std::chrono::duration<int, std::ratio<2, 3> > s1(30); + std::chrono::duration<double, std::ratio<3, 5> > s2(5); + assert(s1 / s2 == 20./3); + } +} diff --git a/libcxx/test/utilities/time/time.duration/time.duration.nonmember/op_divide_rep.fail.cpp b/libcxx/test/utilities/time/time.duration/time.duration.nonmember/op_divide_rep.fail.cpp index 244061fb2a0..99336528882 100644 --- a/libcxx/test/utilities/time/time.duration/time.duration.nonmember/op_divide_rep.fail.cpp +++ b/libcxx/test/utilities/time/time.duration/time.duration.nonmember/op_divide_rep.fail.cpp @@ -1 +1,26 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <chrono>
// duration
// template <class Rep1, class Period, class Rep2>
// duration<typename common_type<Rep1, Rep2>::type, Period>
// operator/(const duration<Rep1, Period>& d, const Rep2& s);
#include <chrono>
#include "../../rep.h"
int main()
{
std::chrono::duration<Rep> d(Rep(15));
d = d / 5;
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// template <class Rep1, class Period, class Rep2> +// duration<typename common_type<Rep1, Rep2>::type, Period> +// operator/(const duration<Rep1, Period>& d, const Rep2& s); + +#include <chrono> + +#include "../../rep.h" + +int main() +{ + std::chrono::duration<Rep> d(Rep(15)); + d = d / 5; +} diff --git a/libcxx/test/utilities/time/time.duration/time.duration.nonmember/op_divide_rep.pass.cpp b/libcxx/test/utilities/time/time.duration/time.duration.nonmember/op_divide_rep.pass.cpp index 81848a84f10..cdd105b8fff 100644 --- a/libcxx/test/utilities/time/time.duration/time.duration.nonmember/op_divide_rep.pass.cpp +++ b/libcxx/test/utilities/time/time.duration/time.duration.nonmember/op_divide_rep.pass.cpp @@ -1 +1,26 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <chrono>
// duration
// template <class Rep1, class Period, class Rep2>
// duration<typename common_type<Rep1, Rep2>::type, Period>
// operator/(const duration<Rep1, Period>& d, const Rep2& s);
#include <chrono>
#include <cassert>
int main()
{
std::chrono::nanoseconds ns(15);
ns = ns / 5;
assert(ns.count() == 3);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// template <class Rep1, class Period, class Rep2> +// duration<typename common_type<Rep1, Rep2>::type, Period> +// operator/(const duration<Rep1, Period>& d, const Rep2& s); + +#include <chrono> +#include <cassert> + +int main() +{ + std::chrono::nanoseconds ns(15); + ns = ns / 5; + assert(ns.count() == 3); +} diff --git a/libcxx/test/utilities/time/time.duration/time.duration.nonmember/op_mod_duration.pass.cpp b/libcxx/test/utilities/time/time.duration/time.duration.nonmember/op_mod_duration.pass.cpp index 2e664d9860b..1d61cb3e7f1 100644 --- a/libcxx/test/utilities/time/time.duration/time.duration.nonmember/op_mod_duration.pass.cpp +++ b/libcxx/test/utilities/time/time.duration/time.duration.nonmember/op_mod_duration.pass.cpp @@ -1 +1,41 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <chrono>
// duration
// template <class Rep1, class Period1, class Rep2, class Period2>
// typename common_type<duration<Rep1, Period1>, duration<Rep2, Period2>>::type
// operator%(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
#include <chrono>
#include <cassert>
int main()
{
{
std::chrono::nanoseconds ns1(15);
std::chrono::nanoseconds ns2(6);
std::chrono::nanoseconds r = ns1 % ns2;
assert(r.count() == 3);
}
{
std::chrono::microseconds us1(15);
std::chrono::nanoseconds ns2(28);
std::chrono::nanoseconds r = us1 % ns2;
assert(r.count() == 20);
}
{
std::chrono::duration<int, std::ratio<3, 5> > s1(6);
std::chrono::duration<int, std::ratio<2, 3> > s2(3);
std::chrono::duration<int, std::ratio<1, 15> > r = s1 % s2;
assert(r.count() == 24);
}
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// template <class Rep1, class Period1, class Rep2, class Period2> +// typename common_type<duration<Rep1, Period1>, duration<Rep2, Period2>>::type +// operator%(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs); + +#include <chrono> +#include <cassert> + +int main() +{ + { + std::chrono::nanoseconds ns1(15); + std::chrono::nanoseconds ns2(6); + std::chrono::nanoseconds r = ns1 % ns2; + assert(r.count() == 3); + } + { + std::chrono::microseconds us1(15); + std::chrono::nanoseconds ns2(28); + std::chrono::nanoseconds r = us1 % ns2; + assert(r.count() == 20); + } + { + std::chrono::duration<int, std::ratio<3, 5> > s1(6); + std::chrono::duration<int, std::ratio<2, 3> > s2(3); + std::chrono::duration<int, std::ratio<1, 15> > r = s1 % s2; + assert(r.count() == 24); + } +} diff --git a/libcxx/test/utilities/time/time.duration/time.duration.nonmember/op_mod_rep.fail.cpp b/libcxx/test/utilities/time/time.duration/time.duration.nonmember/op_mod_rep.fail.cpp index 9e82fdfc1ff..349c6e8a948 100644 --- a/libcxx/test/utilities/time/time.duration/time.duration.nonmember/op_mod_rep.fail.cpp +++ b/libcxx/test/utilities/time/time.duration/time.duration.nonmember/op_mod_rep.fail.cpp @@ -1 +1,26 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <chrono>
// duration
// template <class Rep1, class Period, class Rep2>
// duration<typename common_type<Rep1, Rep2>::type, Period>
// operator%(const duration<Rep1, Period>& d, const Rep2& s)
#include <chrono>
#include "../../rep.h"
int main()
{
std::chrono::duration<Rep> d(Rep(15));
d = d % 5;
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// template <class Rep1, class Period, class Rep2> +// duration<typename common_type<Rep1, Rep2>::type, Period> +// operator%(const duration<Rep1, Period>& d, const Rep2& s) + +#include <chrono> + +#include "../../rep.h" + +int main() +{ + std::chrono::duration<Rep> d(Rep(15)); + d = d % 5; +} diff --git a/libcxx/test/utilities/time/time.duration/time.duration.nonmember/op_times_rep.pass.cpp b/libcxx/test/utilities/time/time.duration/time.duration.nonmember/op_times_rep.pass.cpp index c27ac5c797d..7d83d9db616 100644 --- a/libcxx/test/utilities/time/time.duration/time.duration.nonmember/op_times_rep.pass.cpp +++ b/libcxx/test/utilities/time/time.duration/time.duration.nonmember/op_times_rep.pass.cpp @@ -11,12 +11,12 @@ // duration -// template <class Rep1, class Period, class Rep2> -// duration<typename common_type<Rep1, Rep2>::type, Period> +// template <class Rep1, class Period, class Rep2> +// duration<typename common_type<Rep1, Rep2>::type, Period> // operator*(const duration<Rep1, Period>& d, const Rep2& s); -// template <class Rep1, class Period, class Rep2> -// duration<typename common_type<Rep1, Rep2>::type, Period> +// template <class Rep1, class Period, class Rep2> +// duration<typename common_type<Rep1, Rep2>::type, Period> // operator*(const Rep1& s, const duration<Rep2, Period>& d); #include <chrono> diff --git a/libcxx/test/utilities/time/time.duration/time.duration.nonmember/op_times_rep1.fail.cpp b/libcxx/test/utilities/time/time.duration/time.duration.nonmember/op_times_rep1.fail.cpp index d6cdcbe05dc..dde038083b0 100644 --- a/libcxx/test/utilities/time/time.duration/time.duration.nonmember/op_times_rep1.fail.cpp +++ b/libcxx/test/utilities/time/time.duration/time.duration.nonmember/op_times_rep1.fail.cpp @@ -11,12 +11,12 @@ // duration -// template <class Rep1, class Period, class Rep2> -// duration<typename common_type<Rep1, Rep2>::type, Period> +// template <class Rep1, class Period, class Rep2> +// duration<typename common_type<Rep1, Rep2>::type, Period> // operator*(const duration<Rep1, Period>& d, const Rep2& s); -// template <class Rep1, class Period, class Rep2> -// duration<typename common_type<Rep1, Rep2>::type, Period> +// template <class Rep1, class Period, class Rep2> +// duration<typename common_type<Rep1, Rep2>::type, Period> // operator*(const Rep1& s, const duration<Rep2, Period>& d); #include <chrono> diff --git a/libcxx/test/utilities/time/time.duration/time.duration.nonmember/op_times_rep2.fail.cpp b/libcxx/test/utilities/time/time.duration/time.duration.nonmember/op_times_rep2.fail.cpp index 0b1a38ab058..9dfb7385da8 100644 --- a/libcxx/test/utilities/time/time.duration/time.duration.nonmember/op_times_rep2.fail.cpp +++ b/libcxx/test/utilities/time/time.duration/time.duration.nonmember/op_times_rep2.fail.cpp @@ -11,12 +11,12 @@ // duration -// template <class Rep1, class Period, class Rep2> -// duration<typename common_type<Rep1, Rep2>::type, Period> +// template <class Rep1, class Period, class Rep2> +// duration<typename common_type<Rep1, Rep2>::type, Period> // operator*(const duration<Rep1, Period>& d, const Rep2& s); -// template <class Rep1, class Period, class Rep2> -// duration<typename common_type<Rep1, Rep2>::type, Period> +// template <class Rep1, class Period, class Rep2> +// duration<typename common_type<Rep1, Rep2>::type, Period> // operator*(const Rep1& s, const duration<Rep2, Period>& d); #include <chrono> diff --git a/libcxx/test/utilities/time/time.duration/types.pass.cpp b/libcxx/test/utilities/time/time.duration/types.pass.cpp index 5b6aa81c4a6..8ed179d45dd 100644 --- a/libcxx/test/utilities/time/time.duration/types.pass.cpp +++ b/libcxx/test/utilities/time/time.duration/types.pass.cpp @@ -13,8 +13,8 @@ // Test nested types -// typedef Rep rep; -// typedef Period period; +// typedef Rep rep; +// typedef Period period; #include <chrono> #include <type_traits> diff --git a/libcxx/test/utilities/time/time.point/default_duration.pass.cpp b/libcxx/test/utilities/time/time.point/default_duration.pass.cpp index fe220d3e210..9135f915a63 100644 --- a/libcxx/test/utilities/time/time.point/default_duration.pass.cpp +++ b/libcxx/test/utilities/time/time.point/default_duration.pass.cpp @@ -13,7 +13,7 @@ // Test default template arg: -// template <class Clock, class Duration = typename Clock::duration> +// template <class Clock, class Duration = typename Clock::duration> // class time_point; #include <chrono> diff --git a/libcxx/test/utilities/time/time.point/time.point.cast/time_point_cast.pass.cpp b/libcxx/test/utilities/time/time.point/time.point.cast/time_point_cast.pass.cpp index d12c692bb8e..cd808111550 100644 --- a/libcxx/test/utilities/time/time.point/time.point.cast/time_point_cast.pass.cpp +++ b/libcxx/test/utilities/time/time.point/time.point.cast/time_point_cast.pass.cpp @@ -11,7 +11,7 @@ // time_point -// template <class ToDuration, class Clock, class Duration> +// template <class ToDuration, class Clock, class Duration> // time_point<Clock, ToDuration> // time_point_cast(const time_point<Clock, Duration>& t); diff --git a/libcxx/test/utilities/time/time.point/time.point.cast/toduration.fail.cpp b/libcxx/test/utilities/time/time.point/time.point.cast/toduration.fail.cpp index 412cc07afe0..d611212c4f8 100644 --- a/libcxx/test/utilities/time/time.point/time.point.cast/toduration.fail.cpp +++ b/libcxx/test/utilities/time/time.point/time.point.cast/toduration.fail.cpp @@ -11,7 +11,7 @@ // time_point -// template <class ToDuration, class Clock, class Duration> +// template <class ToDuration, class Clock, class Duration> // time_point<Clock, ToDuration> // time_point_cast(const time_point<Clock, Duration>& t); diff --git a/libcxx/test/utilities/time/time.point/time.point.comparisons/op_equal.fail.cpp b/libcxx/test/utilities/time/time.point/time.point.comparisons/op_equal.fail.cpp index 7122a8ba298..e6f34c558a6 100644 --- a/libcxx/test/utilities/time/time.point/time.point.comparisons/op_equal.fail.cpp +++ b/libcxx/test/utilities/time/time.point/time.point.comparisons/op_equal.fail.cpp @@ -11,11 +11,11 @@ // time_point -// template <class Clock, class Duration1, class Duration2> +// template <class Clock, class Duration1, class Duration2> // bool // operator==(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs); -// template <class Clock, class Duration1, class Duration2> +// template <class Clock, class Duration1, class Duration2> // bool // operator!=(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs); diff --git a/libcxx/test/utilities/time/time.point/time.point.comparisons/op_equal.pass.cpp b/libcxx/test/utilities/time/time.point/time.point.comparisons/op_equal.pass.cpp index 6d1a0dcc7cf..8e204502840 100644 --- a/libcxx/test/utilities/time/time.point/time.point.comparisons/op_equal.pass.cpp +++ b/libcxx/test/utilities/time/time.point/time.point.comparisons/op_equal.pass.cpp @@ -11,11 +11,11 @@ // time_point -// template <class Clock, class Duration1, class Duration2> +// template <class Clock, class Duration1, class Duration2> // bool // operator==(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs); -// template <class Clock, class Duration1, class Duration2> +// template <class Clock, class Duration1, class Duration2> // bool // operator!=(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs); diff --git a/libcxx/test/utilities/time/time.point/time.point.comparisons/op_less.fail.cpp b/libcxx/test/utilities/time/time.point/time.point.comparisons/op_less.fail.cpp index f98dca131bd..4e4fb1d65b8 100644 --- a/libcxx/test/utilities/time/time.point/time.point.comparisons/op_less.fail.cpp +++ b/libcxx/test/utilities/time/time.point/time.point.comparisons/op_less.fail.cpp @@ -11,19 +11,19 @@ // time_point -// template <class Clock, class Duration1, class Duration2> +// template <class Clock, class Duration1, class Duration2> // bool // operator< (const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs); -// template <class Clock, class Duration1, class Duration2> +// template <class Clock, class Duration1, class Duration2> // bool // operator> (const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs); -// template <class Clock, class Duration1, class Duration2> +// template <class Clock, class Duration1, class Duration2> // bool // operator<=(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs); -// template <class Clock, class Duration1, class Duration2> +// template <class Clock, class Duration1, class Duration2> // bool // operator>=(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs); diff --git a/libcxx/test/utilities/time/time.point/time.point.comparisons/op_less.pass.cpp b/libcxx/test/utilities/time/time.point/time.point.comparisons/op_less.pass.cpp index abbb304d04e..8acdc1cae65 100644 --- a/libcxx/test/utilities/time/time.point/time.point.comparisons/op_less.pass.cpp +++ b/libcxx/test/utilities/time/time.point/time.point.comparisons/op_less.pass.cpp @@ -11,19 +11,19 @@ // time_point -// template <class Clock, class Duration1, class Duration2> +// template <class Clock, class Duration1, class Duration2> // bool // operator< (const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs); -// template <class Clock, class Duration1, class Duration2> +// template <class Clock, class Duration1, class Duration2> // bool // operator> (const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs); -// template <class Clock, class Duration1, class Duration2> +// template <class Clock, class Duration1, class Duration2> // bool // operator<=(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs); -// template <class Clock, class Duration1, class Duration2> +// template <class Clock, class Duration1, class Duration2> // bool // operator>=(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs); diff --git a/libcxx/test/utilities/time/time.point/time.point.cons/convert.fail.cpp b/libcxx/test/utilities/time/time.point/time.point.cons/convert.fail.cpp index 68fd0a0cbe6..58241a9f22d 100644 --- a/libcxx/test/utilities/time/time.point/time.point.cons/convert.fail.cpp +++ b/libcxx/test/utilities/time/time.point/time.point.cons/convert.fail.cpp @@ -11,7 +11,7 @@ // time_point -// template <class Duration2> +// template <class Duration2> // time_point(const time_point<clock, Duration2>& t); // Duration2 shall be implicitly convertible to duration. diff --git a/libcxx/test/utilities/time/time.point/time.point.cons/convert.pass.cpp b/libcxx/test/utilities/time/time.point/time.point.cons/convert.pass.cpp index 69547a4c1b4..bdd260eff35 100644 --- a/libcxx/test/utilities/time/time.point/time.point.cons/convert.pass.cpp +++ b/libcxx/test/utilities/time/time.point/time.point.cons/convert.pass.cpp @@ -11,7 +11,7 @@ // time_point -// template <class Duration2> +// template <class Duration2> // time_point(const time_point<clock, Duration2>& t); #include <chrono> diff --git a/libcxx/test/utilities/time/time.point/time.point.nonmember/op_+.pass.cpp b/libcxx/test/utilities/time/time.point/time.point.nonmember/op_+.pass.cpp index ed31cece003..fc627e10e37 100644 --- a/libcxx/test/utilities/time/time.point/time.point.nonmember/op_+.pass.cpp +++ b/libcxx/test/utilities/time/time.point/time.point.nonmember/op_+.pass.cpp @@ -11,12 +11,12 @@ // time_point -// template <class Clock, class Duration1, class Rep2, class Period2> -// time_point<Clock, typename common_type<Duration1, duration<Rep2, Period2>>::type> +// template <class Clock, class Duration1, class Rep2, class Period2> +// time_point<Clock, typename common_type<Duration1, duration<Rep2, Period2>>::type> // operator+(const time_point<Clock, Duration1>& lhs, const duration<Rep2, Period2>& rhs); -// template <class Rep1, class Period1, class Clock, class Duration2> -// time_point<Clock, typename common_type<duration<Rep1, Period1>, Duration2>::type> +// template <class Rep1, class Period1, class Clock, class Duration2> +// time_point<Clock, typename common_type<duration<Rep1, Period1>, Duration2>::type> // operator+(const duration<Rep1, Period1>& lhs, const time_point<Clock, Duration2>& rhs); #include <chrono> diff --git a/libcxx/test/utilities/time/time.point/time.point.nonmember/op_-duration.pass.cpp b/libcxx/test/utilities/time/time.point/time.point.nonmember/op_-duration.pass.cpp index c3e0d62b660..c2bca855983 100644 --- a/libcxx/test/utilities/time/time.point/time.point.nonmember/op_-duration.pass.cpp +++ b/libcxx/test/utilities/time/time.point/time.point.nonmember/op_-duration.pass.cpp @@ -11,8 +11,8 @@ // time_point -// template <class Clock, class Duration1, class Rep2, class Period2> -// time_point<Clock, typename common_type<Duration1, duration<Rep2, Period2>>::type> +// template <class Clock, class Duration1, class Rep2, class Period2> +// time_point<Clock, typename common_type<Duration1, duration<Rep2, Period2>>::type> // operator-(const time_point<Clock, Duration1>& lhs, const duration<Rep2, Period2>& rhs); #include <chrono> diff --git a/libcxx/test/utilities/time/time.point/time.point.nonmember/op_-time_point.pass.cpp b/libcxx/test/utilities/time/time.point/time.point.nonmember/op_-time_point.pass.cpp index f8ac80bde37..0ea405f76af 100644 --- a/libcxx/test/utilities/time/time.point/time.point.nonmember/op_-time_point.pass.cpp +++ b/libcxx/test/utilities/time/time.point/time.point.nonmember/op_-time_point.pass.cpp @@ -11,8 +11,8 @@ // time_point -// template <class Clock, class Duration1, class Duration2> -// typename common_type<Duration1, Duration2>::type +// template <class Clock, class Duration1, class Duration2> +// typename common_type<Duration1, Duration2>::type // operator-(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs); #include <chrono> diff --git a/libcxx/test/utilities/time/time.traits/time.traits.specializations/duration.pass.cpp b/libcxx/test/utilities/time/time.traits/time.traits.specializations/duration.pass.cpp index dfccbd5cbf8..f638f630921 100644 --- a/libcxx/test/utilities/time/time.traits/time.traits.specializations/duration.pass.cpp +++ b/libcxx/test/utilities/time/time.traits/time.traits.specializations/duration.pass.cpp @@ -9,10 +9,10 @@ // <chrono> -// template <class Rep1, class Period1, class Rep2, class Period2> +// template <class Rep1, class Period1, class Rep2, class Period2> // struct common_type<chrono::duration<Rep1, Period1>, chrono::duration<Rep2, Period2>> // { -// typedef chrono::duration<typename common_type<Rep1, Rep2>::type, see below }> type; +// typedef chrono::duration<typename common_type<Rep1, Rep2>::type, see below }> type; // }; #include <chrono> diff --git a/libcxx/test/utilities/time/time.traits/time.traits.specializations/time_point.pass.cpp b/libcxx/test/utilities/time/time.traits/time.traits.specializations/time_point.pass.cpp index b0965e10457..55d14e1b2aa 100644 --- a/libcxx/test/utilities/time/time.traits/time.traits.specializations/time_point.pass.cpp +++ b/libcxx/test/utilities/time/time.traits/time.traits.specializations/time_point.pass.cpp @@ -9,10 +9,10 @@ // <chrono> -// template <class Clock, class Duration1, class Duration2> +// template <class Clock, class Duration1, class Duration2> // struct common_type<chrono::time_point<Clock, Duration1>, chrono::time_point<Clock, Duration2>> -// { -// typedef chrono::time_point<Clock, typename common_type<Duration1, Duration2>::type> type; +// { +// typedef chrono::time_point<Clock, typename common_type<Duration1, Duration2>::type> type; // }; #include <chrono> diff --git a/libcxx/test/utilities/tuple/tuple.tuple/DefaultOnly.h b/libcxx/test/utilities/tuple/tuple.tuple/DefaultOnly.h index d40e9c13446..bdcf46d19ff 100644 --- a/libcxx/test/utilities/tuple/tuple.tuple/DefaultOnly.h +++ b/libcxx/test/utilities/tuple/tuple.tuple/DefaultOnly.h @@ -23,4 +23,4 @@ public: int DefaultOnly::count = 0; -#endif +#endif // DEFAULTONLY_H diff --git a/libcxx/test/utilities/tuple/tuple.tuple/MoveOnly.h b/libcxx/test/utilities/tuple/tuple.tuple/MoveOnly.h index b7d62b71374..c3468387e24 100644 --- a/libcxx/test/utilities/tuple/tuple.tuple/MoveOnly.h +++ b/libcxx/test/utilities/tuple/tuple.tuple/MoveOnly.h @@ -21,8 +21,8 @@ public: int get() const {return data_;} - bool operator==(const MoveOnly& x) const {return data_ == x.data_;} - bool operator< (const MoveOnly& x) const {return data_ < x.data_;} + bool operator==(const MoveOnly& x) const {return data_ == x.data_;} + bool operator< (const MoveOnly& x) const {return data_ < x.data_;} }; namespace std { @@ -36,6 +36,6 @@ struct hash<MoveOnly> } -#endif +#endif // _LIBCPP_MOVE -#endif +#endif // MOVEONLY_H diff --git a/libcxx/test/utilities/tuple/tuple.tuple/alloc_first.h b/libcxx/test/utilities/tuple/tuple.tuple/alloc_first.h index 2b2183a4502..948f2a49976 100644 --- a/libcxx/test/utilities/tuple/tuple.tuple/alloc_first.h +++ b/libcxx/test/utilities/tuple/tuple.tuple/alloc_first.h @@ -46,4 +46,4 @@ struct alloc_first bool alloc_first::allocator_constructed = false; -#endif +#endif // ALLOC_FIRST_H diff --git a/libcxx/test/utilities/tuple/tuple.tuple/alloc_last.h b/libcxx/test/utilities/tuple/tuple.tuple/alloc_last.h index 7601c9d8714..e87cb2118bc 100644 --- a/libcxx/test/utilities/tuple/tuple.tuple/alloc_last.h +++ b/libcxx/test/utilities/tuple/tuple.tuple/alloc_last.h @@ -46,4 +46,4 @@ struct alloc_last bool alloc_last::allocator_constructed = false; -#endif +#endif // ALLOC_LAST_H diff --git a/libcxx/test/utilities/tuple/tuple.tuple/allocators.h b/libcxx/test/utilities/tuple/tuple.tuple/allocators.h index 7075f85e222..0e4b7f3299d 100644 --- a/libcxx/test/utilities/tuple/tuple.tuple/allocators.h +++ b/libcxx/test/utilities/tuple/tuple.tuple/allocators.h @@ -150,8 +150,6 @@ public: A3 select_on_container_copy_construction() const {return A3(-1);} }; - - template <class T> bool A3<T>::copy_called = false; template <class T> bool A3<T>::move_called = false; template <class T> bool A3<T>::constructed = false; @@ -171,6 +169,6 @@ bool operator!=(const A3<T>& x, const A3<U>& y) return !(x == y); } -#endif +#endif // _LIBCPP_MOVE -#endif +#endif // ALLOCATORS_H diff --git a/libcxx/test/utilities/tuple/tuple.tuple/tuple.assign/move_pair.pass.cpp b/libcxx/test/utilities/tuple/tuple.tuple/tuple.assign/move_pair.pass.cpp index 793cef9d288..7970a704448 100644 --- a/libcxx/test/utilities/tuple/tuple.tuple/tuple.assign/move_pair.pass.cpp +++ b/libcxx/test/utilities/tuple/tuple.tuple/tuple.assign/move_pair.pass.cpp @@ -34,7 +34,6 @@ struct D explicit D(int i) : B(i) {} }; - int main() { { diff --git a/libcxx/test/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_UTypes.pass.cpp b/libcxx/test/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_UTypes.pass.cpp index 262a4d6edb0..a790bf7427d 100644 --- a/libcxx/test/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_UTypes.pass.cpp +++ b/libcxx/test/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_UTypes.pass.cpp @@ -35,7 +35,7 @@ int main() assert(std::get<1>(t) == 1); } { - std::tuple<MoveOnly, MoveOnly, MoveOnly> t(std::allocator_arg, A1<int>(), + std::tuple<MoveOnly, MoveOnly, MoveOnly> t(std::allocator_arg, A1<int>(), MoveOnly(0), 1, 2); assert(std::get<0>(t) == 0); @@ -55,14 +55,14 @@ int main() } // extensions { - std::tuple<MoveOnly, MoveOnly, MoveOnly> t(std::allocator_arg, A1<int>(), + std::tuple<MoveOnly, MoveOnly, MoveOnly> t(std::allocator_arg, A1<int>(), 0, 1); assert(std::get<0>(t) == 0); assert(std::get<1>(t) == 1); assert(std::get<2>(t) == MoveOnly()); } { - std::tuple<MoveOnly, MoveOnly, MoveOnly> t(std::allocator_arg, A1<int>(), + std::tuple<MoveOnly, MoveOnly, MoveOnly> t(std::allocator_arg, A1<int>(), 0); assert(std::get<0>(t) == 0); assert(std::get<1>(t) == MoveOnly()); diff --git a/libcxx/test/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_move_pair.pass.cpp b/libcxx/test/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_move_pair.pass.cpp index b0821dc3018..562d0733832 100644 --- a/libcxx/test/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_move_pair.pass.cpp +++ b/libcxx/test/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_move_pair.pass.cpp @@ -38,7 +38,6 @@ struct D explicit D(int i) : B(i) {} }; - int main() { { diff --git a/libcxx/test/utilities/tuple/tuple.tuple/tuple.cnstr/move_pair.pass.cpp b/libcxx/test/utilities/tuple/tuple.tuple/tuple.cnstr/move_pair.pass.cpp index b06da1cb063..a005c65d53b 100644 --- a/libcxx/test/utilities/tuple/tuple.tuple/tuple.cnstr/move_pair.pass.cpp +++ b/libcxx/test/utilities/tuple/tuple.tuple/tuple.cnstr/move_pair.pass.cpp @@ -33,7 +33,6 @@ struct D explicit D(int i) : B(i) {} }; - int main() { { diff --git a/libcxx/test/utilities/tuple/tuple.tuple/tuple.creation/forward_as_tuple.pass.cpp b/libcxx/test/utilities/tuple/tuple.tuple/tuple.creation/forward_as_tuple.pass.cpp index 4ea7d4ed12c..10b76d2befd 100644 --- a/libcxx/test/utilities/tuple/tuple.tuple/tuple.creation/forward_as_tuple.pass.cpp +++ b/libcxx/test/utilities/tuple/tuple.tuple/tuple.creation/forward_as_tuple.pass.cpp @@ -12,7 +12,6 @@ // template<class... Types> // tuple<Types&&...> forward_as_tuple(Types&&... t); - #include <tuple> #include <cassert> diff --git a/libcxx/test/utilities/utility/forward/forward.pass.cpp b/libcxx/test/utilities/utility/forward/forward.pass.cpp index ebb1b518def..cfc800dc02e 100644 --- a/libcxx/test/utilities/utility/forward/forward.pass.cpp +++ b/libcxx/test/utilities/utility/forward/forward.pass.cpp @@ -32,7 +32,7 @@ two test(const A&); four test(A&&); eight test(const A&&); -#endif +#endif // _LIBCPP_MOVE int main() { @@ -54,7 +54,7 @@ int main() static_assert(sizeof(test(std::forward<const A>(ca))) == 8, ""); static_assert(sizeof(test(std::forward<const A>(csource()))) == 8, ""); -#else +#else // _LIBCPP_MOVE static_assert(sizeof(test(std::forward<A&>(a))) == 1, ""); static_assert(sizeof(test(std::forward<A>(a))) == 1, ""); @@ -69,5 +69,5 @@ int main() static_assert(sizeof(test(std::forward<const A&>(csource()))) == 2, ""); static_assert(sizeof(test(std::forward<const A>(ca))) == 2, ""); static_assert(sizeof(test(std::forward<const A>(csource()))) == 2, ""); -#endif +#endif // _LIBCPP_MOVE } diff --git a/libcxx/test/utilities/utility/forward/move_copy.pass.cpp b/libcxx/test/utilities/utility/forward/move_copy.pass.cpp index dd0281eab7b..6cc31489154 100644 --- a/libcxx/test/utilities/utility/forward/move_copy.pass.cpp +++ b/libcxx/test/utilities/utility/forward/move_copy.pass.cpp @@ -29,13 +29,13 @@ public: A(A&&) {++move_ctor;} A& operator=(A&&); -#else +#else // _LIBCPP_MOVE A(const A&) {++copy_ctor;} A& operator=(A&); operator std::__rv<A> () {return std::__rv<A>(*this);} A(std::__rv<A>) {++move_ctor;} -#endif +#endif // _LIBCPP_MOVE A() {} }; diff --git a/libcxx/test/utilities/utility/forward/move_if_noexcept.pass.cpp b/libcxx/test/utilities/utility/forward/move_if_noexcept.pass.cpp index 2e59f36e20d..2c7718ae30d 100644 --- a/libcxx/test/utilities/utility/forward/move_if_noexcept.pass.cpp +++ b/libcxx/test/utilities/utility/forward/move_if_noexcept.pass.cpp @@ -45,11 +45,11 @@ int main() static_assert((std::is_same<decltype(std::move_if_noexcept(ci)), const int&&>::value), ""); static_assert((std::is_same<decltype(std::move_if_noexcept(a)), const A&>::value), ""); static_assert((std::is_same<decltype(std::move_if_noexcept(ca)), const A&>::value), ""); -#else +#else // _LIBCPP_MOVE static_assert((std::is_same<decltype(std::move_if_noexcept(i)), const int>::value), ""); static_assert((std::is_same<decltype(std::move_if_noexcept(ci)), const int>::value), ""); static_assert((std::is_same<decltype(std::move_if_noexcept(a)), const A>::value), ""); static_assert((std::is_same<decltype(std::move_if_noexcept(ca)), const A>::value), ""); -#endif +#endif // _LIBCPP_MOVE } diff --git a/libcxx/test/utilities/utility/forward/move_only.pass.cpp b/libcxx/test/utilities/utility/forward/move_only.pass.cpp index de12e3ff62c..56cba6fa1dd 100644 --- a/libcxx/test/utilities/utility/forward/move_only.pass.cpp +++ b/libcxx/test/utilities/utility/forward/move_only.pass.cpp @@ -17,20 +17,20 @@ class move_only #ifdef _LIBCPP_MOVE move_only(const move_only&); move_only& operator=(const move_only&); -#else +#else // _LIBCPP_MOVE move_only(move_only&); move_only& operator=(move_only&); -#endif +#endif // _LIBCPP_MOVE public: #ifdef _LIBCPP_MOVE move_only(move_only&&) {} move_only& operator=(move_only&&) {} -#else +#else // _LIBCPP_MOVE operator std::__rv<move_only> () {return std::__rv<move_only>(*this);} move_only(std::__rv<move_only>) {} -#endif +#endif // _LIBCPP_MOVE move_only() {} }; diff --git a/libcxx/test/utilities/utility/forward/move_only1.fail.cpp b/libcxx/test/utilities/utility/forward/move_only1.fail.cpp index 5c577d695e4..a6dbc7898cd 100644 --- a/libcxx/test/utilities/utility/forward/move_only1.fail.cpp +++ b/libcxx/test/utilities/utility/forward/move_only1.fail.cpp @@ -20,20 +20,20 @@ class move_only #ifdef _LIBCPP_MOVE move_only(const move_only&); move_only& operator=(const move_only&); -#else +#else // _LIBCPP_MOVE move_only(move_only&); move_only& operator=(move_only&); -#endif +#endif // _LIBCPP_MOVE public: #ifdef _LIBCPP_MOVE move_only(move_only&&) {} move_only& operator=(move_only&&) {} -#else +#else // _LIBCPP_MOVE operator std::__rv<move_only> () {return std::__rv<move_only>(*this);} move_only(std::__rv<move_only>) {} -#endif +#endif // _LIBCPP_MOVE move_only() {} }; diff --git a/libcxx/test/utilities/utility/forward/move_only2.fail.cpp b/libcxx/test/utilities/utility/forward/move_only2.fail.cpp index 6c50b4cfc59..2058d8481db 100644 --- a/libcxx/test/utilities/utility/forward/move_only2.fail.cpp +++ b/libcxx/test/utilities/utility/forward/move_only2.fail.cpp @@ -20,20 +20,20 @@ class move_only #ifdef _LIBCPP_MOVE move_only(const move_only&); move_only& operator=(const move_only&); -#else +#else // _LIBCPP_MOVE move_only(move_only&); move_only& operator=(move_only&); -#endif +#endif // _LIBCPP_MOVE public: #ifdef _LIBCPP_MOVE move_only(move_only&&) {} move_only& operator=(move_only&&) {} -#else +#else // _LIBCPP_MOVE operator std::__rv<move_only> () {return std::__rv<move_only>(*this);} move_only(std::__rv<move_only>) {} -#endif +#endif // _LIBCPP_MOVE move_only() {} }; diff --git a/libcxx/test/utilities/utility/forward/move_only3.fail.cpp b/libcxx/test/utilities/utility/forward/move_only3.fail.cpp index 105c19178ec..331f59f8f72 100644 --- a/libcxx/test/utilities/utility/forward/move_only3.fail.cpp +++ b/libcxx/test/utilities/utility/forward/move_only3.fail.cpp @@ -17,20 +17,20 @@ class move_only #ifdef _LIBCPP_MOVE move_only(const move_only&); move_only& operator=(const move_only&); -#else +#else // _LIBCPP_MOVE move_only(move_only&); move_only& operator=(move_only&); -#endif +#endif // _LIBCPP_MOVE public: #ifdef _LIBCPP_MOVE move_only(move_only&&) {} move_only& operator=(move_only&&) {} -#else +#else // _LIBCPP_MOVE operator std::__rv<move_only> () {return std::__rv<move_only>(*this);} move_only(std::__rv<move_only>) {} -#endif +#endif // _LIBCPP_MOVE move_only() {} }; diff --git a/libcxx/test/utilities/utility/forward/move_only4.fail.cpp b/libcxx/test/utilities/utility/forward/move_only4.fail.cpp index 10df3f57a54..99135b704e2 100644 --- a/libcxx/test/utilities/utility/forward/move_only4.fail.cpp +++ b/libcxx/test/utilities/utility/forward/move_only4.fail.cpp @@ -20,20 +20,20 @@ class move_only #ifdef _LIBCPP_MOVE move_only(const move_only&); move_only& operator=(const move_only&); -#else +#else // _LIBCPP_MOVE move_only(move_only&); move_only& operator=(move_only&); -#endif +#endif // _LIBCPP_MOVE public: #ifdef _LIBCPP_MOVE move_only(move_only&&) {} move_only& operator=(move_only&&) {} -#else +#else // _LIBCPP_MOVE operator std::__rv<move_only> () {return std::__rv<move_only>(*this);} move_only(std::__rv<move_only>) {} -#endif +#endif // _LIBCPP_MOVE move_only() {} }; diff --git a/libcxx/test/utilities/utility/pairs/pairs.pair/U_V.pass.cpp b/libcxx/test/utilities/utility/pairs/pairs.pair/U_V.pass.cpp index 6809c27cf60..814313bc644 100644 --- a/libcxx/test/utilities/utility/pairs/pairs.pair/U_V.pass.cpp +++ b/libcxx/test/utilities/utility/pairs/pairs.pair/U_V.pass.cpp @@ -26,5 +26,5 @@ int main() assert(*p.first == 3); assert(p.second == nullptr); } -#endif +#endif // _LIBCPP_MOVE } diff --git a/libcxx/test/utilities/utility/pairs/pairs.pair/assign_rv_pair.pass.cpp b/libcxx/test/utilities/utility/pairs/pairs.pair/assign_rv_pair.pass.cpp index bd82eb3fd6c..42ded4c563c 100644 --- a/libcxx/test/utilities/utility/pairs/pairs.pair/assign_rv_pair.pass.cpp +++ b/libcxx/test/utilities/utility/pairs/pairs.pair/assign_rv_pair.pass.cpp @@ -28,5 +28,5 @@ int main() assert(*p2.first == 3); assert(p2.second == 4); } -#endif +#endif // _LIBCPP_MOVE } diff --git a/libcxx/test/utilities/utility/pairs/pairs.pair/assign_rv_pair_U_V.pass.cpp b/libcxx/test/utilities/utility/pairs/pairs.pair/assign_rv_pair_U_V.pass.cpp index c0708c79d27..787f54b02cb 100644 --- a/libcxx/test/utilities/utility/pairs/pairs.pair/assign_rv_pair_U_V.pass.cpp +++ b/libcxx/test/utilities/utility/pairs/pairs.pair/assign_rv_pair_U_V.pass.cpp @@ -39,5 +39,5 @@ int main() assert(p2.first == nullptr); assert(p2.second == 4); } -#endif +#endif // _LIBCPP_MOVE } diff --git a/libcxx/test/utilities/utility/pairs/pairs.pair/make_pair.pass.cpp b/libcxx/test/utilities/utility/pairs/pairs.pair/make_pair.pass.cpp index 5b19a5fd3f0..b38655d36d0 100644 --- a/libcxx/test/utilities/utility/pairs/pairs.pair/make_pair.pass.cpp +++ b/libcxx/test/utilities/utility/pairs/pairs.pair/make_pair.pass.cpp @@ -36,5 +36,5 @@ int main() assert(p1.first == nullptr); assert(p1.second == 4); } -#endif +#endif // _LIBCPP_MOVE } diff --git a/libcxx/test/utilities/utility/pairs/pairs.pair/piecewise.pass.cpp b/libcxx/test/utilities/utility/pairs/pairs.pair/piecewise.pass.cpp index 6685166908b..45ba68a6ffb 100644 --- a/libcxx/test/utilities/utility/pairs/pairs.pair/piecewise.pass.cpp +++ b/libcxx/test/utilities/utility/pairs/pairs.pair/piecewise.pass.cpp @@ -31,5 +31,5 @@ int main() assert(p3.first == P1(3, nullptr)); assert(p3.second == P2(nullptr, 4)); } -#endif +#endif // _LIBCPP_HAS_NO_VARIADICS } diff --git a/libcxx/test/utilities/utility/pairs/pairs.pair/rv_pair_U_V.pass.cpp b/libcxx/test/utilities/utility/pairs/pairs.pair/rv_pair_U_V.pass.cpp index 13fbfe84b4a..f34fa9cb9a1 100644 --- a/libcxx/test/utilities/utility/pairs/pairs.pair/rv_pair_U_V.pass.cpp +++ b/libcxx/test/utilities/utility/pairs/pairs.pair/rv_pair_U_V.pass.cpp @@ -38,5 +38,5 @@ int main() assert(p2.first == nullptr); assert(p2.second == 4); } -#endif +#endif // _LIBCPP_MOVE } diff --git a/libcxx/test/utilities/utility/pairs/pairs.pair/types.pass.cpp b/libcxx/test/utilities/utility/pairs/pairs.pair/types.pass.cpp index 8ed4d1b7a18..deda5dbee02 100644 --- a/libcxx/test/utilities/utility/pairs/pairs.pair/types.pass.cpp +++ b/libcxx/test/utilities/utility/pairs/pairs.pair/types.pass.cpp @@ -15,7 +15,6 @@ // typedef T1 first_type; // typedef T2 second_type; - #include <utility> #include <type_traits> diff --git a/libcxx/test/utilities/utility/utility.swap/swap.pass.cpp b/libcxx/test/utilities/utility/utility.swap/swap.pass.cpp index e4c0f388ea6..067fb19055d 100644 --- a/libcxx/test/utilities/utility/utility.swap/swap.pass.cpp +++ b/libcxx/test/utilities/utility/utility.swap/swap.pass.cpp @@ -9,8 +9,8 @@ // <utility> -// template<class T> -// requires MoveAssignable<T> && MoveConstructible<T> +// template<class T> +// requires MoveAssignable<T> && MoveConstructible<T> // void // swap(T& a, T& b); @@ -42,7 +42,7 @@ test1() assert(*j == 1); } -#endif +#endif // _LIBCPP_MOVE int main() { diff --git a/libcxx/test/utilities/utility/utility.swap/swap_array.pass.cpp b/libcxx/test/utilities/utility/utility.swap/swap_array.pass.cpp index a8b351ebc5b..28d4dca7e45 100644 --- a/libcxx/test/utilities/utility/utility.swap/swap_array.pass.cpp +++ b/libcxx/test/utilities/utility/utility.swap/swap_array.pass.cpp @@ -9,8 +9,8 @@ // <utility> -// template<ValueType T, size_t N> -// requires Swappable<T> +// template<ValueType T, size_t N> +// requires Swappable<T> // void // swap(T (&a)[N], T (&b)[N]); @@ -54,7 +54,7 @@ test1() assert(*j[2] == 3); } -#endif +#endif // _LIBCPP_MOVE int main() { |