我编译了clang 3.6.0 (trunk 219085)和g++ 4.9.1。为了使用正确的libstdc++
(6.0.20),而不是我系统中的那个,我有这些环境变量:
set -x LD_LIBRARY_PATH /home/remyabel/gcc-4.9.1/x86_64-unknown-linux-gnu/libstdc++-v3/src/.libs /usr/local/lib
set -x PATH ~/install/gcc-4.9.1/bin /home/remyabel/llvm/build/Release+Asserts/bin /home/remyabel/llvm/build/Release+Asserts/lib $PATH
以下调用有效:
g++4.9 -std=c++11 test.cpp
g++4.9 -std=c++1y test.cpp
g++4.9 -std=c++14 test.cpp
clang++ -std=c++11 test.cpp
但clang的C ++ 14模式不会让它编译:
clang++ -std=c++1y test.cpp
clang++ -std=c++14 test.cpp
我实际上可以在coliru(clang 3.5.0)上重现这个问题,所以我不认为这个问题纯粹是我。
错误讯息:
In file included from main.cpp:4:
In file included from /usr/local/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.9.0/../../../../include/c++/4.9.0/regex:58:
In file included from /usr/local/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.9.0/../../../../include/c++/4.9.0/bits/regex.h:2721:
/usr/local/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.9.0/../../../../include/c++/4.9.0/bits/regex.tcc:632:11: error: member function '_M_end_of_seq' not viable: 'this' argument has type 'const std::regex_token_iterator<__gnu_cxx::__normal_iterator<const char *, std::basic_string<char> >, char, std::regex_traits<char> >', but function is not marked const
if (_M_end_of_seq() && __rhs._M_end_of_seq())
^~~~~~~~~~~~~
/usr/local/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.9.0/../../../../include/c++/4.9.0/bits/regex.h:2641:24: note: in instantiation of member function 'std::regex_token_iterator<__gnu_cxx::__normal_iterator<const char *, std::basic_string<char> >, char, std::regex_traits<char> >::operator==' requested here
{ return !(*this == __rhs); }
^
/usr/local/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.9.0/../../../../include/c++/4.9.0/bits/stl_algobase.h:305:19: note: in instantiation of member function 'std::regex_token_iterator<__gnu_cxx::__normal_iterator<const char *, std::basic_string<char> >, char, std::regex_traits<char> >::operator!=' requested here
for (; __first != __last; ++__result, ++__first)
^
/usr/local/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.9.0/../../../../include/c++/4.9.0/bits/stl_algobase.h:396:36: note: in instantiation of function template specialization 'std::__copy_move<false, false, std::forward_iterator_tag>::__copy_m<std::regex_token_iterator<__gnu_cxx::__normal_iterator<const char *, std::basic_string<char> >, char, std::regex_traits<char> >, std::ostream_iterator<std::basic_string<char>, char, std::char_traits<char> > >' requested here
_Category>::__copy_m(__first, __last, __result);
^
/usr/local/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.9.0/../../../../include/c++/4.9.0/bits/stl_algobase.h:432:23: note: in instantiation of function template specialization 'std::__copy_move_a<false, std::regex_token_iterator<__gnu_cxx::__normal_iterator<const char *, std::basic_string<char> >, char, std::regex_traits<char> >, std::ostream_iterator<std::basic_string<char>, char, std::char_traits<char> > >' requested here
return _OI(std::__copy_move_a<_IsMove>(std::__niter_base(__first),
^
/usr/local/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.9.0/../../../../include/c++/4.9.0/bits/stl_algobase.h:464:20: note: in instantiation of function template specialization 'std::__copy_move_a2<false, std::regex_token_iterator<__gnu_cxx::__normal_iterator<const char *, std::basic_string<char> >, char, std::regex_traits<char> >, std::ostream_iterator<std::basic_string<char>, char, std::char_traits<char> > >' requested here
return (std::__copy_move_a2<__is_move_iterator<_II>::__value>
^
main.cpp:13:9: note: in instantiation of function template specialization 'std::copy<std::regex_token_iterator<__gnu_cxx::__normal_iterator<const char *, std::basic_string<char> >, char, std::regex_traits<char> >, std::ostream_iterator<std::basic_string<char>, char, std::char_traits<char> > >' requested here
std::copy( std::sregex_token_iterator(text.begin(), text.end(), ws_re, -1),
^
/usr/local/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.9.0/../../../../include/c++/4.9.0/bits/regex.h:2690:7: note: '_M_end_of_seq' declared here
_M_end_of_seq()
^
In file included from main.cpp:4:
In file included from /usr/local/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.9.0/../../../../include/c++/4.9.0/regex:58:
In file included from /usr/local/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.9.0/../../../../include/c++/4.9.0/bits/regex.h:2721:
/usr/local/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.9.0/../../../../include/c++/4.9.0/bits/regex.tcc:637:11: error: member function '_M_end_of_seq' not viable: 'this' argument has type 'const std::regex_token_iterator<__gnu_cxx::__normal_iterator<const char *, std::basic_string<char> >, char, std::regex_traits<char> >', but function is not marked const
if (_M_end_of_seq() || _M_suffix.matched
^~~~~~~~~~~~~
/usr/local/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.9.0/../../../../include/c++/4.9.0/bits/regex.h:2690:7: note: '_M_end_of_seq' declared here
_M_end_of_seq()
测试代码:
#include <iostream>
#include <algorithm>
#include <iterator>
#include <regex>
int main()
{
std::string text = "Quick brown fox.";
// tokenization (non-matched fragments)
// Note that regex is matched only two times: when the third value is obtained
// the iterator is a suffix iterator.
std::regex ws_re("\\s+"); // whitespace
std::copy( std::sregex_token_iterator(text.begin(), text.end(), ws_re, -1),
std::sregex_token_iterator(),
std::ostream_iterator<std::string>(std::cout, "\n"));
// iterating the first submatches
std::string html = "<p><a href=\"http://google.com\">google</a> "
"< a HREF =\"http://cppreference.com\">cppreference</a>\n</p>";
std::regex url_re("<\\s*A\\s+[^>]*href\\s*=\\s*\"([^\"]*)\"", std::regex::icase);
std::copy( std::sregex_token_iterator(html.begin(), html.end(), url_re, 1),
std::sregex_token_iterator(),
std::ostream_iterator<std::string>(std::cout, "\n"));
}
答案 0 :(得分:5)
这不是一个铿锵的错误。如果有的话,它是一个GCC / libstdc ++错误。相关功能是
constexpr bool
_M_end_of_seq()
{ return _M_result == nullptr; }
在C ++ 11中,constexpr
成员函数隐式const
。在C ++ 14中,它们不是。 GCC目前还没有在C ++ 14模式下实现这一变化,这就是你的代码编译的原因。
你应该提交针对libstdc ++的错误,而不是clang。