This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/64369] New: Wreturn-local-addr for const argument with packed attribute
- From: "a3at.mail at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Sat, 20 Dec 2014 21:54:22 +0000
- Subject: [Bug c++/64369] New: Wreturn-local-addr for const argument with packed attribute
- Auto-submitted: auto-generated
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?