From 2fbec91fe86ce6733d4ff7ca2039fb7b236ae5ab Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Tue, 10 Jun 2014 03:31:28 +0300 Subject: [PATCH] Add negative tests for cref() and rvalues. --- test/Jamfile.v2 | 2 ++ test/ref_rv_fail4.cpp | 23 +++++++++++++++++++++++ test/ref_rv_fail5.cpp | 27 +++++++++++++++++++++++++++ 3 files changed, 52 insertions(+) create mode 100644 test/ref_rv_fail4.cpp create mode 100644 test/ref_rv_fail5.cpp diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index f34efe4..d88d6cb 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -22,6 +22,8 @@ run ref_test.cpp ; compile-fail ref_rv_fail1.cpp ; compile-fail ref_rv_fail2.cpp ; compile-fail ref_rv_fail3.cpp ; +compile-fail ref_rv_fail4.cpp ; +compile-fail ref_rv_fail5.cpp ; compile-fail ref_implicit_fail.cpp ; compile-fail ref_implicit_fail2.cpp ; diff --git a/test/ref_rv_fail4.cpp b/test/ref_rv_fail4.cpp new file mode 100644 index 0000000..7f49123 --- /dev/null +++ b/test/ref_rv_fail4.cpp @@ -0,0 +1,23 @@ +// +// Test that an rvalue can't be passed to cref() +// +// Copyright 2014 Agustin Berge +// Copyright 2014 Peter Dimov +// +// Distributed under the Boost Software License, Version 1.0. +// See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt +// + +#include + +#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) + +int main() +{ + boost::reference_wrapper r = boost::cref( 2 ); // should fail +} + +#else +# error To fail, this test requires rvalue references. +#endif diff --git a/test/ref_rv_fail5.cpp b/test/ref_rv_fail5.cpp new file mode 100644 index 0000000..84bc467 --- /dev/null +++ b/test/ref_rv_fail5.cpp @@ -0,0 +1,27 @@ +// +// Test that a const rvalue can't be passed to cref() +// +// Copyright 2014 Agustin Berge +// Copyright 2014 Peter Dimov +// +// Distributed under the Boost Software License, Version 1.0. +// See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt +// + +#include + +#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) + +struct X {}; + +X const crv() { return X(); } + +int main() +{ + boost::reference_wrapper r = boost::cref( crv() ); // must fail +} + +#else +# error To fail, this test requires rvalue references. +#endif