Bug 52374 - [C++11] Fails to transform id-expression into dependent base member access in lambda expression
Summary: [C++11] Fails to transform id-expression into dependent base member access in...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.7.0
: P3 normal
Target Milestone: 4.8.1
Assignee: Jason Merrill
URL:
Keywords: c++-lambda, rejects-valid
Depends on:
Blocks: lambdas
  Show dependency treegraph
 
Reported: 2012-02-24 16:45 UTC by Ai Azuma
Modified: 2022-03-11 00:32 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2012-02-24 00:00:00


Attachments
Output of -v option and preprocessed file (1.17 KB, text/plain)
2012-02-24 16:45 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-02-24 16:45:10 UTC
Created attachment 26742 [details]
Output of -v option and preprocessed file

In the lambda expression's compound statement, id-expressions referring to non-static members should be transformed into class member access expressions by prefixing `(*this).'. However, GCC fails the transformation when id-expressions involved are qualified-ids and refer to dependent base members.

A test case is as follows;

////////////////////////////////////////////////////////////////////
struct B
{
  int get() const { return 42; }
};

template<typename X>
struct D
  : public X
{
  int get() const { return [this]() -> int { return X::get(); }(); }
};

int main()
{
  D<B> d;
  d.get();
}

////////////////////////////////////////////////////////////////////

For the above mentioned well-formed code, 4.7.0 20120218 (experimental) with -std=c++11 complains as follows;

main.cpp: In instantiation of 'D<X>::get() const [with X = B]::<lambda()>':
main.cpp:10:29:   required from 'struct D<X>::get() const [with X = B]::<lambda()>'
main.cpp:10:65:   required from 'int D<X>::get() const [with X = B]'
main.cpp:16:9:   required from here
main.cpp:10:60: error: cannot call member function 'int B::get() const' without object

`X::get' in the lambda expression should be implicitly transformed into `(*this).X::get', and the test case should compile successfully.
Comment 1 Jason Merrill 2013-03-17 02:39:18 UTC
Author: jason
Date: Sun Mar 17 02:39:04 2013
New Revision: 196743

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=196743
Log:
	PR c++/52374
	* pt.c (tsubst_qualified_id): Use current_nonlambda_class_type.

Added:
    trunk/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-this13.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/pt.c
Comment 2 Jason Merrill 2013-03-23 19:24:48 UTC
Fixed for 4.8.1.