Bug 45401 - [C++0x] reference collapsing and reference qualifiers
Summary: [C++0x] reference collapsing and reference qualifiers
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.5.0
: P3 normal
Target Milestone: 4.6.1
Assignee: Jason Merrill
URL:
Keywords: accepts-invalid, rejects-valid
Depends on:
Blocks:
 
Reported: 2010-08-24 20:29 UTC by Hubert Tong
Modified: 2011-05-26 03:09 UTC (History)
3 users (show)

See Also:
Host: powerpc64-unknown-linux-gnu
Target: powerpc64-unknown-linux-gnu
Build:
Known to work:
Known to fail: 4.3.2, 4.4.0, 4.5.0
Last reconfirmed: 2011-05-25 20:31:01


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Hubert Tong 2010-08-24 20:29:41 UTC
Based on the wording in FCD 14882 (WG21 N3092), reference collapsing preserves
the target type in the case where an attempt is made to create an rvalue
reference to a reference. The standard does not include reference qualifiers--
such as __restrict__ or (for the SPU port) __ea--however.

In the following code, rvrefToRestrictLvref should have the same type as
restrictLvref based on 8.3.2 [dcl.ref] paragraph 6:

   If a typedef (7.1.3), a type template-parameter (14.3.1), or a decltype-
   specifier (7.1.6.2) denotes a type TR that is a reference to a type T, an
   attempt to create the type "lvalue reference to cv TR" creates the type
   "lvalue reference to T", while an attempt to create the type "rvalue
   reference to cv TR" creates the type TR.

The following test case demonstrates that GCC is finding the type to be
'int &'; that is, the __restrict is gone and the two typedefs fail to denote
the same type.

The test case is meant to compile clean.


### Self-contained source (dataa.cpp):
typedef int &__restrict restrictLvref;
typedef restrictLvref &&rvrefToRestrictLvref;
typedef restrictLvref rvrefToRestrictLvref;


### Command to reproduce:
g++ -std=gnu++0x -c dataa.cpp


### Compiler output:
dataa.cpp:3:23: error: conflicting declaration 'typedef int& __restrict__ rvrefToRestrictLvref'
dataa.cpp:2:25: error: 'rvrefToRestrictLvref' has a previous declaration as 'typedef int& rvrefToRestrictLvref'


### g++ -v output:
Using built-in specs.
Target: powerpc64-unknown-linux-gnu
Configured with: ../gcc-4.5.0/configure --prefix=/data/gcc
--program-suffix=-4.5.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
Thread model: posix
gcc version 4.5.0 (GCC)
Comment 1 Jason Merrill 2011-05-26 02:22:42 UTC
Author: jason
Date: Thu May 26 02:22:39 2011
New Revision: 174255

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=174255
Log:
	PR c++/45401
	* decl.c (grokdeclarator): Don't change type when adding rvalue ref
	to another reference type.

Added:
    trunk/gcc/testsuite/g++.dg/cpp0x/rv-restrict.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/decl.c
    trunk/gcc/testsuite/ChangeLog
Comment 2 Jason Merrill 2011-05-26 03:06:13 UTC
Author: jason
Date: Thu May 26 03:06:09 2011
New Revision: 174260

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=174260
Log:
	PR c++/45401
	* decl.c (grokdeclarator): Don't change type when adding rvalue ref
	to another reference type.

Added:
    branches/gcc-4_6-branch/gcc/testsuite/g++.dg/cpp0x/rv-restrict.C
Modified:
    branches/gcc-4_6-branch/gcc/cp/ChangeLog
    branches/gcc-4_6-branch/gcc/cp/decl.c
    branches/gcc-4_6-branch/gcc/testsuite/ChangeLog
Comment 3 Jason Merrill 2011-05-26 03:09:41 UTC
Fixed for 4.6.1.