[PATCH] D88833: [clang-tidy] Do not warn on pointer decays in system macros

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Oct 7 06:28:07 PDT 2020


aaron.ballman added a comment.

Despite my earlier happiness with the patch, it's now a bit unclear to me from the C++ Core Guideline wording what the right behavior here actually is. The bounds profile is trying to ensure you don't access out-of-range elements of a container and the decay part specifically seems to be more about how it impacts pointer arithmetic.

My intuition is that `sys_fn_decay_str(__PRETTY_FUNCTION__)` and `sys_fn_decay_str(SYS_STRING)` outside of a system header should diagnose the same way, as should the `user_fn_decay_str` variants of it. Both are decays of a string expanded from something outside of the user's control and requiring a cast for one and not the other seems inexplicable. However, it's not clear to me whether the C++ core guidelines would expect a diagnostic for these cases or not, but we currently diagnose one way and not the other, which seems wrong.

WDYT?



================
Comment at: clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsArrayToPointerDecayCheck.cpp:56-58
+    const ValueDecl *SymbolDecl = SymbolDeclRef->getDecl();
+    if (SymbolDecl && SM.isInSystemHeader(SymbolDecl->getLocation()))
+      return true;
----------------
```
if (const ValueDecl *VD = SymDeclRef->getDecl())
  return SM.isInSystemHeader(VD->getLocation());
```


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D88833/new/

https://reviews.llvm.org/D88833



More information about the cfe-commits mailing list