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 (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?