c++: use YY_NOEXCEPT where it helps

Suggested by Don Macpherson.
<https://github.com/akimd/bison/issues/80>

* data/skeletons/c++.m4, data/skeletons/glr2.cc,
* data/skeletons/lalr1.cc, data/skeletons/stack.hh: Use YY_NOEXCEPT
where it helps constructors.
This commit is contained in:
Akim Demaille
2021-09-18 08:02:41 +02:00
parent dd6e78360a
commit 3fc3ef658e
4 changed files with 28 additions and 28 deletions

View File

@@ -308,7 +308,7 @@ m4_define([b4_symbol_type_define],
typedef Base super_type; typedef Base super_type;
/// Default constructor. /// Default constructor.
basic_symbol () basic_symbol () YY_NOEXCEPT
: value ()]b4_locations_if([ : value ()]b4_locations_if([
, location ()])[ , location ()])[
{} {}
@@ -437,16 +437,22 @@ m4_define([b4_symbol_type_define],
/// Type access provider for token (enum) based symbols. /// Type access provider for token (enum) based symbols.
struct by_kind struct by_kind
{ {
/// The symbol kind as needed by the constructor.
typedef token_kind_type kind_type;
/// Default constructor. /// Default constructor.
by_kind (); by_kind () YY_NOEXCEPT;
#if 201103L <= YY_CPLUSPLUS #if 201103L <= YY_CPLUSPLUS
/// Move constructor. /// Move constructor.
by_kind (by_kind&& that); by_kind (by_kind&& that) YY_NOEXCEPT;
#endif #endif
/// Copy constructor. /// Copy constructor.
by_kind (const by_kind& that); by_kind (const by_kind& that) YY_NOEXCEPT;
/// Constructor from (external) token numbers.
by_kind (kind_type t) YY_NOEXCEPT;
]b4_glr2_cc_if([[ ]b4_glr2_cc_if([[
/// Copy assignment. /// Copy assignment.
@@ -456,12 +462,6 @@ m4_define([b4_symbol_type_define],
by_kind& operator= (by_kind&& that); by_kind& operator= (by_kind&& that);
]])[ ]])[
/// The symbol kind as needed by the constructor.
typedef token_kind_type kind_type;
/// Constructor from (external) token numbers.
by_kind (kind_type t);
/// Record that this symbol is empty. /// Record that this symbol is empty.
void clear () YY_NOEXCEPT; void clear () YY_NOEXCEPT;
@@ -490,7 +490,7 @@ m4_define([b4_symbol_type_define],
typedef basic_symbol<by_kind> super_type; typedef basic_symbol<by_kind> super_type;
/// Empty symbol. /// Empty symbol.
symbol_type () {} symbol_type () YY_NOEXCEPT {}
/// Constructor for valueless symbols, and symbols from each type. /// Constructor for valueless symbols, and symbols from each type.
]b4_type_foreach([_b4_symbol_constructor_define])dnl ]b4_type_foreach([_b4_symbol_constructor_define])dnl
@@ -564,23 +564,23 @@ m4_define([b4_public_types_define],
} }
// by_kind. // by_kind.
]b4_inline([$1])b4_parser_class[::by_kind::by_kind () ]b4_inline([$1])b4_parser_class[::by_kind::by_kind () YY_NOEXCEPT
: kind_ (]b4_symbol(empty, kind)[) : kind_ (]b4_symbol(empty, kind)[)
{} {}
#if 201103L <= YY_CPLUSPLUS #if 201103L <= YY_CPLUSPLUS
]b4_inline([$1])b4_parser_class[::by_kind::by_kind (by_kind&& that) ]b4_inline([$1])b4_parser_class[::by_kind::by_kind (by_kind&& that) YY_NOEXCEPT
: kind_ (that.kind_) : kind_ (that.kind_)
{ {
that.clear (); that.clear ();
} }
#endif #endif
]b4_inline([$1])b4_parser_class[::by_kind::by_kind (const by_kind& that) ]b4_inline([$1])b4_parser_class[::by_kind::by_kind (const by_kind& that) YY_NOEXCEPT
: kind_ (that.kind_) : kind_ (that.kind_)
{} {}
]b4_inline([$1])b4_parser_class[::by_kind::by_kind (token_kind_type t) ]b4_inline([$1])b4_parser_class[::by_kind::by_kind (token_kind_type t) YY_NOEXCEPT
: kind_ (yytranslate_ (t)) : kind_ (yytranslate_ (t))
{} {}
@@ -643,7 +643,7 @@ m4_define([b4_token_constructor_define], [])
# sometimes in the cc file. # sometimes in the cc file.
m4_define([b4_yytranslate_define], m4_define([b4_yytranslate_define],
[ b4_inline([$1])b4_parser_class[::symbol_kind_type [ b4_inline([$1])b4_parser_class[::symbol_kind_type
]b4_parser_class[::yytranslate_ (int t) ]b4_parser_class[::yytranslate_ (int t) YY_NOEXCEPT
{ {
]b4_api_token_raw_if( ]b4_api_token_raw_if(
[[ return static_cast<symbol_kind_type> (t);]], [[ return static_cast<symbol_kind_type> (t);]],

View File

@@ -348,7 +348,7 @@ m4_define([b4_shared_declarations],
/// Convert a scanner token kind \a t to a symbol kind. /// Convert a scanner token kind \a t to a symbol kind.
/// In theory \a t should be a token_kind_type, but character literals /// In theory \a t should be a token_kind_type, but character literals
/// are valid, yet not members of the token_kind_type enum. /// are valid, yet not members of the token_kind_type enum.
static symbol_kind_type yytranslate_ (int t); static symbol_kind_type yytranslate_ (int t) YY_NOEXCEPT;
]b4_parse_error_bmatch( ]b4_parse_error_bmatch(
[simple], [simple],
@@ -3136,13 +3136,13 @@ b4_dollar_popdef])[]dnl
} }
static bool static bool
yy_is_shift_action (int yyaction) yy_is_shift_action (int yyaction) YY_NOEXCEPT
{ {
return 0 < yyaction; return 0 < yyaction;
} }
static bool static bool
yy_is_error_action (int yyaction) yy_is_error_action (int yyaction) YY_NOEXCEPT
{ {
return yyaction == 0; return yyaction == 0;
} }

View File

@@ -325,11 +325,11 @@ m4_define([b4_shared_declarations],
/// Whether the given \c yypact_ value indicates a defaulted state. /// Whether the given \c yypact_ value indicates a defaulted state.
/// \param yyvalue the value to check /// \param yyvalue the value to check
static bool yy_pact_value_is_default_ (int yyvalue); static bool yy_pact_value_is_default_ (int yyvalue) YY_NOEXCEPT;
/// Whether the given \c yytable_ value indicates a syntax error. /// Whether the given \c yytable_ value indicates a syntax error.
/// \param yyvalue the value to check /// \param yyvalue the value to check
static bool yy_table_value_is_error_ (int yyvalue); static bool yy_table_value_is_error_ (int yyvalue) YY_NOEXCEPT;
static const ]b4_int_type(b4_pact_ninf, b4_pact_ninf)[ yypact_ninf_; static const ]b4_int_type(b4_pact_ninf, b4_pact_ninf)[ yypact_ninf_;
static const ]b4_int_type(b4_table_ninf, b4_table_ninf)[ yytable_ninf_; static const ]b4_int_type(b4_table_ninf, b4_table_ninf)[ yytable_ninf_;
@@ -337,7 +337,7 @@ m4_define([b4_shared_declarations],
/// Convert a scanner token kind \a t to a symbol kind. /// Convert a scanner token kind \a t to a symbol kind.
/// In theory \a t should be a token_kind_type, but character literals /// In theory \a t should be a token_kind_type, but character literals
/// are valid, yet not members of the token_kind_type enum. /// are valid, yet not members of the token_kind_type enum.
static symbol_kind_type yytranslate_ (int t); static symbol_kind_type yytranslate_ (int t) YY_NOEXCEPT;
]b4_parse_error_bmatch( ]b4_parse_error_bmatch(
[simple], [simple],
@@ -474,7 +474,7 @@ m4_define([b4_shared_declarations],
void yypush_ (const char* m, state_type s, YY_MOVE_REF (symbol_type) sym); void yypush_ (const char* m, state_type s, YY_MOVE_REF (symbol_type) sym);
/// Pop \a n symbols from the stack. /// Pop \a n symbols from the stack.
void yypop_ (int n = 1); void yypop_ (int n = 1) YY_NOEXCEPT;
/// Constants. /// Constants.
enum enum
@@ -779,7 +779,7 @@ m4_if(b4_prefix, [yy], [],
} }
void void
]b4_parser_class[::yypop_ (int n) ]b4_parser_class[::yypop_ (int n) YY_NOEXCEPT
{ {
yystack_.pop (n); yystack_.pop (n);
} }
@@ -822,13 +822,13 @@ m4_if(b4_prefix, [yy], [],
} }
bool bool
]b4_parser_class[::yy_pact_value_is_default_ (int yyvalue) ]b4_parser_class[::yy_pact_value_is_default_ (int yyvalue) YY_NOEXCEPT
{ {
return yyvalue == yypact_ninf_; return yyvalue == yypact_ninf_;
} }
bool bool
]b4_parser_class[::yy_table_value_is_error_ (int yyvalue) ]b4_parser_class[::yy_table_value_is_error_ (int yyvalue) YY_NOEXCEPT
{ {
return yyvalue == yytable_ninf_; return yyvalue == yytable_ninf_;
} }

View File

@@ -37,7 +37,7 @@ m4_define([b4_stack_define],
typedef typename S::size_type size_type; typedef typename S::size_type size_type;
typedef typename std::ptrdiff_t index_type; typedef typename std::ptrdiff_t index_type;
stack (size_type n = 200) stack (size_type n = 200) YY_NOEXCEPT
: seq_ (n) : seq_ (n)
{} {}
@@ -116,7 +116,7 @@ m4_define([b4_stack_define],
class slice class slice
{ {
public: public:
slice (const stack& stack, index_type range) slice (const stack& stack, index_type range) YY_NOEXCEPT
: stack_ (stack) : stack_ (stack)
, range_ (range) , range_ (range)
{} {}