Clang Flag: -Wreturn-local-addr / -Wno-return-local-addr

From emmtrix Wiki
Jump to navigation Jump to search
The Clang flags -Wreturn-local-addr and -Wno-return-local-addr are used to manage warnings for potentially unsafe code practices related to returning addresses of local variables. Specifically:
  • The -Wreturn-local-addr flag is designed to emit warnings when the address of a local variable might be returned. This could lead to undefined behavior since the local variable's lifetime ends when the function returns, and accessing it outside its scope is invalid. However, there are no elements listed under Default Inactive for -Wreturn-local-addr, indicating this flag does not have specific cases or scenarios predefined in this article where it would become active by default or through explicit activation.
  • Conversely, -Wno-return-local-addr is used to suppress warnings that would otherwise be triggered by situations where a function may return the address of a local variable. This flag is pertinent when developers are confident that the flagged code does not lead to undefined behavior or when the warning is deemed a false positive. The article lists several scenarios under Default Active where warnings are generated by default, indicating areas where this flag could be relevant to suppress such warnings.

Developers might use these flags when compiling source code with Clang to ensure safer practices around memory management and address handling or to clean up compiler output by suppressing warnings deemed unnecessary or irrelevant to the specific context of the project.

 
AI Generated

Supergroups

Subroups

Warnings/Remarks

Default Active (Deactivate with -Wno-return-local-addr)

warn_ret_addr_label warning: returning address of label, which is local
warn_ret_local_temp_addr_ref
warning: returning
address of
reference to
local temporary object

warn_ret_stack_addr_ref
warning:
address of
reference to
stack memory associated with
local variable
parameter
B returned

Default Inactive (Activate with -Wreturn-local-addr)

None