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:
Antonio Sanchez 2021-03-17 14:18:50 -07:00 committed by Rasmus Munk Larsen
parent ed964ba3f1
commit c3fbc6cec7

View File

@ -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: