This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/54975] New: [C++11] cv-qualifiers of typedef-name are ignored in lambda expression
- From: "ai.azuma at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Thu, 18 Oct 2012 13:29:46 +0000
- Subject: [Bug c++/54975] New: [C++11] cv-qualifiers of typedef-name are ignored in lambda expression
- Auto-submitted: auto-generated
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54975
Bug #: 54975
Summary: [C++11] cv-qualifiers of typedef-name are ignored in
lambda expression
Classification: Unclassified
Product: gcc
Version: 4.8.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: ai.azuma@gmail.com
Created attachment 28485
--> http://gcc.gnu.org/bugzilla/attachment.cgi?id=28485
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.