相关疑难解决方法(0)

简单的std :: regex_search()代码不能用Apple clang ++ -std = c ++ 14编译

这是MCVE:

#include <iostream>
#include <regex>

std::string s()
{
    return "test";
}

int main()
{
    static const std::regex regex(R"(\w)");
    std::smatch smatch;

    if (std::regex_search(s(), smatch, regex)) {
        std::cout << smatch[0] << std::endl;
    }

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

编译很好:

$ clang ++ -std = c ++ 11 main.cpp

但不是:

$ clang ++ -std = c ++ 14 main.cpp

后一种情况下的错误消息(使用-std = c ++ 14):

main.cpp:14:9: error: call to deleted function 'regex_search'
    if (std::regex_search(s(), smatch, regex)) {
        ^~~~~~~~~~~~~~~~~
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/regex:5998:1: note: 
      candidate function [with _ST = std::__1::char_traits<char>, …
Run Code Online (Sandbox Code Playgroud)

c++ c++11 clang++ c++14

14
推荐指数
2
解决办法
1897
查看次数

标签 统计

c++ ×1

c++11 ×1

c++14 ×1

clang++ ×1