This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/81420] New: When a reference is bound to a member in the base of a temporary, lifetime of the temporary is not extended


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

            Bug ID: 81420
           Summary: When a reference is bound to a member in the base of a
                    temporary, lifetime of the temporary is not extended
           Product: gcc
           Version: 8.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ryan.brown at ableton dot com
  Target Milestone: ---

This is a followup to bug #54293. The incorrect behavior can be seen by
modifying the test introduced for that bug [0] to use a base class:

int d;

struct A
{
  int i;
  ~A() { ++d; };
};

struct B : A {};

int main()
{
  {
    const int &r = B().i;
    if (d != 0)
      return 1;
  }
  if (d != 1)
    return 1;
}

This test passes for clang HEAD and fails for GCC HEAD.

[0]
https://gcc.gnu.org/viewcvs/gcc/trunk/gcc/testsuite/g%2B%2B.dg/init/ref19.C?view=markup&pathrev=240819

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]