bison-patches
[Top][All Lists]
Advanced

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

[PATCH 3/9] glr2.cc: remove usage of PTRDIFF_MAX


From: Akim Demaille
Subject: [PATCH 3/9] glr2.cc: remove usage of PTRDIFF_MAX
Date: Sat, 12 Sep 2020 16:51:49 +0200

From: Valentin Tolmer <valentin.tolmer@gmail.com>

* data/skeletons/glr2.cc: Use std::ptrdiff_t and numeric_limits.
---
 TODO                   | 12 ------------
 data/skeletons/glr2.cc | 14 ++++++--------
 2 files changed, 6 insertions(+), 20 deletions(-)

diff --git a/TODO b/TODO
index c9321ecb..56c0b80e 100644
--- a/TODO
+++ b/TODO
@@ -162,18 +162,6 @@ Line -1 and -3 should mention CATEGORIE, not CATEGORY.
 *** glr.c
 Get rid of scaffolding in glr.c.
 
-*** pragmas in glr2.cc
-Remove the pragmas that disable some warnings:
-
-    // On MacOS, PTRDIFF_MAX is defined as long long, which Clang's
-    // -pedantic reports as being a C++11 extension.
-    #if defined __APPLE__ && YY_CPLUSPLUS < 201103L \
-        && defined __clang__ && 4 <= __clang_major__
-    # pragma clang diagnostic ignored "-Wc++11-long-long"
-    #endif
-
-We should use clean C++ code.
-
 *** namespaces in glr2.cc
 StrongIndexAlias should be in the parser's namespace.  Possibly even an
 inner class.
diff --git a/data/skeletons/glr2.cc b/data/skeletons/glr2.cc
index 39eb8b36..a5af6f4f 100644
--- a/data/skeletons/glr2.cc
+++ b/data/skeletons/glr2.cc
@@ -130,6 +130,7 @@ b4_percent_code_get([[requires]])[
 #include <cstring> // memcpy
 #include <iostream>
 #include <iomanip>
+#include <limits>
 #include <stdexcept>
 #include <stdint.h>
 #include <string>
@@ -144,13 +145,6 @@ b4_percent_code_get([[requires]])[
 ]b4_cast_define[
 ]b4_null_define[
 
-// On MacOS, PTRDIFF_MAX is defined as long long, which Clang's
-// -pedantic reports as being a C++11 extension.
-#if defined __APPLE__ && YY_CPLUSPLUS < 201103L \
-    && defined __clang__ && 4 <= __clang_major__
-# pragma clang diagnostic ignored "-Wc++11-long-long"
-#endif
-
 template <typename Parameter>
 class StrongIndexAlias
 {
@@ -211,12 +205,16 @@ class StrongIndexAlias
   }
 
  private:
-  static const ptrdiff_t INVALID_INDEX = PTRDIFF_MAX;
+  static const std::ptrdiff_t INVALID_INDEX;
 
   // WARNING: 0-initialized.
   std::ptrdiff_t value_;
 };
 
+template<typename T>
+const std::ptrdiff_t StrongIndexAlias<T>::INVALID_INDEX =
+  std::numeric_limits<std::ptrdiff_t>::max();
+
 // Whether we are compiled with exception support.
 #ifndef YY_EXCEPTIONS
 # if defined __GNUC__ && !defined __EXCEPTIONS
-- 
2.28.0




reply via email to

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