From 5d907db2a86604064f8321b002d02ad545f45f7e Mon Sep 17 00:00:00 2001 From: Andrew Metcalf Date: Tue, 7 Sep 2021 11:17:10 -0700 Subject: [PATCH 1/3] Handle differences in math headers compiling with Clang --- user/inc/Arduino.h | 4 ++++ wiring/src/spark_wiring_usbserial.cpp | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/user/inc/Arduino.h b/user/inc/Arduino.h index 408650b7df..ef772fda9b 100644 --- a/user/inc/Arduino.h +++ b/user/inc/Arduino.h @@ -193,6 +193,9 @@ typedef volatile uint32_t RwReg; // C++ only #ifdef __cplusplus +#ifndef __clang__ +// Under clang, "math.h" does not put isnan/isinf inside the std namespace so this would fail + #ifndef isnan using std::isnan; #endif @@ -201,6 +204,7 @@ using std::isnan; using std::isinf; #endif +#endif // __clang__ // Hardware serial defines diff --git a/wiring/src/spark_wiring_usbserial.cpp b/wiring/src/spark_wiring_usbserial.cpp index 012f3c2236..edb305c891 100644 --- a/wiring/src/spark_wiring_usbserial.cpp +++ b/wiring/src/spark_wiring_usbserial.cpp @@ -24,6 +24,11 @@ ****************************************************************************** */ +#ifdef __clang__ +// Needed for std::{min,max} in Clang +#include +#endif + #include "spark_wiring_usbserial.h" #include "platform_headers.h" From 4b850fd306327c5afa2ae5c7722db366bfd86793 Mon Sep 17 00:00:00 2001 From: Andrew Metcalf Date: Tue, 7 Sep 2021 14:42:24 -0700 Subject: [PATCH 2/3] Respond to PR comments avoiding Clang-specific directives --- user/inc/Arduino.h | 18 +++++++++++++----- wiring/src/spark_wiring_usbserial.cpp | 3 --- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/user/inc/Arduino.h b/user/inc/Arduino.h index ef772fda9b..6b0c86b857 100644 --- a/user/inc/Arduino.h +++ b/user/inc/Arduino.h @@ -18,6 +18,15 @@ #include +#ifdef __cplusplus +// In order to support compiling with Clang, explicitly include cmath here since the Clang version +// of the math.h header included above does not include cmath. This is a no-op compiling with GCC +// since the GCC version of math.h includes cmath. We still include math.h under C++ for backwards +// compatibility with user code that might assume certain math functions in the global namespace from +// math.h. +#include +#endif + // #ifndef isnan // #error isnan is not defined please ensure this header is included before any STL headers // #endif @@ -193,8 +202,10 @@ typedef volatile uint32_t RwReg; // C++ only #ifdef __cplusplus -#ifndef __clang__ -// Under clang, "math.h" does not put isnan/isinf inside the std namespace so this would fail +// In order to support compiling with Clang, explicitly include cmath here since the Clang version +// of the math.h header included above does not include cmath. This is a no-op compiling with GCC +// since the GCC version of math.h includes cmath. Replacing the math.h include above +#include #ifndef isnan using std::isnan; @@ -204,8 +215,6 @@ using std::isnan; using std::isinf; #endif -#endif // __clang__ - // Hardware serial defines #ifndef UBRRH @@ -307,4 +316,3 @@ typedef USARTSerial HardwareSerial; #endif /* ARDUINO_H */ - diff --git a/wiring/src/spark_wiring_usbserial.cpp b/wiring/src/spark_wiring_usbserial.cpp index edb305c891..b2ad8fc28d 100644 --- a/wiring/src/spark_wiring_usbserial.cpp +++ b/wiring/src/spark_wiring_usbserial.cpp @@ -24,10 +24,7 @@ ****************************************************************************** */ -#ifdef __clang__ -// Needed for std::{min,max} in Clang #include -#endif #include "spark_wiring_usbserial.h" #include "platform_headers.h" From f82133aac9adb4ce5fbbd34363dc3e4ebc3b3ce8 Mon Sep 17 00:00:00 2001 From: Andrew Metcalf Date: Tue, 7 Sep 2021 18:54:15 -0700 Subject: [PATCH 3/3] Remove duplicate include --- user/inc/Arduino.h | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/user/inc/Arduino.h b/user/inc/Arduino.h index 6b0c86b857..a4bbecbdb5 100644 --- a/user/inc/Arduino.h +++ b/user/inc/Arduino.h @@ -202,11 +202,6 @@ typedef volatile uint32_t RwReg; // C++ only #ifdef __cplusplus -// In order to support compiling with Clang, explicitly include cmath here since the Clang version -// of the math.h header included above does not include cmath. This is a no-op compiling with GCC -// since the GCC version of math.h includes cmath. Replacing the math.h include above -#include - #ifndef isnan using std::isnan; #endif @@ -215,6 +210,7 @@ using std::isnan; using std::isinf; #endif + // Hardware serial defines #ifndef UBRRH