c++: use YY_NOEXCEPT where it helps
Akim Demaille <[email protected]> Sat, 18 Sep 2021 15:30:00 +0200
| Newsgroups | gmane.comp.parsers.bison.patches |
|---|---|
| Message-ID | <[email protected]> |
commit 3fc3ef658e855565d2fa83f0a05a0369edbede1f Author: Akim Demaille <[email protected]> Date: Sat Sep 18 08:02:41 2021 +0200 c++: use YY_NOEXCEPT where it helps =20 Suggested by Don Macpherson. <https://github.com/akimd/bison/issues/80> =20 * data/skeletons/c++.m4, data/skeletons/glr2.cc, * data/skeletons/lalr1.cc, data/skeletons/stack.hh: Use YY_NOEXCEPT where it helps constructors. diff --git a/data/skeletons/c++.m4 b/data/skeletons/c++.m4 index 42f6404e..2ae8423a 100644 --- a/data/skeletons/c++.m4 +++ b/data/skeletons/c++.m4 @@ -308,7 +308,7 @@ m4_define([b4_symbol_type_define], typedef Base super_type; =20 /// Default constructor. - basic_symbol () + basic_symbol () YY_NOEXCEPT : value ()]b4_locations_if([ , location ()])[ {} @@ -437,16 +437,22 @@ m4_define([b4_symbol_type_define], /// Type access provider for token (enum) based symbols. struct by_kind { + /// The symbol kind as needed by the constructor. + typedef token_kind_type kind_type; + /// Default constructor. - by_kind (); + by_kind () YY_NOEXCEPT; =20 #if 201103L <=3D YY_CPLUSPLUS /// Move constructor. - by_kind (by_kind&& that); + by_kind (by_kind&& that) YY_NOEXCEPT; #endif =20 /// 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; =20 ]b4_glr2_cc_if([[ /// Copy assignment. @@ -456,12 +462,6 @@ m4_define([b4_symbol_type_define], by_kind& operator=3D (by_kind&& that); ]])[ =20 - /// 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. void clear () YY_NOEXCEPT; =20 @@ -490,7 +490,7 @@ m4_define([b4_symbol_type_define], typedef basic_symbol<by_kind> super_type; =20 /// Empty symbol. - symbol_type () {} + symbol_type () YY_NOEXCEPT {} =20 /// Constructor for valueless symbols, and symbols from each = type. ]b4_type_foreach([_b4_symbol_constructor_define])dnl @@ -564,23 +564,23 @@ m4_define([b4_public_types_define], } =20 // 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)[) {} =20 #if 201103L <=3D 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_) { that.clear (); } #endif =20 - ]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_) {} =20 - ]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)) {} =20 @@ -643,7 +643,7 @@ m4_define([b4_token_constructor_define], []) # sometimes in the cc file. m4_define([b4_yytranslate_define], [ 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( [[ return static_cast<symbol_kind_type> (t);]], diff --git a/data/skeletons/glr2.cc b/data/skeletons/glr2.cc index 8b06c37a..757d68d4 100644 --- a/data/skeletons/glr2.cc +++ b/data/skeletons/glr2.cc @@ -348,7 +348,7 @@ m4_define([b4_shared_declarations], /// Convert a scanner token kind \a t to a symbol kind. /// In theory \a t should be a token_kind_type, but character = literals /// 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; =20 ]b4_parse_error_bmatch( [simple], @@ -3136,13 +3136,13 @@ b4_dollar_popdef])[]dnl } =20 static bool - yy_is_shift_action (int yyaction) + yy_is_shift_action (int yyaction) YY_NOEXCEPT { return 0 < yyaction; } =20 static bool - yy_is_error_action (int yyaction) + yy_is_error_action (int yyaction) YY_NOEXCEPT { return yyaction =3D=3D 0; } diff --git a/data/skeletons/lalr1.cc b/data/skeletons/lalr1.cc index 11fcf923..7cb69d3d 100644 --- a/data/skeletons/lalr1.cc +++ b/data/skeletons/lalr1.cc @@ -325,11 +325,11 @@ m4_define([b4_shared_declarations], =20 /// Whether the given \c yypact_ value indicates a defaulted state. /// \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; =20 /// Whether the given \c yytable_ value indicates a syntax error. /// \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; =20 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_; @@ -337,7 +337,7 @@ m4_define([b4_shared_declarations], /// Convert a scanner token kind \a t to a symbol kind. /// In theory \a t should be a token_kind_type, but character = literals /// 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; =20 ]b4_parse_error_bmatch( [simple], @@ -474,7 +474,7 @@ m4_define([b4_shared_declarations], void yypush_ (const char* m, state_type s, YY_MOVE_REF = (symbol_type) sym); =20 /// Pop \a n symbols from the stack. - void yypop_ (int n =3D 1); + void yypop_ (int n =3D 1) YY_NOEXCEPT; =20 /// Constants. enum @@ -779,7 +779,7 @@ m4_if(b4_prefix, [yy], [], } =20 void - ]b4_parser_class[::yypop_ (int n) + ]b4_parser_class[::yypop_ (int n) YY_NOEXCEPT { yystack_.pop (n); } @@ -822,13 +822,13 @@ m4_if(b4_prefix, [yy], [], } =20 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 =3D=3D yypact_ninf_; } =20 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 =3D=3D yytable_ninf_; } diff --git a/data/skeletons/stack.hh b/data/skeletons/stack.hh index bd5756c1..98913258 100644 --- a/data/skeletons/stack.hh +++ b/data/skeletons/stack.hh @@ -37,7 +37,7 @@ m4_define([b4_stack_define], typedef typename S::size_type size_type; typedef typename std::ptrdiff_t index_type; =20 - stack (size_type n =3D 200) + stack (size_type n =3D 200) YY_NOEXCEPT : seq_ (n) {} =20 @@ -116,7 +116,7 @@ m4_define([b4_stack_define], class slice { public: - slice (const stack& stack, index_type range) + slice (const stack& stack, index_type range) YY_NOEXCEPT : stack_ (stack) , range_ (range) {}