Skip to content

Exception utils: remove redundant what() implementations #6608

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 8, 2022

Conversation

tautschnig
Copy link
Collaborator

Make a std::string reason a member of the base class, and make
what() default to returning reason. This avoids duplicating the same
implementation across several child classes.

While at it, also fix the missing init-to-nil in one of
incorrect_goto_program_exceptiont's constructors.

  • Each commit message has a non-empty body, explaining why the change was made.
  • Methods or procedures I have added are documented, following the guidelines provided in CODING_STANDARD.md.
  • n/a The feature or user visible behaviour I have added or modified has been documented in the User Guide in doc/cprover-manual/
  • Regression or unit tests are included, or existing tests cover the modified code (in this case I have detailed which ones those are in the commit message).
  • n/a My commit message includes data points confirming performance improvements (if claimed).
  • My PR is restricted to a single feature or bugfix.
  • n/a White-space or formatting changes outside the feature-related changed lines are in commits of their own.

@kroening
Copy link
Member

The change means that there are two mechanisms for communicating the what message -- either via overloading what, or by setting reason. Pick one?

@codecov
Copy link

codecov bot commented Jan 23, 2022

Codecov Report

Merging #6608 (86b13e9) into develop (afc53d8) will increase coverage by 0.00%.
The diff coverage is 84.00%.

Impacted file tree graph

@@           Coverage Diff            @@
##           develop    #6608   +/-   ##
========================================
  Coverage    76.73%   76.73%           
========================================
  Files         1579     1579           
  Lines       181999   181994    -5     
========================================
- Hits        139652   139650    -2     
+ Misses       42347    42344    -3     
Impacted Files Coverage Δ
src/goto-programs/slice_global_inits.h 0.00% <0.00%> (ø)
src/goto-programs/string_instrumentation.h 0.00% <0.00%> (ø)
src/goto-programs/restrict_function_pointers.cpp 80.67% <100.00%> (+0.40%) ⬆️
src/memory-analyzer/gdb_api.h 100.00% <100.00%> (+9.52%) ⬆️
src/solvers/smt2/smt2_tokenizer.h 96.96% <100.00%> (ø)
src/util/exception_utils.cpp 97.77% <100.00%> (+3.43%) ⬆️
src/util/exception_utils.h 92.85% <100.00%> (-7.15%) ⬇️
... and 2 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3f175c9...86b13e9. Read the comment docs.

@tautschnig
Copy link
Collaborator Author

The change means that there are two mechanisms for communicating the what message -- either via overloading what, or by setting reason. Pick one?

Isn't reason the raw data and what its formatted representation? I agree that it may be possible to rely on the default what() implementation by building the formatted representation in the constructor, but this also makes it impossible to later get back the raw data. I actually have this in #5837, where a get_reason() is added to one of the child classes.

Copy link
Contributor

@chrisr-diffblue chrisr-diffblue left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks!

Copy link
Contributor

@NlightNFotis NlightNFotis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just one comment.

@@ -23,7 +21,7 @@ class smt2_tokenizert
line_no=1;
}

class smt2_errort : public cprover_exception_baset
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason this was removed from the inheritance chain? Would it be better if message was removed and substituted with reason?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this class, message is a std::ostringstream, making it really different from the parent class. Really, there is no meaningful commonality.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only benefit would be to catch all these exceptions at once, which could be done by another 'base class with reason' above the existing base, but that's minor IMO.

@tautschnig tautschnig force-pushed the cleanup/exception-utils branch from 824db62 to a3cca59 Compare February 3, 2022 16:44
Make a `std::string reason` a member of the base class, and make
`what()` default to returning `reason`. This avoids duplicating the same
implementation across several child classes.

While at it, also fix the missing init-to-nil in one of
incorrect_goto_program_exceptiont's constructors.
@tautschnig tautschnig force-pushed the cleanup/exception-utils branch from a3cca59 to 86b13e9 Compare February 7, 2022 21:27
@tautschnig tautschnig merged commit c351198 into diffblue:develop Feb 8, 2022
@tautschnig tautschnig deleted the cleanup/exception-utils branch February 8, 2022 08:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants