[PATCH] D112209: [clangd] IncludeCleaner: Complicated rules for enum usage
Kirill Bobyrev via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Oct 25 13:04:46 PDT 2021
This revision was automatically updated to reflect the committed changes.
Closed by commit rG593814a10cb4: [clangd] IncludeCleaner: Complicated rules for enum usage (authored by kbobyrev).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D112209/new/
https://reviews.llvm.org/D112209
Files:
clang-tools-extra/clangd/IncludeCleaner.cpp
clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
Index: clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
+++ clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
@@ -103,6 +103,30 @@
"struct ^X { enum ^Language { ^CXX = 42, Python = 9000}; };",
"int Lang = X::CXX;",
},
+ {
+ "enum class ^Color : int;",
+ "enum class Color : int {};",
+ },
+ {
+ "enum class Color : int {};",
+ "enum class Color : int;",
+ },
+ {
+ "enum class ^Color;",
+ "Color c;",
+ },
+ {
+ "enum class ^Color : int;",
+ "Color c;",
+ },
+ {
+ "enum class ^Color : char;",
+ "Color *c;",
+ },
+ {
+ "enum class ^Color : char {};",
+ "Color *c;",
+ },
{
// When a type is resolved via a using declaration, the
// UsingShadowDecl is not referenced in the AST.
Index: clang-tools-extra/clangd/IncludeCleaner.cpp
===================================================================
--- clang-tools-extra/clangd/IncludeCleaner.cpp
+++ clang-tools-extra/clangd/IncludeCleaner.cpp
@@ -80,6 +80,15 @@
return true;
}
+ // Enums may be usefully forward-declared as *complete* types by specifying
+ // an underlying type. In this case, the definition should see the declaration
+ // so they can be checked for compatibility.
+ bool VisitEnumDecl(EnumDecl *D) {
+ if (D->isThisDeclarationADefinition() && D->getIntegerTypeSourceInfo())
+ add(D);
+ return false;
+ }
+
private:
using Base = RecursiveASTVisitor<ReferencedLocationCrawler>;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D112209.382094.patch
Type: text/x-patch
Size: 1754 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20211025/e520750b/attachment.bin>
More information about the cfe-commits
mailing list