In the first case, it is easy for the compiler to show that you are returning a link to a local variable; in the second case, it is more complicated, because it just has an arbitrary reference, which happens to be related to a local variable. This is probably why you get a warning in the first case, but not in the second.
And no, in the first case it p1is just normal int, not int&.
source
share