今天把一些VS 2005工程升级到VS 2010,在升级过程中,遇到regex库编译错误。如下:

error C2332: 'struct' : missing tag name
error C3306: 'regex::detail::': unnamed class template is not allowed
error C2143: syntax error : missing ';' before 'static_assert'
error C2059: syntax error : ';'

  出现该错误的代码来自restack.h,如下:

namespace detail
{

// For compile-time assertions that generate
// no run-time overhead.
template< bool f > struct static_assert;
template   struct static_assert { static_assert() {} };

  该问题的原因是regex定义的static_assert模板与VS 2010的关键字冲突,将regex中的改名,比如改成_static_assert后就正常了。

  参考资料: