Clang 3.5.0 std :: wregex编译错误

时间:2014-12-21 16:06:56

标签: c++ regex c++11 clang++

当我尝试创建一个宽正则表达式时,Clang打印出一个奇怪的错误(std :: wregex)

#include <regex>
#include <string>

int main() {
    std::wregex myRegex( L"Hello Regex" );
    return 0;
}

此代码使用g ++(--std = c ++ 11-Wall)编译时没有任何错误或警告,但是clang ++( - std = c ++ 11)会生成此错误:

In file included from test.cpp:1:
In file included from /usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../include/c++/4.9.2/regex:60:
/usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../include/c++/4.9.2/bits/regex_compiler.h:413:20: error: non-type template argument is not a constant expression
                                   std::bitset<1 << (8 * sizeof(_CharT))>,
                                               ^~~~~~~~~~~~~~~~~~~~~~~~~
/usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../include/c++/4.9.2/bits/regex_compiler.tcc:398:53: note: in instantiation of template class
      'std::__detail::_BracketMatcher<std::regex_traits<wchar_t>, false, false>' requested here
      _BracketMatcher<_TraitsT, __icase, __collate> __matcher
                                                    ^
/usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../include/c++/4.9.2/bits/regex_compiler.tcc:316:25: note: in instantiation of function template specialization
      'std::__detail::_Compiler<std::regex_traits<wchar_t> >::_M_insert_character_class_matcher<false, false>' requested here
        __INSERT_REGEX_MATCHER(_M_insert_character_class_matcher);
                               ^
/usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../include/c++/4.9.2/bits/regex_compiler.tcc:288:8: note: expanded from macro '__INSERT_REGEX_MATCHER'
              __func<false, false>(args);\
              ^
/usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../include/c++/4.9.2/bits/regex_compiler.tcc:136:17: note: in instantiation of member function
      'std::__detail::_Compiler<std::regex_traits<wchar_t> >::_M_atom' requested here
      if (this->_M_atom())
                ^
/usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../include/c++/4.9.2/bits/regex_compiler.tcc:118:17: note: in instantiation of member function
      'std::__detail::_Compiler<std::regex_traits<wchar_t> >::_M_term' requested here
      if (this->_M_term())
                ^
/usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../include/c++/4.9.2/bits/regex_compiler.tcc:97:13: note: in instantiation of member function
      'std::__detail::_Compiler<std::regex_traits<wchar_t> >::_M_alternative' requested here
      this->_M_alternative();
            ^
/usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../include/c++/4.9.2/bits/regex_compiler.tcc:82:13: note: in instantiation of member function
      'std::__detail::_Compiler<std::regex_traits<wchar_t> >::_M_disjunction' requested here
      this->_M_disjunction();
            ^
/usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../include/c++/4.9.2/bits/regex_compiler.h:155:14: note: in instantiation of member function
      'std::__detail::_Compiler<std::regex_traits<wchar_t> >::_Compiler' requested here
      return _Cmplr(__first, __last, __traits, __flags)._M_get_nfa();
             ^
/usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../include/c++/4.9.2/bits/regex.h:532:27: note: in instantiation of function template specialization
      'std::__detail::__compile_nfa<std::regex_traits<wchar_t> >' requested here
          _M_automaton(__detail::__compile_nfa(_M_original_str.c_str(),
                                 ^
/usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../include/c++/4.9.2/bits/regex.h:452:9: note: in instantiation of function template specialization 'std::basic_regex<wchar_t,
      std::regex_traits<wchar_t> >::basic_regex<const wchar_t *>' requested here
      : basic_regex(__p, __p + _Rx_traits::length(__p), __f)
        ^
test.cpp:5:17: note: in instantiation of member function 'std::basic_regex<wchar_t, std::regex_traits<wchar_t> >::basic_regex' requested here
    std::wregex myRegex( L"Hello Regex" );
                ^
/usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../include/c++/4.9.2/bits/regex_compiler.h:413:22: note: shift count 32 >= width of type 'int' (32 bits)
                                   std::bitset<1 << (8 * sizeof(_CharT))>,
                                                 ^
/usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../include/c++/4.9.2/bits/regex_compiler.h:413:20: error: non-type template argument is not a constant expression
                                   std::bitset<1 << (8 * sizeof(_CharT))>,
                                               ^~~~~~~~~~~~~~~~~~~~~~~~~
/usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../include/c++/4.9.2/bits/regex_compiler.tcc:398:53: note: in instantiation of template class
      'std::__detail::_BracketMatcher<std::regex_traits<wchar_t>, false, true>' requested here
      _BracketMatcher<_TraitsT, __icase, __collate> __matcher
                                                    ^
/usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../include/c++/4.9.2/bits/regex_compiler.tcc:316:25: note: in instantiation of function template specialization
      'std::__detail::_Compiler<std::regex_traits<wchar_t> >::_M_insert_character_class_matcher<false, true>' requested here
        __INSERT_REGEX_MATCHER(_M_insert_character_class_matcher);
                               ^
/usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../include/c++/4.9.2/bits/regex_compiler.tcc:290:8: note: expanded from macro '__INSERT_REGEX_MATCHER'
              __func<false, true>(args);\
              ^
/usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../include/c++/4.9.2/bits/regex_compiler.tcc:136:17: note: in instantiation of member function
      'std::__detail::_Compiler<std::regex_traits<wchar_t> >::_M_atom' requested here
      if (this->_M_atom())
                ^
/usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../include/c++/4.9.2/bits/regex_compiler.tcc:118:17: note: in instantiation of member function
      'std::__detail::_Compiler<std::regex_traits<wchar_t> >::_M_term' requested here
      if (this->_M_term())
                ^
/usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../include/c++/4.9.2/bits/regex_compiler.tcc:97:13: note: in instantiation of member function
      'std::__detail::_Compiler<std::regex_traits<wchar_t> >::_M_alternative' requested here
      this->_M_alternative();
            ^
/usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../include/c++/4.9.2/bits/regex_compiler.tcc:82:13: note: in instantiation of member function
      'std::__detail::_Compiler<std::regex_traits<wchar_t> >::_M_disjunction' requested here
      this->_M_disjunction();
            ^
/usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../include/c++/4.9.2/bits/regex_compiler.h:155:14: note: in instantiation of member function
      'std::__detail::_Compiler<std::regex_traits<wchar_t> >::_Compiler' requested here
      return _Cmplr(__first, __last, __traits, __flags)._M_get_nfa();
             ^
/usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../include/c++/4.9.2/bits/regex.h:532:27: note: in instantiation of function template specialization
      'std::__detail::__compile_nfa<std::regex_traits<wchar_t> >' requested here
          _M_automaton(__detail::__compile_nfa(_M_original_str.c_str(),
                                 ^
/usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../include/c++/4.9.2/bits/regex.h:452:9: note: in instantiation of function template specialization 'std::basic_regex<wchar_t,
      std::regex_traits<wchar_t> >::basic_regex<const wchar_t *>' requested here
      : basic_regex(__p, __p + _Rx_traits::length(__p), __f)
        ^
test.cpp:5:17: note: in instantiation of member function 'std::basic_regex<wchar_t, std::regex_traits<wchar_t> >::basic_regex' requested here
    std::wregex myRegex( L"Hello Regex" );
                ^
/usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../include/c++/4.9.2/bits/regex_compiler.h:413:22: note: shift count 32 >= width of type 'int' (32 bits)
                                   std::bitset<1 << (8 * sizeof(_CharT))>,
                                                 ^
/usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../include/c++/4.9.2/bits/regex_compiler.h:413:20: error: non-type template argument is not a constant expression
                                   std::bitset<1 << (8 * sizeof(_CharT))>,
                                               ^~~~~~~~~~~~~~~~~~~~~~~~~
/usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../include/c++/4.9.2/bits/regex_compiler.tcc:398:53: note: in instantiation of template class
      'std::__detail::_BracketMatcher<std::regex_traits<wchar_t>, true, false>' requested here
      _BracketMatcher<_TraitsT, __icase, __collate> __matcher
                                                    ^
/usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../include/c++/4.9.2/bits/regex_compiler.tcc:316:25: note: in instantiation of function template specialization
      'std::__detail::_Compiler<std::regex_traits<wchar_t> >::_M_insert_character_class_matcher<true, false>' requested here
        __INSERT_REGEX_MATCHER(_M_insert_character_class_matcher);
                               ^
/usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../include/c++/4.9.2/bits/regex_compiler.tcc:293:8: note: expanded from macro '__INSERT_REGEX_MATCHER'
              __func<true, false>(args);\
              ^
/usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../include/c++/4.9.2/bits/regex_compiler.tcc:136:17: note: in instantiation of member function
      'std::__detail::_Compiler<std::regex_traits<wchar_t> >::_M_atom' requested here
      if (this->_M_atom())
                ^
/usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../include/c++/4.9.2/bits/regex_compiler.tcc:118:17: note: in instantiation of member function
      'std::__detail::_Compiler<std::regex_traits<wchar_t> >::_M_term' requested here
      if (this->_M_term())
                ^
/usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../include/c++/4.9.2/bits/regex_compiler.tcc:97:13: note: in instantiation of member function
      'std::__detail::_Compiler<std::regex_traits<wchar_t> >::_M_alternative' requested here
      this->_M_alternative();
            ^
/usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../include/c++/4.9.2/bits/regex_compiler.tcc:82:13: note: in instantiation of member function
      'std::__detail::_Compiler<std::regex_traits<wchar_t> >::_M_disjunction' requested here
      this->_M_disjunction();
            ^
/usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../include/c++/4.9.2/bits/regex_compiler.h:155:14: note: in instantiation of member function
      'std::__detail::_Compiler<std::regex_traits<wchar_t> >::_Compiler' requested here
      return _Cmplr(__first, __last, __traits, __flags)._M_get_nfa();
             ^
/usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../include/c++/4.9.2/bits/regex.h:532:27: note: in instantiation of function template specialization
      'std::__detail::__compile_nfa<std::regex_traits<wchar_t> >' requested here
          _M_automaton(__detail::__compile_nfa(_M_original_str.c_str(),
                                 ^
/usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../include/c++/4.9.2/bits/regex.h:452:9: note: in instantiation of function template specialization 'std::basic_regex<wchar_t,
      std::regex_traits<wchar_t> >::basic_regex<const wchar_t *>' requested here
      : basic_regex(__p, __p + _Rx_traits::length(__p), __f)
        ^
test.cpp:5:17: note: in instantiation of member function 'std::basic_regex<wchar_t, std::regex_traits<wchar_t> >::basic_regex' requested here
    std::wregex myRegex( L"Hello Regex" );
                ^
/usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../include/c++/4.9.2/bits/regex_compiler.h:413:22: note: shift count 32 >= width of type 'int' (32 bits)
                                   std::bitset<1 << (8 * sizeof(_CharT))>,
                                                 ^
/usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../include/c++/4.9.2/bits/regex_compiler.h:413:20: error: non-type template argument is not a constant expression
                                   std::bitset<1 << (8 * sizeof(_CharT))>,
                                               ^~~~~~~~~~~~~~~~~~~~~~~~~
/usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../include/c++/4.9.2/bits/regex_compiler.tcc:398:53: note: in instantiation of template class
      'std::__detail::_BracketMatcher<std::regex_traits<wchar_t>, true, true>' requested here
      _BracketMatcher<_TraitsT, __icase, __collate> __matcher
                                                    ^
/usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../include/c++/4.9.2/bits/regex_compiler.tcc:316:25: note: in instantiation of function template specialization
      'std::__detail::_Compiler<std::regex_traits<wchar_t> >::_M_insert_character_class_matcher<true, true>' requested here
        __INSERT_REGEX_MATCHER(_M_insert_character_class_matcher);
                               ^
/usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../include/c++/4.9.2/bits/regex_compiler.tcc:295:8: note: expanded from macro '__INSERT_REGEX_MATCHER'
              __func<true, true>(args);\
              ^
/usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../include/c++/4.9.2/bits/regex_compiler.tcc:136:17: note: in instantiation of member function
      'std::__detail::_Compiler<std::regex_traits<wchar_t> >::_M_atom' requested here
      if (this->_M_atom())
                ^
/usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../include/c++/4.9.2/bits/regex_compiler.tcc:118:17: note: in instantiation of member function
      'std::__detail::_Compiler<std::regex_traits<wchar_t> >::_M_term' requested here
      if (this->_M_term())
                ^
/usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../include/c++/4.9.2/bits/regex_compiler.tcc:97:13: note: in instantiation of member function
      'std::__detail::_Compiler<std::regex_traits<wchar_t> >::_M_alternative' requested here
      this->_M_alternative();
            ^
/usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../include/c++/4.9.2/bits/regex_compiler.tcc:82:13: note: in instantiation of member function
      'std::__detail::_Compiler<std::regex_traits<wchar_t> >::_M_disjunction' requested here
      this->_M_disjunction();
            ^
/usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../include/c++/4.9.2/bits/regex_compiler.h:155:14: note: in instantiation of member function
      'std::__detail::_Compiler<std::regex_traits<wchar_t> >::_Compiler' requested here
      return _Cmplr(__first, __last, __traits, __flags)._M_get_nfa();
             ^
/usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../include/c++/4.9.2/bits/regex.h:532:27: note: in instantiation of function template specialization
      'std::__detail::__compile_nfa<std::regex_traits<wchar_t> >' requested here
          _M_automaton(__detail::__compile_nfa(_M_original_str.c_str(),
                                 ^
/usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../include/c++/4.9.2/bits/regex.h:452:9: note: in instantiation of function template specialization 'std::basic_regex<wchar_t,
      std::regex_traits<wchar_t> >::basic_regex<const wchar_t *>' requested here
      : basic_regex(__p, __p + _Rx_traits::length(__p), __f)
        ^
test.cpp:5:17: note: in instantiation of member function 'std::basic_regex<wchar_t, std::regex_traits<wchar_t> >::basic_regex' requested here
    std::wregex myRegex( L"Hello Regex" );
                ^
/usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../include/c++/4.9.2/bits/regex_compiler.h:413:22: note: shift count 32 >= width of type 'int' (32 bits)
                                   std::bitset<1 << (8 * sizeof(_CharT))>,
                                                 ^
4 errors generated.

GCC版本:4.9.2

锵:

clang version 3.5.0 (tags/RELEASE_350/final)
Target: x86_64-unknown-linux-gnu
Thread model: posix

这是一个clang bug还是clang需要一些额外的标题?正常的std :: regex适用于gcc和clang。

1 个答案:

答案 0 :(得分:0)

它已经在libstdc ++ trunk中修复,但没有向后移植到4.9。

https://gcc.gnu.org/viewcvs/gcc/trunk/libstdc++-v3/include/bits/regex_compiler.h?r1=211143&r2=211142&pathrev=211143

https://gcc.gnu.org/viewcvs/gcc/trunk/libstdc++-v3/include/bits/regex_compiler.h?r1=218322&r2=218321&pathrev=218322

这是因为1 << (8 * sizeof(_CharT))1 << 32(_CharT是wchar_t,这里是4字节大)并且它会导致未定义的行为,因为此处1具有类型int并且sizeof(int)是4。