[llvm-branch-commits] [clang-tools-extra] f697050 - [clangd] PopulateSwitch: disable on dependent enums.

Adam Czachorowski via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Wed Nov 25 05:24:11 PST 2020


Author: Adam Czachorowski
Date: 2020-11-25T14:12:29+01:00
New Revision: f6970503d291b7cae70fe583bed392387f93f9e4

URL: https://github.com/llvm/llvm-project/commit/f6970503d291b7cae70fe583bed392387f93f9e4
DIFF: https://github.com/llvm/llvm-project/commit/f6970503d291b7cae70fe583bed392387f93f9e4.diff

LOG: [clangd] PopulateSwitch: disable on dependent enums.

If the enum is a dependent type, we would crash somewhere in
getIntWidth(). -Wswitch diagnostic doesn't work on dependent enums
either.

Differential Revision: https://reviews.llvm.org/D92051

Added: 
    

Modified: 
    clang-tools-extra/clangd/refactor/tweaks/PopulateSwitch.cpp
    clang-tools-extra/clangd/unittests/TweakTests.cpp

Removed: 
    


################################################################################
diff  --git a/clang-tools-extra/clangd/refactor/tweaks/PopulateSwitch.cpp b/clang-tools-extra/clangd/refactor/tweaks/PopulateSwitch.cpp
index 852888f6a043..bae80cdecf59 100644
--- a/clang-tools-extra/clangd/refactor/tweaks/PopulateSwitch.cpp
+++ b/clang-tools-extra/clangd/refactor/tweaks/PopulateSwitch.cpp
@@ -126,7 +126,7 @@ bool PopulateSwitch::prepare(const Selection &Sel) {
     return false;
 
   EnumD = EnumT->getDecl();
-  if (!EnumD)
+  if (!EnumD || EnumD->isDependentType())
     return false;
 
   // We trigger if there are any values in the enum that aren't covered by the

diff  --git a/clang-tools-extra/clangd/unittests/TweakTests.cpp b/clang-tools-extra/clangd/unittests/TweakTests.cpp
index fd815d2c4c27..4a2360dda739 100644
--- a/clang-tools-extra/clangd/unittests/TweakTests.cpp
+++ b/clang-tools-extra/clangd/unittests/TweakTests.cpp
@@ -3084,6 +3084,12 @@ TEST_F(PopulateSwitchTest, Test) {
           R""(enum Enum {A,B,b=B}; ^switch (A) {case A:case B:break;})"",
           "unavailable",
       },
+      {
+          // Enum is dependent type
+          File,
+          R""(template<typename T> void f() {enum Enum {A}; ^switch (A) {}})"",
+          "unavailable",
+      },
   };
 
   for (const auto &Case : Cases) {


        


More information about the llvm-branch-commits mailing list