[Mesa-dev] [PATCH mesa 01/16] c99_{compat, math}.h: check for macro existance before using it

Eric Engestrom eric.engestrom at imgtec.com
Fri Nov 24 18:07:41 UTC 2017


Fixes thousands of warnings when using -Wundef, which is about to land,
as these two files are included virtually everywhere.

Signed-off-by: Eric Engestrom <eric.engestrom at imgtec.com>
---
 include/c99_compat.h | 6 +++---
 include/c99_math.h   | 5 +++--
 2 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/include/c99_compat.h b/include/c99_compat.h
index cb690c6e2a0180702a5b..008630b7868b77b4b5fd 100644
--- a/include/c99_compat.h
+++ b/include/c99_compat.h
@@ -81,7 +81,7 @@
      /* Intel compiler supports inline keyword */
 #  elif defined(__WATCOMC__) && (__WATCOMC__ >= 1100)
 #    define inline __inline
-#  elif (__STDC_VERSION__ >= 199901L)
+#  elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
      /* C99 supports inline keyword */
 #  else
 #    define inline
@@ -96,7 +96,7 @@
  * - http://cellperformance.beyond3d.com/articles/2006/05/demystifying-the-restrict-keyword.html
  */
 #ifndef restrict
-#  if (__STDC_VERSION__ >= 199901L)
+#  if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
      /* C99 */
 #  elif defined(__GNUC__)
 #    define restrict __restrict__
@@ -112,7 +112,7 @@
  * C99 __func__ macro
  */
 #ifndef __func__
-#  if (__STDC_VERSION__ >= 199901L)
+#  if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
      /* C99 */
 #  elif defined(__GNUC__)
 #    define __func__ __FUNCTION__
diff --git a/include/c99_math.h b/include/c99_math.h
index e906c26aa543bc1adfd1..629ee26ba2a803242950 100644
--- a/include/c99_math.h
+++ b/include/c99_math.h
@@ -45,7 +45,7 @@
 
 
 #if !defined(_MSC_VER) && \
-    __STDC_VERSION__ < 199901L && \
+    defined(__STDC_VERSION__) &&  __STDC_VERSION__ < 199901L && \
     (!defined(_XOPEN_SOURCE) || _XOPEN_SOURCE < 600) && \
     !defined(__cplusplus)
 
@@ -190,7 +190,8 @@ fpclassify(double x)
  * undefines those functions, which in glibc 2.23, are defined as macros rather
  * than functions as in glibc 2.22.
  */
-#if __cplusplus >= 201103L && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 23))
+#if defined(__cplusplus) && __cplusplus >= 201103L && \
+    defined(__GLIBC__) && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 23))
 #include <cmath>
 
 using std::fpclassify;
-- 
Cheers,
  Eric



More information about the mesa-dev mailing list