We are using LCOV/GCOV to produce test coverage of our projects. Recently we tried to enable branch-coverage additionally. But it looks like, this just doesn\'t yield the re
You can try g++ -O3 --coverage main.cpp -o testcov. I have tried this with g++-5.4 on your file and it works fine, meaning exceptions are discarded with standard printf and string calls.
In fact, any optimization flag other than O0 will cause gcov to ignore exceptions generated for plain standard library calls in a CPP file. I am not sure if normal exceptions will also be optimized away (I don't think so, but haven't tried it yet).
But, I am not sure if you have any requirement in your project that only O0 should be used with your code and not O1, O2, O3 or even Os.