diff --git a/include/boost/none.hpp b/include/boost/none.hpp index db744e5..a37c45c 100644 --- a/include/boost/none.hpp +++ b/include/boost/none.hpp @@ -1,5 +1,5 @@ // Copyright (C) 2003, Fernando Luis Cacciola Carballal. -// Copyright (C) 2014 Andrzej Krzemienski. +// Copyright (C) 2014, 2015 Andrzej Krzemienski. // // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at diff --git a/include/boost/none_t.hpp b/include/boost/none_t.hpp index 608cb0c..fa73654 100644 --- a/include/boost/none_t.hpp +++ b/include/boost/none_t.hpp @@ -1,5 +1,5 @@ // Copyright (C) 2003, Fernando Luis Cacciola Carballal. -// Copyright (C) 2014 Andrzej Krzemienski. +// Copyright (C) 2014, 2015 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 diff --git a/include/boost/optional/detail/optional_config.hpp b/include/boost/optional/detail/optional_config.hpp index 45caff9..6e1fa8b 100644 --- a/include/boost/optional/detail/optional_config.hpp +++ b/include/boost/optional/detail/optional_config.hpp @@ -82,4 +82,18 @@ #endif // defined(__GNUC__) +#if defined(__GNUC__) +// On some initial rvalue reference implementations GCC does it in a strange way, +// preferring perfect-forwarding constructor to implicit copy constructor. + +# if (__GNUC__ == 4 && __GNUC_MINOR__ == 4) +# define BOOST_OPTIONAL_CONFIG_NO_PROPER_CONVERT_FROM_CONST_INT +# endif + +# if (__GNUC__ == 4 && __GNUC_MINOR__ == 5) +# define BOOST_OPTIONAL_CONFIG_NO_PROPER_CONVERT_FROM_CONST_INT +# endif + +#endif // defined(__GNUC__) + #endif // header guard diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 29faeba..765fe53 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -64,6 +64,8 @@ import testing ; [ run-fail optional_xconfig_NO_PROPER_ASSIGN_FROM_CONST_INT_fail.cpp ] [ run optional_xconfig_NO_PROPER_CONVERT_FROM_CONST_INT_pass.cpp ] [ run-fail optional_xconfig_NO_PROPER_CONVERT_FROM_CONST_INT_fail.cpp ] + [ run optional_xconfig_NO_LEGAL_CONVERT_FROM_REF_pass.cpp ] + [ compile-fail optional_xconfig_NO_LEGAL_CONVERT_FROM_REF_fail.cpp ] [ run optional_xconfig_HACK_TO_LIST_PREDEFINED_MACROS.cpp ] ; } diff --git a/test/optional_xconfig_HACK_TO_LIST_PREDEFINED_MACROS.cpp b/test/optional_xconfig_HACK_TO_LIST_PREDEFINED_MACROS.cpp index 561c843..f733bac 100644 --- a/test/optional_xconfig_HACK_TO_LIST_PREDEFINED_MACROS.cpp +++ b/test/optional_xconfig_HACK_TO_LIST_PREDEFINED_MACROS.cpp @@ -15,7 +15,7 @@ int main() { #if defined(__GNUC__) - int empty = 0; + int empty = -1; BOOST_TEST_EQ(empty, __GNUC__); BOOST_TEST_EQ(empty, __GNUC_MINOR__); BOOST_TEST_EQ(empty, __GNUC_PATCHLEVEL__); diff --git a/test/optional_xconfig_NO_LEGAL_CONVERT_FROM_REF_fail.cpp b/test/optional_xconfig_NO_LEGAL_CONVERT_FROM_REF_fail.cpp new file mode 100644 index 0000000..18d6c87 --- /dev/null +++ b/test/optional_xconfig_NO_LEGAL_CONVERT_FROM_REF_fail.cpp @@ -0,0 +1,37 @@ +// Copyright (C) 2015 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 + +#include "boost/core/ignore_unused.hpp" +#include "boost/core/lightweight_test.hpp" +#include "boost/optional/detail/optional_config.hpp" + +#ifndef BOOST_OPTIONAL_CONFIG_NO_LEGAL_CONVERT_FROM_REF + +static_assert(false, "failed as requested"); + +#else + +struct S {}; + +struct Binder +{ + S& ref_; + template Binder (R&&r) : ref_(r) {} +}; + +int main() +{ + S s ; + Binder b = s; + boost::ignore_unused(b); +} + +#endif diff --git a/test/optional_xconfig_NO_LEGAL_CONVERT_FROM_REF_pass.cpp b/test/optional_xconfig_NO_LEGAL_CONVERT_FROM_REF_pass.cpp new file mode 100644 index 0000000..be7d47c --- /dev/null +++ b/test/optional_xconfig_NO_LEGAL_CONVERT_FROM_REF_pass.cpp @@ -0,0 +1,41 @@ +// Copyright (C) 2015 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 + +#include "boost/core/ignore_unused.hpp" +#include "boost/core/lightweight_test.hpp" +#include "boost/optional/detail/optional_config.hpp" + +#ifndef BOOST_OPTIONAL_CONFIG_NO_LEGAL_CONVERT_FROM_REF + +struct S {}; + +struct Binder +{ + S& ref_; + template Binder (R&&r) : ref_(r) {} +}; + +int main() +{ + S s ; + Binder b = s; + boost::ignore_unused(b); + return 0; +} + +#else + +int main() +{ + return 0; +} + +#endif