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

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

 



[ moving from autoconf@ to -patches ]

* Richard Guenther wrote on Tue, Jun 01, 2010 at 01:52:07PM CEST:
> 
> Any progress here?  If we want to switch on --enable-build-with-cxx
> by default then this has to be addressed.

Proposed patches for Autoconf.  Tested with CC=g++ in TESTSUITEFLAGS and
without.

One remaining nit is that the configure cache variables carry the whole
signature, are quite long, and sensitive to white space in the
declaration.  Oh well.  Any other issues with it?

Thanks, and sorry for the long delay,
Ralf
>From dbfbf0d2e550d7d304f5fb8edfa5a340aebc4d21 Mon Sep 17 00:00:00 2001
From: Joern Rennecke <joern.rennecke@xxxxxxxxxxxx>
Date: Tue, 1 Jun 2010 20:06:54 +0200
Subject: [PATCH 1/2] Generalize AC_CHECK_DECL for C++: allow optional arguments.

* general.m4 (_AC_CHECK_DECL_BODY): Process trailing function
argument types as arguments to use for C++.
(_AC_CHECK_DECLS): Filter out trailing function argument types
when henerating the HAVE_DECL_* macro.

Signed-off-by: Ralf Wildenhues <Ralf.Wildenhues@xxxxxx>
---
 ChangeLog               |    8 ++++++++
 lib/autoconf/general.m4 |   15 +++++++++++----
 2 files changed, 19 insertions(+), 4 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 1452eb3..8041556 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2010-06-01  Joern Rennecke  <joern.rennecke@xxxxxxxxxxxx>  (tiny change)
+
+	Generalize AC_CHECK_DECL for C++: allow optional arguments.
+	* general.m4 (_AC_CHECK_DECL_BODY): Process trailing function
+	argument types as arguments to use for C++.
+	(_AC_CHECK_DECLS): Filter out trailing function argument types
+	when henerating the HAVE_DECL_* macro.
+
 2010-05-25  Stefano Lattarini  <stefano.lattarini@xxxxxxxxx>
 	    Eric Blake  <eblake@xxxxxxxxxx>
 
