[PATCH] D12446: [PATCH] Enable clang-tidy misc-static-assert for C11

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Fri Aug 28 14:01:43 PDT 2015


aaron.ballman created this revision.
aaron.ballman added reviewers: alexfh, djasper.
aaron.ballman added a subscriber: cfe-commits.

This patch adds support for the C11 _Static_assert macro to clang-tidy's misc-static-assert checker. There are a few things I'm not overly satisfied with, and welcome suggestions on how to improve, if desired.

1) If <assert.h> is included, then static_assert() is also fine to use. Presumably, in order for the assert() check to trigger, <assert.h> has to be included, but I don't feel particularly comfortable with that assumption. If there's a way to access a Preprocessor instance from check(), we can use getMacroDefinitionAtLoc() to determine whether static_assert() is defined and a valid replacement for assert(). For right now, I'm always using _Static_assert() in C11 mode to be on the safe side.
2) My Python skills are rudimentary at best. If there's a better way to update check_clang_tidy.py to handle file extensions, that would be great. This change is required or else the script fails on .c test cases that check fixes because of writing out to a .tmp.cpp file instead of a .tmp.c file conflicts with the language options specified on the RUN line.

~Aaron

http://reviews.llvm.org/D12446

Files:
  clang-tidy/misc/StaticAssertCheck.cpp
  test/clang-tidy/check_clang_tidy.py
  test/clang-tidy/misc-static-assert-c11.c
  test/clang-tidy/misc-static-assert-c99.c

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D12446.33461.patch
Type: text/x-patch
Size: 5076 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150828/212284d5/attachment.bin>


More information about the cfe-commits mailing list