在Clang中使用指向成员的指针和地址空间 [英] Using pointers-to-members and address spaces in Clang
问题描述
我正在具有多个地址空间的目标上使用C ++代码。我想使用的代码具有指向成员的指针:
I'm working on C++ code on a target that has multiple address spaces. The code I would like to use has pointers to members:
struct foo {
int bar;
int baz;
};
typedef int foo::*foo_member;
foo_member m = &foo::bar;
#define AS1 __attribute__((address_space(1)))
int main()
{
foo AS1* f = /* ... */;
f->*m = 4;
}
到目前为止很好。但是,当我尝试获取指向实际成员的指针时,事情会变得很有趣:
So far so good. However, things get funny when I try to get a pointer to the actual member:
int main()
{
foo AS1* f = /* ... */;
int AS1* x = &(f->*m);
}
Clang 3.7.0(标签/ RELEASE_370 / final)抱怨:
Clang 3.7.0 (tags/RELEASE_370/final) complains:
test.cpp:14:11: error: cannot initialize a variable of type
'__attribute__((address_space(1))) int *' with an rvalue of type 'int *'
int AS1* x = &(f->*m);
^ ~~~~~~~~
似乎地址的运算符(或取消成员引用?)删除地址空间限定符。
It seems that the address-of operator (or the member dereference?) drops the address space qualifier.
如何在确保不删除地址空间的同时使用指向具有地址空间的成员的指针?
How can I use pointers to members with address spaces while ensuring that the address space is not dropped?
推荐答案
这是一个编译器错误。 已报告,并且已提交了补丁。
It's a compiler bug. It's been reported and a patch has been submitted.
这篇关于在Clang中使用指向成员的指针和地址空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!