Bug 79133

Summary: lambda capture shadowing parameter & decltype confusion
Product: gcc Reporter: Nathan Sidwell <nathan>
Component: c++Assignee: Ville Voutilainen <ville.voutilainen>
Status: RESOLVED FIXED    
Severity: normal CC: daniel.kruegler, ville.voutilainen, webrown.cpp
Priority: P3 Keywords: accepts-invalid, c++-lambda
Version: 7.0   
Target Milestone: 9.0   
Host: Target:
Build: Known to work:
Known to fail: Last reconfirmed: 2018-04-24 00:00:00
Bug Depends on:    
Bug Blocks: 54367    
Attachments: reproducer

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.