[Bug c++/57528] New: Missed warning for putting reference to temporary in class member

jewillco at osl dot iu.edu gcc-bugzilla@gcc.gnu.org
Tue Jun 4 18:07:00 GMT 2013


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57528

            Bug ID: 57528
           Summary: Missed warning for putting reference to temporary in
                    class member
           Product: gcc
           Version: 4.9.0
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jewillco at osl dot iu.edu

It would be nice to have a warning on code such as:

struct b {
  const int& r;
  b(int r): r(r) {}
};

that is almost certainly unintended since it always binds a reference to a
temporary in a case where the reference outlives the temporary.  "g++ (GCC)
4.9.0 20130519 (experimental)" does not warn on this code with -Wall -Wextra,
whether with -O2 or without.  Uses of the struct b (including with a literal
number as constructor argument) do not produce warnings either.



More information about the Gcc-bugs mailing list