This is an archive of the discontinued LLVM Phabricator instance.

[clang-tidy] add checker for hicpp to ensure all exceptions are derived from std::exception
ClosedPublic

Authored by JonasToth on Aug 10 2017, 9:24 AM.

Details

Summary

This check enforces rule 15.1.
It checks, that all thrown exceptions are of type std::exception (or derived).

Diff Detail

Event Timeline

JonasToth created this revision.Aug 10 2017, 9:24 AM
JonasToth updated this revision to Diff 110597.Aug 10 2017, 9:29 AM

Some comment slipped through. Fixed now

Eugene.Zelenko added inline comments.
docs/ReleaseNotes.rst
60

Please move it to new check list in alphabetical order.

63

This check should be omitted.

docs/clang-tidy/checks/hicpp-exception-baseclass.rst
8 ↗(On Diff #110597)

Probably empty line should separate statements.

JonasToth marked 3 inline comments as done.Aug 10 2017, 11:51 AM

[Doc] fix first review comments

[Fix] list problem, some interference with other branch

aaron.ballman added inline comments.Aug 11 2017, 5:27 AM
clang-tidy/hicpp/ExceptionBaseclassCheck.cpp
35

How about: "throwing an exception whose type is not derived from 'std::exception'" and an accompanying note that points to the declaration of the exception object, if any?

36

Can just call BadThrow->getSourceRange() instead.

JonasToth marked an inline comment as done.Aug 11 2017, 5:47 AM
JonasToth added inline comments.
clang-tidy/hicpp/ExceptionBaseclassCheck.cpp
35

yes. that would be more telling.

JonasToth updated this revision to Diff 110719.Aug 11 2017, 6:54 AM

adjust diagnostic message, emit note for defined type

JonasToth marked 2 inline comments as done.Aug 11 2017, 6:54 AM
This revision is now accepted and ready to land.Aug 11 2017, 6:59 AM

Still got no commit access :(, but i asked already ;)

Could you please apply this patch?

Still got no commit access :(, but i asked already ;)

Could you please apply this patch?

Can you rebase? It does not apply cleanly. Alternatively, you can wait for @lattner to give you your credentials and commit yourself (he's usually pretty quick at getting those out to folks).

aaron.ballman closed this revision.Aug 11 2017, 9:32 AM

I've commit in r310727.

Ok, i missed this somehow, and i have some concerns...
https://reviews.llvm.org/rL310727#108850

JonasToth reopened this revision.Aug 14 2017, 10:28 AM

i will reopen this one, until the issues are solved.

This revision is now accepted and ready to land.Aug 14 2017, 10:28 AM
JonasToth planned changes to this revision.Aug 14 2017, 10:28 AM
JonasToth added a reviewer: lebedev.ri.
JonasToth updated this revision to Diff 111817.Aug 19 2017, 6:00 AM
  • master remerged into this branch
  • improve testcases for generic code
This revision is now accepted and ready to land.Aug 19 2017, 6:00 AM
JonasToth updated this revision to Diff 111818.Aug 19 2017, 6:07 AM

i did work on the generic code with macros and templates.
i could not reproduce all issues, but in general template exception cause problems with diagnostics and with catching these cases.

the inheritance tree is catched correctly, as far as i can see, maybe you could me with reproducing ur issue @lebedev.ri ?

JonasToth updated this revision to Diff 111819.Aug 19 2017, 6:16 AM

plain macros seem to be handled correctly. Only troublemaker are templates.

JonasToth updated this revision to Diff 111820.Aug 19 2017, 7:49 AM

added more generic cases, and improved the matcher, thanks to @lebedev.ri

JonasToth closed this revision.Aug 23 2017, 5:06 AM

the new code to fix the issues is in D37060, so i will close this revision.