This warning is false positive, because the pointer p not temporary, even though p refers to it. There are more scenarios in which this warning is falsified; See Error 21218 , which uses
char * f() { typedef char* t; const t & r = new char[5]; return r; }
Presumably, if the return type is a reference, Clang looks for const references (related to temporary) in the returned expression, not considering how they are used.
source share