public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/63606] Missing a warning for binding a reference member to a stack allocated parameter
  2014-10-20 22:06 [Bug c++/63606] New: Missing a warning for binding a reference member to a stack allocated parameter bcmpinc at hotmail dot com
@ 2014-10-20 22:06 ` redi at gcc dot gnu.org
  0 siblings, 0 replies; 2+ messages in thread
From: redi at gcc dot gnu.org @ 2014-10-20 22:06 UTC (permalink / raw)
  To: gcc-bugs

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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |DUPLICATE

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
dup

*** This bug has been marked as a duplicate of bug 63181 ***


^ permalink raw reply	[flat|nested] 2+ messages in thread

* [Bug c++/63606] New: Missing a warning for binding a reference member to a stack allocated parameter
@ 2014-10-20 22:06 bcmpinc at hotmail dot com
  2014-10-20 22:06 ` [Bug c++/63606] " redi at gcc dot gnu.org
  0 siblings, 1 reply; 2+ messages in thread
From: bcmpinc at hotmail dot com @ 2014-10-20 22:06 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 63606
           Summary: Missing a warning for binding a reference member to a
                    stack allocated parameter
           Product: gcc
           Version: 4.8.2
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: bcmpinc at hotmail dot com

The code below should produce a warning, as it binds a stack allocated
parameter to a reference member. However, gcc currently does not produce such a
warning.

The code is error prone as it will always result in a dangling reference: the
object being pointed to is destructed when the constructor returns. Similar
buggy code can accidentally be written when one forgets to insert the '&' to
pass-by-reference. Note that the clang compiler does emit a warning, named
-Wdangling-field, for the code below.


struct Bar {
  int a;
};
struct Foo{
  Foo(Bar arg) : bar(arg) {}
  Bar & bar;
};
int main() {
  Bar k;
  Foo oops(k);
  return 0;
}


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2014-10-20 22:06 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-10-20 22:06 [Bug c++/63606] New: Missing a warning for binding a reference member to a stack allocated parameter bcmpinc at hotmail dot com
2014-10-20 22:06 ` [Bug c++/63606] " redi at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).