AC_CHECK_DECLS(basename) (Was: Re: Ping: patches required for --enable-build-with-cxx)

Joern Rennecke joern.rennecke@embecosm.com
Tue Feb 9 01:17:00 GMT 2010


[I've added the gcc mailing list to CC because this is going back to a
  discussion what to do, but left gcc-patches for this post so that it is
  apparent where this thread went.  Follow-ups please remove gcc-patches from
  CC]

Quoting Paolo Bonzini <bonzini@gnu.org>:

> On 02/08/2010 09:58 AM, Joern Rennecke wrote:
>>
>> That would only work if every program that uses libiberty uses
>> AC_SYSTEM_EXTENSIONS .
>
> GCC does, gdb (I think, I don't have it checked out) does and nothing
> else uses basename anyway (they use lbasename).  If problems come up,
> other users can be patched to use AC_USE_SYSTEM_EXTENSIONS.

I've tried going down that route, and it turned out that my original  
patch only
worked due to a typo.  The _GNU_SOURCE inconsistency is a red herring.

The real problem is that when libcpp is configured, it is configured with g++
as the compiler, and the test for a basename declaration fails because
basename is declared in an overloaded way - a const and a non-const
variant - while the test code has:
| int
| main ()
| {
| #ifndef basename
|   (void) basename;
| #endif
|
|   ;
|   return 0;
| }

so g++ complains:

conftest.cpp: In function 'int main()':
conftest.cpp:78:10: error: void cast cannot resolve address of  
overloaded function

and configure mistakenly assumes that no basename declaration exists.
Thus, when libiberty is included, it 'helpfully' provides another declaration
for basename, which makes the build fail.

So, AC_CHECK_DECLS as it is now simply cannot work when configuring with
g++ as compiler for any function that has overloaded declarations.  In
order to do a valid positive check, we'd have to use a valid function
signature - which means we have to know a valid function signature first,
which would be specific to the function.

If we know such a signature, we can use #ifdef __cplusplus to compile
a function call in this case.  A C++ compiler should give an error if
the function was not declared.

We could soup up AC_CHECK_DECLS to know all the standard functions by name,
or at least the overloaded ones - but I'm not sure such a complex solution
will really save time in the long term.

A simpler approach would be to introduce AC_CHECK_BASENAME_DECL to do
this check just for basename.



More information about the Gcc-patches mailing list