Reputation:
I compiled clang 3.6.0 (trunk 219085) and g++ 4.9.1. In order to use the right libstdc++
(6.0.20), and not the one in my system, I have these environment variables:
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
The following invocations work:
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
But C++14 mode for clang won't let it compile:
clang++ -std=c++1y test.cpp
clang++ -std=c++14 test.cpp
I can actually reproduce this problem on coliru (clang 3.5.0), so I don't think this issue is purely me.
Error messages:
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()
And the test code:
#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"));
}
Upvotes: 5
Views: 1201
Reputation: 137425
This isn't a clang bug. If anything, it's a GCC/libstdc++ bug. The relevant function is
constexpr bool
_M_end_of_seq()
{ return _M_result == nullptr; }
In C++11, constexpr
member functions are implicitly const
. In C++14, they are not. GCC doesn't currently implement this change in C++14 mode, which is why your code compiled.
You should be filing a bug against libstdc++, not clang.
Upvotes: 5