在C ++ 14模式下使用Clang为libstdc ++编译正则表达式程序会导致错误

用户名

我编译了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)上重现此问题,所以我认为这个问题并不是我自己。

libstdc++ errors

libc++ no errors

错误讯息:

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"));
}
TC

这不是叮当的错误。如果有的话,这是一个GCC / libstdc ++错误。相关功能是

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

在C ++ 11中,constexpr成员函数是隐式的const在C ++ 14中,它们不是。GCC当前未在C ++ 14模式下实现此更改,因此才编译代码。

您应该针对libstdc ++(而不是clang)提交错误。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

使用正则表达式时C ++程序崩溃

来自分类Dev

与BaseSpider一起使用的正则表达式会导致CrawlSpider错误

来自分类Dev

C ++中的正则表达式编译错误

来自分类Dev

C ++使用正则表达式搜索“正则表达式运算符”

来自分类Dev

C ++正则表达式子字符串发现错误模式

来自分类Dev

C ++正则表达式子字符串发现错误模式

来自分类Dev

使用正则表达式MongoDB C#驱动程序进行过滤

来自分类Dev

C ++ Clang无法解析此正则表达式

来自分类Dev

C#使用正则表达式读取日志文件中的错误

来自分类Dev

C#排除正则表达式模式

来自分类Dev

C ++中的多行正则表达式模式

来自分类Dev

C ++正则表达式:多行替换模式

来自分类Dev

C#中的正则表达式模式问题

来自分类Dev

C#正则表达式以匹配目录模式

来自分类Dev

C#正则表达式模式

来自分类Dev

C#正则表达式查找变量模式

来自分类Dev

C ++ 11正则表达式模式匹配

来自分类Dev

C ++正则表达式:多行替换模式

来自分类Dev

C ++正则表达式错误

来自分类Dev

Objective-C正则表达式为“(空)”

来自分类Dev

使用C#查找日期的正则表达式

来自分类Dev

使用正则表达式C#验证密码

来自分类Dev

如何使用正则表达式C ++?

来自分类Dev

使用C ++正则表达式,结果太慢

来自分类Dev

在C中使用POSIX正则表达式

来自分类Dev

在C中使用正则表达式

来自分类Dev

正则表达式,使用C#查找日期

来自分类Dev

使用C ++正则表达式和太慢的结果

来自分类Dev

使用变量n正则表达式c#