Author: Jun Zhang Date: 2022-04-20T23:45:44+08:00 New Revision: 9f075c3d84fb359efb6496535ab397a6f09609e2
URL: https://github.com/llvm/llvm-project/commit/9f075c3d84fb359efb6496535ab397a6f09609e2 DIFF: https://github.com/llvm/llvm-project/commit/9f075c3d84fb359efb6496535ab397a6f09609e2.diff LOG: Revert "[Clang][Sema] Fix invalid redefinition error in if/switch/for statement" This reverts commit be0905a333d6f7c4d7f5c70c18211463e53473cd. This patch broke build addressed in https://github.com/llvm/llvm-project/issues/54968 Signed-off-by: Jun Zhang <j...@junz.org> Added: Modified: clang/docs/ReleaseNotes.rst clang/lib/Sema/IdentifierResolver.cpp clang/test/SemaCXX/cxx1z-init-statement.cpp Removed: ################################################################################ diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index fb81e9db5691e..03561fe2150aa 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -119,10 +119,6 @@ Bug Fixes 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>`_. -- 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. - This fixes `Issue 54913 <https://github.com/llvm/llvm-project/issues/54913>`_. Improvements to Clang's diagnostics ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/clang/lib/Sema/IdentifierResolver.cpp b/clang/lib/Sema/IdentifierResolver.cpp index 9081714c893f5..cef1ae890e6cb 100644 --- a/clang/lib/Sema/IdentifierResolver.cpp +++ b/clang/lib/Sema/IdentifierResolver.cpp @@ -123,7 +123,7 @@ bool IdentifierResolver::isDeclInScope(Decl *D, DeclContext *Ctx, Scope *S, assert(S->getParent() && "No TUScope?"); // 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()->isControlScope() && !S->isFunctionScope()) { + if (S->getParent()->isControlScope()) { S = S->getParent(); if (S->isDeclScope(D)) return true; diff --git a/clang/test/SemaCXX/cxx1z-init-statement.cpp b/clang/test/SemaCXX/cxx1z-init-statement.cpp index b963c9eabe79b..eea2589ab7c62 100644 --- a/clang/test/SemaCXX/cxx1z-init-statement.cpp +++ b/clang/test/SemaCXX/cxx1z-init-statement.cpp @@ -90,18 +90,3 @@ void test_constexpr_init_stmt() { 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; -} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits