错误:C2061:语法错误:标识符'concurrent_vector <`template-type-parameter-1',`template-type-parameter-2'>'

如何解决错误:C2061:语法错误:标识符'concurrent_vector <`template-type-parameter-1',`template-type-parameter-2'>'

代码可以在Linux和macOS上正常编译/运行。在Windows 10上,我正在使用Visual Studio 2017工具链编译代码,但是我收到此错误

...\deps\tbb-2020.3-win\tbb\include\tbb\concurrent_vector.h:680: error: C2061: Syntax error: identifier 'concurrent_vector<'template-type-parameter-1','template-type-parameter-2'>'

此模板concurrent_vector处发生错误


    //! copying constructor for vector with different allocator type
    template<class M>
    __TBB_DEPRECATED concurrent_vector( const concurrent_vector<T,M>& vector,const allocator_type& a = allocator_type() )
        : internal::allocator_base<T,A>(a),internal::concurrent_vector_base()
    {
        vector_allocator_ptr = &internal_allocator;
        __TBB_TRY {
            internal_copy(vector.internal_vector_base(),sizeof(T),&copy_array);
        } __TBB_CATCH(...) {
            segment_t *table = my_segment.load<relaxed>();
            internal_free_segments( table,internal_clear(&destroy_array),my_first_block.load<relaxed>() );
            __TBB_RETHROW();
        }
    }

错误发生在TBB标头内:

C:\...\deps\tbb-2020.3-win\tbb\include\tbb\concurrent_vector.h

可能是什么原因?

这是更完整的错误日志:

c:\users\m3\repos\3d-editor\editorlib\deps\tbb-2020.3-win\tbb\include\tbb\concurrent_vector.h(680): error C2061: Syntax error: identifier 'concurrent_vector<`template-type-parameter-1',`template-type-parameter-2'>'
c:\users\m3\repos\3d-editor\editorlib\deps\tbb-2020.3-win\tbb\include\tbb\concurrent_vector.h(1167): note: see reference to class template instantiation 'tbb::concurrent_vector<T,A>' being compiled
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\memory_resource(860): note: see reference to class template instantiation 'std::pmr::_Intrusive_stack<std::pmr::monotonic_buffer_resource::_Header,void>' being compiled
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\memory_resource(465): note: see reference to class template instantiation 'std::pmr::_Intrusive_stack<std::pmr::unsynchronized_pool_resource::_Pool::_Chunk,void>' being compiled
c:\users\m3\repos\3d-editor\editorlib\deps\tbb-2020.3-win\tbb\include\tbb\concurrent_vector.h(681): error C2334: unexpected token(s) preceding ':'; skipping apparent function body
c:\users\m3\repos\3d-editor\editorlib\deps\tbb-2020.3-win\tbb\include\tbb\concurrent_vector.h(61): Fatal error C1075: '{': no matching token found
jom: C:\Users\m3\repos\build-3dsceneeditor-Desktop_Qt_5_12_9_MSVC2017_64bit-Debug\editorlib\Makefile.Debug [debug\openvdbutils.obj] Error 2

代码可与Visual Studio 2017中的/Zc:__cplusplus编译器标志一起用于重新创建问题:

#include <tbb/concurrent_vector.h>
int main()
{
    tbb::concurrent_vector<int> vector;
    vector.push_back(1);
    return 0;
}

Error log

解决方法

这似乎是视觉工作室的错误。在TBB github存储库上的issue中,/Zc:__cplusplus编译器标志是原因。

启用该标志会使this code使用c ++ 14 [[deprecated]]属性:

    #if (__cplusplus >= 201402L)
        #define __TBB_DEPRECATED [[deprecated]]
        #define __TBB_DEPRECATED_MSG(msg) [[deprecated(msg)]]
    #elif _MSC_VER
        #define __TBB_DEPRECATED __declspec(deprecated)
        #define __TBB_DEPRECATED_MSG(msg) __declspec(deprecated(msg))
    #elif (__GNUC__ && __TBB_GCC_VERSION >= 40805) || __clang__
        #define __TBB_DEPRECATED __attribute__((deprecated))
        #define __TBB_DEPRECATED_MSG(msg) __attribute__((deprecated(msg)))
    #endif

将此代码交换为始终使用Visual Studio特定的代码似乎可以解决此问题:

    #if _MSC_VER
        #define __TBB_DEPRECATED __declspec(deprecated)
        #define __TBB_DEPRECATED_MSG(msg) __declspec(deprecated(msg))
    #elif (__cplusplus >= 201402L)
        #define __TBB_DEPRECATED [[deprecated]]
        #define __TBB_DEPRECATED_MSG(msg) [[deprecated(msg)]]
    #elif (__GNUC__ && __TBB_GCC_VERSION >= 40805) || __clang__
        #define __TBB_DEPRECATED __attribute__((deprecated))
        #define __TBB_DEPRECATED_MSG(msg) __attribute__((deprecated(msg)))
    #endif

同一个问题的smaller demonstration是:

template <typename T>
class Foo
{
public:
    Foo() {}

    template <typename X>
    [[deprecated]] Foo(const Foo<T>& a)
    {
    }
};

int main()
{
    Foo<int> x;
    return 0;
}

这仅在Visual Studio 2017 it works in 2019中不起作用,因此最简单的解决方法是更新Visual Studio。

已创建一个pull request来解决此问题,reported to Microsoft我不希望MS对其进行修复,因为它已在2019年修复。

,

here所述,一个简短的解决方法是在Windows上降级为 TBB 2020 Update 1 。感谢@AlanBirtles

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?
Java在半透明框架/面板/组件上重新绘画。
Java“ Class.forName()”和“ Class.forName()。newInstance()”之间有什么区别?
在此环境中不提供编译器。也许是在JRE而不是JDK上运行?
Java用相同的方法在一个类中实现两个接口。哪种接口方法被覆盖?
Java 什么是Runtime.getRuntime()。totalMemory()和freeMemory()?
java.library.path中的java.lang.UnsatisfiedLinkError否*****。dll
JavaFX“位置是必需的。” 即使在同一包装中
Java 导入两个具有相同名称的类。怎么处理?
Java 是否应该在HttpServletResponse.getOutputStream()/。getWriter()上调用.close()?
Java RegEx元字符(。)和普通点?