[PATCH] D31370: [clang-tidy] Prototype to check for exception specification
Matthias Gehre via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sat Mar 25 14:45:20 PDT 2017
mgehre added inline comments.
================
Comment at: clang-tidy/modernize/NoexceptCorrectnessCheck.cpp:60
+ N.getNodeAs<FunctionDecl>("direct_throwing_decl")) {
+ // FIXME how is that done? i did not find a noThrow predicate
+ //if (ThrowingDecl->isNoThrow()) {
----------------
JonasToth wrote:
> How can i find out the exception spepcification in a `FunctionDecl`? I would like to check if `noexcept` might be added when it is not justified.
Try `ThrowingDecl ->getType()->getAs<FunctionProtoType>()->getNoexceptSpec()`
================
Comment at: clang-tidy/modernize/NoexceptCorrectnessCheck.cpp:48
+ // hasThrowingExpression
+ anyOf(hasDescendant(cxxDynamicCastExpr()),
+ hasDescendant(cxxNewExpr())),
----------------
`dynamic_cast` can only throw if the new type is a reference type.
================
Comment at: test/clang-tidy/modernize-noexcept-correctness.cpp:4
+float throwing(float x) {
+ // CHECK-MESSAGES: :[[@LINE-1]]: 7: warning: function can be marked noexcept(false)
+ // CHECK-MESSAGES: :[[@LINE+2]]: 5: note: throw expression here
----------------
I find it helpful to get fixits for adding "noexcept", but not so much for adding noexcept(false) because this is already the default. I would prefer to hide generation of fixits that state the default behind an option.
================
Comment at: test/clang-tidy/modernize-noexcept-correctness.cpp:42
+
+// Could throw indirectly.
+float complex_wrongly_noexcept(float x, float y) noexcept {
----------------
Use `FIXME` here?
================
Comment at: test/clang-tidy/modernize-noexcept-correctness.cpp:48
+
+// Could be marked noexcept, but wont right now.
+float complex_non_throwing(float x, float y) {
----------------
Use `FIXME` here?
Repository:
rL LLVM
https://reviews.llvm.org/D31370
More information about the cfe-commits
mailing list