On 02/06 13:14:17, Bill Fischofer wrote:
> Ping. Brian can you please verify that this now works on your system.
> It works on my Ubuntu 16.04 system.

Just built on:

Ubuntu 16.10 - x86_64
Ubuntu 16.04 - aarch64
Arch         - aarch64 & x86_64

so the previous build error I reported seems to have been resolved.

> A review would also be nice. :)

LGTM, please...

Reviewed-and-tested-by: Brian Brooks <brian.bro...@linaro.org>

> On Thu, Feb 2, 2017 at 4:51 PM, Bill Fischofer
> <bill.fischo...@linaro.org> wrote:
> > 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.tu...@firmitas-cs.com>
> > Signed-off-by: Bill Fischofer <bill.fischo...@linaro.org>
> > ---
> > 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(-)
> >
> > 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 <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.
> >   */

I think a plain C-style build time assertion (no special compiler support
needed - besides unused attribute) will work for C++ as well. So the entire
thing could just be:

  #define _SA1(cond_, line_) \
    extern int __static_assertion_ ## line_[1 - 2*!(cond_)] __unused
  #define _SA0(cond_, line_) _SA1(cond_, line_)
  #define ODP_STATIC_ASSERT(cond) _SA0(cond, __LINE__)

It also should be deprecated from the layer in which it currently resides
and used internally only; it adds no value at the data plane abstraction
layer. Code bases will already be using their own mechanism for build time
assertions.

> > +#ifdef __cplusplus

Consistent use of "#if defined(identifier)" advised.

> > +#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)
> >

Newline here could be removed.

> > -#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());
> >
> > --
> > 2.7.4
> >

Reply via email to