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)


-- 
           Summary: [C++0x] reference collapsing and reference qualifiers
           Product: gcc
           Version: 4.5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: hstong at ca dot ibm dot com
  GCC host triplet: powerpc64-unknown-linux-gnu
GCC target triplet: powerpc64-unknown-linux-gnu


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

Reply via email to