From patchwork Thu Feb 2 22:51:55 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bill Fischofer X-Patchwork-Id: 93141 Delivered-To: patch@linaro.org Received: by 10.140.20.99 with SMTP id 90csp339695qgi; Thu, 2 Feb 2017 14:52:06 -0800 (PST) X-Received: by 10.55.161.71 with SMTP id k68mr10921877qke.185.1486075926805; Thu, 02 Feb 2017 14:52:06 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id p12si17897166qte.223.2017.02.02.14.52.06; Thu, 02 Feb 2017 14:52:06 -0800 (PST) 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 6C22360F35; Thu, 2 Feb 2017 22:52:06 +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 EEAAF60F13; Thu, 2 Feb 2017 22:52:01 +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 9792460F27; Thu, 2 Feb 2017 22:51:59 +0000 (UTC) Received: from mail-oi0-f45.google.com (mail-oi0-f45.google.com [209.85.218.45]) by lists.linaro.org (Postfix) with ESMTPS id 9490D60EFB for ; Thu, 2 Feb 2017 22:51:58 +0000 (UTC) Received: by mail-oi0-f45.google.com with SMTP id s203so1515276oie.1 for ; Thu, 02 Feb 2017 14:51:58 -0800 (PST) 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=kwPCqPHkQj6pEHJOEQ21taLIWB5i4rc3KTP4l3WO2ZM=; b=YMMC/r+tmyDKuJ55SyqQ6+vqa+d7UJ4Cx8/kv4WeWxXC8G4++Gil55/W8yzV1stAtk T4pUkx5TXOrFKqQ+IOANE6z/9ZdsvAm6mLjRkB0hINRNceQPNwJBvKw1JzOLfmcvJXFc Lw/XW6p0zexNf+XdJ4oj52fjPW2ANQxhpAKEqrIHLemNpOr+QEfMsWNZ+vrgDoV+DTEO vKKzBVZFcjAkE9vFcCZX5GUmH/Cknk/h1W+0PSdmq5C+VTiqFJ3OY3cUSU2wg92j1Hlh MHBqaUJRaC79GeWZTutom6xs8m5GaRT1rUEUWC7XK40VrFeb2QVdPqfLTUavJCuqlp4D o7LA== X-Gm-Message-State: AIkVDXJ9dQUUTohU9hBKXY/PhutYkGgSfDqkeygK21d+EgnlVZwkHpf7TiUID8L9FwH8M7OgOjQ= X-Received: by 10.202.244.131 with SMTP id s125mr4912541oih.136.1486075917846; Thu, 02 Feb 2017 14:51:57 -0800 (PST) Received: from localhost.localdomain (cpe-70-121-83-241.austin.res.rr.com. [70.121.83.241]) by smtp.gmail.com with ESMTPSA id t53sm13083284otd.6.2017.02.02.14.51.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 02 Feb 2017 14:51:57 -0800 (PST) From: Bill Fischofer To: lng-odp@lists.linaro.org Date: Thu, 2 Feb 2017 16:51:55 -0600 Message-Id: <1486075915-28921-1-git-send-email-bill.fischofer@linaro.org> X-Mailer: git-send-email 2.7.4 Subject: [lng-odp] [PATCHv4] 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" 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 --- Changes for v4: - Remove extraneous debug code 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 | 21 +++++++++++++++------ test/common_plat/miscellaneous/odp_api_from_cpp.cpp | 3 +-- 2 files changed, 16 insertions(+), 8 deletions(-) -- 2.7.4 diff --git a/platform/linux-generic/include/odp/api/debug.h b/platform/linux-generic/include/odp/api/debug.h index 7db1433..44ca5b7 100644 --- a/platform/linux-generic/include/odp/api/debug.h +++ b/platform/linux-generic/include/odp/api/debug.h @@ -19,18 +19,25 @@ extern "C" { #include -#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 +#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 +46,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());