[PATCH] D14824: [PATCH] Add clang-tidy check for static or thread_local objects where construction may throw

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Fri Nov 20 10:05:10 PST 2015


aaron.ballman added a comment.

Btw, here are some statistics as to the rate at which this diagnostic is triggered:

LLVM: 21255 warnings (about 18000 warnings were due to two AST matcher constructors; adding noexcept to those brings the count to 2895 warnings, most of which are cl::opt-related and can be similarly silenced) (2.1MM LoC)
Qt: 0 warnings (4.4MM LoC)
rethinkdb: 44 warnings (5.7MM LoC)
cocos2d: 1339 warnings (984k LoC)
opencv: 203 warnings (657k LoC)

As best I can tell from random sampling, all of the diagnostics are true positives in that the compiler is unaware of whether the constructor will throw or not. However, many of these true positives come from user-provided constructors where the initializer list does all the work, and the constructor body is empty. In the samples I looked at, the constructors do not throw and can be marked noexcept to silence the warning. However, a few of the constructors can throw and this is a definite true positive instead of a practical false positive.

One possible heuristic to silence more of the warnings is to not warn when the constructor called is the default constructor accepting no arguments and the constructor body is trivial, with the belief that default initialization generally does not throw. However, I don't think this diagnostic is chatty enough to warrant that measure when the user can simply add noexcept to the constructor in the event it truly does not throw.


http://reviews.llvm.org/D14824





More information about the cfe-commits mailing list