Bug 29593 - Missing warning.
Summary: Missing warning.
Status: RESOLVED DUPLICATE of bug 986
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.2.0
: P3 minor
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-10-25 17:10 UTC by Chris Jefferson
Modified: 2006-10-26 06:35 UTC (History)
6 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Chris Jefferson 2006-10-25 17:10:30 UTC
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.
Comment 1 Andrew Pinski 2006-10-25 18:56:03 UTC
This warning is hard to get right as there are many many pieces of code that depends on binding an rvalue to an constant reference.

This bug is related to PR 986.
Comment 2 Wolfgang Bangerth 2006-10-26 06:34:14 UTC
This is in fact a duplicate of PR 968.

*** This bug has been marked as a duplicate of 968 ***
Comment 3 Wolfgang Bangerth 2006-10-26 06:34:42 UTC
Ah shoot...
Comment 4 Wolfgang Bangerth 2006-10-26 06:35:08 UTC
I meant PR 986 :(

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