Reputation: 35935
C++11 specifies destructors as noexcept
by default. Is there a way I can get Clang to report cases where my noexcept
destructors might throw an exception (and hence call std::terminate
)?
Upvotes: 1
Views: 775
Reputation: 45684
First, C++ does not specify destructors as noexcept
by default.
It specifies them as noexcept(all subobjects destructors are noexcept)
.
Next, we can categorize expressions and statements in one category each of:
In all of them, only the first case will be marked as exceptional.
In order to give good results, the compiler must be able to analyze the program behavior sufficiently to determine whether for any possible state, a throwing expression is ever executed.
If you are happy with far too many warnings about impossible scenarios, you can get a result here.
Conversely, if you only want to warn about blatant cases, you might also get some results.
Trouble is, all the interesting cases devolve to solving the halting problem.
And no, we are no further along with it.
Upvotes: 1