tbb::cache_aligned_allocator: Getting “request for member…which is of non-class type” with __m128i. User error or bug?

你说的曾经没有我的故事 提交于 2019-12-10 18:57:01

问题


I'm trying to use __m128i as the value type of a cache-aligned vector with GCC, and I'm getting the following error:

/usr/include/tbb/cache_aligned_allocator.h:105:32: error: request for member ‘~tbb::cache_aligned_allocator<__vector(2) long long int>::value_type’ in ‘* p’, which is of non-class type ‘tbb::cache_aligned_allocator<__vector(2) long long int>::value_type {aka __vector(2) long long int}’

The compiler traces it to the following line in tbb/cache_aligned_allocator.h:

void destroy( pointer p ) {p->~value_type();}

Here is the code that triggers the compiler error:

#include <vector>
#include <emmintrin.h>
#include <tbb/cache_aligned_allocator.h>

int main()
{
    std::vector<int, tbb::cache_aligned_allocator<int> > success;
    std::vector<__m128i, tbb::cache_aligned_allocator<__m128i> > failure;
    return 0;
}

According to Debian versioning, my GCC version is 4.6.1-2, and my TBB version is 3.0+r147-1. Is this a bug in Threading Building Blocks, or am I misusing something?


回答1:


I think the problem lies with how the __m128 types are implemented in gcc. They are not actual types in the C++ sense, in that they are neither POD (Plain Old Data, like int/double/char/etc.) nor classes. The vector(2) long long int identifier is how gcc refers to the type internally. The error that you showed is from the compiler complaining about not being able to find a destructor for __m128i because it is not a class type.

A workaround for this could involve creating your own type that is 128 bits in size and using a vector of those instead. You could provide a custom cast operator to the __m128i type for convenience if you want, or just cast a pointer to the first element in the vector to a __m128i if you just want to use the vector as a convenient memory allocation mechanism.



来源:https://stackoverflow.com/questions/8529372/tbbcache-aligned-allocator-getting-request-for-member-which-is-of-non-clas

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!