[Clang][Sema] Fix invalid redefinition error in if/switch/for statement
authorJun Zhang <jun@junz.org>
Fri, 15 Apr 2022 07:14:38 +0000 (15:14 +0800)
committerJun Zhang <jun@junz.org>
Fri, 15 Apr 2022 13:54:39 +0000 (21:54 +0800)
commitbe0905a333d6f7c4d7f5c70c18211463e53473cd
tree2a5829e1732e27f182dafec878629f18545eb863
parent61bd985f2a6f58a5f796ba742a7378e60bf1c51a
[Clang][Sema] Fix invalid redefinition error in if/switch/for statement

Clang should no longer incorrectly diagnose a variable declaration inside of a
lambda expression that shares the name of a variable in a containing
if/while/for/switch init statement as a redeclaration.

After this patch, clang is supposed to accept code below:

void foo() {
  for (int x = [] { int x = 0; return x; }(); ;) ;
}

Fixes https://github.com/llvm/llvm-project/issues/54913

Differential Revision: https://reviews.llvm.org/D123840
clang/docs/ReleaseNotes.rst
clang/lib/Sema/IdentifierResolver.cpp
clang/test/SemaCXX/cxx1z-init-statement.cpp