[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
- [PATCH 0/9] glr2.cc: warnings and style, Akim Demaille, 2020/09/12
- [PATCH 1/9] glr2.cc: add copy constructor to yyGLRStackItem, Akim Demaille, 2020/09/12
- [PATCH 2/9] glr2.cc: remove C-style casts, Akim Demaille, 2020/09/12
- [PATCH 3/9] glr2.cc: remove usage of PTRDIFF_MAX,
Akim Demaille <=
- [PATCH 4/9] glr2.cc: move StrongIndexAlias into the namespace, Akim Demaille, 2020/09/12
- [PATCH 5/9] glr2.cc: coding style changes, Akim Demaille, 2020/09/12
- [PATCH 6/9] glr2.cc: fix GCC10 warning, Akim Demaille, 2020/09/12
- [PATCH 7/9] glr2.cc: formatting changes, Akim Demaille, 2020/09/12
- [PATCH 8/9] glr2.cc: get rid of the C indirection for yy_symbol_print, Akim Demaille, 2020/09/12
- [PATCH 9/9] glr2.cc: address warnings with G++ 4.8, Akim Demaille, 2020/09/12