Handle differences in math headers compiling with Clang#2352
Handle differences in math headers compiling with Clang#2352metcalf wants to merge 3 commits intoparticle-iot:developfrom
Conversation
| ****************************************************************************** | ||
| */ | ||
|
|
||
| #ifdef __clang__ |
There was a problem hiding this comment.
This does not need to be __clang__-specific.
| // C++ only | ||
| #ifdef __cplusplus | ||
|
|
||
| #ifndef __clang__ |
There was a problem hiding this comment.
I would suggest also not using targeting __clang__ specifically and instead include <cmath> if compiling as __cplusplus and math.h otherwise, which should resolve the problem.
There was a problem hiding this comment.
Fixed. Note that my fix still includes math.h in all cases since I think that's required for backwards compatibility with user code as described in the new comment. My C experience is limited so I'm prepared to be wrong about that!
I also chose to put the conditional include of <cmath> adjacent to the include of math.h since I think it's clearer even though it requires a separate #ifndef __cplusplus guard.
| // 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 <cmath> |
There was a problem hiding this comment.
Gah, sorry, I caught this locally but forgot to push. Fixed now.
Problem
Attempting to compile for unit testing using Clang fails due to differences in the math headers with the errors below.
Solution
Add clang-specific preprocessor directives to handle these cases. There appears to be precedent for clang-specific directives in this project:
https://github.com/particle-iot/device-os/search?q=__clang__
Steps to Test
I wrote a demo project to use Bazel and Google Test with Particle for unit testing. To make it compile successfully, I had to include the changes from this PR as a patch:
https://github.com/metcalf/arduino-particle-bazel-demo/blob/main/tools/io_particle_device_os.patch
Example App
N/A
References
Links to the Community, Docs, Other Issues, etc..
Completeness