[PATCH] D35257: [clang-tidy] Add new modernize use unary assert check

Barancsuk Lilla via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Jul 12 06:29:08 PDT 2017


barancsuk added inline comments.


================
Comment at: test/clang-tidy/modernize-unary-static-assert.cpp:16
+  // CHECK-FIXES: {{^}}  FOO{{$}}
+  static_assert(sizeof(a) <= 17, MSG);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use unary 'static_assert' when
----------------
aaron.ballman wrote:
> This probably should not diagnose, but definitely should not provide a fixit -- just because the macro is empty doesn't mean it will *always* be empty. Consider:
> ```
> #if FOO
> #define MSG ""
> #else
> #define MSG "Not empty"
> #endif
> ```
> I think diagnosing this case is just as likely to be a false-positive as not diagnosing, so my preference is to be silent instead of chatty. However, maybe there are other opinions.
You are right. Unfortunately, the message is also from a macro expansion when the whole static assert is from a macro expansion. Maybe it is possible to check whether they are from the same macro, but I think it might better be addressed in a separate patch if there is a need to support that case. 


https://reviews.llvm.org/D35257





More information about the cfe-commits mailing list