bison-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

c++: factor the handling of __cplusplus into YY_CPLUSPLUS


From: Akim Demaille
Subject: c++: factor the handling of __cplusplus into YY_CPLUSPLUS
Date: Tue, 13 Nov 2018 17:20:53 +0100

commit 7adeb80765d994ce6c2dbcdef3bda702aa4cf5d8
Author: Akim Demaille <address@hidden>
Date:   Tue Nov 13 06:49:24 2018 +0100

    c++: factor the handling of __cplusplus into YY_CPLUSPLUS
    
    * data/c++.m4 (b4_cxx_portability): Define it.
    Use it.
    * data/lalr1.cc, data/variant.hh: Use it.

diff --git a/data/c++.m4 b/data/c++.m4
index 066c3799..000902ee 100644
--- a/data/c++.m4
+++ b/data/c++.m4
@@ -53,8 +53,14 @@ m4_define([b4_inline],
 # b4_cxx_portability
 # ------------------
 m4_define([b4_cxx_portability],
-[// Support move semantics when possible.
-#if defined __cplusplus && 201103L <= __cplusplus
+[#if defined __cplusplus
+# define YY_CPLUSPLUS __cplusplus
+#else
+# define YY_CPLUSPLUS 199711L
+#endif
+
+// Support move semantics when possible.
+#if 201103L <= YY_CPLUSPLUS
 # define YY_MOVE           std::move
 # define YY_MOVE_OR_COPY   move
 # define YY_MOVE_REF(Type) Type&&
diff --git a/data/lalr1.cc b/data/lalr1.cc
index 8706eda6..a23bf60c 100644
--- a/data/lalr1.cc
+++ b/data/lalr1.cc
@@ -336,7 +336,7 @@ m4_define([b4_shared_declarations],
       stack_symbol_type (YY_RVREF (stack_symbol_type) that);
       /// Steal the contents from \a sym to build this.
       stack_symbol_type (state_type s, YY_MOVE_REF (symbol_type) sym);
-#if !defined __cplusplus || __cplusplus < 201103L
+#if YY_CPLUSPLUS < 201103L
       /// Assignment, needed by push_back by some old implementations.
       /// Moves the contents of that.
       stack_symbol_type& operator= (stack_symbol_type& that);
@@ -612,7 +612,7 @@ m4_if(b4_prefix, [yy], [],
   {]b4_variant_if([
     b4_symbol_variant([that.type_get ()],
                       [value], [YY_MOVE_OR_COPY], [YY_MOVE (that.value)])])[
-#if defined __cplusplus && 201103L <= __cplusplus
+#if 201103L <= YY_CPLUSPLUS
     // that is emptied.
     that.state = empty_state;
 #endif
@@ -627,7 +627,7 @@ m4_if(b4_prefix, [yy], [],
     that.type = empty_symbol;
   }
 
-#if !defined __cplusplus || __cplusplus < 201103L
+#if YY_CPLUSPLUS < 201103L
   ]b4_parser_class_name[::stack_symbol_type&
   ]b4_parser_class_name[::stack_symbol_type::operator= (stack_symbol_type& 
that)
   {
@@ -685,7 +685,7 @@ m4_if(b4_prefix, [yy], [],
   void
   ]b4_parser_class_name[::yypush_ (const char* m, state_type s, YY_MOVE_REF 
(symbol_type) sym)
   {
-#if defined __cplusplus && 201103L <= __cplusplus
+#if 201103L <= YY_CPLUSPLUS
     yypush_ (m, stack_symbol_type (s, std::move (sym)));
 #else
     stack_symbol_type ss (s, sym);
diff --git a/data/variant.hh b/data/variant.hh
index 5cc3df11..805ddce0 100644
--- a/data/variant.hh
+++ b/data/variant.hh
@@ -125,7 +125,7 @@ m4_define([b4_variant_define],
       return *new (yyas_<T> ()) T ();
     }
 
-# if defined __cplusplus && 201103L <= __cplusplus
+# if 201103L <= YY_CPLUSPLUS
     /// Instantiate a \a T in here from \a t.
     template <typename T, typename U>
     T&
@@ -213,7 +213,7 @@ m4_define([b4_variant_define],
     void
     move (self_type& other)
     {
-# if defined __cplusplus && 201103L <= __cplusplus
+# if 201103L <= YY_CPLUSPLUS
       emplace<T> (std::move (other.as<T> ()));
 # else
       emplace<T> ();
@@ -222,7 +222,7 @@ m4_define([b4_variant_define],
       other.destroy<T> ();
     }
 
-# if defined __cplusplus && 201103L <= __cplusplus
+# if 201103L <= YY_CPLUSPLUS
     /// Move the content of \a other to this.
     template <typename T>
     void
diff --git a/tests/headers.at b/tests/headers.at
index d3037c3a..39285ed9 100644
--- a/tests/headers.at
+++ b/tests/headers.at
@@ -317,6 +317,7 @@ AT_CHECK([[$PERL -n -0777 -e '
       |YYUSE
       |YY_ATTRIBUTE(?:_PURE|_UNUSED)?
       |YY_COPY
+      |YY_CPLUSPLUS
       |YY_IGNORE_MAYBE_UNINITIALIZED_(?:BEGIN|END)
       |YY_INITIAL_VALUE
       |YY_MOVE




reply via email to

[Prev in Thread] Current Thread [Next in Thread]