summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoronqtam <vik.kirilov@gmail.com>2019-03-20 20:12:51 +0200
committeronqtam <vik.kirilov@gmail.com>2019-03-20 20:12:51 +0200
commit15953d3065f8962b0765fdc45f3a63d4af14c8a6 (patch)
tree840b504d44119636c52f15fef7c3338eb558fa0e
parent0682171e6b07500b939bf17c7e2ce424fdcc53c7 (diff)
unified config option for using standard includes instead of forward-declaring types from the std namespace
-rw-r--r--doc/markdown/configuration.md6
-rw-r--r--doc/markdown/faq.md2
-rw-r--r--doc/markdown/stringification.md2
-rw-r--r--doctest/parts/doctest_fwd.h43
4 files changed, 27 insertions, 26 deletions
diff --git a/doc/markdown/configuration.md b/doc/markdown/configuration.md
index 720051f..391c39e 100644
--- a/doc/markdown/configuration.md
+++ b/doc/markdown/configuration.md
@@ -14,7 +14,7 @@ Defining something ```globally``` means for every source file of the binary (exe
- [**```DOCTEST_CONFIG_NUM_CAPTURES_ON_STACK```**](#doctest_config_num_captures_on_stack)
- [**```DOCTEST_CONFIG_TREAT_CHAR_STAR_AS_STRING```**](#doctest_config_treat_char_star_as_string)
- [**```DOCTEST_CONFIG_SUPER_FAST_ASSERTS```**](#doctest_config_super_fast_asserts)
-- [**```DOCTEST_CONFIG_USE_IOSFWD```**](#doctest_config_use_iosfwd)
+- [**```DOCTEST_CONFIG_USE_STD_HEADERS```**](#doctest_config_use_std_headers)
- [**```DOCTEST_CONFIG_NO_COMPARISON_WARNING_SUPPRESSION```**](#doctest_config_no_comparison_warning_suppression)
- [**```DOCTEST_CONFIG_OPTIONS_PREFIX```**](#doctest_config_options_prefix)
- [**```DOCTEST_CONFIG_NO_UNPREFIXED_OPTIONS```**](#doctest_config_no_unprefixed_options)
@@ -101,9 +101,9 @@ It also implies [**```DOCTEST_CONFIG_NO_TRY_CATCH_IN_ASSERTS```**](#doctest_conf
This can be defined both globally and in specific source files only.
-### **```DOCTEST_CONFIG_USE_IOSFWD```**
+### **```DOCTEST_CONFIG_USE_STD_HEADERS```**
-The library by default provides a forward declaration of ```std::ostream``` in order to support the ```operator<<``` [**stringification**](stringification.md) mechanism. This is forbidden by the standard (even though it works everywhere on all tested compilers). However if the user wishes to be 100% standards compliant - then this configuration option can be used to force the inclusion of ```<iosfwd>```.
+The library by default provides a forward declaration of ```std::ostream``` in order to support the ```operator<<``` [**stringification**](stringification.md) mechanism (also ```std::tuple<>``` and ```std::nullptr_t```). This is forbidden by the standard (even though it works everywhere on all tested compilers). However if the user wishes to be 100% standards compliant - then this configuration option can be used to force the inclusion of the relevant standard headers.
Also it is possible that some STL implementation of a compiler with niche usage defines them differently - then there will be compilation errors in STL headers and using this option should fix the problem.
diff --git a/doc/markdown/faq.md b/doc/markdown/faq.md
index 93b6ebd..548ef69 100644
--- a/doc/markdown/faq.md
+++ b/doc/markdown/faq.md
@@ -136,7 +136,7 @@ Yes - but they can be disabled - see the [**```DOCTEST_CONFIG_NO_EXCEPTIONS```**
### Why do I get compiler errors in STL headers when including the doctest header?
-Try using the [**```DOCTEST_CONFIG_USE_IOSFWD```**](configuration.md#doctest_config_use_iosfwd) configuration identifier.
+Try using the [**```DOCTEST_CONFIG_USE_STD_HEADERS```**](configuration.md#doctest_config_use_std_headers) configuration identifier.
### Can different versions of the framework be used within the same binary (executable/dll)?
diff --git a/doc/markdown/stringification.md b/doc/markdown/stringification.md
index dc0224f..4ce7538 100644
--- a/doc/markdown/stringification.md
+++ b/doc/markdown/stringification.md
@@ -86,7 +86,7 @@ You could also [override the translation mechanism](https://github.com/catchorg/
- Check out the [**example**](../../examples/all_features/stringification.cpp) which shows how to stringify ```std::vector<T>``` and other types/exceptions.
- Note that the type ```String``` is used when specializing ```StringMaker<T>``` or overloading ```toString()``` - it is the string type **doctest** works with. ```std::string``` is not an option because doctest would have to include the ```<string>``` header.
-- To support the ```operator<<(std::ostream&...``` stringification the library has to offer a forward declaration of ```std::ostream``` and that is what the library does - but it is forbidden by the standard. It currently works everywhere - on all tested compilers - but if the user wishes to be 100% standards compliant - then the [**```DOCTEST_CONFIG_USE_IOSFWD```**](configuration.md#doctest_config_use_iosfwd) identifier can be used to force the inclusion of ```<iosfwd>```. The reason the header is not included by default is that on MSVC (for example) it drags a whole bunch of stuff with it - and after the preprocessor is finished the translation unit has grown to 42k lines of C++ code - while Clang and the libc++ are so well implemented that including ```<iosfwd>``` there results in 400 lines of code.
+- To support the ```operator<<(std::ostream&...``` stringification the library has to offer a forward declaration of ```std::ostream``` and that is what the library does - but it is forbidden by the standard. It currently works everywhere - on all tested compilers - but if the user wishes to be 100% standards compliant - then the [**```DOCTEST_CONFIG_USE_STD_HEADERS```**](configuration.md#doctest_config_use_std_headers) identifier can be used to force the inclusion of ```<iosfwd>```. The reason the header is not included by default is that on MSVC (for example) it drags a whole bunch of stuff with it - and after the preprocessor is finished the translation unit has grown to 42k lines of C++ code - while Clang and the libc++ are so well implemented that including ```<iosfwd>``` there results in 400 lines of code.
---
diff --git a/doctest/parts/doctest_fwd.h b/doctest/parts/doctest_fwd.h
index e201ec8..14c8a2c 100644
--- a/doctest/parts/doctest_fwd.h
+++ b/doctest/parts/doctest_fwd.h
@@ -360,20 +360,33 @@ extern "C" __declspec(dllimport) void __stdcall DebugBreak();
#define DOCTEST_BREAK_INTO_DEBUGGER() ((void)0)
#endif // linux
+// this is kept here for backwards compatibility since the config option was changed
+#ifdef DOCTEST_CONFIG_USE_IOSFWD
+#define DOCTEST_CONFIG_USE_STD_HEADERS
+#endif // DOCTEST_CONFIG_USE_IOSFWD
+
+#ifdef DOCTEST_CONFIG_USE_STD_HEADERS
+#include <iosfwd>
+#include <cstddef>
+#else // DOCTEST_CONFIG_USE_STD_HEADERS
+
#if DOCTEST_CLANG
// to detect if libc++ is being used with clang (the _LIBCPP_VERSION identifier)
#include <ciso646>
#endif // clang
+#ifdef _LIBCPP_VERSION
+#define DOCTEST_STD_NAMESPACE_BEGIN _LIBCPP_BEGIN_NAMESPACE_STD
+#define DOCTEST_STD_NAMESPACE_END _LIBCPP_END_NAMESPACE_STD
+#else // _LIBCPP_VERSION
+#define DOCTEST_STD_NAMESPACE_BEGIN namespace std {
+#define DOCTEST_STD_NAMESPACE_END }
+#endif // _LIBCPP_VERSION
+
// Forward declaring 'X' in namespace std is not permitted by the C++ Standard.
DOCTEST_MSVC_SUPPRESS_WARNING_WITH_PUSH(4643)
-#if defined(DOCTEST_CONFIG_USE_IOSFWD)
-#include <iosfwd>
-#endif // DOCTEST_CONFIG_USE_IOSFWD
-
-#ifdef _LIBCPP_VERSION
-_LIBCPP_BEGIN_NAMESPACE_STD
+DOCTEST_STD_NAMESPACE_BEGIN
typedef decltype(nullptr) nullptr_t;
template <class charT>
struct char_traits;
@@ -384,24 +397,12 @@ class basic_ostream;
typedef basic_ostream<char, char_traits<char>> ostream;
template <class... Types>
class tuple;
-_LIBCPP_END_NAMESPACE_STD
-#else // _LIBCPP_VERSION
-namespace std {
-typedef decltype(nullptr) nullptr_t;
-template <class charT>
-struct char_traits;
-template <>
-struct char_traits<char>;
-template <class charT, class traits>
-class basic_ostream;
-typedef basic_ostream<char, char_traits<char>> ostream;
-template <class... Types>
-class tuple;
-} // namespace std
-#endif // _LIBCPP_VERSION
+DOCTEST_STD_NAMESPACE_END
DOCTEST_MSVC_SUPPRESS_WARNING_POP
+#endif // DOCTEST_CONFIG_USE_STD_HEADERS
+
#ifdef DOCTEST_CONFIG_INCLUDE_TYPE_TRAITS
#include <type_traits>
#endif // DOCTEST_CONFIG_INCLUDE_TYPE_TRAITS