junaire updated this revision to Diff 423079.
junaire added a comment.

Add a release note.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D123840/new/

https://reviews.llvm.org/D123840

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/IdentifierResolver.cpp
  clang/test/SemaCXX/cxx1z-init-statement.cpp


Index: clang/test/SemaCXX/cxx1z-init-statement.cpp
===================================================================
--- clang/test/SemaCXX/cxx1z-init-statement.cpp
+++ clang/test/SemaCXX/cxx1z-init-statement.cpp
@@ -90,3 +90,18 @@
   static_assert(constexpr_switch_init(-2) == 0, "");
   static_assert(constexpr_switch_init(-5) == -1, "");
 }
+
+int test_lambda_init() {
+  if (int x = []() {int x = 42; return x; }(); x) {
+  };
+
+  switch (int y = []() {int y = 42; return y; }(); y) {
+  case 42:
+    return 1;
+  }
+
+  for (int x = [] { int x = 0; return x; }();;)
+    ;
+
+  return 0;
+}
Index: clang/lib/Sema/IdentifierResolver.cpp
===================================================================
--- clang/lib/Sema/IdentifierResolver.cpp
+++ clang/lib/Sema/IdentifierResolver.cpp
@@ -121,7 +121,10 @@
       // of the controlled statement.
       //
       assert(S->getParent() && "No TUScope?");
-      if (S->getParent()->getFlags() & Scope::ControlScope) {
+      // If the current decl is in a lambda, we shouldn't consider this is a
+      // redefinition as lambda has its own scope.
+      if (S->getParent()->getFlags() & Scope::ControlScope &&
+          !S->isFunctionScope()) {
         S = S->getParent();
         if (S->isDeclScope(D))
           return true;
Index: clang/docs/ReleaseNotes.rst
===================================================================
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -119,6 +119,9 @@
   This fixes Issue `Issue 52802 
<https://github.com/llvm/llvm-project/issues/52802>`_.
 - Unknown type attributes with a ``[[]]`` spelling are no longer diagnosed 
twice.
   This fixes Issue `Issue 54817 
<https://github.com/llvm/llvm-project/issues/54817>`_.
+- No longer produce a wrong redefinition error if variables are defined in 
if/for/switch init statements
+  and lambda.
+  This fixes `Issue 54913 
<https://github.com/llvm/llvm-project/issues/54913>`_.
 
 Improvements to Clang's diagnostics
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^


Index: clang/test/SemaCXX/cxx1z-init-statement.cpp
===================================================================
--- clang/test/SemaCXX/cxx1z-init-statement.cpp
+++ clang/test/SemaCXX/cxx1z-init-statement.cpp
@@ -90,3 +90,18 @@
   static_assert(constexpr_switch_init(-2) == 0, "");
   static_assert(constexpr_switch_init(-5) == -1, "");
 }
+
+int test_lambda_init() {
+  if (int x = []() {int x = 42; return x; }(); x) {
+  };
+
+  switch (int y = []() {int y = 42; return y; }(); y) {
+  case 42:
+    return 1;
+  }
+
+  for (int x = [] { int x = 0; return x; }();;)
+    ;
+
+  return 0;
+}
Index: clang/lib/Sema/IdentifierResolver.cpp
===================================================================
--- clang/lib/Sema/IdentifierResolver.cpp
+++ clang/lib/Sema/IdentifierResolver.cpp
@@ -121,7 +121,10 @@
       // of the controlled statement.
       //
       assert(S->getParent() && "No TUScope?");
-      if (S->getParent()->getFlags() & Scope::ControlScope) {
+      // If the current decl is in a lambda, we shouldn't consider this is a
+      // redefinition as lambda has its own scope.
+      if (S->getParent()->getFlags() & Scope::ControlScope &&
+          !S->isFunctionScope()) {
         S = S->getParent();
         if (S->isDeclScope(D))
           return true;
Index: clang/docs/ReleaseNotes.rst
===================================================================
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -119,6 +119,9 @@
   This fixes Issue `Issue 52802 <https://github.com/llvm/llvm-project/issues/52802>`_.
 - Unknown type attributes with a ``[[]]`` spelling are no longer diagnosed twice.
   This fixes Issue `Issue 54817 <https://github.com/llvm/llvm-project/issues/54817>`_.
+- No longer produce a wrong redefinition error if variables are defined in if/for/switch init statements
+  and lambda.
+  This fixes `Issue 54913 <https://github.com/llvm/llvm-project/issues/54913>`_.
 
 Improvements to Clang's diagnostics
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to