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.
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.
This is in fact a duplicate of PR 968. *** This bug has been marked as a duplicate of 968 ***
Ah shoot...
I meant PR 986 :( *** This bug has been marked as a duplicate of 986 ***