bug-bison
[Top][All Lists]
Advanced

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

Re: (non)Use of C++ 11 constructs in skeleton


From: Akim Demaille
Subject: Re: (non)Use of C++ 11 constructs in skeleton
Date: Fri, 1 May 2020 06:52:51 +0200

Hi Don,

> Le 19 mai 2019 à 10:12, Akim Demaille <address@hidden> a écrit :
> 
> Hi Don,
> 
>> Le 19 mai 2019 à 04:02, Don Macpherson <address@hidden> a écrit :
>> 
>> Hi,
>> Various places in the C++ skeleton have comments of the form:
>> 
>> /// This class is not copyable
>> /// Prohibit blind copies
>> 
>> while not actually informing the compiler of this fact (though the use of =
>> delete).
>> 
>> Given that the skeleton already has other C++11 conditional code, and that
>> the code produced by the skeleton is consumed within the users code base,
>> the output from the skeleton should endeavour to appropriately use other
>> modern C++ features.
> 
> Yes, you are right, we should also do that.  So far I resisted the temptation 
> to keep the out simple and avoid cascades of #if, but maybe we should do it 
> anyway.
> 
> Bison 3.4 is about to be published, I'm not going to do that now, but we'll 
> do that afterwards.

Well, we are one year later, in exactly the same situation, since 3.6 is
about to be released.

But let's do it.

Cheers!

commit 5b4725d85a38beeeded4800d91829e7ed65f6d7a
Author: Akim Demaille <address@hidden>
Date:   Fri May 1 06:36:19 2020 +0200

    c++: use modern idioms to make classes non-copyable
    
    Reported by Don Macpherson.
    https://lists.gnu.org/r/bug-bison/2019-05/msg00015.html
    https://github.com/akimd/bison/issues/36
    
    * data/skeletons/lalr1.cc, data/skeletons/stack.hh,
    * data/skeletons/variant.hh: Delete the copy-ctor and the copy operator.

diff --git a/THANKS b/THANKS
index 9d49461e..157efc00 100644
--- a/THANKS
+++ b/THANKS
@@ -57,6 +57,7 @@ Derek M. Jones            address@hidden
 Di-an Jan                 address@hidden
 Dick Streefland           address@hidden
 Didier Godefroy           address@hidden
+Don Macpherson            address@hidden
 Efi Fogel                 address@hidden
 Enrico Scholz             address@hidden
 Eric Blake                address@hidden
diff --git a/data/skeletons/lalr1.cc b/data/skeletons/lalr1.cc
index 81aff234..2b27088f 100644
--- a/data/skeletons/lalr1.cc
+++ b/data/skeletons/lalr1.cc
@@ -204,6 +204,13 @@ m4_define([b4_shared_declarations],
     ]b4_parser_class[ (]b4_parse_param_decl[);
     virtual ~]b4_parser_class[ ();
 
+#if 201103L <= YY_CPLUSPLUS
+    /// Non copyable.
+    ]b4_parser_class[ (const ]b4_parser_class[&) = delete;
+    /// Non copyable.
+    ]b4_parser_class[& operator= (const ]b4_parser_class[&) = delete;
+#endif
+
     /// Parse.  An alias for parse ().
     /// \returns  0 iff parsing succeeded.
     int operator() ();
@@ -255,10 +262,13 @@ m4_define([b4_shared_declarations],
     };
 ]])[
   private:
-    /// This class is not copyable.
+#if YY_CPLUSPLUS < 201103L
+    /// Non copyable.
     ]b4_parser_class[ (const ]b4_parser_class[&);
-    ]b4_parser_class[& operator= (const ]b4_parser_class[&);]b4_lac_if([[
-
+    /// Non copyable.
+    ]b4_parser_class[& operator= (const ]b4_parser_class[&);
+#endif
+]b4_lac_if([[
     /// Check the lookahead yytoken.
     /// \returns  true iff the token will be eventually shifted.
     bool yy_lac_check_ (symbol_kind_type yytoken) const;
diff --git a/data/skeletons/stack.hh b/data/skeletons/stack.hh
index 6c41fbf8..0fd36258 100644
--- a/data/skeletons/stack.hh
+++ b/data/skeletons/stack.hh
@@ -41,6 +41,13 @@ m4_define([b4_stack_define],
         : seq_ (n)
       {}
 
+#if 201103L <= YY_CPLUSPLUS
+      /// Non copyable.
+      stack (const stack&) = delete;
+      /// Non copyable.
+      stack& operator= (const stack&) = delete;
+#endif
+
       /// Random access.
       ///
       /// Index 0 returns the topmost element.
@@ -126,8 +133,12 @@ m4_define([b4_stack_define],
       };
 
     private:
+#if YY_CPLUSPLUS < 201103L
+      /// Non copyable.
       stack (const stack&);
+      /// Non copyable.
       stack& operator= (const stack&);
+#endif
       /// The wrapped container.
       S seq_;
     };
diff --git a/data/skeletons/variant.hh b/data/skeletons/variant.hh
index 13a35c6d..b594af38 100644
--- a/data/skeletons/variant.hh
+++ b/data/skeletons/variant.hh
@@ -115,6 +115,13 @@ m4_define([b4_value_type_declare],
       new (yyas_<T> ()) T (YY_MOVE (t));
     }
 
+#if 201103L <= YY_CPLUSPLUS
+    /// Non copyable.
+    semantic_type (const self_type&) = delete;
+    /// Non copyable.
+    self_type& operator= (const self_type&) = delete;
+#endif
+
     /// Destruction, allowed only if empty.
     ~semantic_type () YY_NOEXCEPT
     {]b4_parse_assert_if([
@@ -258,9 +265,12 @@ m4_define([b4_value_type_declare],
     }
 
   private:
-    /// Prohibit blind copies.
-    self_type& operator= (const self_type&);
+#if YY_CPLUSPLUS < 201103L
+    /// Non copyable.
     semantic_type (const self_type&);
+    /// Non copyable.
+    self_type& operator= (const self_type&);
+#endif
 
     /// Accessor to raw memory as \a T.
     template <typename T>




reply via email to

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