Compare commits

..

1 Commits

Author SHA1 Message Date
Andrey Semashev
27f9276945 Fix C++20 incompatibility from using exception specifications.
C++20 removed support for `throw()` exception specifications, so at
least clang-19 is now emitting errors on them. Replaced exception
specifications with BOOST_NOEXCEPT_OR_NOTHROW, which converts `throw()`
to `noexcept`, but keeps the code formally compatible with C++03.
2024-04-08 03:17:53 +03:00
5 changed files with 27 additions and 63 deletions

View File

@@ -116,33 +116,24 @@ jobs:
- toolset: clang
compiler: clang++-13
cxxstd: "11,14,17,20,2b"
container: ubuntu:22.04
os: ubuntu-latest
os: ubuntu-22.04
install: clang-13
- toolset: clang
compiler: clang++-14
cxxstd: "11,14,17,20,2b"
container: ubuntu:22.04
os: ubuntu-latest
os: ubuntu-22.04
install: clang-14
- toolset: clang
compiler: clang++-15
cxxstd: "11,14,17,20,2b"
container: ubuntu:22.04
os: ubuntu-latest
os: ubuntu-22.04
install: clang-15
- toolset: clang
compiler: clang++-16
cxxstd: "11,14,17,20,2b"
os: ubuntu-latest
container: ubuntu:23.04
os: ubuntu-latest
install: clang-16
- toolset: clang
compiler: clang++-17
cxxstd: "11,14,17,20,2b"
container: ubuntu:23.10
os: ubuntu-latest
install: clang-17
- toolset: clang
cxxstd: "11,14,17,2a"
os: macos-11
@@ -236,7 +227,7 @@ jobs:
runs-on: ${{matrix.os}}
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v3
- name: Setup Boost
shell: cmd
@@ -280,7 +271,7 @@ jobs:
runs-on: ${{matrix.os}}
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v3
- name: Install packages
if: matrix.install
@@ -328,7 +319,7 @@ jobs:
runs-on: ${{matrix.os}}
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v3
- name: Install packages
if: matrix.install
@@ -386,7 +377,7 @@ jobs:
runs-on: ${{matrix.os}}
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v3
- name: Install packages
if: matrix.install
@@ -439,7 +430,7 @@ jobs:
runs-on: ${{matrix.os}}
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v3
- name: Setup Boost
shell: cmd
@@ -488,7 +479,7 @@ jobs:
runs-on: ${{matrix.os}}
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v3
- name: Setup Boost
shell: cmd
@@ -555,7 +546,7 @@ jobs:
runs-on: ${{matrix.os}}
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v3
- name: Setup Boost
shell: cmd

View File

