public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/53288] New: [C++11] Reference fails to bind directly to prvalue member access expression
@ 2012-05-09  4:44 hstong at ca dot ibm.com
  2012-05-09 17:31 ` [Bug c++/53288] " redi at gcc dot gnu.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: hstong at ca dot ibm.com @ 2012-05-09  4:44 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53288

             Bug #: 53288
           Summary: [C++11] Reference fails to bind directly to prvalue
                    member access expression
    Classification: Unclassified
           Product: gcc
           Version: 4.6.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: hstong@ca.ibm.com
              Host: powerpc64-unknown-linux-gnu
            Target: powerpc64-unknown-linux-gnu


In the reference initialization,
   const B &b = A(1).b;
the initializer expression is a class prvalue.

The requirement to bind an lvalue reference to a non-volatile const type
directly to a reference-compatible class prvalue dates back to DR 391 which
PR 25950 intended to implement.

The error messages complaining about the private and deleted move constructor
indicate that direct binding was not done.


### Self-contained source (tempbind_expr_ref.cpp):> cat tempbind_expr_ref.cpp
extern "C" int printf(const char *, ...);

struct B {
   B(int data) : _data(data) {
printf("ctor B(int) body:       (this=%p,_data=%d)\n", (void *)this, _data);
   }
   ~B() {
printf("dtor for B:             (this=%p,_data=%d)\n", (void *)this, _data);
   }

   int _data;

private:
   B() = delete;
   B(const B &) = delete;
   B(B &&) = delete;
};

struct A {
   B b;
   A(int data) : b(data) {
printf("ctor A(int) body:       (this=%p,_data=%d)\n", (void *)this, b._data);
   }
   ~A() {
printf("dtor for A:             (this=%p,_data=%d)\n", (void *)this, b._data);
   }

private:
   A() = delete;
   A(const A &) = delete;
   A(A &&) = delete;
};

const B &b = A(1).b;

int main() {
    printf("main() user body begins\n");
    printf("main() user body ends\n");
}


### Compiler invocation:
g++-4.6.0 tempbind_expr_ref.cpp -std=c++0x


### Compiler output:
tempbind_expr_ref.cpp:16:4: error: 'B::B(B&&)' is private
tempbind_expr_ref.cpp:34:19: error: within this context
tempbind_expr_ref.cpp:34:19: error: use of deleted function 'B::B(B&&)'
tempbind_expr_ref.cpp:16:4: error: declared here


### g++ -v output:> g++-4.6.0 -v
Using built-in specs.
COLLECT_GCC=g++-4.6.0
COLLECT_LTO_WRAPPER=/data/gcc/libexec/gcc/powerpc64-unknown-linux-gnu/4.6.0/lto-wrapper
Target: powerpc64-unknown-linux-gnu
Configured with: ./configure --prefix=/data/gcc --program-suffix=-4.6.0
--disable-libssp --disable-libgcj --enable-version-specific-runtime-libs
--with-cpu=default32 --enable-secureplt --with-long-double-128 --enable-shared
--enable-__cxa_atexit --enable-threads=posix --enable-languages=c,c++,fortran
--with-gmp=/usr/local
Thread model: posix
gcc version 4.6.0 (GCC)


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c++/53288] [C++11] Reference fails to bind directly to prvalue member access expression
  2012-05-09  4:44 [Bug c++/53288] New: [C++11] Reference fails to bind directly to prvalue member access expression hstong at ca dot ibm.com
@ 2012-05-09 17:31 ` redi at gcc dot gnu.org
  2012-06-07 21:37 ` [Bug c++/53288] [C++11] Lifetime of temporary object backing pointer-to-member expression not extended hstong at ca dot ibm.com
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: redi at gcc dot gnu.org @ 2012-05-09 17:31 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53288

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jason at gcc dot gnu.org

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-05-09 17:23:42 UTC ---
It compiles fine with 4.7 or trunk.

I think this is a dup of an existing bug Jason fixed, possibly one he reported
himself, about elements of rvalue arrays.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c++/53288] [C++11] Lifetime of temporary object backing pointer-to-member expression not extended
  2012-05-09  4:44 [Bug c++/53288] New: [C++11] Reference fails to bind directly to prvalue member access expression hstong at ca dot ibm.com
  2012-05-09 17:31 ` [Bug c++/53288] " redi at gcc dot gnu.org
@ 2012-06-07 21:37 ` hstong at ca dot ibm.com
  2022-06-09 18:00 ` iamsupermouse at mail dot ru
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: hstong at ca dot ibm.com @ 2012-06-07 21:37 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53288

Hubert Tong <hstong at ca dot ibm.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|rejects-valid               |wrong-code
            Version|4.6.0                       |4.7.0
            Summary|[C++11] Reference fails to  |[C++11] Lifetime of
                   |bind directly to prvalue    |temporary object backing
                   |member access expression    |pointer-to-member
                   |                            |expression not extended
      Known to fail|4.4.0, 4.5.0, 4.6.0         |4.7.0

