Is there a way to define using typedef integral/float type which implies no aliasng?
something equivalent to (but primitive construct):
template < typename T >
struct restrict { T* __restrict data; };
as related question, is it possible to ask gcc what it determines alias/no alias of pointer is?
As noted in the comments, many newer C++ compilers do support the C99 implementation of the restrict type qualifier. Since
restrictis not a reserved keyword in C++, the compilers generally use__restrictor__restrict__. Both GCC and Visual C++ document this nicely, with explicit references to C99.The C++ 1998 standard states that “The
typedefspecifier shall not … be combined in a decl-specifier-seq with any kind of specifier except a type-specifier.” Essentially, it must be a list of type-specifiers, which includes the two cv-qualifiers,constandvolatile.C99 defines typedef similarly, except that its list of qualifiers includes
restrict.It would seem reasonable to anticipate similar support in typedefs for the nonstandard
__restrict… but you never know!A clever and easy way to test this is as follows:
This simply exploits the fact that if the unresolved
link_failsymbol is found in the object file, the linker will throw an error. If the compiler is properly restricting the two arguments, then it should know the value ofa, even afterbis changed. Thus, it should strip the entire if block from the generated object file since it will never be run.Note that although GCC supported the restrict syntax since at least version 3.0, it really didn’t perform the proper optimizations until version 4.5.