Skip to content

Commit 04e12dc

Browse files
Fix bug where reference to temporary string was returned
This is fortunately only in a unit tests and apparently hasn’t caused any problems so far, but we nevertheless should avoid returning references to temporaries. As a bonus the fixed code is simpler.
1 parent 7405bfb commit 04e12dc

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

jbmc/unit/java-testing-utils/require_goto_statements.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,17 @@ class no_decl_found_exceptiont : public std::exception
3434
{
3535
public:
3636
explicit no_decl_found_exceptiont(const std::string &var_name)
37-
: _varname(var_name)
37+
: message{"Failed to find declaration for: " + var_name}
3838
{
3939
}
4040

4141
virtual const char *what() const throw()
4242
{
43-
std::ostringstream stringStream;
44-
stringStream << "Failed to find declaration for: " << _varname;
45-
return stringStream.str().c_str();
43+
return message.c_str();
4644
}
4745

4846
private:
49-
std::string _varname;
47+
std::string message;
5048
};
5149

5250
pointer_assignment_locationt find_struct_component_assignments(

0 commit comments

Comments
 (0)