User account creation filtered due to spam.

Bug 56701 - [C++11] The *this* pointer fails to bind to rvalue reference to pointer type
Summary: [C++11] The *this* pointer fails to bind to rvalue reference to pointer type
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.8.0
: P3 normal
Target Milestone: 4.9.0
Assignee: Jason Merrill
URL:
Keywords: rejects-valid
: 69208 (view as bug list)
Depends on:
Blocks:
 
Reported: 2013-03-23 22:38 UTC by Jesse Good
Modified: 2016-08-15 02:22 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2013-03-24 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jesse Good 2013-03-23 22:38:14 UTC
The following fails to compile with gcc 4.8.0:

struct A
{
  void f(){ A*&& a = this; }
};
int main(){}

Error messages:
error: invalid initialization of reference of type 'A*&&' from expression of type 'A* const'
void f(){ A*&& a = this; }


According to 9.3.2p1, the this pointer is a prvalue of type A*, not A* const as the error message suggests.
Comment 1 Jonathan Wakely 2013-03-24 20:12:51 UTC
Confirmed, the reference should be bound to a temporary of type A*
Comment 2 Jason Merrill 2013-03-28 20:05:11 UTC
Fixed for 4.9.
Comment 3 TC 2015-09-04 22:13:19 UTC
This still breaks:

struct A
{
  void f(){ A*&& a = &*this; }
};
int main(){}
Comment 4 Jonathan Wakely 2016-08-06 13:50:10 UTC
(In reply to TC from comment #3)
> This still breaks:
> 
> struct A
> {
>   void f(){ A*&& a = &*this; }
> };
> int main(){}

Jason, should this be reopened?
Comment 5 Jason Merrill 2016-08-09 14:09:05 UTC
Author: jason
Date: Tue Aug  9 14:08:33 2016
New Revision: 239285

URL: https://gcc.gnu.org/viewcvs?rev=239285&root=gcc&view=rev
Log:
	PR c++/56701 - wrong type of &*this

	* typeck.c (cp_build_addr_expr_1): Remove special *this handling.

Added:
    trunk/gcc/testsuite/g++.dg/cpp0x/rv-this2.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/typeck.c
Comment 6 Jason Merrill 2016-08-09 14:09:31 UTC
New testcase fixed for GCC 7.
Comment 7 TC 2016-08-15 02:22:12 UTC
*** Bug 69208 has been marked as a duplicate of this bug. ***