diff --git a/lib/autoconf/general.m4 b/lib/autoconf/general.m4
index b7ac62f..fecfb72 100644
--- a/lib/autoconf/general.m4
+++ b/lib/autoconf/general.m4
@@ -2792,10 +2792,16 @@ AC_DEFUN([AC_CHECK_FILES],
 # Shell function body for AC_CHECK_DECL.
 m4_define([_AC_CHECK_DECL_BODY],
 [  AS_LINENO_PUSH([$[]1])
-  AC_CACHE_CHECK([whether $[]2 is declared], [$[]3],
+  [as_decl_name=`echo $][2|sed 's/(.*//'`]
+  [as_decl_use=`echo $][2|sed -e 's/(/((/' -e 's/)/) 0&/' -e 's/,/) 0& (/g'`]
+  AC_CACHE_CHECK([whether $as_decl_name is declared], [$[]3],
   [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([$[]4],
-[@%:@ifndef $[]2
-  (void) $[]2;
+[@%:@ifndef $[]as_decl_name
+@%:@ifdef __cplusplus
+  (void) $[]as_decl_use;
+@%:@else
+  (void) $[]as_decl_name;
+@%:@endif
 @%:@endif
 ])],
 		   [AS_VAR_SET([$[]3], [yes])],
@@ -2831,7 +2837,8 @@ AS_VAR_POPDEF([ac_Symbol])dnl
 # ACTION-IF-FOUND or ACTION-IF-NOT-FOUND.
 m4_define([_AC_CHECK_DECLS],
 [AC_CHECK_DECL([$1], [ac_have_decl=1], [ac_have_decl=0], [$4])]dnl
-[AC_DEFINE_UNQUOTED(AS_TR_CPP([HAVE_DECL_$1]), [$ac_have_decl],
+[AC_DEFINE_UNQUOTED(AS_TR_CPP(m4_bpatsubst(HAVE_DECL_[$1],[(.*])),
+  [$ac_have_decl],
   [Define to 1 if you have the declaration of `$1',
    and to 0 if you don't.])]dnl
 [m4_ifvaln([$2$3], [AS_IF([test $ac_have_decl = 1], [$2], [$3])])])
-- 
1.7.0.rc1.161.g90487

>From ef0cd33aa5bc626a4a0063062aaae5fd80bf185f Mon Sep 17 00:00:00 2001
From: Ralf Wildenhues <Ralf.Wildenhues@xxxxxx>
Date: Tue, 1 Jun 2010 21:54:39 +0200
Subject: [PATCH 2/2] Documentation and tests for the AC_CHECK_DECL change.

* lib/autoconf/general.m4 (_AC_CHECK_DECL_BODY): Squash trailing
spaces in as_decl_name.
(_AC_CHECK_DECLS): Likewise for the define.
* tests/semantics.at (AC_CHECK_DECLS): Extend test.
* doc/autoconf.texi (Generic Declarations): Update.
* NEWS: Update.

Signed-off-by: Ralf Wildenhues <Ralf.Wildenhues@xxxxxx>
---
 ChangeLog               |   10 ++++++++++
 NEWS                    |    3 +++
 doc/autoconf.texi       |   14 +++++++++++---
 lib/autoconf/general.m4 |    4 ++--
 tests/semantics.at      |   35 +++++++++++++++++++++++++++++++++--
 5 files changed, 59 insertions(+), 7 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 8041556..08bcde8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2010-06-01  Ralf Wildenhues  <Ralf.Wildenhues@xxxxxx>
+
+	Documentation and tests for the AC_CHECK_DECL change.
+	* lib/autoconf/general.m4 (_AC_CHECK_DECL_BODY): Squash trailing
+	spaces in as_decl_name.
+	(_AC_CHECK_DECLS): Likewise for the define.
+	* tests/semantics.at (AC_CHECK_DECLS): Extend test.
+	* doc/autoconf.texi (Generic Declarations): Update.
+	* NEWS: Update.
+
 2010-06-01  Joern Rennecke  <joern.rennecke@xxxxxxxxxxxx>  (tiny change)
 
 	Generalize AC_CHECK_DECL for C++: allow optional arguments.
diff --git a/NEWS b/NEWS
index afd8907..04cf8dd 100644
--- a/NEWS
+++ b/NEWS
@@ -16,6 +16,9 @@ GNU Autoconf NEWS - User visible changes.
 
 ** Autoconf should work on EBCDIC hosts.
 
+** AC_CHECK_DECL and AC_CHECK_DECLS accept optional function argument types
+   for overloaded C++ functions.
+
 * Major changes in Autoconf 2.65 (2009-11-21) [stable]
   Released by Eric Blake, based on git versions 2.64.*.
 
diff --git a/doc/autoconf.texi b/doc/autoconf.texi
index 3df0d3f..eab9ab2 100644
--- a/doc/autoconf.texi
+++ b/doc/autoconf.texi
@@ -6275,8 +6275,14 @@ Generic Declarations
 
 This macro actually tests whether @var{symbol} is defined as a macro or
 can be used as an r-value, not whether it is really declared, because it
-is much safer to avoid
-introducing extra declarations when they are not needed.
+is much safer to avoid introducing extra declarations when they are not
+needed.  In order to facilitate use of C++ and overloaded function
+declarations, it is possible to specify function argument types in
+parentheses for types which can be zero-initialized:
+
+@example
+AC_CHECK_DECL([basename(char *)])
+@end example
 
 This macro caches its result in the @code{ac_cv_have_decl_@var{symbol}}
 variable, with characters not suitable for a variable name mapped to
@@ -6289,7 +6295,8 @@ Generic Declarations
 @acindex{CHECK_DECLS}
 @cvindex HAVE_DECL_@var{symbol}
 @caindex have_decl_@var{symbol}
-For each of the @var{symbols} (@emph{comma}-separated list), define
+For each of the @var{symbols} (@emph{comma}-separated list with optional
+function argument types for C++ overloads), define
 @code{HAVE_DECL_@var{symbol}} (in all capitals) to @samp{1} if
 @var{symbol} is declared, otherwise to @samp{0}.  If
 @var{action-if-not-found} is given, it is additional shell code to
@@ -6306,6 +6313,7 @@ Generic Declarations
 AC_CHECK_DECLS([strlen])
 AC_CHECK_DECLS([malloc, realloc, calloc, free])
 AC_CHECK_DECLS([j0], [], [], [[#include <math.h>]])
+AC_CHECK_DECLS([[basename(char *)], [dirname(char *)]])
 @end example
 
 Unlike the other @samp{AC_CHECK_*S} macros, when a @var{symbol} is not
diff --git a/lib/autoconf/general.m4 b/lib/autoconf/general.m4
index fecfb72..762a56c 100644
--- a/lib/autoconf/general.m4
+++ b/lib/autoconf/general.m4
@@ -2792,7 +2792,7 @@ AC_DEFUN([AC_CHECK_FILES],
 # Shell function body for AC_CHECK_DECL.
 m4_define([_AC_CHECK_DECL_BODY],
 [  AS_LINENO_PUSH([$[]1])
-  [as_decl_name=`echo $][2|sed 's/(.*//'`]
+  [as_decl_name=`echo $][2|sed 's/ *(.*//'`]
   [as_decl_use=`echo $][2|sed -e 's/(/((/' -e 's/)/) 0&/' -e 's/,/) 0& (/g'`]
   AC_CACHE_CHECK([whether $as_decl_name is declared], [$[]3],
   [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([$[]4],
@@ -2837,7 +2837,7 @@ AS_VAR_POPDEF([ac_Symbol])dnl
 # ACTION-IF-FOUND or ACTION-IF-NOT-FOUND.
 m4_define([_AC_CHECK_DECLS],
 [AC_CHECK_DECL([$1], [ac_have_decl=1], [ac_have_decl=0], [$4])]dnl
-[AC_DEFINE_UNQUOTED(AS_TR_CPP(m4_bpatsubst(HAVE_DECL_[$1],[(.*])),
+[AC_DEFINE_UNQUOTED(AS_TR_CPP(m4_bpatsubst(HAVE_DECL_[$1],[ *(.*])),
   [$ac_have_decl],
   [Define to 1 if you have the declaration of `$1',
    and to 0 if you don't.])]dnl
diff --git a/tests/semantics.at b/tests/semantics.at
index bb4481b..b703fd4 100644
--- a/tests/semantics.at
+++ b/tests/semantics.at
@@ -109,9 +109,40 @@ AT_CHECK_MACRO([AC_CHECK_DECLS],
 		   struct { int x[20]; } mystruct;
 		   extern int myfunc();
 		   #define mymacro1(arg) arg
-		   #define mymacro2]])]],
+		   #define mymacro2]])
+  # The difference in space-before-open-paren is intentional.
+  AC_CHECK_DECLS([basenam (char *), dirnam(char *),
+		  [moreargs (char, short, int, long, void *, char [], float, double)]],,,
+		 [[#ifdef __cplusplus
+		   extern "C++" char *basenam (char *);
+		   extern "C++" const char *basenam (const char *);
+		   #else
+		   extern char *basenam (const char *);
+		   #endif
+		   #ifdef __cplusplus
+		   extern "C" {
+		   #endif
+		   extern int moreargs (char, short, int, long, void *,
+					char [], float, double);
+		   #ifdef __cplusplus
+		   }
+		   #endif
+		   ]])
+  AC_CHECK_DECL([declared (char *)],, [AS_EXIT([1])],
+		[[#ifdef __cplusplus
+		  extern "C++" char *declared (char *);
+		  extern "C++" const char *declared (const char *);
+		  #else
+		  extern char *declared (const char *);
+		  #endif
+		]])
+  AC_CHECK_DECL([undeclared (char *)], [AS_EXIT([1])],, [[]])
+]],
 [AT_CHECK_DEFINES(
-[#define HAVE_DECL_MYENUM 1
+[#define HAVE_DECL_BASENAM 1
+#define HAVE_DECL_DIRNAM 0
+#define HAVE_DECL_MOREARGS 1
+#define HAVE_DECL_MYENUM 1
 #define HAVE_DECL_MYFUNC 1
 #define HAVE_DECL_MYMACRO1 1
 #define HAVE_DECL_MYMACRO2 1
-- 
1.7.0.rc1.161.g90487

_______________________________________________
Autoconf mailing list
Autoconf@xxxxxxx
http://lists.gnu.org/mailman/listinfo/autoconf

[Index of Archives]     [GCC Help]     [Kernel Discussion]     [RPM Discussion]     [Red Hat Development]     [Yosemite News]     [Linux USB]     [Samba]

  Powered by Linux