[Bug c++/107132] New: a temporary object with an x-value is not destroyed and is bound to a variable

2022-10-03 Thread lisp2d at rambler dot ru via Gcc-bugs
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.

2023-04-15 Thread lisp2d at rambler dot ru via Gcc-bugs
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.

2023-04-16 Thread lisp2d at rambler dot ru via Gcc-bugs
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.

2023-04-16 Thread lisp2d at rambler dot ru via Gcc-bugs
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.

2023-04-16 Thread lisp2d at rambler dot ru via Gcc-bugs
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);