https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64369
Bug ID: 64369 Summary: Wreturn-local-addr for const argument with packed attribute Product: gcc Version: 4.9.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: a3at.mail at gmail dot com Created attachment 34306 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=34306&action=edit Werror=return-local-addr Here is simple test case (also in attachment): #ifdef NOWARN #define __packed #else #define __packed __attribute__((packed)); #endif struct Addr { int s_addr; }; struct R1 { Addr addr; } __packed; const Addr& ipAddress(const R1 &r) { return r.addr; } void foo() { R1 r1; (void)ipAddress(r1).s_addr; } And here is the compiler output for gcc/clang: $ for c in clang++-3.5 g++; do echo =====$c && $c --version && $c -c test.cpp; done =====clang++-3.5 Debian clang version 3.5.0-8 (tags/RELEASE_350/final) (based on LLVM 3.5.0) Target: x86_64-pc-linux-gnu Thread model: posix =====g++ g++ (Debian 4.9.1-19) 4.9.1 Copyright (C) 2014 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. test.cpp: In function ‘const Addr& ipAddress(const R1&)’: test.cpp:16:47: warning: returning reference to temporary [-Wreturn-local-addr] const Addr& ipAddress(const R1 &r) { return r.addr; } ^ Is this is the correct behavior or what?