Skip to content

Commit 07d0703

Browse files
committed
Refactor invariant_failedt definition.
1 parent a7b972d commit 07d0703

File tree

2 files changed

+15
-35
lines changed

2 files changed

+15
-35
lines changed

src/util/invariant.cpp

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,6 @@ void print_backtrace(
7979
std::ostream &out)
8080
{
8181
#ifdef __GLIBC__
82-
out << "Backtrace\n" << std::flush;
83-
8482
void * stack[50] = {};
8583

8684
std::size_t entries=backtrace(stack, sizeof(stack) / sizeof(void *));
@@ -116,21 +114,14 @@ void report_exception_to_stderr(const invariant_failedt &reason)
116114
std::cerr << "--- end invariant violation report ---\n";
117115
}
118116

119-
std::string invariant_failedt::get_invariant_failed_message(
120-
const std::string &file,
121-
const std::string &function,
122-
int line,
123-
const std::string &backtrace,
124-
const std::string &reason) const
117+
std::string invariant_failedt::what() const noexcept
125118
{
126119
std::ostringstream out;
127120
out << "Invariant check failed\n"
128-
<< "File " << file
129-
<< " function " << function
130-
<< " line " << line << '\n'
121+
<< "File: " << file << ":" << line << " function: " << function << '\n'
131122
<< "Condition: " << condition << '\n'
132-
<< "Reason: " << reason
133-
<< "\nBacktrace:\n"
123+
<< "Reason: " << reason << '\n'
124+
<< "Backtrace:" << '\n'
134125
<< backtrace << '\n';
135126
return out.str();
136127
}

src/util/invariant.h

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -75,40 +75,29 @@ Author: Martin Brain, [email protected]
7575
class invariant_failedt
7676
{
7777
private:
78-
std::string get_invariant_failed_message(
79-
const std::string &file,
80-
const std::string &function,
81-
int line,
82-
const std::string &backtrace,
83-
const std::string &reason) const;
84-
85-
public:
8678
const std::string file;
8779
const std::string function;
8880
const int line;
8981
const std::string backtrace;
90-
const std::string reason;
9182
const std::string condition;
83+
const std::string reason;
9284

93-
std::string what() const noexcept
94-
{
95-
return get_invariant_failed_message(
96-
file, function, line, backtrace, reason);
97-
};
85+
public:
86+
std::string what() const noexcept;
9887

9988
invariant_failedt(
10089
const std::string &_file,
10190
const std::string &_function,
10291
int _line,
10392
const std::string &_backtrace,
104-
const std::string &_reason,
105-
const std::string &_condition)
93+
const std::string &_condition,
94+
const std::string &_reason)
10695
: file(_file),
10796
function(_function),
10897
line(_line),
10998
backtrace(_backtrace),
110-
reason(_reason),
111-
condition(_condition)
99+
condition(_condition),
100+
reason(_reason)
112101
{
113102
}
114103
};
@@ -171,8 +160,8 @@ invariant_violated_structured(
171160
function,
172161
line,
173162
backtrace,
174-
std::forward<Params>(params)...,
175-
condition);
163+
condition,
164+
std::forward<Params>(params)...);
176165
// We now have a structured exception ready to use;
177166
// in future this is the place to put a 'throw'.
178167
report_exception_to_stderr(to_throw);
@@ -230,8 +219,8 @@ invariant_violated_string(
230219
__FILE__, \
231220
__this_function__, \
232221
__LINE__, \
233-
__VA_ARGS__, \
234-
#CONDITION); /* NOLINT */ \
222+
#CONDITION, \
223+
__VA_ARGS__); /* NOLINT */ \
235224
} while(false)
236225

237226
#endif // End CPROVER_DO_NOT_CHECK / CPROVER_ASSERT / ... if block

0 commit comments

Comments
 (0)