Bug 71546 - lambda capture fails with "was not declared in this scope"
Summary: lambda capture fails with "was not declared in this scope"
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: unknown
: P3 normal
Target Milestone: 8.0
Assignee: Not yet assigned to anyone
URL:
Keywords: rejects-valid
Depends on:
Blocks: lambdas
  Show dependency treegraph
 
Reported: 2016-06-15 21:03 UTC by Stefaan De Roeck
Modified: 2018-02-27 20:59 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2017-10-05 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Stefaan De Roeck 2016-06-15 21:03:09 UTC
The following code fails to compile:

#include <memory>

int main()
{
  int x1;
  [e = std::make_shared <int> (), x1]() {};
}

saying:
/tmp/gcc-explorer-compiler116515-85-117auiu/example.cpp: In function 'int main()':
6 : error: 'x1' was not declared in this scope
[e = std::make_shared <int> (), x1]() {};
^~
6 : error: redeclaration of '<typeprefixerror>x1'
5 : note: previous declaration 'int x1'
int x1;
^~
Compilation failed

(tested on gcc.godbolt.org, using gcc-6.1 -std=c++14)
Comment 1 Jason Merrill 2018-02-27 20:58:07 UTC
Author: jason
Date: Tue Feb 27 20:57:35 2018
New Revision: 258043

URL: https://gcc.gnu.org/viewcvs?rev=258043&root=gcc&view=rev
Log:
	PR c++/71546 - lambda init-capture with qualified-id.

	* parser.c (cp_parser_lambda_introducer): Clear scope after
	each lambda capture.

Added:
    trunk/gcc/testsuite/g++.dg/cpp1y/lambda-init17.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/parser.c
Comment 2 Jason Merrill 2018-02-27 20:59:36 UTC
Fixed for GCC 8.