[clang-tools-extra] [clang-tidy] offer option to check sugared types in avoid-c-arrays check (PR #131468)
Piotr Zegar via cfe-commits
cfe-commits at lists.llvm.org
Sat Mar 15 15:13:08 PDT 2025
================
@@ -96,6 +97,26 @@ void AvoidCArraysCheck::check(const MatchFinder::MatchResult &Result) {
diag(ArrayType->getBeginLoc(),
"do not declare %select{C-style|C VLA}0 arrays, use %1 instead")
<< IsVLA << llvm::join(RecommendTypes, " or ");
+
+ if (CheckSugaredTypes) {
+ PrintingPolicy PrintPolicy{getLangOpts()};
+ PrintPolicy.SuppressTagKeyword = true;
+
+ const auto TypeName = ArrayType->getType().getAsString(PrintPolicy);
+ const auto DesugaredTypeName = ArrayType->getType()
+ ->getUnqualifiedDesugaredType()
+ ->getCanonicalTypeInternal()
+ .getAsString(PrintPolicy);
+ if (TypeName != DesugaredTypeName) {
----------------
PiotrZSL wrote:
avoid using string comparison, compare types
https://github.com/llvm/llvm-project/pull/131468
More information about the cfe-commits
mailing list