Luk*_*rth 28 c++ language-lawyer clang++ c++17
这段代码不能在 Clang (6,7,8,9,trunk) 中编译,但在 GCC (7.1, 8.1, 9.1) 中编译得很好:
template<class T> struct TypeHolder { using type = T; };
template<int i>
class Outer {
private:
template<class T>
static constexpr auto compute_type() {
if constexpr (i == 42) {
return TypeHolder<bool>{};
} else {
return TypeHolder<T>{};
}
}
public:
template<class T>
using TheType = typename decltype(Outer<i>::compute_type<T>())::type;
};
int main() {
Outer<42>::TheType<int> i;
}
Run Code Online (Sandbox Code Playgroud)
叮当告诉我:
<source>:17:49: error: 'compute_type' is a private member of 'Outer<42>'
Run Code Online (Sandbox Code Playgroud)
......这当然是,但我尝试访问该成员中同一类。我不明白为什么它不应该在那里访问。我是否遇到了(我应该提交)Clang 错误?
您可以在Godbolt 的编译器资源管理器中玩弄代码。
| 归档时间: |
|
| 查看次数: |
590 次 |
| 最近记录: |