[PATCH weston] sdk: make C++11 plugins build again

2013-12-09 Thread Giulio Camuffo
compositor.h must not define a 'static_assert' macro, since that
conflicts with the new 'static_assert' in the standard and breaks
the build.
---
 desktop-shell/shell.c | 4 
 src/compositor.h  | 4 
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/desktop-shell/shell.c b/desktop-shell/shell.c
index 5f6bd6d..9fbac00 100644
--- a/desktop-shell/shell.c
+++ b/desktop-shell/shell.c
@@ -43,6 +43,10 @@
 #define DEFAULT_NUM_WORKSPACES 1
 #define DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH 200
 
+#ifndef static_assert
+#define static_assert(cond, msg)
+#endif
+
 struct focus_state {
struct weston_seat *seat;
struct workspace *ws;
diff --git a/src/compositor.h b/src/compositor.h
index ab3de19..9f34d40 100644
--- a/src/compositor.h
+++ b/src/compositor.h
@@ -45,10 +45,6 @@ extern C {
 
 #define ARRAY_LENGTH(a) (sizeof (a) / sizeof (a)[0])
 
-#ifndef static_assert
-#define static_assert(cond, msg)
-#endif
-
 #define container_of(ptr, type, member) ({ \
const __typeof__( ((type *)0)-member ) *__mptr = (ptr);\
(type *)( (char *)__mptr - offsetof(type,member) );})
-- 
1.8.5.1

___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/wayland-devel


Re: [PATCH weston] sdk: make C++11 plugins build again

2013-12-09 Thread Kristian Høgsberg
On Mon, Dec 09, 2013 at 10:47:58PM +0100, Giulio Camuffo wrote:
 compositor.h must not define a 'static_assert' macro, since that
 conflicts with the new 'static_assert' in the standard and breaks
 the build.

Ugh, ok, sorry.  Maybe we need a private header file where we can hide
all our C macros - ARRAY_LENGTH, static_assert, container_of etc.

Anyway, applied this patch for now, thanks.

Kristian

 ---
  desktop-shell/shell.c | 4 
  src/compositor.h  | 4 
  2 files changed, 4 insertions(+), 4 deletions(-)
 
 diff --git a/desktop-shell/shell.c b/desktop-shell/shell.c
 index 5f6bd6d..9fbac00 100644
 --- a/desktop-shell/shell.c
 +++ b/desktop-shell/shell.c
 @@ -43,6 +43,10 @@
  #define DEFAULT_NUM_WORKSPACES 1
  #define DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH 200
  
 +#ifndef static_assert
 +#define static_assert(cond, msg)
 +#endif
 +
  struct focus_state {
   struct weston_seat *seat;
   struct workspace *ws;
 diff --git a/src/compositor.h b/src/compositor.h
 index ab3de19..9f34d40 100644
 --- a/src/compositor.h
 +++ b/src/compositor.h
 @@ -45,10 +45,6 @@ extern C {
  
  #define ARRAY_LENGTH(a) (sizeof (a) / sizeof (a)[0])
  
 -#ifndef static_assert
 -#define static_assert(cond, msg)
 -#endif
 -
  #define container_of(ptr, type, member) ({   \
   const __typeof__( ((type *)0)-member ) *__mptr = (ptr);\
   (type *)( (char *)__mptr - offsetof(type,member) );})
 -- 
 1.8.5.1
 
 ___
 wayland-devel mailing list
 wayland-devel@lists.freedesktop.org
 http://lists.freedesktop.org/mailman/listinfo/wayland-devel
___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/wayland-devel


Re: [PATCH weston] sdk: make C++11 plugins build again

2013-12-09 Thread Thiago Macieira
On segunda-feira, 9 de dezembro de 2013 15:57:16, Kristian Høgsberg wrote:
 Ugh, ok, sorry.  Maybe we need a private header file where we can hide
 all our C macros - ARRAY_LENGTH, static_assert, container_of etc.

This poor man's static_assert should work in C99 mode too:

#include assert.h
#if !defined(static_assert)  (!defined(__cplusplus) || __cplusplus  201103L)
#  define static_assert(cond, msg)  enum { \
   CONCAT(_static_assert_, __COUNTER__) = sizeof(char[(cond) ? 1 : -1])  \
};
#endif

For proper CONCAT defined elsewhere.

Or, for a public header:
#include assert.h
#if defined(static_assert) || (defined(__cplusplus)  __cplusplus = 201103L)
#  define wl_static_assert(cond) static_assert(cond, #cond)
#else
#  define wl_static_assert(cond)  enum { \
   CONCAT(_static_assert_, __COUNTER__) = sizeof(char[(cond) ? 1 : -1])  \
};
#endif

For failed assertions, it will produce:

C89, C99, C++98:
error: array size is negative

C11, C++11:
error: static_assert failed fail

-- 
Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel Open Source Technology Center


signature.asc
Description: This is a digitally signed message part.
___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/wayland-devel