【发布时间】:2023-03-24 21:39:01
【问题描述】:
我在 Windows 上编译此代码时遇到问题。
这段代码可以在 Linux 上正确编译,无论是使用 clang 还是 gcc。我正在使用 msvc 19.29。
Msvc 退出并出现不太有用的错误 C1001。
struct Object{};
class Storage {
Object &createObject() {
qStorrage.push_back(Object{});
return qStorrage.back();
}
template <class... Objs>
void deleteObject(const Objs&...obj)
{
const auto e = std::remove_if(qStorrage.begin(), qStorrage.end(), [&](const auto &i) { return ((i == obj) || ...); });
qStorrage.erase(e, qStorrage.end());
}
}
目标是能够传递Object的多个引用被删除,避免多次调用同一个函数。
Storage stor;
auto a = stor.create();
auto b = stor.create();
stor.delete(a, b);
你知道为什么 MSVC 编译失败吗?
编辑:
这是实际文件:
https://github.com/zcorniere/logger-cpp/blob/windows/include/Logger.hpp
https://github.com/zcorniere/logger-cpp/blob/windows/example/example.cpp
使用参数 BUILD_EXAMPLE 开启的 cmake 构建
编辑2: 这是msvc错误信息,抱歉我忘记了
message : This diagnostic occurred in the compiler generated function 'bool ProgressBar::operator ==(const ProgressBar &) const' [C:\Users\Zacharie Corniere\Documents\GitHub\logger-cpp\build\example\example.vcxproj]
[build] C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include\xmemory(1967): message : see reference to function template instantiation 'bool Logger::deleteProgressBar::<lambda_1>::operator ()<ProgressBar>(const _T1 &) const' being compiled [logger-cpp\build\example\example.vcxproj]
[build] with
[build] [
[build] _T1=ProgressBar
[build] ]
[build] logger-cpp\include\Logger.hpp(51): message : see reference to function template instantiation '_FwdIt std::remove_if<std::_Deque_iterator<std::_Deque_val<std::_Deque_simple_types<_Ty>>>,Logger::deleteProgressBar::<lambda_1>>(_FwdIt,const _FwdIt,_Pr)' being compiled [logger-cpp\build\example\example.vcxproj]
[build] with
[build] [
[build] _FwdIt=std::_Deque_iterator<std::_Deque_val<std::_Deque_simple_types<ProgressBar>>>,
[build] _Ty=ProgressBar,
[build] _Pr=Logger::deleteProgressBar::<lambda_1>
[build] ]
【问题讨论】:
-
在询问有关构建错误的问题时,请始终包含 full 和 complete 错误输出,并以文本形式复制粘贴。适当的minimal reproducible example 也会有所帮助。
-
什么编译器错误?您使用的是相同的 C++ 版本吗?
-
我用编译器错误更新了问题。我正在使用 c++20
标签: c++ templates c++20 fold-expression c1001