@@ -8,10 +8,6 @@
#include <boost/throw_exception.hpp>
#ifndef BOOST_NO_CXX17_HDR_OPTIONAL
# include <optional>
#endif
// forward declaration
namespace boost { template<class T> class optional; }
@@ -173,22 +169,6 @@ namespace boost { namespace program_options {
v = boost::any(boost::optional<T>(boost::any_cast<T>(a)));
}
#ifndef BOOST_NO_CXX17_HDR_OPTIONAL
/** Validates std::optional arguments. */
template<class T, class charT>
void validate(boost::any& v,
const std::vector<std::basic_string<charT> >& s,
std::optional<T>*,
int)
{
validators::check_first_occurrence(v);
validators::get_single_string(s);
boost::any a;
validate(a, s, (T*)0, 0);
v = boost::any(std::optional<T>(boost::any_cast<T>(a)));
}
#endif
template<class T, class charT>
void
typed_value<T, charT>::

View File

@@ -121,7 +121,7 @@ namespace boost { namespace program_options {
/** gcc says that throw specification on dtor is loosened
* without this line
* */
BOOST_DEFAULTED_FUNCTION(~error_with_option_name() throw(), {})
BOOST_DEFAULTED_FUNCTION(~error_with_option_name() BOOST_NOEXCEPT_OR_NOTHROW, {})
//void dump() const
@@ -183,7 +183,7 @@ namespace boost { namespace program_options {
/** Creates the error_message on the fly
* Currently a thin wrapper for substitute_placeholders() */
virtual const char* what() const throw();
virtual const char* what() const BOOST_NOEXCEPT_OR_NOTHROW;
protected:
/** Used to hold the error text returned by what() */
@@ -209,7 +209,7 @@ namespace boost { namespace program_options {
multiple_values()
: error_with_option_name("option '%canonical_option%' only takes a single argument"){}
BOOST_DEFAULTED_FUNCTION(~multiple_values() throw(), {})
BOOST_DEFAULTED_FUNCTION(~multiple_values() BOOST_NOEXCEPT_OR_NOTHROW, {})
};
/** Class thrown when there are several occurrences of an
@@ -220,7 +220,7 @@ namespace boost { namespace program_options {
multiple_occurrences()
: error_with_option_name("option '%canonical_option%' cannot be specified more than once"){}
BOOST_DEFAULTED_FUNCTION(~multiple_occurrences() throw(), {})
BOOST_DEFAULTED_FUNCTION(~multiple_occurrences() BOOST_NOEXCEPT_OR_NOTHROW, {})
};
@@ -233,7 +233,7 @@ namespace boost { namespace program_options {
{
}
BOOST_DEFAULTED_FUNCTION(~required_option() throw(), {})
BOOST_DEFAULTED_FUNCTION(~required_option() BOOST_NOEXCEPT_OR_NOTHROW, {})
};
/** Base class of unparsable options,
@@ -258,7 +258,7 @@ namespace boost { namespace program_options {
/** Does NOT set option name, because no option name makes sense */
virtual void set_option_name(const std::string&) {}
BOOST_DEFAULTED_FUNCTION(~error_with_no_option_name() throw(), {})
BOOST_DEFAULTED_FUNCTION(~error_with_no_option_name() BOOST_NOEXCEPT_OR_NOTHROW, {})
};
@@ -270,7 +270,7 @@ namespace boost { namespace program_options {
{
}
BOOST_DEFAULTED_FUNCTION(~unknown_option() throw(), {})
BOOST_DEFAULTED_FUNCTION(~unknown_option() BOOST_NOEXCEPT_OR_NOTHROW, {})
};
@@ -283,9 +283,9 @@ namespace boost { namespace program_options {
m_alternatives(xalternatives)
{}
BOOST_DEFAULTED_FUNCTION(~ambiguous_option() throw(), {})
BOOST_DEFAULTED_FUNCTION(~ambiguous_option() BOOST_NOEXCEPT_OR_NOTHROW, {})
const std::vector<std::string>& alternatives() const throw() {return m_alternatives;}
const std::vector<std::string>& alternatives() const BOOST_NOEXCEPT_OR_NOTHROW {return m_alternatives;}
protected:
/** Makes all substitutions using the template */
@@ -320,7 +320,7 @@ namespace boost { namespace program_options {
{
}
BOOST_DEFAULTED_FUNCTION(~invalid_syntax() throw(), {})
BOOST_DEFAULTED_FUNCTION(~invalid_syntax() BOOST_NOEXCEPT_OR_NOTHROW, {})
kind_t kind() const {return m_kind;}
@@ -340,7 +340,7 @@ namespace boost { namespace program_options {
m_substitutions["invalid_line"] = invalid_line;
}
BOOST_DEFAULTED_FUNCTION(~invalid_config_file_syntax() throw(), {})
BOOST_DEFAULTED_FUNCTION(~invalid_config_file_syntax() BOOST_NOEXCEPT_OR_NOTHROW, {})
/** Convenience functions for backwards compatibility */
virtual std::string tokens() const {return m_substitutions.find("invalid_line")->second; }
@@ -355,7 +355,7 @@ namespace boost { namespace program_options {
const std::string& original_token = "",
int option_style = 0):
invalid_syntax(kind, option_name, original_token, option_style) {}
BOOST_DEFAULTED_FUNCTION(~invalid_command_line_syntax() throw(), {})
BOOST_DEFAULTED_FUNCTION(~invalid_command_line_syntax() BOOST_NOEXCEPT_OR_NOTHROW, {})
};
@@ -380,7 +380,7 @@ namespace boost { namespace program_options {
{
}
BOOST_DEFAULTED_FUNCTION(~validation_error() throw(), {})
BOOST_DEFAULTED_FUNCTION(~validation_error() BOOST_NOEXCEPT_OR_NOTHROW, {})
kind_t kind() const { return m_kind; }

View File

@@ -260,7 +260,7 @@ namespace boost { namespace program_options {
}
const char* error_with_option_name::what() const throw()
const char* error_with_option_name::what() const BOOST_NOEXCEPT_OR_NOTHROW
{
// will substitute tokens each time what is run()
substitute_placeholders(m_error_template);

View File

@@ -7,9 +7,6 @@ namespace po = boost::program_options;
#include <boost/optional.hpp>
#ifndef BOOST_NO_CXX17_HDR_OPTIONAL
# include <optional>
#endif
#include <string>
#include "minitest.hpp"
@@ -22,10 +19,9 @@ std::vector<std::string> sv(const char* array[], unsigned size)
return r;
}
template<template<typename> class OptionalType>
void test_optional()
{
OptionalType<int> foo, bar, baz;
boost::optional<int> foo, bar, baz;
po::options_description desc;
desc.add_options()
@@ -52,9 +48,6 @@ void test_optional()
int main(int, char*[])
{
test_optional<boost::optional>();
#ifndef BOOST_NO_CXX17_HDR_OPTIONAL
test_optional<std::optional>();
#endif
test_optional();
return 0;
}