Bug 85815 - [7/8/9 Regression] incorrect "invalid use of incomplete type" in a lambda on valid code
Summary: [7/8/9 Regression] incorrect "invalid use of incomplete type" in a lambda on ...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 7.3.1
: P2 normal
Target Milestone: 7.4
Assignee: Jason Merrill
URL:
Keywords: diagnostic, rejects-valid
Depends on:
Blocks:
 
Reported: 2018-05-17 07:44 UTC by Valentine
Modified: 2021-11-29 20:05 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work: 6.4.0
Known to fail:
Last reconfirmed: 2018-05-17 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Valentine 2018-05-17 07:44:12 UTC
This valid code:

template<class T>
class A {
    static A* INSTANCE;
    void foobar();
    void moo() {}
};

template<class T>
A<T>* A<T>::INSTANCE = nullptr;

template<class T>
void A<T>::foobar() {
    auto x = []() {
        INSTANCE->moo();
    };
}

(compiled with -Wall)

Gives error:
<source>: In lambda function:

<source>:14:17: error: invalid use of incomplete type 'class A<T>' [-Werror]

         INSTANCE->moo();

This compiles fine with Clang and GCC 6, but fails with the error above with GCC 7 and 8.
Comment 1 Richard Biener 2018-05-17 09:33:01 UTC
Confirmed.
Comment 2 Jason Merrill 2018-05-25 21:03:39 UTC
Author: jason
Date: Fri May 25 21:03:07 2018
New Revision: 260782

URL: https://gcc.gnu.org/viewcvs?rev=260782&root=gcc&view=rev
Log:
	PR c++/85815 - reference to member of enclosing template.

	* search.c (lookup_base): Use currently_open_class.
	(lookup_member): Use it regardless of -fconcepts.
	* parser.c (cp_parser_postfix_dot_deref_expression): Check it.

Added:
    trunk/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-dependent1.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/class.c
    trunk/gcc/cp/parser.c
    trunk/gcc/cp/search.c
Comment 3 Jason Merrill 2018-06-11 22:02:28 UTC
Author: jason
Date: Mon Jun 11 22:01:55 2018
New Revision: 261460

URL: https://gcc.gnu.org/viewcvs?rev=261460&root=gcc&view=rev
Log:
	PR c++/85815 - reference to member of enclosing template.

	* search.c (lookup_base): Use currently_open_class.
	(lookup_member): Use it regardless of -fconcepts.
	* parser.c (cp_parser_postfix_dot_deref_expression): Check it.

Added:
    branches/gcc-8-branch/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-dependent1.C
Modified:
    branches/gcc-8-branch/gcc/cp/ChangeLog
    branches/gcc-8-branch/gcc/cp/class.c
    branches/gcc-8-branch/gcc/cp/parser.c
    branches/gcc-8-branch/gcc/cp/search.c
Comment 4 Jason Merrill 2018-06-12 19:53:33 UTC
Fixed for 7.4/8.2.
Comment 5 Jason Merrill 2018-06-12 19:53:45 UTC
Author: jason
Date: Tue Jun 12 19:53:10 2018
New Revision: 261524

URL: https://gcc.gnu.org/viewcvs?rev=261524&root=gcc&view=rev
Log:
	PR c++/85815 - reference to member of enclosing template.

	* parser.c (cp_parser_postfix_dot_deref_expression): Check
	currently_open_class.

Added:
    branches/gcc-7-branch/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-dependent1.C
Modified:
    branches/gcc-7-branch/gcc/cp/ChangeLog
    branches/gcc-7-branch/gcc/cp/parser.c