TBB 编译器错误 -"my_task":必须初始化引用



我在项目中的多个地方使用TBB。但是似乎自从我将Visual Studio从15.6.X(X是最新版本(更新到15.7.1以来,我在几个地方都遇到了编译器错误,告诉我

[...]tbb\task_group.h(94(: 错误 C2530:"my_task": 必须初始化引用

查看引用的代码 (tbb/task_group.h(:

//! Base class for types that should not be assigned.
class no_assign {
// Deny assignment
void operator=( const no_assign& );
public:
#if __GNUC__
//! Explicitly define default construction, because otherwise gcc issues gratuitous warning.
no_assign() {}
#endif /* __GNUC__ */
};
//! Base class for types that should not be copied or assigned.
class no_copy: no_assign {
//! Deny copy construction
no_copy( const no_copy& );
public:
//! Allow default construction
no_copy() {}
};
// ...
class ref_count_guard : internal::no_copy {
task& my_task;  // compiler error occurs here
public:
ref_count_guard( task& t ) : my_task(t) {
my_task.increment_ref_count();
}
~ref_count_guard() {
my_task.decrement_ref_count();
}
};

我不明白为什么编译器在那里抱怨,因为引用是由构造函数初始化的。在我的代码中发现问题也不是那么容易,因为编译器错误发生在每个使用 TBB 的源文件中,我认为自从上次成功编译以来我没有改变任何东西(除了更新 VS(。

我想到的一种可能性与这个问题有关。如果 msvc 默认以某种方式继承基类构造函数,则将继承解释错误的默认构造函数。但是测试这个场景似乎反驳了它(随着代码的编译(。

为什么 msvc 在这里抱怨?

更新

这个最小的示例在我的系统上重现了错误:

#include <vector>
#include <tbb/tbb.h>
#include <tbb/flow_graph.h>       
void main()
{
std::vector<int> src{1, 2, 3, 4, 5};
tbb::parallel_for_each(src.begin(), src.end(), [](int) { });
}

更新 2

看起来只包括tbb/tbb.h会导致错误发生。我什至不需要打电话。使用新的编译器版本重建 tbb 也无济于事。

编辑

github上的交叉问题。

只需删除/permissive- (例如,在 C/C++ 选项中将一致性模式设置为否(就可以解决此问题。 我想英特尔很快就会解决这个问题。

当使用/permissive-选项时,这是一个编译器错误。可以使用以下代码重现它:

struct U {
template<typename T>
void foo() {
class A {
int& iref;
public:
A(int& ir) : iref(ir) { }
};
int the_answer = 42;
A a(the_answer);
}
};
int main() {
U u;
u.foo<int>();
return 0;
}

该代码完全有效,C++合规。如您所见,引用在构造函数的成员初始值设定项列表中显式初始化。这也似乎是VS中的回归,因为至少VS 2017(15.0.something(的初始版本使用/permissive-编译了此代码。

最新更新