John W. Eaton wrote: > I received a report about the following error on an OS X system: > > In file included from /usr/include/sys/time.h:197, > from ../libgnu/sys/time.h:40, > from ../libgnu/sys/select.h:51, > from /usr/include/unistd.h:519, > from ../libgnu/unistd.h:29, > from > /usr/include/c++/4.2.1/i686-apple-darwin10/bits/os_defines.h:61, > from > /usr/include/c++/4.2.1/i686-apple-darwin10/bits/c++config.h:41, > from /usr/include/c++/4.2.1/cstddef:50, > from Array.h:30, > from MArray.h:28, > from dMatrix.h:27, > from ODESFunc.h:26, > from ODES.h:26, > from ODES.cc:27: > ../libgnu/stdlib.h:737: error: previous declaration of ‘int > _gl_warn_on_use’ with ‘C++’ linkage > ../libgnu/time.h:350: error: conflicts with new declaration with ‘C’ linkage > > so it seems that _gl_warn_on_use should be declared extern "C" to > avoid this kind of problem.
Yes, I agree. We cannot control whether all gnulib include files are included in C++ mode. Here apparently <time.h> is included in C mode. This may be a bug in the system include files; it may also lead to unintended consequences. But anyway, it's safe to make the change you suggested. I've committed this: 2010-03-20 Bruno Haible <br...@clisp.org> Make _GL_WARN_ON_USE usable in C++ and C mode in the same compilation. * build-aux/warn-on-use.h (_GL_WARN_EXTERN_C): New macro. (_GL_WARN_ON_USE, _GL_WARN_ON_USE_CXX): Likewise. Reported by John W. Eaton <j...@gnu.org>. --- build-aux/warn-on-use.h.orig Sun Mar 21 00:48:23 2010 +++ build-aux/warn-on-use.h Sun Mar 21 00:47:33 2010 @@ -70,7 +70,7 @@ # else /* Unsupported. */ # define _GL_WARN_ON_USE(function, message) \ -extern int _gl_warn_on_use +_GL_WARN_EXTERN_C int _gl_warn_on_use # endif #endif @@ -87,6 +87,16 @@ __attribute__ ((__warning__ (msg))) # else /* Unsupported. */ # define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \ -extern int _gl_warn_on_use +_GL_WARN_EXTERN_C int _gl_warn_on_use +# endif +#endif + +/* _GL_WARN_EXTERN_C declaration; + performs the declaration with C linkage. */ +#ifndef _GL_WARN_EXTERN_C +# if defined __cplusplus +# define _GL_WARN_EXTERN_C extern "C" +# else +# define _GL_WARN_EXTERN_C extern # endif #endif Additionally, it raises my attention to the fact that .h files must not have #include statements inside extern "C" { ... } blocks. This fixes the two violations of this rule that I can see in gnulib. 2010-03-20 Bruno Haible <br...@clisp.org> Ensure no #include statements inside extern "C" { ... }. * lib/obstack.h: Shrink extern "C" { ... } region so that it does not contain #include statements. * lib/time.in.h: Likewise. --- lib/obstack.h.orig Sun Mar 21 01:12:15 2010 +++ lib/obstack.h Sun Mar 21 01:07:00 2010 @@ -103,10 +103,6 @@ #ifndef _OBSTACK_H #define _OBSTACK_H 1 - -#ifdef __cplusplus -extern "C" { -#endif /* We need the type of a pointer subtraction. If __PTRDIFF_TYPE__ is defined, as with GNU C, use that; that way we don't pollute the @@ -139,6 +135,10 @@ #include <string.h> +#ifdef __cplusplus +extern "C" { +#endif + struct _obstack_chunk /* Lives at front of each chunk. */ { char *limit; /* 1 past end of this chunk */ --- lib/time.in.h.orig Sun Mar 21 01:12:15 2010 +++ lib/time.in.h Sun Mar 21 01:08:00 2010 @@ -46,10 +46,6 @@ /* The definition of _GL_WARN_ON_USE is copied here. */ -# ifdef __cplusplus -extern "C" { -# endif - /* Some systems don't define struct timespec (e.g., AIX 4.1, Ultrix 4.3). Or they define it with the wrong member names or define it in <sys/time.h> (e.g., FreeBSD circa 1997). */ @@ -57,6 +53,11 @@ # if @SYS_TIME_H_DEFINES_STRUCT_TIMESPEC@ # include <sys/time.h> # else + +# ifdef __cplusplus +extern "C" { +# endif + # undef timespec # define timespec rpl_timespec struct timespec @@ -64,11 +65,12 @@ time_t tv_sec; long int tv_nsec; }; -# endif -# endif -# ifdef __cplusplus +# ifdef __cplusplus } +# endif + +# endif # endif /* Sleep for at least RQTP seconds unless interrupted, If interrupted,