This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/29593] New: Missing warning.


The following code has a subtle bug:

#include <assert.h>

class Blah
{
public:
  const unsigned int &myfoo;
  Blah(const unsigned int &p):
    myfoo(p) {}
  const unsigned int getfoo()
  {
    return myfoo;
  }
};

int main()
{
  int foo(42);
  Blah baz(foo);

  ++foo;

  assert(foo == baz.getfoo());

  return 0;
}

When "foo" is passed to the constructor for "baz", as foo is not unsigned a
temporary is made and a constant reference to it is passed to Blah.

No warnings for this code appear in 4.2.0 at the highest warning levels. Would
it be possible to add a warning, such as "reference is bound to converted
temporary"? I'm not sure how many false-positives would be generated, but I do
know this bug too a long time to find for someone.


-- 
           Summary: Missing warning.
           Product: gcc
           Version: 4.2.0
            Status: UNCONFIRMED
          Severity: minor
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: chris at bubblescope dot net


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]