https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101572

            Bug ID: 101572
           Summary: Temporary object lifetime is not prolonged as required
                    by the standard
           Product: gcc
           Version: 11.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: fchelnokov at gmail dot com
  Target Milestone: ---

In this example program
```
#include <iostream>

struct S
{
    virtual ~S() { std::cout << "~S() "; }
};

struct U : S {};

int main() 
{
    [[maybe_unused]] auto && u = dynamic_cast<const U&>( static_cast<const S&>(
U{} ) );
    std::cout << ". ";
}
```
https://gcc.godbolt.org/z/c9nE7Gsn6

the lifetime of temporary object is not prolonged as required by the standard:
https://en.cppreference.com/w/cpp/language/reference_initialization#Lifetime_of_a_temporary
Clang correctly prolongs it.

The problem seems in dynamic_cast.

Reply via email to