Bug 54975 - [4.7/4.8 Regression] cv-qualifiers of typedef-name are ignored in lambda expression
Summary: [4.7/4.8 Regression] cv-qualifiers of typedef-name are ignored in lambda expr...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.8.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: c++-lambda, rejects-valid
Depends on:
Blocks: lambdas
  Show dependency treegraph
 
Reported: 2012-10-18 13:29 UTC by Ai Azuma
Modified: 2022-03-11 00:32 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work: 4.6.4
Known to fail: 4.7.3, 4.8.0
Last reconfirmed: 2012-11-30 00:00:00


Attachments
Output of -v option and preprocessed file with GCC 4.8.0 20121014 (1.29 KB, text/plain)
2012-10-18 13:29 UTC, Ai Azuma
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Ai Azuma 2012-10-18 13:29:46 UTC
Created attachment 28485 [details]
Output of -v option and preprocessed file with GCC 4.8.0 20121014

The following valid code reproduces the problem;

/////////////////////////////
template<typename T>
struct identity
{
  typedef T type;
};

template<typename T>
void f()
{
  typedef typename T::type A;
  int i = 42;
  int const &cri = i;
  int volatile &vri = i;
  [&]() {
    A const &x = cri;    // Problem here
    A volatile &y = vri; // Likewise
  };
}

int main()
{
  f<identity<int> >();
}
/////////////////////////////

In the lambda-expression, initilizations of cv-qualified references are obviously legal. However, GCC 4.8.0 20121014 complains as follows;

main.cpp: In instantiation of 'f() [with T = identity<int>]::__lambda0':
main.cpp:16:21:   required from 'struct f() [with T = identity<int>]::__lambda0'
main.cpp:14:3:   required from 'void f() [with T = identity<int>]'
main.cpp:22:21:   required from here
main.cpp:15:18: error: invalid initialization of reference of type 'identity<int>::type& {aka int&}' from expression of type 'const int'
     A const &x = cri;
                  ^
main.cpp:16:21: error: invalid initialization of reference of type 'identity<int>::type& {aka int&}' from expression of type 'volatile int'
     A volatile &y = vri;
                     ^

The error messages look as if there were no cv-qualifiers in the declarators.

Note that GCC 4.7.3 20121013 also fails to compile, but GCC 4.6.4 20121012 compiles successfully.
Comment 1 Paolo Carlini 2012-11-30 11:22:04 UTC
Thus this seems a regression.
Comment 2 paolo@gcc.gnu.org 2012-12-07 09:53:14 UTC
Author: paolo
Date: Fri Dec  7 09:53:04 2012
New Revision: 194297

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=194297
Log:
2012-12-07  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/54975
	* g++.dg/cpp0x/lambda/lambda-typedef.C: New.

Added:
    trunk/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-typedef.C
Modified:
    trunk/gcc/testsuite/ChangeLog
Comment 3 Paolo Carlini 2012-12-07 09:54:44 UTC
Fixed for 4.7.3 and 4.8 by patch for bug 55058.