TICS Coding Standard Viewer 
TIOBE Software Quality Framework
Print-friendly version
©TIOBE Software www.tiobe.com
 
C++ Coding Standard
Search

Rule:  OLC#003Checked automatically with code checker

Synopsis:A function must never return, or in any other way give access to, references or pointers to local variables outside the scope in which they are declared
Language:C++
Severity Level:2
Category:Object Life Cycle


Description:

If a function returns a reference or a pointer to a local variable, the memory to which it refers will already have been deallocated, when this reference or pointer is used. Note that the scope in this rule refers to the lifetime-scope. It is never allowed that a function gives access to a local automatic stack variable. However, if the lifetime of a local variable exceeds the lifetime of its block, then it may well be appropriate to give access to it from other scopes. This might be the case for static or new allocated objects.



Literature References:
Ellemtel Rule 34
ISC++ Rule 5.9