Skip to content

Commit 1d7ccef

Browse files
committed
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.
1 parent 5f233f0 commit 1d7ccef

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

include/boost/program_options/errors.hpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ namespace boost { namespace program_options {
121121
/** gcc says that throw specification on dtor is loosened
122122
* without this line
123123
* */
124-
BOOST_DEFAULTED_FUNCTION(~error_with_option_name() throw(), {})
124+
BOOST_DEFAULTED_FUNCTION(~error_with_option_name() BOOST_NOEXCEPT_OR_NOTHROW, {})
125125

126126

127127
//void dump() const
@@ -183,7 +183,7 @@ namespace boost { namespace program_options {
183183

184184
/** Creates the error_message on the fly
185185
* Currently a thin wrapper for substitute_placeholders() */
186-
virtual const char* what() const throw();
186+
virtual const char* what() const BOOST_NOEXCEPT_OR_NOTHROW;
187187

188188
protected:
189189
/** Used to hold the error text returned by what() */
@@ -209,7 +209,7 @@ namespace boost { namespace program_options {
209209
multiple_values()
210210
: error_with_option_name("option '%canonical_option%' only takes a single argument"){}
211211

212-
BOOST_DEFAULTED_FUNCTION(~multiple_values() throw(), {})
212+
BOOST_DEFAULTED_FUNCTION(~multiple_values() BOOST_NOEXCEPT_OR_NOTHROW, {})
213213
};
214214

215215
/** Class thrown when there are several occurrences of an
@@ -220,7 +220,7 @@ namespace boost { namespace program_options {
220220
multiple_occurrences()
221221
: error_with_option_name("option '%canonical_option%' cannot be specified more than once"){}
222222

223-
BOOST_DEFAULTED_FUNCTION(~multiple_occurrences() throw(), {})
223+
BOOST_DEFAULTED_FUNCTION(~multiple_occurrences() BOOST_NOEXCEPT_OR_NOTHROW, {})
224224

225225
};
226226

@@ -233,7 +233,7 @@ namespace boost { namespace program_options {
233233
{
234234
}
235235

236-
BOOST_DEFAULTED_FUNCTION(~required_option() throw(), {})
236+
BOOST_DEFAULTED_FUNCTION(~required_option() BOOST_NOEXCEPT_OR_NOTHROW, {})
237237
};
238238

239239
/** Base class of unparsable options,
@@ -258,7 +258,7 @@ namespace boost { namespace program_options {
258258
/** Does NOT set option name, because no option name makes sense */
259259
virtual void set_option_name(const std::string&) {}
260260

261-
BOOST_DEFAULTED_FUNCTION(~error_with_no_option_name() throw(), {})
261+
BOOST_DEFAULTED_FUNCTION(~error_with_no_option_name() BOOST_NOEXCEPT_OR_NOTHROW, {})
262262
};
263263

264264

@@ -270,7 +270,7 @@ namespace boost { namespace program_options {
270270
{
271271
}
272272

273-
BOOST_DEFAULTED_FUNCTION(~unknown_option() throw(), {})
273+
BOOST_DEFAULTED_FUNCTION(~unknown_option() BOOST_NOEXCEPT_OR_NOTHROW, {})
274274
};
275275

276276

@@ -283,9 +283,9 @@ namespace boost { namespace program_options {
283283
m_alternatives(xalternatives)
284284
{}
285285

286-
BOOST_DEFAULTED_FUNCTION(~ambiguous_option() throw(), {})
286+
BOOST_DEFAULTED_FUNCTION(~ambiguous_option() BOOST_NOEXCEPT_OR_NOTHROW, {})
287287

288-
const std::vector<std::string>& alternatives() const throw() {return m_alternatives;}
288+
const std::vector<std::string>& alternatives() const BOOST_NOEXCEPT_OR_NOTHROW {return m_alternatives;}
289289

290290
protected:
291291
/** Makes all substitutions using the template */
@@ -320,7 +320,7 @@ namespace boost { namespace program_options {
320320
{
321321
}
322322

323-
BOOST_DEFAULTED_FUNCTION(~invalid_syntax() throw(), {})
323+
BOOST_DEFAULTED_FUNCTION(~invalid_syntax() BOOST_NOEXCEPT_OR_NOTHROW, {})
324324

325325
kind_t kind() const {return m_kind;}
326326

@@ -340,7 +340,7 @@ namespace boost { namespace program_options {
340340
m_substitutions["invalid_line"] = invalid_line;
341341
}
342342

343-
BOOST_DEFAULTED_FUNCTION(~invalid_config_file_syntax() throw(), {})
343+
BOOST_DEFAULTED_FUNCTION(~invalid_config_file_syntax() BOOST_NOEXCEPT_OR_NOTHROW, {})
344344

345345
/** Convenience functions for backwards compatibility */
346346
virtual std::string tokens() const {return m_substitutions.find("invalid_line")->second; }
@@ -355,7 +355,7 @@ namespace boost { namespace program_options {
355355
const std::string& original_token = "",
356356
int option_style = 0):
357357
invalid_syntax(kind, option_name, original_token, option_style) {}
358-
BOOST_DEFAULTED_FUNCTION(~invalid_command_line_syntax() throw(), {})
358+
BOOST_DEFAULTED_FUNCTION(~invalid_command_line_syntax() BOOST_NOEXCEPT_OR_NOTHROW, {})
359359
};
360360

361361

@@ -380,7 +380,7 @@ namespace boost { namespace program_options {
380380
{
381381
}
382382

383-
BOOST_DEFAULTED_FUNCTION(~validation_error() throw(), {})
383+
BOOST_DEFAULTED_FUNCTION(~validation_error() BOOST_NOEXCEPT_OR_NOTHROW, {})
384384

385385
kind_t kind() const { return m_kind; }
386386

src/value_semantic.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ namespace boost { namespace program_options {
260260
}
261261

262262

263-
const char* error_with_option_name::what() const throw()
263+
const char* error_with_option_name::what() const BOOST_NOEXCEPT_OR_NOTHROW
264264
{
265265
// will substitute tokens each time what is run()
266266
substitute_placeholders(m_error_template);

0 commit comments

Comments
 (0)