From 6a790e0c9781db4c47d1bf8b679b7526539e8eee Mon Sep 17 00:00:00 2001 From: Andrzej Krzemienski Date: Mon, 5 May 2014 19:08:11 +0200 Subject: [PATCH] Added a test that tests the compiler if references are bound correctly. Also added the second copyright notice. --- .../a_note_about_optional_bool_.html | 2 +- doc/html/boost_optional/acknowledgments.html | 2 +- .../dependencies_and_portability.html | 2 +- .../boost_optional/detailed_semantics.html | 2 +- doc/html/boost_optional/development.html | 2 +- doc/html/boost_optional/examples.html | 2 +- .../exception_safety_guarantees.html | 2 +- .../boost_optional/implementation_notes.html | 2 +- .../boost_optional/in_place_factories.html | 2 +- .../boost_optional/optional_references.html | 2 +- ...for_assignment_of_optional_references.html | 2 +- doc/html/boost_optional/synopsis.html | 2 +- .../boost_optional/type_requirements.html | 2 +- doc/html/index.html | 3 +- doc/optional.qbk | 1 + include/boost/optional/optional.hpp | 2 + test/Jamfile.v2 | 1 + test/optional_test_the_compiler.cpp | 108 ++++++++++++++++++ 18 files changed, 127 insertions(+), 14 deletions(-) create mode 100644 test/optional_test_the_compiler.cpp diff --git a/doc/html/boost_optional/a_note_about_optional_bool_.html b/doc/html/boost_optional/a_note_about_optional_bool_.html index c9f3a78..272a894 100644 --- a/doc/html/boost_optional/a_note_about_optional_bool_.html +++ b/doc/html/boost_optional/a_note_about_optional_bool_.html @@ -70,7 +70,7 @@ -
-
-
-
-
-
-
-
-
-
-
-
-
+

Distributed under the Boost Software License, Version 1.0. (See accompanying @@ -163,7 +164,7 @@

- +

Last revised: April 29, 2014 at 20:56:30 GMT

Last revised: May 05, 2014 at 07:44:56 GMT


diff --git a/doc/optional.qbk b/doc/optional.qbk index fc65f14..d5608be 100644 --- a/doc/optional.qbk +++ b/doc/optional.qbk @@ -2,6 +2,7 @@ [quickbook 1.4] [authors [Cacciola Carballal, Fernando Luis]] [copyright 2003-2007 Fernando Luis Cacciola Carballal] + [copyright 2014 Andrzej Krzemieński] [category miscellaneous] [id optional] [dirname optional] diff --git a/include/boost/optional/optional.hpp b/include/boost/optional/optional.hpp index 0a01141..0849e90 100644 --- a/include/boost/optional/optional.hpp +++ b/include/boost/optional/optional.hpp @@ -1,4 +1,5 @@ // Copyright (C) 2003, 2008 Fernando Luis Cacciola Carballal. +// Copyright (C) 2014 Andrzej Krzemienski. // // Use, modification, and distribution is subject to the Boost Software // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at @@ -11,6 +12,7 @@ // // Revisions: // 27 Apr 2008 (improved swap) Fernando Cacciola, Niels Dekker, Thorsten Ottosen +// 05 May 2014 (Added move semantics) Andrzej Krzemienski // #ifndef BOOST_OPTIONAL_OPTIONAL_FLC_19NOV2002_HPP #define BOOST_OPTIONAL_OPTIONAL_FLC_19NOV2002_HPP diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 7218ffa..d9137bd 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -23,6 +23,7 @@ import testing ; [ run optional_test_io.cpp ] [ run optional_test_move.cpp ] [ run optional_test_equals_none.cpp ] + [ run optional_test_the_compiler.cpp ] [ compile-fail optional_test_fail1.cpp ] [ compile-fail optional_test_fail3a.cpp ] [ compile-fail optional_test_fail3b.cpp ] diff --git a/test/optional_test_the_compiler.cpp b/test/optional_test_the_compiler.cpp new file mode 100644 index 0000000..dea10cb --- /dev/null +++ b/test/optional_test_the_compiler.cpp @@ -0,0 +1,108 @@ +// Copyright (C) 2014 Andrzej Krzemienski. +// +// Use, modification, and distribution is subject to 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) +// +// See http://www.boost.org/lib/optional for documentation. +// +// You are welcome to contact the author at: +// akrzemi1@gmail.com +// +// Revisions: +// +#include +#include +//#include + +#define BOOST_ENABLE_ASSERT_HANDLER + +//#include "boost/bind/apply.hpp" // Included just to test proper interaction with boost::apply<> as reported by Daniel Wallin +#include "boost/mpl/bool.hpp" +#include "boost/mpl/bool_fwd.hpp" // For mpl::true_ and mpl::false_ +#include "boost/static_assert.hpp" + +#include "boost/optional/optional.hpp" + +#ifdef __BORLANDC__ +#pragma hdrstop +#endif + +#include "boost/test/minimal.hpp" +#include "optional_test_common.cpp" + + +const int global_i = 0; + +class TestingReferenceBinding +{ +public: + TestingReferenceBinding(const int& ii) + { + BOOST_CHECK(&ii == &global_i); + } + + void operator=(const int& ii) + { + BOOST_CHECK(&ii == &global_i); + } + #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES + void operator=(int&&) + { + BOOST_CHECK(false); + } + #endif +}; + +class TestingReferenceBinding2 // same definition as above, I need a different type +{ +public: + TestingReferenceBinding2(const int& ii) + { + BOOST_CHECK(&ii == &global_i); + } + + void operator=(const int& ii) + { + BOOST_CHECK(&ii == &global_i); + } + #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES + void operator=(int&&) + { + BOOST_CHECK(false); + } + #endif +}; + + +void test_broken_compiler() +{ +// we are not testing boost::optional here, but the c++ compiler +// if this test fails, optional references will obviously fail too + + const int& iref = global_i; + BOOST_CHECK(&iref == &global_i); + + TestingReferenceBinding ttt = global_i; + ttt = global_i; + + TestingReferenceBinding2 ttt2 = iref; + ttt2 = iref; +} + + +int test_main( int, char* [] ) +{ + try + { + test_broken_compiler(); + } + catch ( ... ) + { + BOOST_ERROR("Unexpected Exception caught!"); + } + + return 0; +} + +