This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/29593] New: Missing warning.
- From: "chris at bubblescope dot net" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 25 Oct 2006 17:10:30 -0000
- Subject: [Bug c++/29593] New: Missing warning.
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
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