Currently Visual C++ is shipped with runtime where malloc() is decorated with __declspec( restrict ).
MSDN says this decoration states to the compiler that a pointer returned by malloc() cannot be aliased by any other pointer. Okay, two subsequent calls to malloc() indeed return distinct pointers. But what happens if I call
void* memory1 = malloc( 10 );
free( memory1 );
void* memory2 = malloc( 10 );
//here memory1 may be equal to memory2
In this case the two pointers can point to the very same location. How does this correlate with cannot be aliased by any other pointer implication of __declspec( restrict )?
The standard has this to say about “object lifetime” (§3.8 in N3290):
After you’ve
free‘d the block pointed to bymemory1, that object is dead. It has ceased to exist. Dereferencing that pointer would be undefined behavior.memory2could be assigned the same memory address, but it wouldn’t “alias” anything: what was at that location has passed away.