fixes the tools

-  bisect_failures no longer compare CGAL assertion messages
- rewrite Exception_ostream, because throwing in an `ios_base` operation has no effect but setting the bad bit.
This commit is contained in:
Laurent Rineau 2025-12-02 16:53:12 +01:00
parent 284d228b96
commit fdbbdb4cdc
2 changed files with 56 additions and 30 deletions

View File

@ -12,48 +12,71 @@
#ifndef CGAL_EXCEPTION_OSTREAM_H #ifndef CGAL_EXCEPTION_OSTREAM_H
#define CGAL_EXCEPTION_OSTREAM_H #define CGAL_EXCEPTION_OSTREAM_H
#include <ios>
#include <ostream> #include <ostream>
#include <sstream> #include <sstream>
#include <stdexcept>
#include <string> #include <string>
#include <CGAL/exceptions.h>
namespace CGAL { namespace CGAL {
/** /**
* \class Exception_basic_ostream * \class Exception_basic_ostream
* \brief A std::basic_ostream that throws an exception with its buffer content when flushed. * \brief A stream-like object that throws an exception with its buffer content when destroyed.
* *
* Usage: * Usage:
* \code * \code
* {
* CGAL::Exception_basic_ostream os; * CGAL::Exception_basic_ostream os;
* os << "Error: " << value << std::endl; // throws std::runtime_error with the message * os << "Error: " << value;
* } // throws std::runtime_error with the message when os goes out of scope
* \endcode * \endcode
* *
* \tparam CharT Character type (default: char) * \note This class is move-only.
* \tparam Traits Character traits (default: std::char_traits<CharT>) *
* \tparam CharT Character type (default: `char`)
* \tparam Traits Character traits (default: `std::char_traits<CharT>`)
*/ */
template <typename CharT = char, typename Traits = std::char_traits<CharT>> template <typename CharT = char, typename Traits = std::char_traits<CharT>>
class Exception_basic_ostream : public std::basic_ostream<CharT, Traits> { class Exception_basic_ostream {
class buffer_type : public std::basic_stringbuf<CharT, Traits> { std::basic_ostringstream<CharT, Traits> stream_;
public: public:
using int_type = typename Traits::int_type; Exception_basic_ostream() = default;
buffer_type() = default;
// When the buffer is flushed, throw an exception with the buffer content // move-only
int sync() override { Exception_basic_ostream(Exception_basic_ostream&&) = default;
std::basic_string<CharT, Traits> msg = this->str(); Exception_basic_ostream& operator=(Exception_basic_ostream&&) = default;
this->str({}); // clear buffer
throw std::runtime_error(std::string(msg.begin(), msg.end())); ~Exception_basic_ostream() noexcept(false) {
std::basic_string<CharT, Traits> msg = stream_.str();
if(!msg.empty()) {
throw CGAL::Failure_exception("CGAL", "", __FILE__, __LINE__, std::string(msg.begin(), msg.end()));
} }
}; }
buffer_type buffer_;
public: template<typename T>
Exception_basic_ostream() : std::basic_ostream<CharT, Traits>(&buffer_) {} Exception_basic_ostream& operator<<(T&& value) {
// Disallow copy and move stream_ << std::forward<T>(value);
Exception_basic_ostream(const Exception_basic_ostream&) = delete; return *this;
Exception_basic_ostream& operator=(const Exception_basic_ostream&) = delete; }
Exception_basic_ostream(Exception_basic_ostream&&) = delete;
Exception_basic_ostream& operator=(Exception_basic_ostream&&) = delete; // Support for stream manipulators
~Exception_basic_ostream() override = default; Exception_basic_ostream& operator<<(std::basic_ostream<CharT, Traits>& (*manip)(std::basic_ostream<CharT, Traits>&)) {
stream_ << manip;
return *this;
}
Exception_basic_ostream& operator<<(std::basic_ios<CharT, Traits>& (*manip)(std::basic_ios<CharT, Traits>&)) {
stream_ << manip;
return *this;
}
Exception_basic_ostream& operator<<(std::ios_base& (*manip)(std::ios_base&)) {
stream_ << manip;
return *this;
}
}; };
/// /relates Exception_basic_ostream /// /relates Exception_basic_ostream
@ -62,8 +85,8 @@ using Exception_ostream = Exception_basic_ostream<char>;
/// /relates Exception_basic_ostream /// /relates Exception_basic_ostream
using Exception_wostream = Exception_basic_ostream<wchar_t>; using Exception_wostream = Exception_basic_ostream<wchar_t>;
inline Exception_ostream& exception_ostream() { inline Exception_ostream exception_ostream() {
static Exception_ostream os; Exception_ostream os;
return os; return os;
} }

View File

@ -21,10 +21,13 @@
#include <CGAL/utility.h> #include <CGAL/utility.h>
#include <cmath> #include <cmath>
#include <cstddef>
#include <cstdlib>
#include <exception> #include <exception>
#include <iostream> #include <iostream>
#include <optional> #include <optional>
#include <string> #include <string>
#include <tuple>
namespace CGAL { namespace CGAL {
@ -170,8 +173,8 @@ int bisect_failures(const InputData& data,
if(cgal_exception) { if(cgal_exception) {
if(initial_cgal_exception && if(initial_cgal_exception &&
cgal_exception->message() == initial_cgal_exception->message() && // cgal_exception->message() == initial_cgal_exception->message() &&
cgal_exception->expression() == initial_cgal_exception->expression() && // cgal_exception->expression() == initial_cgal_exception->expression() &&
cgal_exception->library() == initial_cgal_exception->library() && cgal_exception->library() == initial_cgal_exception->library() &&
cgal_exception->filename() == initial_cgal_exception->filename() && cgal_exception->filename() == initial_cgal_exception->filename() &&
cgal_exception->line_number() == initial_cgal_exception->line_number()) cgal_exception->line_number() == initial_cgal_exception->line_number())