c++ - 无法在其 type-id 表达式中实例化包含 lambda 作为模板参数的别名模板
问题描述
考虑以下 C++20 代码:
template <class T>
struct TypeWrapper {};
template <auto F>
struct NonTypeWrapper {};
namespace using_value {
using alias = NonTypeWrapper<42>;
using user = TypeWrapper<alias>; //Ok
}
namespace using_value_with_template {
template <bool B>
using alias = NonTypeWrapper<42>;
template <bool B>
using user = TypeWrapper<alias<B>>; //Ok
}
namespace using_lambda {
using alias = NonTypeWrapper<[] () {}>;
using user = TypeWrapper<alias>; //Ok
}
namespace using_lambda_with_template {
template <bool B>
using alias = NonTypeWrapper<[] () {}>;
template <bool B>
using user = TypeWrapper<alias<B>>; //error: template argument 1 is invalid
}
(编译器-浏览器:https ://godbolt.org/z/bWGhn6PWW )
GCC 无法编译此代码并出现以下错误:
<source>:32:37: error: template argument 1 is invalid
32 | using user = TypeWrapper<alias<B>>; //error: template argument 1 is invalid
|
Clang 还不支持 lambdas 作为模板参数,所以我只能使用 GCC。
两个问题:
有什么理由不能实例化包含 lambdas 作为其类型 ID 表达式中的模板参数的别名模板,还是 GCC 错误?
为什么 GCC 会打印出如此无益的信息?编译器不应该至少给我们一个关于为什么参数无效的线索吗?
解决方案
推荐阅读
- c# - 通过尝试从肥皂服务检索数据,HTTP 请求未经授权
- angular - Angular:根据单选按钮值更改更改复选框的选中状态
- c# - 是否有 CMD 或 C# 的命令来查找特定文件,然后将该文件复制到其他文件夹?
- tensorflow - FCN 训练和测试期间的不同图像尺寸
- android - 尝试编译 Cordova 时,会出现这样的错误
- python - 将字典值传递给散列函数
- node.js - 有没有办法点击无头镀铬?
- linux - 使用带有模式映射的外部文件替换模式后的行
- javascript - 为什么我的函数被多次调用,而我按下只调用一次函数的按钮?
- sql-server - 需要帮助创建一个限制数量超过特定数量的触发器