[xproto] _X_NONNULL and C++ 11

Mark Kettenis mark.kettenis at xs4all.nl
Sat May 27 12:10:59 UTC 2017


> Date: Sat, 27 May 2017 13:33:25 +0200
> From: walter harms <wharms at bfs.de>
> 
> Am 27.05.2017 11:02, schrieb Matthieu Herrb:
> > Hi,
> > 
> > Marc Espie recently found out that the X_NONNULL macro in Xfuncproto.h
> > is generating spurious warnings when included in C++ code build with
> > clang++ -std=c++11.
> > 
> > Other OpenBSD developper tried to find uses of the macro in the wild
> > and didn't find any, even in the X.Org lib app or xserver tree.
> > 
> > So, should this macro definition be removed alltogether (acking that
> > no-one cares to use it) or just apply the patch below ?
> > 
> > From 6ae956660879d70e078025c3d8f1ac3fd438cad2 Mon Sep 17 00:00:00 2001
> > From: Marc Espie <espie at nerim.net>
> > Date: Sat, 27 May 2017 10:55:04 +0200
> > Subject: [PATCH] Fix compiling any C++ code including Xfuncproto.h with
> >  clang++ -std=c++11
> > 
> > It shouldn't warn, bu it will use the "legacy" varargs macros and whine.
> > ---
> >  Xfuncproto.h.in | 3 ++-
> >  1 file changed, 2 insertions(+), 1 deletion(-)
> > 
> > diff --git a/Xfuncproto.h.in b/Xfuncproto.h.in
> > index b88493d..1be3f55 100644
> > --- a/Xfuncproto.h.in
> > +++ b/Xfuncproto.h.in
> > @@ -166,7 +166,8 @@ in this Software without prior written authorization from The Open Group.
> >     argument macros, must be only used inside #ifdef _X_NONNULL guards, as
> >     many legacy X clients are compiled in C89 mode still. */
> >  #if __has_attribute(nonnull) \
> > -    && defined(__STDC_VERSION__) && (__STDC_VERSION__ - 0 >= 199901L) /* C99 */
> > +    && (defined(__STDC_VERSION__) && (__STDC_VERSION__ - 0 >= 199901L) \
> > +    || (defined(__cplusplus) && (__cplusplus - 0 >= 201103L))) /* C99 C++11 */
> >  #define _X_NONNULL(...)  __attribute__((nonnull(__VA_ARGS__)))
> >  #elif __has_attribute(nonnull) \
> >      || defined(__GNUC__) &&  ((__GNUC__ * 100 + __GNUC_MINOR__) >= 303)
> > 
> > 
> > 
> 
> So far i understand this is a problem with clang++. "spurious
> warning" sounds for me more like a compiler bug (assuming that gcc
> has no problems with that). So why not make that a NOOP until fixed
> in clang ?

GCC 4.9.4 warns as well:

$ g++ -pedantic -std=c++11 -I/usr/X11R6/include xfunc.cc
In file included from xfunc.cc:1:0:
/usr/X11R6/include/X11/Xfuncproto.h:173:24: warning: ISO C does not permit named variadic macros [-Wvariadic-macros]
 #define _X_NONNULL(args...)  __attribute__((nonnull(args)))



More information about the xorg-devel mailing list