Skip to content

Commit 6b61b1a

Browse files
DiamonDinoiaserge-sans-paille
authored andcommitted
fix: avoid per-instantiation vtable issues with MinGW GCC in doctest
Replace INFO() macro calls with concrete StringContextScope class to work around MinGW GCC generating a unique vtable per template instantiation. INFO() creates ContextScope<Lambda> which triggers this issue; the concrete class has a single vtable definition shared across all instantiations. - Add StringContextScope struct inheriting from doctest::detail::ContextScopeBase - Add make_context_info() helper to create context without template lambdas - Update CHECK_BATCH_EQ, CHECK_SCALAR_EQ, CHECK_VECTOR_EQ macros to use new helper
1 parent 5a7d696 commit 6b61b1a

File tree

1 file changed

+30
-10
lines changed

1 file changed

+30
-10
lines changed

test/test_utils.hpp

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -386,27 +386,47 @@ namespace detail
386386
b.store_unaligned(dst.data() + i);
387387
}
388388

389+
// Non-template context scope to avoid per-instantiation vtable issues with MinGW GCC.
390+
// INFO() creates a ContextScope<Lambda> with a unique vtable per template instantiation.
391+
// This concrete class has a single vtable definition shared across all instantiations.
392+
struct StringContextScope : doctest::detail::ContextScopeBase
393+
{
394+
std::string msg_;
395+
explicit StringContextScope(std::string msg)
396+
: msg_(std::move(msg))
397+
{
398+
}
399+
void stringify(std::ostream* os) const override { *os << msg_; }
400+
};
401+
402+
template <class T>
403+
StringContextScope make_context_info(const char* name, const T& val)
404+
{
405+
return StringContextScope(std::string(name) + ":" + doctest::toString(val).c_str());
406+
}
389407
}
390408

391-
#define CHECK_BATCH_EQ(b1, b2) \
392-
do \
393-
{ \
394-
INFO(#b1 ":", b1); \
395-
INFO(#b2 ":", b2); \
396-
CHECK_UNARY(::detail::expect_batch_near(b1, b2)); \
409+
// Use make_context_info instead of INFO() to avoid MinGW GCC vtable issues
410+
// (see StringContextScope above).
411+
#define CHECK_BATCH_EQ(b1, b2) \
412+
do \
413+
{ \
414+
auto _ctx1 = ::detail::make_context_info(#b1, b1); \
415+
auto _ctx2 = ::detail::make_context_info(#b2, b2); \
416+
CHECK_UNARY(::detail::expect_batch_near(b1, b2)); \
397417
} while (0)
398418
#define CHECK_SCALAR_EQ(s1, s2) \
399419
do \
400420
{ \
401-
INFO(#s1 ":", s1); \
402-
INFO(#s2 ":", s2); \
421+
auto _ctx1 = ::detail::make_context_info(#s1, s1); \
422+
auto _ctx2 = ::detail::make_context_info(#s2, s2); \
403423
CHECK_UNARY(::detail::expect_scalar_near(s1, s2)); \
404424
} while (0)
405425
#define CHECK_VECTOR_EQ(v1, v2) \
406426
do \
407427
{ \
408-
INFO(#v1 ":", v1); \
409-
INFO(#v2 ":", v2); \
428+
auto _ctx1 = ::detail::make_context_info(#v1, v1); \
429+
auto _ctx2 = ::detail::make_context_info(#v2, v2); \
410430
CHECK_UNARY(::detail::expect_vector_near(v1, v2)); \
411431
} while (0)
412432

0 commit comments

Comments
 (0)