[clang] [-Wunsafe-buffer-usage] Introduce std::array fixits (PR #80084)

via cfe-commits cfe-commits at lists.llvm.org
Wed Feb 7 18:04:33 PST 2024


================
@@ -2495,10 +2471,100 @@ static FixItList fixVariableWithSpan(const VarDecl *VD,
   return fixLocalVarDeclWithSpan(VD, Ctx, getUserFillPlaceHolder(), Handler);
 }
 
+static FixItList fixVarDeclWithArray(const VarDecl *D, const ASTContext &Ctx,
+                                     UnsafeBufferUsageHandler &Handler) {
+  FixItList FixIts{};
+
+  if (auto CAT = dyn_cast<clang::ConstantArrayType>(D->getType())) {
----------------
jkorous-apple wrote:

Sorry for the confusion but I actually changed the conditions in the callers in the commit that addresses the type sugar.
https://github.com/llvm/llvm-project/pull/80084/commits/d49d5fd7e80463223aee9eac4ebd9e3c934cf9bd

My reasoning is that the layers above just check what kind of variable they are dealing with (e. g. pointer vs array) for which they need canonical type.
These rely on more specific functions to produce the fixits in a given context. Ultimately I see it as responsibility of `fixVarDeclWithArray` to handle any local variable of an array type and it shouldn't expect only canonical arrays. Maybe there will be some cases of type sugar for which it'll provide fixits in the future.

https://github.com/llvm/llvm-project/pull/80084


More information about the cfe-commits mailing list