In C++ using clang++, is it possible to overload a method according to address-space qualifiers on the implicit ‘this’ parameter? If so, what is the syntax?
This source suggests that I can place the address-space qualifier after the parameter list but before the curly braces (similar to using the const qualifier on 'this'). I tried the following, but it failed; clang thinks I'm trying to set an address space of the method, rather than of 'this':
// Does not work.
struct SomeClass
{
// method for 'this' in default address space
void doit();
// method for 'this' in address space 300.
void doit() __attribute__((address_space(300)); // clang rejects this syntax
}
The closest I have found is that clang lets me overload a method according to the address spaces of its explicit formal parameters (not 'this'). For example, the code below will print “1\n2\n”.
// Similar, but does not solve my problem:
#include <cstdio>
struct SomeClass
{
void doit(void *v) { printf("1\n"); }
void doit(void __attribute__((address_space(300))) *v) { printf("2\n"); }
};
int main(int argc, char **argv)
{
SomeClass SC;
SC.doit( (void*) 0 );
SC.doit( (void __attribute__((address_space(300))) *) 0 );
return 0;
}