c++ method overloading by address space of *this


Is it possible to overload a method according to the address space of its implicit 'this' parameter? If so, what is the syntax?

I tried the following, but it failed because clang thinks I'm trying to set an address space of the method, rather than of 'this':

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 does not accept 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".


#include <cstdio>

#define __A __attribute__((address_space(300)))

struct SomeClass
  void doit(void *v) { printf("1\n"); }
  void doit(void __A *v) { printf("2\n"); }

int main(int argc, char **argv)
  SomeClass SC;

  SC.doit( (void*) 0 );
  SC.doit( (void __A *) 0 );

  return 0;