This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[patch] PR 54930: add -Wreturn-local-addr


This adds a warning switch for the existing "returning address of
local variable" warnings in the C and C++ FEs which are enabled by
default but have no switch controlling them. Adding a switch allows it
to be turned into an error with -Werror=return-local-addr.  I've added
two tests checking the -Werror form works.

gcc/c-family:
        PR c++/54930
        * c.opt (Wreturn_local_addr): Define new option.

gcc/c:
        PR c++/54930
        * c-typeck.c (c_finish_return): Use OPT_Wreturn_local_addr.

gcc/cp:
        PR c++/54930
        * typeck.c (maybe_warn_about_returning_address_of_local): Use
        OPT_Wreturn_local_addr.

gcc:
        PR c++/54930
        * doc/invoke.texi (Warning Options): Document -Wno-return-local-addr.

gcc/testsuite:
        PR c++/54930
        * gcc.dg/Wreturn-local-addr.c: New.
        * g++.dg/warn/Wno-return-local-addr.C: New.
        * g++.dg/warn/Wreturn-local-addr.C: New.

Tested x86_64-linux, OK for trunk?

Attachment: patch.txt
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]