#include <functional>
#include <map>
#include <string>
#include <iostream>
class X
{
public:
X()
{
std::cout << "Ctor\n";
}
private:
typedef std::map<std::string, std::function<void()>> ValidatorType;
const ValidatorType m_validators = ValidatorType
{
{
"some-string",
[]()
{
std::cout << "Validating...\n";
}
}
};
};
int main()
{
std::cout << "Start...\n";
X x;
std::cout << "Complete...\n";
return 0;
}
The above code builds and runs successfully in debug and release mode on OS X using Xcode 7.2.1 and Clang 7.0.2.
It also works successfully and launches in release mode on Windows 7 using Visual Studio Express 2013 for Windows Desktop.
However, when crashing in debug mode in Windows, it crashes. Access violation occurs before the constructor completes execution. The console output is as follows:
Start...
Ctor
If initialization is m_validatorsmoved to the constructor initialization list, then the error disappears.
Could this be a compiler error or something wrong with the declaration?