diff mbox

[PATCHv3] linux-generic: debug: enable helper use from c++ programs

Message ID 1486075706-27811-1-git-send-email-bill.fischofer@linaro.org
State Superseded
Headers show

Commit Message

Bill Fischofer Feb. 2, 2017, 10:48 p.m. UTC
The ODP_STATIC_ASSERT() macro expands to _Static_assert(), however when
used in C++ programs this needs to expand to static_assert().

This resolves Bug https://bugs.linaro.org/show_bug.cgi?id=2852

Reported-by: Moshe Tubul <moshe.tubul@firmitas-cs.com>
Signed-off-by: Bill Fischofer <bill.fischofer@linaro.org>

---
Changes for v3:
- Support older versions of g++ that don't allow c++11 static assert by default

Changes for v2:
- Update C++ test case to include helper apis to validate this fix

 platform/linux-generic/include/odp/api/debug.h     | 24 ++++++++++++++++------
 .../common_plat/miscellaneous/odp_api_from_cpp.cpp |  3 +--
 2 files changed, 19 insertions(+), 8 deletions(-)

-- 
2.7.4
diff mbox

Patch

diff --git a/platform/linux-generic/include/odp/api/debug.h b/platform/linux-generic/include/odp/api/debug.h
index 7db1433..c4b1115 100644
--- a/platform/linux-generic/include/odp/api/debug.h
+++ b/platform/linux-generic/include/odp/api/debug.h
@@ -19,18 +19,28 @@  extern "C" {
 
 #include <odp/api/spec/debug.h>
 
-#if defined(__GNUC__) && !defined(__clang__)
+#if defined(__GNUC__)
 
-#if __GNUC__ < 4 || (__GNUC__ == 4 && (__GNUC_MINOR__ < 6))
+#if __GNUC__ < 4 || (__GNUC__ == 4 && (__GNUC_MINOR__ < 6)) || \
+	(__GNUC__ < 6 && defined(__cplusplus))
 
 /**
- * @internal _Static_assert was only added in GCC 4.6. Provide a weak replacement
- * for previous versions.
+ * @internal _Static_assert was only added in GCC 4.6 and the C++ version
+ * static_assert for g++ 6 and above.  Provide a weak replacement for previous
+ * versions.
  */
+#ifdef __cplusplus
+#ifndef _ctr
+#define _ctr() __COUNTER__
+#endif
+#define static_assert(e, s) \
+	extern int _sassert[(e) ? 1 : -1]
+#else
 #define _Static_assert(e, s) (extern int (*static_assert_checker(void)) \
 	[sizeof(struct { unsigned int error_if_negative:(e) ? 1 : -1; })])
 
 #endif
+#endif
 
 #endif
 
@@ -39,9 +49,11 @@  extern "C" {
  * if condition 'cond' is false. Macro definition is empty when compiler is not
  * supported or the compiler does not support static assertion.
  */
-#define ODP_STATIC_ASSERT(cond, msg)  _Static_assert(cond, msg)
+#ifndef __cplusplus
+#define ODP_STATIC_ASSERT(cond, msg) _Static_assert(cond, msg)
 
-#ifdef __cplusplus
+#else
+#define ODP_STATIC_ASSERT(cond, msg) static_assert(cond, msg)
 }
 #endif
 
diff --git a/test/common_plat/miscellaneous/odp_api_from_cpp.cpp b/test/common_plat/miscellaneous/odp_api_from_cpp.cpp
index 2b30786..4578ae4 100644
--- a/test/common_plat/miscellaneous/odp_api_from_cpp.cpp
+++ b/test/common_plat/miscellaneous/odp_api_from_cpp.cpp
@@ -1,10 +1,9 @@ 
 #include <cstdio>
 #include <odp_api.h>
-#include <odp/helper/threads.h>
+#include <odp/helper/odph_api.h>
 
 int main(int argc ODP_UNUSED, const char *argv[] ODP_UNUSED)
 {
-
 	printf("\tODP API version: %s\n", odp_version_api_str());
 	printf("\tODP implementation version: %s\n", odp_version_impl_str());