mirror of
https://gitlab.com/libeigen/eigen.git
synced 2024-12-27 07:29:52 +08:00
Use singleton pattern for static registered tests.
The original fails with nvcc+msvc - there's a static order of initialization issue leading to registered tests being cleared. The test then fails on ``` VERIFY(EigenTest::all().size()>0); ``` since `EigenTest` no longer contains any tests. The singleton pattern fixes this.
This commit is contained in:
parent
ed964ba3f1
commit
c3fbc6cec7
12
test/main.h
12
test/main.h
@ -177,20 +177,22 @@ namespace Eigen
|
||||
EigenTest(const char* a_name, void (*func)(void))
|
||||
: m_name(a_name), m_func(func)
|
||||
{
|
||||
ms_registered_tests.push_back(this);
|
||||
get_registered_tests().push_back(this);
|
||||
}
|
||||
const std::string& name() const { return m_name; }
|
||||
void operator()() const { m_func(); }
|
||||
|
||||
static const std::vector<EigenTest*>& all() { return ms_registered_tests; }
|
||||
static const std::vector<EigenTest*>& all() { return get_registered_tests(); }
|
||||
protected:
|
||||
static std::vector<EigenTest*>& get_registered_tests()
|
||||
{
|
||||
static std::vector<EigenTest*>* ms_registered_tests = new std::vector<EigenTest*>();
|
||||
return *ms_registered_tests;
|
||||
}
|
||||
std::string m_name;
|
||||
void (*m_func)(void);
|
||||
static std::vector<EigenTest*> ms_registered_tests;
|
||||
};
|
||||
|
||||
std::vector<EigenTest*> EigenTest::ms_registered_tests;
|
||||
|
||||
// Declare and register a test, e.g.:
|
||||
// EIGEN_DECLARE_TEST(mytest) { ... }
|
||||
// will create a function:
|
||||
|
Loading…
Reference in New Issue
Block a user