Bug 85764 - [8/9 Regression] bogus ‘this’ was not captured for this lambda function error
Summary: [8/9 Regression] bogus ‘this’ was not captured for this lambda function error
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 8.1.0
: P2 normal
Target Milestone: 8.2
Assignee: Jason Merrill
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2018-05-12 23:30 UTC by Sebastian Ullrich
Modified: 2018-06-12 18:49 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work: 6.1.0, 6.2.0, 6.3.0, 7.3.0
Known to fail: 7.1.0, 7.2.0, 8.1.0
Last reconfirmed: 2018-05-29 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Sebastian Ullrich 2018-05-12 23:30:34 UTC
template<typename Key>
class trie {
    static void for_each(int & f, trie const & n, Key & prefix) {
        [&](trie const & c) {
          for_each(f, c, prefix);
        };
    }
    void for_each(int & f) const {
    }
};

---

$ g++ foo.h
foo.h: In lambda function:
foo.h:5:32: error: ‘this’ was not captured for this lambda function
           for_each(f, c, prefix);


Works fine in 7.3. Also works after removing the lambda (i.e. the overload is resolved correctly) or the template.
Comment 1 Jason Merrill 2018-06-02 03:15:22 UTC
Author: jason
Date: Sat Jun  2 03:14:44 2018
New Revision: 261101

URL: https://gcc.gnu.org/viewcvs?rev=261101&root=gcc&view=rev
Log:
	PR c++/85764 - bogus 'this' not captured error.

	* lambda.c (resolvable_dummy_lambda): Use nonlambda_method_basetype.
	(nonlambda_method_basetype): Handle NSDMI.

Added:
    trunk/gcc/testsuite/g++.dg/cpp1y/lambda-generic-this2.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/lambda.c
Comment 2 Jason Merrill 2018-06-11 22:02:43 UTC
Author: jason
Date: Mon Jun 11 22:02:07 2018
New Revision: 261462

URL: https://gcc.gnu.org/viewcvs?rev=261462&root=gcc&view=rev
Log:
	PR c++/85764 - bogus 'this' not captured error.

	* lambda.c (resolvable_dummy_lambda): Use nonlambda_method_basetype.
	(nonlambda_method_basetype): Handle NSDMI.

Added:
    branches/gcc-8-branch/gcc/testsuite/g++.dg/cpp1y/lambda-generic-this2.C
Modified:
    branches/gcc-8-branch/gcc/cp/ChangeLog
    branches/gcc-8-branch/gcc/cp/lambda.c
Comment 3 Jason Merrill 2018-06-12 18:49:06 UTC
Fixed for 8.2.