bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bogus interaction between _GL_INLINE and __NTH when compiling argp.h wit


From: Alexandre Duret-Lutz
Subject: bogus interaction between _GL_INLINE and __NTH when compiling argp.h with g++-4.6 -std=c++0x
Date: Wed, 18 Dec 2013 15:22:31 +0100

Hi,

I'm compiling gnulib 23eecb48e39afd0d267d64d40ba6bf97aa865e13 with gcc-4.6,
and using it from a C++ project compiled with g++-4.6 -std=c++0x


When I attempt to include argp.h, compilation fails:


% cat foo.cc
#include "config.h"
#include "argp.h"
% g++-4.6 -DHAVE_CONFIG_H -Ilib -Wall -Werror -std=c++0x -c foo.cc
In file included from foo.cc:2:0:
lib/argp.h:623:1: error: ‘__leaf__’ attribute has no effect on unit
local functions [-Werror=attributes]
lib/argp.h:635:1: error: ‘__leaf__’ attribute has no effect on unit
local functions [-Werror=attributes]

Looking at the preprocessed output, I can see that the two functions

: ARGP_EI int
: __NTH (__option_is_short (const struct argp_option *__opt))
: /* ... */
: ARGP_EI int
: __NTH (__option_is_end (const struct argp_option *__opt))

were expanded as:

: static __attribute__ ((__unused__)) int
: __attribute__ ((__leaf__)) _option_is_short (const struct
argp_option *__opt) throw ()
: /* ... */
: static __attribute__ ((__unused__)) int
: __attribute__ ((__leaf__)) _option_is_end (const struct argp_option
*__opt) throw ()

So __leaf__ was indeed applied to a static function.  This "static" comes from
the expansion of ARGP_EI:

#define ARGP_EI _GL_INLINE                       /* in argp.h */
#define _GL_INLINE static _GL_UNUSED             /* in config.h */
#define _GL_UNUSED __attribute__ ((__unused__))  /* in config.h */


The warning disappears if I use g++-4.6 without the -std=c++0x option.  In this
case these prototypes become:

: extern inline __attribute__ ((__gnu_inline__)) int
: __attribute__ ((__leaf__)) _option_is_short (const struct
argp_option *__opt) throw ()
: /* ... */
: extern inline __attribute__ ((__gnu_inline__)) int
: __attribute__ ((__leaf__)) _option_is_end (const struct argp_option
*__opt) throw ()

because now config.h has

#define _GL_INLINE extern inline __attribute__ ((__gnu_inline__))



The warning also disappear if I use g++-4.7 -std=c++0x.  Then we get:

: inline int
: __attribute__ ((__leaf__)) _option_is_short (const struct
argp_option *__opt) throw ()
: /* ... */
: inline int
: __attribute__ ((__leaf__)) _option_is_end (const struct argp_option
*__opt) throw ()

with

#define _GL_INLINE inline   /* in config.h */

(The difference between 4.6 -std=c++0x and 4.7 -std=c++0x is that the
former defines __GNUC_GNU_INLINE__ while the latter defines
__GNUC_STDC_INLINE__.)


Comments:
1. I do not understand the effect of marking an inline function as leaf, or
   as nothrow.  Shouldn't these attributes be only used to help the
compiler when
   a function is declared, but its body is unknown?
2. Shouldn't _GL_INLINE/_GL_EXTERN_INLINE simply always expand to
'inline' in C++?



I've patched my copy of argp.h as suggested in point 1 above to fix my
compilation issue (patch attached). But as the implication of __NTH in
conjunction with _GL_INLINE is unclear to me, I'm not sure whether
this is sane.

-- 
Alexandre Duret-Lutz

Attachment: 0001-argp-fix-compilation-with-g-4.6-std-c-0x.patch
Description: Text Data


reply via email to

[Prev in Thread] Current Thread [Next in Thread]