[clangd] IncludeCleaner: Complicated rules for enum usage

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D112209
This commit is contained in:
Kirill Bobyrev 2021-10-25 21:26:37 +02:00
parent bf6e259b21
commit 593814a10c
2 changed files with 33 additions and 0 deletions

View File

@ -80,6 +80,15 @@ public:
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>;

View File

@ -103,6 +103,30 @@ TEST(IncludeCleaner, ReferencedLocations) {
"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.