From patchwork Thu Apr 6 11:39:50 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Uvarov X-Patchwork-Id: 96929 Delivered-To: patch@linaro.org Received: by 10.140.89.233 with SMTP id v96csp688919qgd; Thu, 6 Apr 2017 04:42:59 -0700 (PDT) X-Received: by 10.55.201.202 with SMTP id m71mr23348839qkl.31.1491478979077; Thu, 06 Apr 2017 04:42:59 -0700 (PDT) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id v62si1178741qkd.32.2017.04.06.04.42.58; Thu, 06 Apr 2017 04:42:59 -0700 (PDT) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 37A50642EE; Thu, 6 Apr 2017 11:42:58 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on ip-10-142-244-252 X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, URIBL_BLOCKED autolearn=disabled version=3.4.0 Received: from [127.0.0.1] (localhost [127.0.0.1]) by lists.linaro.org (Postfix) with ESMTP id 6E36360C05; Thu, 6 Apr 2017 11:42:47 +0000 (UTC) X-Original-To: lng-odp@lists.linaro.org Delivered-To: lng-odp@lists.linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 33ED564349; Thu, 6 Apr 2017 11:42:38 +0000 (UTC) Received: from mail-lf0-f50.google.com (mail-lf0-f50.google.com [209.85.215.50]) by lists.linaro.org (Postfix) with ESMTPS id 5E19E60D43 for ; Thu, 6 Apr 2017 11:40:01 +0000 (UTC) Received: by mail-lf0-f50.google.com with SMTP id x137so24386861lff.3 for ; Thu, 06 Apr 2017 04:40:01 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=it/ycXOLxvNz38w31XU+vEaZ86NdAn1ysEGelr6FpVA=; b=LgWbx5vtGCWGebxXOdurQIrrbJiRlIJEJrHV/cLrUxwxO/HJ0MAZMlTX80/y4SEu/9 jIg3rohD7Td86AEkCpPVNU1auxgJxshnsFOyAKvlvWjVBH9oY/4U9iWa6rqfKeYhXZzJ 4vuDXzrmU3ZMk/pnz2Svm5BSQ6HxFTt98nLIswS9WsDrl4NYVjSXRkoQA7gEd7aiFfDy NOcXHX9oQ/kH6tQCz5gX4qlMImr7NShAVYy390UoNa5NJ1HYE4idKGKhgeTmoz0EP+BW Njx1xeg6zPyW8mjzqUVBChhWmm/8i/BzdUqzvPYSwjbfNxNASKDJyR7y3ScMfmLP7tpc R4NQ== X-Gm-Message-State: AFeK/H2DFVB7jg4OUYCvUXXL64bU7ZR8OnpZP5r+EOi6EH3SAYP5Vwog7+o11Zm10kdgpqanIF37Crvd X-Received: by 10.46.69.85 with SMTP id s82mr9657377lja.12.1491478799845; Thu, 06 Apr 2017 04:39:59 -0700 (PDT) Received: from localhost.localdomain (ppp95-165-131-83.pppoe.spdop.ru. [95.165.131.83]) by smtp.gmail.com with ESMTPSA id b16sm285208lfe.30.2017.04.06.04.39.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 06 Apr 2017 04:39:59 -0700 (PDT) From: Maxim Uvarov To: lng-odp@lists.linaro.org Date: Thu, 6 Apr 2017 14:39:50 +0300 Message-Id: <20170406113950.31356-1-maxim.uvarov@linaro.org> X-Mailer: git-send-email 2.11.0.295.gd7dffce Subject: [lng-odp] [PATCH] linux-generic: debug: enable helper use from c++ programs X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: "The OpenDataPlane \(ODP\) List" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" From: Bill Fischofer 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 Signed-off-by: Bill Fischofer --- /** Email created from pull request 9 (Bill-Fischofer-Linaro:master) ** https://github.com/Linaro/odp/pull/9 ** Patch: https://github.com/Linaro/odp/pull/9.patch ** Base sha: 503708078bf6ab9228d23ad65660b42248600c2d ** Merge commit sha: 439821b5943299fcdf399dd63afc3555609007cd **/ platform/linux-generic/include/odp/api/debug.h | 41 ++++++++++++++++------ .../common_plat/miscellaneous/odp_api_from_cpp.cpp | 3 +- 2 files changed, 32 insertions(+), 12 deletions(-) diff --git a/platform/linux-generic/include/odp/api/debug.h b/platform/linux-generic/include/odp/api/debug.h index 7db1433..b0f91b1 100644 --- a/platform/linux-generic/include/odp/api/debug.h +++ b/platform/linux-generic/include/odp/api/debug.h @@ -19,17 +19,36 @@ extern "C" { #include -#if defined(__GNUC__) && !defined(__clang__) - -#if __GNUC__ < 4 || (__GNUC__ == 4 && (__GNUC_MINOR__ < 6)) - /** - * @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. */ -#define _Static_assert(e, s) (extern int (*static_assert_checker(void)) \ - [sizeof(struct { unsigned int error_if_negative:(e) ? 1 : -1; })]) +#define _odp_merge(a, b) a##b +#define _odp_label(a) _odp_merge(_ODP_SASSERT_, a) +#define _ODP_SASSERT _odp_label(__COUNTER__) +#define _ODP_SASSERT_ENUM(e) { _ODP_SASSERT = 1 / !!(e) } +#define _odp_static_assert(e, s) enum _ODP_SASSERT_ENUM(e) + +#if defined(__clang__) +#if defined(__cplusplus) +#if !__has_feature(cxx_static_assert) && !defined(static_assert) +#define static_assert(e, s) _odp_static_assert(e, s) +#endif +#elif !__has_feature(c_static_assert) && !defined(_Static_assert) +#define _Static_assert(e, s) _odp_static_assert(e, s) +#endif +#elif defined(__GNUC__) +#if __GNUC__ < 4 || (__GNUC__ == 4 && (__GNUC_MINOR__ < 6)) || \ + (__GNUC__ < 6 && defined(__cplusplus)) +#if defined(__cplusplus) +#if !defined(static_assert) +#define static_assert(e, s) _odp_static_assert(e, s) +#endif +#elif !defined(_Static_assert) +#define _Static_assert(e, s) _odp_static_assert(e, s) +#endif #endif #endif @@ -39,9 +58,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 #include -#include +#include 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());