This is an automated email from the git hooks/post-receive script.

guillem pushed a commit to branch master
in repository dpkg.

View the commit online:
https://git.dpkg.org/cgit/dpkg/dpkg.git/commit/?id=33f375f87425ad26e85ba4c27beaf6296ea72d98

commit 33f375f87425ad26e85ba4c27beaf6296ea72d98
Author: Guillem Jover <[email protected]>
AuthorDate: Tue Feb 4 04:12:44 2020 +0100

    libdpkg: Use a new DPKG_STATIC_CAST macro that works in C and C++
    
    Warned-by: clang++-10 -Wold-style-cast
---
 debian/changelog   |  1 +
 lib/dpkg/c-ctype.h |  3 ++-
 lib/dpkg/macros.h  | 15 +++++++++++++++
 3 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/debian/changelog b/debian/changelog
index 62aab448d..2f0772549 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -198,6 +198,7 @@ dpkg (1.20.0) UNRELEASED; urgency=medium
     - libdpkg: Define new VARBUF_OBJECT macro.
     - libdpkg: Add new ATOMIC_FILE_NORMAL enum value to avoid a cast in C++.
     - libdpkg: Use a new DPKG_NULL macro that works in C and C++.
+    - libdpkg: Use a new DPKG_STATIC_CAST macro that works in C and C++.
   * Build system:
     - Bump minimal Perl version to 5.24.1.
     - Add a serial versioning to the m4 files.
diff --git a/lib/dpkg/c-ctype.h b/lib/dpkg/c-ctype.h
index 959085a3a..b04fda86b 100644
--- a/lib/dpkg/c-ctype.h
+++ b/lib/dpkg/c-ctype.h
@@ -122,7 +122,8 @@ c_isalnum(int c)
 static inline int
 c_tolower(int c)
 {
-       return (c_isupper(c) ? ((unsigned char)c & ~0x20) | 0x20 : c);
+       return (c_isupper(c) ?
+               (DPKG_STATIC_CAST(unsigned char, c) & ~0x20) | 0x20 : c);
 }
 
 DPKG_END_DECLS
diff --git a/lib/dpkg/macros.h b/lib/dpkg/macros.h
index a513b6685..6eaedf844 100644
--- a/lib/dpkg/macros.h
+++ b/lib/dpkg/macros.h
@@ -102,6 +102,21 @@
 #define DPKG_NULL      NULL
 #endif
 
+/**
+ * @def DPKG_STATIC_CAST
+ *
+ * Cast an expression to a given type that works on C or C++.
+ *
+ * To be used only on header files, where having to conditionalize the code
+ * to use either NULL or nullptr would be too cumbersome. Non-header files
+ * should use the appropriate constant directly.
+ */
+#if defined(__cplusplus)
+#define DPKG_STATIC_CAST(type, expr) static_cast<type>(expr)
+#else
+#define DPKG_STATIC_CAST(type, expr) (type)(expr)
+#endif
+
 /**
  * @def DPKG_BIT
  *

-- 
Dpkg.Org's dpkg

Reply via email to