https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90905

            Bug ID: 90905
           Summary: missing -Wreturn-local-addr returning a local
                    std::string::c_str()
           Product: gcc
           Version: 9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: msebor at gcc dot gnu.org
  Target Milestone: ---

Compiling function f0 below on its own triggers a -Wreturn-local-addr for the
return statement as one would expect.  But compiling the equivalent f1 fails to
trigger the same warning.  Worse yet, compiling both functions in the samne
translatin unit suppresses the warning for f0.

#include <string>

#if F0

const char s[] = "abc";

const char* f0 ()
{
  std::string str (s);
  return str.c_str ();
}

#endif

#if F1

const char *p = "def";

const char* f1 ()
{
  std::string str (p);
  return str.c_str ();
}

#endif

Reply via email to