【发布时间】:2017-12-18 07:25:35
【问题描述】:
我最近遇到了这样的代码问题:
constexpr auto lambda = []{};
template<auto& l>
struct Lambda {};
template<auto& l>
void test(Lambda<l>) {}
int main() {
test(Lambda<lambda>{});
}
clang 和 GCC 都告诉它不能推断出l。
但是,如果我在那里添加 const:
// ----v
template<const auto& l>
void test(Lambda<l>) {}
然后一切都与clang一起工作。 GCC 仍然失败。这里发生了什么事?不能自己推断const吗?在这两种情况下都没有推断出 l 是 GCC 错误吗?
【问题讨论】:
标签: c++ templates language-lawyer c++17 template-argument-deduction