[PATCH] D70265: [clang-tidy] Add CppCoreGuidelines I.2 "Avoid non-const global variables" check

Kim Viggedal via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Mar 31 22:32:50 PDT 2020


vingeldal added a comment.

In D70265#1953335 <https://reviews.llvm.org/D70265#1953335>, @lebedev.ri wrote:

> Hello.
>  2 points:
>
> rG512767eb3fe9c34c655a480d034147c54f1d4f85 <https://reviews.llvm.org/rG512767eb3fe9c34c655a480d034147c54f1d4f85> doesn't reference this review,
>  so it's a bit hard to find. Please try to reference it next time.


Will do

> Is this check really intentionally complaining about function-scope static variables?
>  How are they global?
>  https://godbolt.org/z/2QMemL
> 
>   void bar(int*);
>   
>   void foo() {
>     static int a;
>     bar(&a);
>   }
> 
> 
> 
> 
>   <source>:4:14: warning: variable 'a' is non-const and globally accessible, consider making it const [cppcoreguidelines-avoid-non-const-global-variables]
>     static int a;
>                ^

I think that's a false positive, I think it's caught because the variable is static, I'll submit a patch where that doesn't happen ASAP.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70265





More information about the cfe-commits mailing list