--- Comment #2 from Hubert Tong <hstong at ca dot ibm.com> 2012-06-07 21:36:54 UTC ---
(In reply to comment #1)
> It compiles fine with 4.7 or trunk.
> 
> I think this is a dup of an existing bug Jason fixed, possibly one he reported
> himself, about elements of rvalue arrays.

Confirmed that the above works as expected under 4.7.

However, replacing:
const B &b = A(1).b;

with:
const B &b = A(1).*(&A::b);

produces an executable whose output indicates that the lifetime of the
temporary is not being extended:

ctor B(int) body:       (this=0xffe9f7d8,_data=1)
ctor A(int) body:       (this=0xffe9f7d8,_data=1)
dtor for A:             (this=0xffe9f7d8,_data=1)
dtor for B:             (this=0xffe9f7d8,_data=1)
main() user body begins
main() user body ends

### g++ -v output:> g++-4.7.0 -v
Using built-in specs.
COLLECT_GCC=g++-4.7.0
COLLECT_LTO_WRAPPER=/data/gcc/libexec/gcc/powerpc64-unknown-linux-gnu/4.7.0/lto-wrapper
Target: powerpc64-unknown-linux-gnu
Configured with: ../gcc-4.7.0/configure --prefix=/data/gcc
--program-suffix=-4.7.0 --disable-libssp --disable-libgcj
--enable-version-specific-runtime-libs --with-cpu=default32 --enable-secureplt
--with-long-double-128 --enable-shared --enable-__cxa_atexit
--enable-threads=posix --enable-languages=c,c++,fortran --with-mpfr=/usr/local/
--with-mpc=/usr/local/ --with-gmp=/usr/local/
Thread model: posix
gcc version 4.7.0 (GCC)


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c++/53288] [C++11] Lifetime of temporary object backing pointer-to-member expression not extended
  2012-05-09  4:44 [Bug c++/53288] New: [C++11] Reference fails to bind directly to prvalue member access expression hstong at ca dot ibm.com
  2012-05-09 17:31 ` [Bug c++/53288] " redi at gcc dot gnu.org
  2012-06-07 21:37 ` [Bug c++/53288] [C++11] Lifetime of temporary object backing pointer-to-member expression not extended hstong at ca dot ibm.com
@ 2022-06-09 18:00 ` iamsupermouse at mail dot ru
  2022-12-19 22:33 ` jason at gcc dot gnu.org
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: iamsupermouse at mail dot ru @ 2022-06-09 18:00 UTC (permalink / raw)
  To: gcc-bugs

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

Egor <iamsupermouse at mail dot ru> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |iamsupermouse at mail dot ru

--- Comment #4 from Egor <iamsupermouse at mail dot ru> ---
Still happens on 12.1 and trunk.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c++/53288] [C++11] Lifetime of temporary object backing pointer-to-member expression not extended
  2012-05-09  4:44 [Bug c++/53288] New: [C++11] Reference fails to bind directly to prvalue member access expression hstong at ca dot ibm.com
                   ` (2 preceding siblings ...)
  2022-06-09 18:00 ` iamsupermouse at mail dot ru
@ 2022-12-19 22:33 ` jason at gcc dot gnu.org
  2023-01-23  0:36 ` cvs-commit at gcc dot gnu.org
  2023-08-11 20:36 ` jason at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: jason at gcc dot gnu.org @ 2022-12-19 22:33 UTC (permalink / raw)
  To: gcc-bugs

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

Jason Merrill <jason at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
           Assignee|unassigned at gcc dot gnu.org      |jason at gcc dot gnu.org

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c++/53288] [C++11] Lifetime of temporary object backing pointer-to-member expression not extended
  2012-05-09  4:44 [Bug c++/53288] New: [C++11] Reference fails to bind directly to prvalue member access expression hstong at ca dot ibm.com
                   ` (3 preceding siblings ...)
  2022-12-19 22:33 ` jason at gcc dot gnu.org
@ 2023-01-23  0:36 ` cvs-commit at gcc dot gnu.org
  2023-08-11 20:36 ` jason at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-01-23  0:36 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The trunk branch has been updated by Jason Merrill <jason@gcc.gnu.org>:

https://gcc.gnu.org/g:208c6678c25bd9a11e6c5911a4c123cb6b7f3d6e

commit r13-5283-g208c6678c25bd9a11e6c5911a4c123cb6b7f3d6e
Author: Jason Merrill <jason@redhat.com>
Date:   Tue Dec 20 16:27:43 2022 -0500

    c++: lifetime extension with .* expression [PR53288]

    This PR points out a case where we are not extending the lifetime of a
    temporary when the subobject is denoted by a pointer-to-member operation.
    These rules were clarified in C++20 by CWG1299.

    There are other cases that also need to be handled under CWG1299, but are
    not fixed by this patch.

            PR c++/53288
            DR 1299

    gcc/cp/ChangeLog:

            * call.cc (extend_ref_init_temps_1): Handle ptrmem expression.

    gcc/testsuite/ChangeLog:

            * g++.dg/init/lifetime4.C: New test.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c++/53288] [C++11] Lifetime of temporary object backing pointer-to-member expression not extended
  2012-05-09  4:44 [Bug c++/53288] New: [C++11] Reference fails to bind directly to prvalue member access expression hstong at ca dot ibm.com
                   ` (4 preceding siblings ...)
  2023-01-23  0:36 ` cvs-commit at gcc dot gnu.org
@ 2023-08-11 20:36 ` jason at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: jason at gcc dot gnu.org @ 2023-08-11 20:36 UTC (permalink / raw)
  To: gcc-bugs

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

Jason Merrill <jason at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |13.0
             Status|ASSIGNED                    |RESOLVED
         Resolution|---                         |FIXED

--- Comment #6 from Jason Merrill <jason at gcc dot gnu.org> ---
Fixed for GCC 13.

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2023-08-11 20:36 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-05-09  4:44 [Bug c++/53288] New: [C++11] Reference fails to bind directly to prvalue member access expression hstong at ca dot ibm.com
2012-05-09 17:31 ` [Bug c++/53288] " redi at gcc dot gnu.org
2012-06-07 21:37 ` [Bug c++/53288] [C++11] Lifetime of temporary object backing pointer-to-member expression not extended hstong at ca dot ibm.com
2022-06-09 18:00 ` iamsupermouse at mail dot ru
2022-12-19 22:33 ` jason at gcc dot gnu.org
2023-01-23  0:36 ` cvs-commit at gcc dot gnu.org
2023-08-11 20:36 ` jason at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).