On Fri, Sep 20, 2013 at 3:07 AM, Tobias Burnus <tobias.burnus@xxxxxxxxxxxxxxxxxxx> wrote: > > I was wondering how to convey to GCC that two pointers do not alias. > That works nicely in the argument list, > void foo(mytype *__restrict__ arg) > > However, it does not seem to work for C++'s member variables. Even > if one has on the class the declaration with __restrict. Neither does > casting to a restrict pointer work. I'm not sure how that could work. By definition the restrict qualifier is only meaningful in a specific context, with respect to other pointers with the restrict qualifier. It would not make sense to declare that every restrict qualified pointer in the entire program may not conflict with every other restrict qualified pointer in the entire program. That would be too limiting. What GCC implements is what the C99 standard specifies. Within a function you can have a set of restrict qualified pointers. Any write through a restrict qualified pointer may not be read through any other restrict qualified pointer (unless the second pointer is based on the first, which is defined by the standard). If we found it useful, we could introduce a new attribute for C++ class members. We could declare that within a class, all members with that attribute could not alias. But to make that useful we would have to make that attribute inheritable--we wouldn't want people to have to use it for local variables. I think it would be hard to define correctly--it was hard to define the C99 restrict qualifier. Another possibly more profitable approach would be to define a new function attribute. In functions with that attribute we would declare that none of the pointers that were not based on each other could alias. This would be difficult to use correctly but it would be fairly precise and might be sufficient for what you need. Ian