Prior to this patch ExceptionAnalyzer reported many false
positives due to insufficient checking of conversion rules
inside exception handlers.
One false positive example from the previous version:
void foo() noexcept { try { int a = 1; throw &a; } catch (const int *) { } }
In function foo() the &a is caught by the handler, but clang-tidy
reports the following warning:
warning: an exception may be thrown in function 'foo' which should not throw exceptions [bugprone-exception-escape]
The standard says the following about exception handling:
[N4849 14.4 Handling an exception]
(3) A handler is a match for an exception object of type E if
- The handler is of type cv T or cv T& and E and T are the same type (ignoring the top-level cv-qualifiers), or
- the handler is of type cv T or cv T& and T is an unambiguous public base class of E, or
- the handler is of type cv T or const T& where T is a pointer or pointer-to-member type and E is a pointer or pointer-to-member type that can be converted to T by one or more of
- a standard pointer conversion (7.3.11) not involving conversions to pointers to private or protected or ambiguous classes
- a function pointer conversion (7.3.13)
- a qualification conversion (7.3.5), or
- the handler is of type cv T or const T& where T is a pointer or pointer-to-member type and E is std::nullptr_t.
This patch is supposed to implement all of these checks.
Did you take a look at ASTContext::hasCvrSimilarType? I wonder if it is already doing what you want.