https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122729

--- Comment #5 from Kang-Che Sung <Explorer09 at gmail dot com> ---
> > #if !defined(HAVE_DECL_BASENAME) || !HAVE_DECL_BASENAME

> is NOT correct either because then it might conflict with the basename from 
> the headers. This is why I said you need to have the HAVE_* defined correctly 
> before including libiberty.h .

Excuse me. That confused me more.

Allow me to quote the section from the header...

> #if !HAVE_DECL_BASENAME
> #if defined (__GNU_LIBRARY__ ) || defined (__linux__) \
>  || defined (__FreeBSD__) || defined (__OpenBSD__) || defined (__NetBSD__) \
>  || defined (__CYGWIN__) || defined (__CYGWIN32__) || defined (__MINGW32__) \
>  || defined (__DragonFly__) || defined (HAVE_DECL_BASENAME)
> extern char *basename (const char *) ATTRIBUTE_RETURNS_NONNULL 
> ATTRIBUTE_NONNULL(1);
> #else
> /* Do not allow basename to be used if there is no prototype seen.  We
>    either need to use the above prototype or have one from
>    autoconf which would result in HAVE_DECL_BASENAME being set.  */
> #define basename basename_cannot_be_used_without_a_prototype
> #endif
> #endif

First there is a "defined (HAVE_DECL_BASENAME)" after the "defined
(__DragonFly__)" part, which would look totally useless if HAVE_DECL_BASENAME
was required to be defined before libiberty.h is included.

Second, I expect when the HAVE_DECL_BASENAME was not defined, the preprocessor
would reach this line "#define basename
basename_cannot_be_used_without_a_prototype", which would effectively prevent
any basename() call from working. If HAVE_DECL_BASENAME was required to be
defined at the start, then the "basename_cannot_be_used" line would be
unreachable. Anyway there was no hint in the header code that
HAVE_DECL_BASENAME was required before including.

Reply via email to