I'm accustomed to using __attribute__((nonnull))
when expressing pointers that should not be null.
void f(int* ptr) __attribute__((nonnull));
int main(){
int* ptr = new int(1);
f(ptr);
}
void f(int* ptr){/*impl*/}
However, with the GSL, there is also the not_null<T*>
wrapper type.
void function1(gsl::not_null<int*> n);
void f(gsl::not_null<int*> n);
int main(){
int* ptr = new int(1);
f(ptr);
}
void f(gsl::not_null<int*> n){/*impl*/}
Assuming the language facilities are there to support the GSL version, should I always be using not_null<T*>
in place of __attribute__((nonnull))
now?
I've been under the impression that the compiler attribute may aid in optimizations, but the wrapper version resolves down to an unattributed pointer.