[Bug c++/81597] New: returns link to temporary value
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81597 Bug ID: 81597 Summary: returns link to temporary value Product: gcc Version: 4.8.5 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: lisp2d at rambler dot ru Target Milestone: --- Functions returning C && , C const && , C const & from temporary object will ALWAYS with wrong result. Warning is good but ... To do : prevent return rvalue from those functions. example : //> g++ -std=c++11 returntemp.cpp -o returntemp #include int && f ( ) { return 1 ; } int && g ( ) { return 2 ; } int const && ft ( ) { return 7 ; } int const && gt ( ) { return 8 ; } int const & fc ( ) { return 5 ; } int const & gc ( ) { return 6 ; } int fok ( ) { return 3 ; } int gok ( ) { return 4 ; } int main ( int , char * * ) { std :: cout << "int &&" << std :: endl ; { int && x ( f ( ) ) ; std :: cout << "x=" << x << std :: endl ; int && y ( g ( ) ) ; std :: cout << "y=" << y << std :: endl ; std :: cout << "x=" << x << std :: endl ; } std :: cout << "---" << std :: endl ; std :: cout << "int const &&" << std :: endl ; { int const && x ( ft ( ) ) ; std :: cout << "x=" << x << std :: endl ; int const && y ( gt ( ) ) ; std :: cout << "y=" << y << std :: endl ; std :: cout << "x=" << x << std :: endl ; } std :: cout << "---" << std :: endl ; std :: cout << "int const &" << std :: endl ; { int const & x ( fc ( ) ) ; std :: cout << "x=" << x << std :: endl ; int const & y ( gc ( ) ) ; std :: cout << "y=" << y << std :: endl ; std :: cout << "x=" << x << std :: endl ; } std :: cout << "---" << std :: endl ; std :: cout << "int" << std :: endl ; { int && x ( fok ( ) ) ; std :: cout << "x=" << x << std :: endl ; int && y ( gok ( ) ) ; std :: cout << "y=" << y << std :: endl ; std :: cout << "x=" << x << std :: endl ; } } result : int && x=1 y=2 x=32621 --- int const && x=7 y=8 x=32621 --- int const & x=5 y=6 x=32621 --- int x=3 y=4 x=3
[Bug c++/81597] returns link to temporary value
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81597 --- Comment #2 from Lisp2D --- Make an error (don't compile) when returns rvalue from these functions. To forbid or banning.
[Bug c++/81597] returns link to temporary value
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81597 --- Comment #4 from Lisp2D --- -Werror=return-local-addr it is all i want thnx
[Bug c++/107132] New: a temporary object with an x-value is not destroyed and is bound to a variable
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107132 Bug ID: 107132 Summary: a temporary object with an x-value is not destroyed and is bound to a variable Product: gcc Version: 12.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: lisp2d at rambler dot ru Target Milestone: --- a temporary object with an x-value is not destroyed and is bound to a variable the question is taken from a social network https://ru.stackoverflow.com/questions/1450260/Продление-времени-жизни-временного-объекта-в-присваивании/1450517#1450517 with tests https://godbolt.org/#z:OYLghAFBqd5QCxAYwPYBMCmBRdBLAF1QCcAaPECAMzwBtMA7AQwFtMQByARg9KtQYEAysib0QXACx8BBAKoBnTAAUAHpwAMvAFYTStJg1DIApACYAQuYukl9ZATwDKjdAGFUtAK4sGISQBspK4AMngMmAByPgBGmMQgAJykAA6oCoRODB7evv5BaRmOAmER0SxxCcl2mA5ZQgRMxAQ5Pn6Btpj2xQwNTQSlUbHxSbaNza15HQrjA%2BFDFSOJAJS2qF7EyOwc5gDM4cjeWADUJrtuTjPEmKxn2CYaAIIPj%2BEEx1hXXnUCCmdWTy%2BDmOj1OAHYLMcAH6PCDLY4MVCYVRbFLvEwQ06WayfAjEb49P67SEYgAi4NJ/xeLzexxYTHCcPBANBzJexw5xzQDBmIPMAWOTFOu3JzwhZOFooxVjBlOJ7M5M3QIBQ63R5zObixZlJmCBhOO4WOCjQKXYnI55jMwrcmo%2BerxBKyChtdrAOwArG4GO6qU8Lbj8T8eZLjho/ayyQqlSq0F51bbztrdfrncc1emqMbTeara6k4Gnb981rfV6fTt5U8yRxVrROB7eH4OFpSKhOLbsZZjetNpgsbseKQCJpa6sANb%2BRIAOkkc40AA4uBpEguwR6wbsgvWOJIm6O25xeAoQBph6PVnBYDBECBkbV4yRyJQmsAFMpDF0hAhUAB3ZtDmgLApHQTA9B%2BES0N%2Bf4AbwQEgfQCTAFwZhmKQ8F0PEADy8bQf%2BnBDveyCPMQb5HsEqi1A0%2BDNrw/CCCIYjsFIMiCIoKjqC2Oh6AYRgoNY1j6HgMQnpAqyoGizqcAAtEqZykqYXYWGYrYKL2Wx6Eq4QQV%2BP74dwvB4pg2xDr%2BxBMCkBG1voDb7lxh4cNglHII%2BxDHKoC4BNJASSMcwDIMgxwodO1oQJ2ViWKQxy4IQJADlwyyGReqwIDcWAJHCNm7rwLAgLsuzTokGiBIkuylQEGgelwVUeqQzatu2HDHqe55cZeN4QEgRGuc%2BECvu%2Bn5QXpsHoagwGgeBg14SNGGISgvHAAA%2Bo6DDjqN42IThwjDVZFG1CRZFNXtyDUeE5H0cIojiCxF3sWoB66GhC38UpQkifA4mSb8MlySKikRcpqnqcxYw0TpQ0wbtRkmbwZkWVZda2XVB6NU5D5EG5HleT5XILccEAreO8JhQJkXRfgGPxYlrVaMsKVpSMmU7nupC5YOs5gmYYJcFwARgpViQBLs0j1bwjXNWeI5taQV63t1GO9f14PTbts1gVkys7QZ60ISMABuyApCki161wiSLQYBAOotqg%2BTrmHEFtKva0RB0nkdRGnbRrGXUxEjSLdSj3fZui7PohjGKTNi0MJomZRJhKcAA9DG/3WCpx7A5pBBg1NWtDtDu1w5ZBmIxwjbI/ZqPOa57k4ywCgG8cpszpbDr4%2BFgnk7Fbl7AlSVtfTTDpZQZcs2zkjTgEqEeokkhlflHpmFItWiw5Es02OpCTh6GjTh6B%2BJFwC5FShkhmAEtU7rsdkNeRUu02XZi32L9/JaQevxBkziSEAA%3D #include int destructions; struct A { ~A() noexcept { ++destructions; } }; int main() { { const A& a = A{} = A{}; std::cout << "Destructions in scope: " << destructions << '\n'; destructions = 0; } std::cout << "Destructions out of scope: " << destructions << '\n'; } the object under variable a should be dead. But it's still alive.
[Bug c++/109529] New: the r-value volatile object is not accepted by the l-value volatile constant argument.
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109529 Bug ID: 109529 Summary: the r-value volatile object is not accepted by the l-value volatile constant argument. Product: gcc Version: 12.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: lisp2d at rambler dot ru Target Milestone: --- void funy(int const &){} void fun(int volatile const &){} int main(){ int y ; funy(y); // good funy(static_cast(y)); // good funy(static_cast(y)); // good int volatile x ; fun(x); // good fun(static_cast(x)); // error fun(static_cast(x)); // error }
[Bug c++/109529] the r-value volatile object is not accepted by the l-value volatile constant argument.
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109529 --- Comment #3 from Lisp2D --- (In reply to Andrew Pinski from comment #2) > Since `static_cast(x)` is considered rvalue and `int I can't find a reason anywhere in the standard why the volatile property prevents conversion from `&&` to `const &`.
[Bug c++/109529] the r-value volatile object is not accepted by the l-value volatile constant argument.
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109529 --- Comment #6 from Lisp2D --- (In reply to Andrew Pinski from comment #4) > https://stackoverflow.com/questions/40193008/why-a-const-volatile-reference- stackoverflow offers to link an rvalue reference to a variable for this. But I think this is historical stupidity. int volatile && rx = static_cast < int volatile && > ( x ) ; int volatile const & lx = rx ; fun(lx);
[Bug c++/109529] the r-value volatile object is not accepted by the l-value volatile constant argument.
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109529 --- Comment #7 from Lisp2D --- .. or int volatile && rx = static_cast < int volatile && > ( x ) ; fun(rx);