I use the clang analyzer to check C ++ code for errors and errors. I have the following construct:
#include <cstdlib> #include <iostream> double somethingThatMayThrow() throw (std::exception) { if( rand() % 2 ) { throw std::exception(); } return 5.0; } int main() { double value = 2.0; try { value = somethingThatMayThrow(); } catch( const std::exception& ) { std::cout << "oops" << std::endl; } double someOtherValue = value + 1.0; std::cout << someOtherValue << std::endl; return 0; }
The analyzer now complains that the initial value of the value variable is never read. However, it is clear that the value is used in the last line if and only if there is an exception in the try block. Is this understanding correct and am I looking at an error in the analyzer? Or am I missing something?
How does the standard define this behavior? What happens to the left side of the job if the right side is selected?
The screenshot below shows the actual code complained of by the analyzer, which has the same structure as my example above:

source share