Bug 79133 - lambda capture shadowing parameter & decltype confusion
Summary: lambda capture shadowing parameter & decltype confusion
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 7.0
: P3 normal
Target Milestone: ---
Assignee: Ville Voutilainen
URL:
Keywords: accepts-invalid, c++-lambda
: 57443 86361 (view as bug list)
Depends on:
Blocks: lambdas
  Show dependency treegraph
 
Reported: 2017-01-18 15:33 UTC by Nathan Sidwell
Modified: 2022-03-11 00:32 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2018-04-24 00:00:00


Attachments
reproducer (198 bytes, text/plain)
2017-01-18 15:33 UTC, Nathan Sidwell
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Nathan Sidwell 2017-01-18 15:33:54 UTC
Created attachment 40535 [details]
reproducer

When a simple lambda capture and a lambda parameter share a name, the capture object is seen inside the lambda.  Except inside decltype, which sees the parameter.

The attached testcase produces (at -O2):

	subq	$8, %rsp
	movl	$1, %edi <-- size of lambda parm 'z'
	call	_Z3Barj
	movl	$4, %edi <-- size of lambda capture 'z'
	call	_Z3Barj
	movl	$5, %eax <-- value of lambda capture 'z'
	addq	$8, %rsp
	ret

Possibly related email:
https://gcc.gnu.org/ml/gcc-patches/2017-01/msg01331.html
Comment 2 Jonathan Wakely 2018-04-24 12:23:28 UTC
Core DR 2211 makes this ill-formed, so it should be rejected.
Comment 3 Jonathan Wakely 2018-04-24 12:24:36 UTC
*** Bug 57443 has been marked as a duplicate of this bug. ***
Comment 4 Jonathan Wakely 2018-05-23 14:13:56 UTC
CCing Ville as he reported the core issue and had assigned the PR 57443 dup to himself.
Comment 5 Ville Voutilainen 2018-07-06 22:03:32 UTC
*** Bug 86361 has been marked as a duplicate of this bug. ***
Comment 6 ville 2018-08-07 13:46:48 UTC
Author: ville
Date: Tue Aug  7 13:46:16 2018
New Revision: 263357

URL: https://gcc.gnu.org/viewcvs?rev=263357&root=gcc&view=rev
Log:
PR c++/79133

gcc/cp/

PR c++/79133
* name-lookup.c (check_local_shadow): Reject captures and parameters
with the same name.

testsuite/

PR c++/79133
* g++.dg/cpp0x/lambda/lambda-shadow3.C: New.
* g++.dg/cpp1y/lambda-generic-variadic18.C: Likewise.

Added:
    trunk/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-shadow3.C
    trunk/gcc/testsuite/g++.dg/cpp1y/lambda-generic-variadic18.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/name-lookup.c
Comment 7 Ville Voutilainen 2018-08-07 13:47:38 UTC
Fixed.