From patchwork Thu Feb 2 22:48:26 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bill Fischofer X-Patchwork-Id: 93140 Delivered-To: patch@linaro.org Received: by 10.140.20.99 with SMTP id 90csp338672qgi; Thu, 2 Feb 2017 14:48:38 -0800 (PST) X-Received: by 10.55.76.204 with SMTP id z195mr10774522qka.128.1486075718240; Thu, 02 Feb 2017 14:48:38 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id a28si17874144qta.159.2017.02.02.14.48.37; Thu, 02 Feb 2017 14:48:38 -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 8813560F35; Thu, 2 Feb 2017 22:48:37 +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 8DAEA60F13; Thu, 2 Feb 2017 22:48:33 +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 3AB0860F27; Thu, 2 Feb 2017 22:48:31 +0000 (UTC) Received: from mail-ot0-f175.google.com (mail-ot0-f175.google.com [74.125.82.175]) by lists.linaro.org (Postfix) with ESMTPS id 450D660EFB for ; Thu, 2 Feb 2017 22:48:30 +0000 (UTC) Received: by mail-ot0-f175.google.com with SMTP id 32so1829060oth.3 for ; Thu, 02 Feb 2017 14:48:30 -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=3me1FRMCH9DNby/aphtlOhSjRQIlMNDGJEmvIsbW8VY=; b=Ej6AHWXQspkeq/hjGoGaA1QzZzmBL+YABDjo59V2qb6f2qNAEoGe6N5AlYhXAIjT3d HgJIYqp33PrK4A0ybXQdVL32JnqhaLbfpOENVj86O1XK40JhD+YHiZaYHSu7qiAkVMZ3 CzVm7lPhV4J516FvUGl/6DUOcQxpXbUaJk91Wt43mGtjXLeP8qK6P5F9ZiSDLv16aLnS 75MllJpd6zGHF5AzgWPBP2ZjAnqP4GZwbWrGchw7N1SaHfyPRnzDRRUVaYjYtR1MUxIB 8EylONTRBG+vlKPRUf4/zekU1mu1n9cbwHbKCKYOyO+J1y/MpxwFkDgYlmwwZqYbIg99 Xkyg== X-Gm-Message-State: AMke39nSTD+yYmVsgYs2xY6jJ5SvcwPQSG3/E0fApTPtXxGXFHKhxpJg4Qs0PcQ1Oe6qsMKZpzE= X-Received: by 10.157.35.98 with SMTP id k31mr4862521otd.109.1486075709579; Thu, 02 Feb 2017 14:48:29 -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 s66sm13013949oie.28.2017.02.02.14.48.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 02 Feb 2017 14:48:28 -0800 (PST) From: Bill Fischofer To: lng-odp@lists.linaro.org Date: Thu, 2 Feb 2017 16:48:26 -0600 Message-Id: <1486075706-27811-1-git-send-email-bill.fischofer@linaro.org> X-Mailer: git-send-email 2.7.4 Subject: [lng-odp] [PATCHv3] 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 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 --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 -#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 #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());