【发布时间】:2021-12-20 07:31:00
【问题描述】:
在我的世界里,StrictNodeType 应该是定义 PredContainer 和 SuccContainer 类型的任何东西,所以我写了
template<typename N>
concept StrictNodeType = requires {
typename N::PredContainer;
typename N::SuccContainer;
};
但是,GCC-11.2 给了我以下错误:
error: satisfaction of atomic constraint 'requires{typename N::PredContainer;typename N::SuccContainer;} [with N = typename std::remove_cvref<_Tp>::type::Node]' depends on itself
164 | concept StrictNodeType = requires {
| ^~~~~~~~~~
165 | typename N::PredContainer;
| ~~~~~~~~~~~~~~~~~~~~~~~~~~
166 | typename N::SuccContainer;something;
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
167 | };
这怎么可能?为什么 GCC 不能简单地检查给定类型并检查它是否提供了请求的子类型?
这是一个最小的破坏示例:
#include <type_traits>
template<typename N>
concept StrictNodeType = requires {
typename N::something;
};
template<StrictNodeType N> using Int = int;
template<int>
struct X {using type = Int<X>; };
using ThisBreaks = Int<X<0>>;
【问题讨论】:
-
没有一个最小的例子,这个问题几乎没有用,因为很难猜出你没有提供的代码。
-
GCC 11.2 compiles this code without error。你能在edit这个问题中加入minimal reproducible example吗?
-
好吧,我的意思是,不应该有 任何代码 会产生此错误,因为无论其他代码如何,
StrictNodeType不会 依赖于自己。 -
@igel: "不管其余的代码" 很明显这很重要,因为你是唯一得到错误的人。
-
部分错误被截断。另外,即使不是因为这个错误,代码仍然是无效的,因为这个概念不会被满足。
标签: c++ c++20 c++-concepts