[PATCH] D92051: [clangd] PopulateSwitch: disable on dependent enums.

Adam Czachorowski via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Nov 24 11:52:55 PST 2020


adamcz created this revision.
Herald added subscribers: cfe-commits, usaxena95, kadircet, arphaman.
Herald added a project: clang.
adamcz requested review of this revision.
Herald added subscribers: MaskRay, ilya-biryukov.

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D92051

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


Index: clang-tools-extra/clangd/unittests/TweakTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/TweakTests.cpp
+++ clang-tools-extra/clangd/unittests/TweakTests.cpp
@@ -3025,6 +3025,12 @@
           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) {
Index: clang-tools-extra/clangd/refactor/tweaks/PopulateSwitch.cpp
===================================================================
--- clang-tools-extra/clangd/refactor/tweaks/PopulateSwitch.cpp
+++ clang-tools-extra/clangd/refactor/tweaks/PopulateSwitch.cpp
@@ -126,7 +126,7 @@
     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


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D92051.307424.patch
Type: text/x-patch
Size: 1083 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20201124/f10f897d/attachment.bin>


More information about the cfe-commits mailing list