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)
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
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
Fixed for 4.6.1.