exception translators written in header files now register only one entry - fixed #98
diff --git a/doctest/doctest.h b/doctest/doctest.h
index 3bbffd6..f26c711 100644
--- a/doctest/doctest.h
+++ b/doctest/doctest.h
@@ -2316,11 +2316,11 @@
// for registering exception translators
#define DOCTEST_REGISTER_EXCEPTION_TRANSLATOR_IMPL(translatorName, signature) \
- static doctest::String translatorName(signature); \
+ inline doctest::String translatorName(signature); \
DOCTEST_GLOBAL_NO_WARNINGS(DOCTEST_ANONYMOUS(_DOCTEST_ANON_TRANSLATOR_)) = \
doctest::registerExceptionTranslator(translatorName); \
DOCTEST_GLOBAL_NO_WARNINGS_END() \
- static doctest::String translatorName(signature)
+ doctest::String translatorName(signature)
#define DOCTEST_REGISTER_EXCEPTION_TRANSLATOR(signature) \
DOCTEST_REGISTER_EXCEPTION_TRANSLATOR_IMPL(DOCTEST_ANONYMOUS(_DOCTEST_ANON_TRANSLATOR_), \
@@ -4295,7 +4295,9 @@
}
void registerExceptionTranslatorImpl(const IExceptionTranslator* translateFunction) {
- getExceptionTranslators().push_back(translateFunction);
+ if(std::find(getExceptionTranslators().begin(), getExceptionTranslators().end(),
+ translateFunction) == getExceptionTranslators().end())
+ getExceptionTranslators().push_back(translateFunction);
}
String translateActiveException() {
diff --git a/doctest/parts/doctest_fwd.h b/doctest/parts/doctest_fwd.h
index 03e1595..023cc41 100644
--- a/doctest/parts/doctest_fwd.h
+++ b/doctest/parts/doctest_fwd.h
@@ -2313,11 +2313,11 @@
// for registering exception translators
#define DOCTEST_REGISTER_EXCEPTION_TRANSLATOR_IMPL(translatorName, signature) \
- static doctest::String translatorName(signature); \
+ inline doctest::String translatorName(signature); \
DOCTEST_GLOBAL_NO_WARNINGS(DOCTEST_ANONYMOUS(_DOCTEST_ANON_TRANSLATOR_)) = \
doctest::registerExceptionTranslator(translatorName); \
DOCTEST_GLOBAL_NO_WARNINGS_END() \
- static doctest::String translatorName(signature)
+ doctest::String translatorName(signature)
#define DOCTEST_REGISTER_EXCEPTION_TRANSLATOR(signature) \
DOCTEST_REGISTER_EXCEPTION_TRANSLATOR_IMPL(DOCTEST_ANONYMOUS(_DOCTEST_ANON_TRANSLATOR_), \
diff --git a/doctest/parts/doctest_impl.h b/doctest/parts/doctest_impl.h
index 76720f5..30f7189 100644
--- a/doctest/parts/doctest_impl.h
+++ b/doctest/parts/doctest_impl.h
@@ -1104,7 +1104,9 @@
}
void registerExceptionTranslatorImpl(const IExceptionTranslator* translateFunction) {
- getExceptionTranslators().push_back(translateFunction);
+ if(std::find(getExceptionTranslators().begin(), getExceptionTranslators().end(),
+ translateFunction) == getExceptionTranslators().end())
+ getExceptionTranslators().push_back(translateFunction);
}
String translateActiveException() {