Add flag that forces custom stringification methods to be provided (#595)
* Add flag that forces custom stringification methods to be provided
* Add docs
diff --git a/doc/markdown/configuration.md b/doc/markdown/configuration.md
index 66655b3..b157e6b 100644
--- a/doc/markdown/configuration.md
+++ b/doc/markdown/configuration.md
@@ -12,6 +12,7 @@
- [**```DOCTEST_CONFIG_IMPLEMENTATION_IN_DLL```**](#doctest_config_implementation_in_dll)
- [**```DOCTEST_CONFIG_NO_SHORT_MACRO_NAMES```**](#doctest_config_no_short_macro_names)
- [**```DOCTEST_CONFIG_TREAT_CHAR_STAR_AS_STRING```**](#doctest_config_treat_char_star_as_string)
+- [**```DOCTEST_CONFIG_REQUIRE_STRINGIFICATION_FOR_ALL_USED_TYPES```**](#doctest_config_require_stringification_for_all_used_types)
- [**```DOCTEST_CONFIG_SUPER_FAST_ASSERTS```**](#doctest_config_super_fast_asserts)
- [**```DOCTEST_CONFIG_USE_STD_HEADERS```**](#doctest_config_use_std_headers)
- [**```DOCTEST_CONFIG_VOID_CAST_EXPRESSIONS```**](#doctest_config_void_cast_expressions)
@@ -81,6 +82,12 @@
This should be defined globally.
+### **```DOCTEST_CONFIG_REQUIRE_STRINGIFICATION_FOR_ALL_USED_TYPES```**
+
+By default if stringification is not available for a type, it is simply printed as `{?}`. By enabling this flag, whenever a type is used in an assert that does not provide stringification, the compilation is stopped.
+
+This can be defined both globally and in specific source files only.
+
### **```DOCTEST_CONFIG_SUPER_FAST_ASSERTS```**
This config option makes the assert macros (except for those dealing with exceptions) compile [**much faster**](benchmarks.md#cost-of-an-assertion-macro)! (31-91% - depending on the type - [**normal**](assertions.md#expression-decomposing-asserts) or [**binary**](assertions.md#binary-and-unary-asserts))
diff --git a/doctest/doctest.h b/doctest/doctest.h
index adcee29..6c292a1 100644
--- a/doctest/doctest.h
+++ b/doctest/doctest.h
@@ -896,6 +896,9 @@
struct StringMakerBase {
template <typename T>
static String convert(const DOCTEST_REF_WRAP(T)) {
+#ifdef DOCTEST_CONFIG_REQUIRE_STRINGIFICATION_FOR_ALL_USED_TYPES
+ static_assert(false, "No stringification detected for type T. See string conversion manual");
+#endif
return "{?}";
}
};
diff --git a/doctest/parts/doctest_fwd.h b/doctest/parts/doctest_fwd.h
index d387ecd..aa789af 100644
--- a/doctest/parts/doctest_fwd.h
+++ b/doctest/parts/doctest_fwd.h
@@ -893,6 +893,9 @@
struct StringMakerBase {
template <typename T>
static String convert(const DOCTEST_REF_WRAP(T)) {
+#ifdef DOCTEST_CONFIG_REQUIRE_STRINGIFICATION_FOR_ALL_USED_TYPES
+ static_assert(false, "No stringification detected for type T. See string conversion manual");
+#endif
return "{?}";
}
};