2014-10-07 14 views
5

Skompilowałem clang 3.6.0 (trunk 219085) i g++ 4.9.1. W celu skorzystania z prawa libstdc++ (6.0.20), a nie to, w moim systemie, mam te zmienne środowiskowe:Kompilowanie programu regex w języku clang dla libstdC++ w trybie C++ 14 powoduje błędy

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 

następujące wywołania praca:

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 

Ale C++ 14 tryb dla brzękiem nie pozwoli go skompilować:

clang++ -std=c++1y test.cpp 
clang++ -std=c++14 test.cpp 

faktycznie mogę odtworzyć ten problem na coliru (dzyń 3.5.0), więc nie sądzę, ten problem jest czysto mnie.

libstdc++ errors

libc++ no errors

komunikaty o błędach:

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() 

I kod testowy:

#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

Wohoo, możesz mi powiedzieć, jak brzmi 4.6.0, a także podać numery loterii na kilka następnych tygodni, tak jak mogłem, mając pewien wgląd w przyszłość ... Zgaduję, że masz na myśli klang 3.6.0, a może nawet 3.5.0? –

+0

@Mats LOL oops. –

Odpowiedz

5

To nie jest błąd klang. Jeśli już, to jest to błąd GCC/libstdC++. Odpowiednia funkcja jest

constexpr bool 
_M_end_of_seq() 
{ return _M_result == nullptr; } 

W 11, constexpr funkcji członka C++ są niejawnie const. W C++ 14 nie są. GCC obecnie nie wdraża tej zmiany w trybie C++ 14, dlatego Twój kod został skompilowany.

Powinieneś zgłosić błąd przeciwko libstdC++, a nie clang.

+5

Teraz naprawiony na bagażniku GCC i zostanie naprawiony dla wersji 4.9.2 –