gcc - Red Hat 上的 GCC 8.3.1-3 在具有使用模板参数的静态函数的模板类上失败
问题描述
在 RedHat 7 上使用 devtoolset-8 时:
[eftlab@49af022e5a7c git]$ which g++
/opt/rh/devtoolset-8/root/usr/bin/g++
[eftlab@49af022e5a7c git]$ /opt/rh/devtoolset-8/root/usr/bin/g++ --version
g++ (GCC) 8.3.1 20190311 (Red Hat 8.3.1-3)
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
[eftlab@49af022e5a7c git]$
我遇到了一个我想验证的错误:
#include <iostream>
#include <functional>
template<class ParentT>
class OpenSession {
public:
std::function<void()> Run() {
auto parent = parent_;
return [parent](std::function<void()> onSuccess, std::function<void()> onReject) mutable {
std::function<void()> toRun = [](){};
RunCallback(parent, toRun);
};
}
void RunCallback(std::function<void()>& toRun) {}
private:
ParentT* parent_ = nullptr;
static void RunCallback(ParentT* parent, std::function<void()>& toRun) {}
};
int main(int, const char**) {
return 0;
}
编译它g++ -std=c++17 test.cpp
,我得到以下错误:
test.cpp: In lambda function:
test.cpp:13:32: error: 'this' was not captured for this lambda function
RunCallback(parent, toRun);
^
在我看来,当 lambda 捕获正在检查其参数时,它看起来像在模板类中,它不知道这里有对模板函数的引用,这让我重命名了我的方法,因为即使更改为OpenSession<ParentT>::RunCallback(parent, toRun);
编译器仍然看不到我真正指的是静态函数。有没有人有任何很棒的编译器标志可以调整这个或任何其他建议?谢谢
解决方案
推荐阅读
- f# - “无效约束:用于约束的类型是密封的”无效
- visual-studio - 无法再打包 Android 项目,因为我激活了 Proguard
- c++ - 从 .txt 文件读取数据并放入向量时,Linux 比 Windows 快得多。我将如何加速 Windows 来做同样的事情?
- database - 将 WordPress localhost 数据库部署到实时服务器
- jquery - 阻止联系表单发送网址
- javascript - Fullpage.js 通过向下滚动水平滚动并在一个部分再次完成水平滚动后向下滚动?
- python - 如果满足特定条件,则从 DataFrame 中删除行
- alexa - 拦截 Google Assistant 或 Alexa 上的语音命令
- c# - 开发 ViewModel 以在 WPF 视图和旧的不可观察数据类型之间进行接口
- javascript - 使用 ReactJS 从同级组件调用方法