2014-10-07 20 views
5

Tôi đã biên dịch clang 3.6.0 (trunk 219085)g++ 4.9.1. Để sử dụng quyền libstdc++ (6.0.20), và không phải là một trong hệ thống của tôi, tôi có các biến môi trường:Biên dịch chương trình regex trong tiếng kêu cho libstdC++ trong chế độ C++ 14 gây ra lỗi

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 

Các lời gọi sau đây làm việc:

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 

Nhưng C++ 14 chế độ cho clang sẽ không cho phép nó biên dịch:

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

Tôi thực sự có thể tái tạo vấn đề này trên coliru (clang 3.5.0), vì vậy tôi không nghĩ vấn đề này hoàn toàn là tôi.

libstdc++ errors

libc++ no errors

Thông báo lỗi:

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

Và mã kiểm tra:

#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, bạn có thể cho tôi biết clang 4.6.0 là gì không, và cũng cung cấp cho chúng tôi số xổ số trong vài tuần tới, như tôi có thể hiểu rõ hơn về tương lai ... 3.6.0 hoặc thậm chí là 3.5.0? –

+0

@Mats LOL oops. –

Trả lời

5

Đây không phải là một lỗi clang. Nếu có, đó là lỗi GCC/libstdC++. Chức năng liên quan là

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

Trong C++ 11, constexpr chức năng thành viên hoàn toàn là const. Trong C++ 14, chúng không có. GCC hiện không thực hiện thay đổi này trong chế độ C++ 14, đó là lý do tại sao mã của bạn được biên dịch.

Bạn nên gửi lỗi chống libstdC++, chứ không phải clang.

+5

Bây giờ cố định trên thân GCC, và sẽ được cố định cho 4.9.2 –

Các vấn đề liên quan