[PATCH] D130800: [clang][Headers] Avoid compiler warnings in builtin headers

Artem Belevich via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Aug 2 13:47:37 PDT 2022


tra added a subscriber: yaxunl.
tra added inline comments.


================
Comment at: clang/lib/Headers/__clang_cuda_builtin_vars.h:14
+#ifndef __cplusplus
+#error CUDA header must be used from C++
+#endif
----------------
Nit: the error message sounds a bit odd.
Perhaps rephrase it as `This CUDA header requires C++`.


================
Comment at: clang/lib/Headers/__clang_hip_cmath.h:381
 // decltype is only available in C++11 and above.
-#if __cplusplus >= 201103L
+#if defined(__cplusplus) && __cplusplus >= 201103L
 // __hip_promote
----------------
HIP headers are also not expected to compile w/o C++ and we may want a `#error`here, too. 

Actually, I'm not even sure if we shopuld/need to add `#if defined(__cplusplus)`in files that are clearly C++ -- undefined macro warning will be the least of one's worries if they attempt to compile it w/o C++.

Perhaps it would make sense to limit these changes to the headers intended to be used from both C and C++? Both CUDA and HIP are expected to never be included from a non-C++ compilation and will never trigger the undefined macro warning on `__cplusplus`.

@yaxunl - FYI.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D130800/new/

https://reviews.llvm.org/D130800



More information about the cfe-commits mailing list