From bb1f3d690af6a5a450e866134e80bfc1b4b8019c Mon Sep 17 00:00:00 2001 From: Daniel James Date: Sat, 9 Jul 2011 17:13:39 +0000 Subject: [PATCH 1/3] Detail: More pessimistic `container_fwd.hpp` Have a separate config stage, which by default disables forward declaration of containers. Also add a test to check that if it is disabled correctly. Removed forward declaration of std::pair - since it's almost always included by ``. [SVN r72990] --- include/boost/detail/container_fwd.hpp | 89 +++++++++++++------ test/Jamfile | 2 + test/container_fwd/Jamfile | 22 +++++ .../container_fwd_test.cpp | 0 .../container_no_fwd_test.cpp | 0 test/container_fwd/correctly_disable_fail.cpp | 43 +++++++++ 6 files changed, 131 insertions(+), 25 deletions(-) create mode 100644 test/container_fwd/Jamfile rename test/{ => container_fwd}/container_fwd_test.cpp (100%) rename test/{ => container_fwd}/container_no_fwd_test.cpp (100%) create mode 100644 test/container_fwd/correctly_disable_fail.cpp diff --git a/include/boost/detail/container_fwd.hpp b/include/boost/detail/container_fwd.hpp index 1a58935..037fec7 100644 --- a/include/boost/detail/container_fwd.hpp +++ b/include/boost/detail/container_fwd.hpp @@ -1,25 +1,76 @@ -// Copyright 2005-2008 Daniel James. +// Copyright 2005-2011 Daniel James. // 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) +// Note: if you change this include guard, you also need to change +// container_fwd_compile_fail.cpp #if !defined(BOOST_DETAIL_CONTAINER_FWD_HPP) #define BOOST_DETAIL_CONTAINER_FWD_HPP -#if defined(_MSC_VER) && (_MSC_VER >= 1020) +#if defined(_MSC_VER) && (_MSC_VER >= 1020) && \ + !defined(BOOST_DETAIL_TEST_CONFIG_ONLY) # pragma once #endif #include #include -#if defined(BOOST_DETAIL_NO_CONTAINER_FWD) \ - || ((defined(__GLIBCPP__) || defined(__GLIBCXX__)) \ - && (defined(_GLIBCXX_DEBUG) || defined(_GLIBCXX_PARALLEL))) \ - || BOOST_WORKAROUND(__BORLANDC__, > 0x551) \ - || BOOST_WORKAROUND(__DMC__, BOOST_TESTED_AT(0x842)) \ - || (defined(__SGI_STL_PORT) || defined(_STLPORT_VERSION)) \ - || (defined(_LIBCPP_VERSION)) +#if !defined(BOOST_DETAIL_NO_CONTAINER_FWD) +# if defined(__SGI_STL_PORT) || defined(_STLPORT_VERSION) + // STLport +# define BOOST_DETAIL_NO_CONTAINER_FWD +# elif defined(__LIBCOMO__) + // Comeau STL: +# define BOOST_DETAIL_NO_CONTAINER_FWD +# elif defined(__STD_RWCOMPILER_H__) || defined(_RWSTD_VER) + // Rogue Wave library: +# define BOOST_DETAIL_NO_CONTAINER_FWD +# elif defined(_LIBCPP_VERSION) + // libc++ +# define BOOST_DETAIL_NO_CONTAINER_FWD +# elif defined(__GLIBCPP__) || defined(__GLIBCXX__) + // GNU libstdc++ 3 +# if defined(_GLIBCXX_DEBUG) || defined(_GLIBCXX_PARALLEL) +# define BOOST_DETAIL_NO_CONTAINER_FWD +# endif +# elif defined(__STL_CONFIG_H) + // generic SGI STL + // + // Forward declaration seems to be okay, but it has a copule of odd + // implementations. +# define BOOST_CONTAINER_FWD_BAD_BITSET +# if !defined(__STL_NON_TYPE_TMPL_PARAM_BUG) +# define BOOST_CONTAINER_FWD_BAD_DEQUE +# endif +# elif defined(__MSL_CPP__) + // MSL standard lib: +# define BOOST_DETAIL_NO_CONTAINER_FWD +# elif defined(__IBMCPP__) + // take the default VACPP std lib +# define BOOST_DETAIL_NO_CONTAINER_FWD +# elif defined(MSIPL_COMPILE_H) + // Modena C++ standard library +# define BOOST_DETAIL_NO_CONTAINER_FWD +# elif (defined(_YVALS) && !defined(__IBMCPP__)) || defined(_CPPLIB_VER) + // Dinkumware Library (this has to appear after any possible replacement + // libraries) + // + // Works fine. +# else +# define BOOST_DETAIL_NO_CONTAINER_FWD +# endif +#endif + +// BOOST_DETAIL_TEST_* macros are for testing only +// and shouldn't be relied upon. But you can use +// BOOST_DETAIL_NO_CONTAINER_FWD to prevent forward +// declaration of containers. + +#if !defined(BOOST_DETAIL_TEST_CONFIG_ONLY) + +#if defined(BOOST_DETAIL_NO_CONTAINER_FWD) && \ + !defined(BOOST_DETAIL_TEST_FORCE_CONTAINER_FWD) #include #include @@ -34,17 +85,6 @@ #include -#if !defined(__SGI_STL_PORT) && !defined(_STLPORT_VERSION) && \ - defined(__STL_CONFIG_H) - -#define BOOST_CONTAINER_FWD_BAD_BITSET - -#if !defined(__STL_NON_TYPE_TMPL_PARAM_BUG) -#define BOOST_CONTAINER_FWD_BAD_DEQUE -#endif - -#endif - #if defined(BOOST_CONTAINER_FWD_BAD_DEQUE) #include #endif @@ -74,11 +114,7 @@ namespace std #else template class complex; #endif -} -// gcc 3.4 and greater -namespace std -{ #if !defined(BOOST_CONTAINER_FWD_BAD_DEQUE) template class deque; #endif @@ -101,6 +137,9 @@ namespace std #pragma warning(pop) #endif -#endif +#endif // BOOST_DETAIL_NO_CONTAINER_FWD && + // !defined(BOOST_DETAIL_TEST_FORCE_CONTAINER_FWD) + +#endif // BOOST_DETAIL_TEST_CONFIG_ONLY #endif diff --git a/test/Jamfile b/test/Jamfile index 9413621..59c0a8d 100644 --- a/test/Jamfile +++ b/test/Jamfile @@ -5,6 +5,8 @@ # file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) ################################################################################ +build-project container_fwd ; + project detail/test : requirements clang:-Wno-unused diff --git a/test/container_fwd/Jamfile b/test/container_fwd/Jamfile new file mode 100644 index 0000000..dc49d62 --- /dev/null +++ b/test/container_fwd/Jamfile @@ -0,0 +1,22 @@ + +# Copyright 2011 Daniel James. +# 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) + +import testing ; + +project detail/test/container_fwd + : requirements + all + intel:on + gcc:"-pedantic -Wstrict-aliasing -fstrict-aliasing -Wextra -Wsign-promo -Wunused-parameter -Wconversion" + darwin:"-pedantic -Wstrict-aliasing -fstrict-aliasing -Wextra -Wsign-promo -Wunused-parameter -Wconversion" + on + ; + +run container_fwd_test.cpp : : : release : container_fwd_release ; +run container_fwd_test.cpp : : : debug : container_fwd_debug ; +run container_no_fwd_test.cpp ; + +compile-fail correctly_disable_fail.cpp : release : correctly_disable_release ; +compile-fail correctly_disable_fail.cpp : debug : correctly_disable_debug ; diff --git a/test/container_fwd_test.cpp b/test/container_fwd/container_fwd_test.cpp similarity index 100% rename from test/container_fwd_test.cpp rename to test/container_fwd/container_fwd_test.cpp diff --git a/test/container_no_fwd_test.cpp b/test/container_fwd/container_no_fwd_test.cpp similarity index 100% rename from test/container_no_fwd_test.cpp rename to test/container_fwd/container_no_fwd_test.cpp diff --git a/test/container_fwd/correctly_disable_fail.cpp b/test/container_fwd/correctly_disable_fail.cpp new file mode 100644 index 0000000..2301686 --- /dev/null +++ b/test/container_fwd/correctly_disable_fail.cpp @@ -0,0 +1,43 @@ + +// Copyright 2011 Daniel James. +// 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) + +// This tests if container forwarding is correctly disabled. If it isn't +// disabled it causes a compile error (which causes the test to pass). +// If it is disabled it tries container forwarding. If it doesn't work +// then there will be a compile error, indicating that it is correctly +// disabled. But if there isn't a compile error that indicates that +// container forwarding might work. +// +// Since this test only tries std::vector, it might get it wrong but I didn't +// want it to fail because of some incompatibility with a trickier class. + +#define BOOST_DETAIL_TEST_CONFIG_ONLY +#include + +#if !defined(BOOST_DETAIL_NO_CONTAINER_FWD) +#error "Failing in order to pass test" +#else +#define BOOST_DETAIL_TEST_FORCE_CONTAINER_FWD + +#undef BOOST_DETAIL_CONTAINER_FWD_HPP +#undef BOOST_DETAIL_TEST_CONFIG_ONLY + +#include + +template +void test(std::vector const&) +{ +} + +#include + +int main () +{ + std::vector x; + test(x); +} + +#endif + From e87588af6abdaaad21d29f54893de0c65d52c898 Mon Sep 17 00:00:00 2001 From: Daniel James Date: Sun, 10 Jul 2011 13:15:08 +0000 Subject: [PATCH 2/3] Detail: test container_fwd for debug version of standard library. [SVN r72996] --- test/container_fwd/Jamfile | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/test/container_fwd/Jamfile b/test/container_fwd/Jamfile index dc49d62..3581521 100644 --- a/test/container_fwd/Jamfile +++ b/test/container_fwd/Jamfile @@ -14,9 +14,13 @@ project detail/test/container_fwd on ; -run container_fwd_test.cpp : : : release : container_fwd_release ; -run container_fwd_test.cpp : : : debug : container_fwd_debug ; run container_no_fwd_test.cpp ; +run container_fwd_test.cpp : : : : container_fwd ; +run container_fwd_test.cpp : : + : _STLP_DEBUG _GLIBCXX_DEBUG + : container_fwd_debug ; -compile-fail correctly_disable_fail.cpp : release : correctly_disable_release ; -compile-fail correctly_disable_fail.cpp : debug : correctly_disable_debug ; +compile-fail correctly_disable_fail.cpp : : correctly_disable ; +compile-fail correctly_disable_fail.cpp + : _STLP_DEBUG _GLIBCXX_DEBUG + : correctly_disable_debug ; From 8a12de16a4fe1029ef2f441f23db8e3ee0c1c8b2 Mon Sep 17 00:00:00 2001 From: Daniel James Date: Thu, 14 Jul 2011 09:47:51 +0000 Subject: [PATCH 3/3] Detail: Turn off warnings as errors for compile-fail tests. The test shouldn't succeed because the compile failed because of a warning. [SVN r73096] --- test/container_fwd/Jamfile | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/container_fwd/Jamfile b/test/container_fwd/Jamfile index 3581521..b39d447 100644 --- a/test/container_fwd/Jamfile +++ b/test/container_fwd/Jamfile @@ -20,7 +20,9 @@ run container_fwd_test.cpp : : : _STLP_DEBUG _GLIBCXX_DEBUG : container_fwd_debug ; -compile-fail correctly_disable_fail.cpp : : correctly_disable ; compile-fail correctly_disable_fail.cpp - : _STLP_DEBUG _GLIBCXX_DEBUG + : off + : correctly_disable ; +compile-fail correctly_disable_fail.cpp + : off _STLP_DEBUG _GLIBCXX_DEBUG : correctly_disable_debug ;