Github user jeking3 commented on a diff in the pull request:
https://github.com/apache/thrift/pull/469#discussion_r29955740
--- Diff: compiler/cpp/src/generate/t_cpp_generator.cc ---
@@ -1699,6 +1723,24 @@ void
t_cpp_generator::generate_struct_ostream_operator(std::ofstream& out, t_str
out << "}" << endl << endl;
}
+/**
+ * Generates what() method for exceptions
+ */
+void t_cpp_generator::generate_exception_what_method(std::ofstream& out,
t_struct* tstruct) {
+ out << indent();
+ generate_exception_what_method_decl(out, tstruct, true);
+ out << " {" << endl;
+
+ indent_up();
+
+ out << indent() << "std::stringstream ss;" << endl;
+ out << indent() << "ss << \"TException - service has thrown: \" <<
*this;" << endl;
+ out << indent() << "return ss.str().c_str();" << endl;
--- End diff --
You could store the content of the string in a std::string member variable
on construction then return mString.c_str(), holding the string variable. The
specification (even C++11) is very flimsy about specifying the valid lifetime
of this pointer.
Also we will need to revisit this when we enable a feature (documented in
other Jira tickets) to set the minimum required C++ version of the resulting
generated code. Before C++11, what is specified as throw(), with C++11 this
changes to noexcept;
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---