* Problems with gcc + exceptions + -pedantic + libiberty.h
@ 2002-01-07 16:07 John Levon
2002-01-07 16:16 ` DJ Delorie
2002-01-07 18:30 ` Andrew Cagney
0 siblings, 2 replies; 13+ messages in thread
From: John Levon @ 2002-01-07 16:07 UTC (permalink / raw)
To: binutils
This is on my system : binutils-2.10.0.18-1
libiberty.h has code as follows :
39 /* HAVE_DECL_* is a three-state macro: undefined, 0 or 1. If it is
40 undefined, we haven't run the autoconf check so provide the
41 declaration without arguments. If it is 0, we checked and failed
42 to find the declaration so provide a fully prototyped one. If it
43 is 1, we found it so don't provide any declaration at all. */
44 #if defined (__GNU_LIBRARY__ ) || defined (__linux__) || defined (__FreeBSD__) || defined (__OpenBSD__) || defined (__CYGWIN__) || defined (__CYGWIN32__) || (defined (HAVE_DECL_BASENAME) && !HAVE_DECL_BASENAME)
45 extern char *basename PARAMS ((const char *));
46 #else
47 # if !defined (HAVE_DECL_BASENAME)
48 extern char *basename ();
49 # endif
50 #endif
unfortunately, when compiled with g++ 3.x with exceptions enabled, and with -pedantic,
you get a (correct I think) error message stating that this prototype clashes with my
system's string.h :
328 /* Return the file name within directory of FILENAME. We don't
329 declare the function if the `basename' macro is available (defined
330 in <libgen.h>) which makes the XPG version of this function
331 available. */
332 extern char *basename (__const char *__filename) __THROW;
333 # endif
(from glibc-devel-2.2-12, RH 7.0). These clash as __THROW becomes throw(), unlike
libiberty's prototype which obviously has no exception specification.
Currently I have just worked around this problem by disabling -pedantic; however I would
prefer a real fix.
Does someone have any comments on whose bug this is, and, more importantly, what needs to
be done to fix the problem ?
thanks
john
--
"I went to set up a Yahoo ID for my dog. (Don't ask, but the DOG'S email was cluttering my inbox)."
- Ruthless Advisorette
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Problems with gcc + exceptions + -pedantic + libiberty.h
2002-01-07 16:07 Problems with gcc + exceptions + -pedantic + libiberty.h John Levon
@ 2002-01-07 16:16 ` DJ Delorie
2002-01-07 16:21 ` Alan Modra
2002-01-07 18:30 ` Andrew Cagney
1 sibling, 1 reply; 13+ messages in thread
From: DJ Delorie @ 2002-01-07 16:16 UTC (permalink / raw)
To: levon; +Cc: binutils
Since Linux is specifically mentioned in libiberty.h, and linux is the
one having the problem, I suppose it would be acceptable for the
linux-specific case to do something different in libiberty.h.
However, a better solution is to add the gcc-specific prototype
detection logic to some common area, and teach projects to use it.
Then, libiberty.h can default to "no prototype" unless the detection
tells it what to do.
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Problems with gcc + exceptions + -pedantic + libiberty.h
2002-01-07 16:16 ` DJ Delorie
@ 2002-01-07 16:21 ` Alan Modra
2002-01-07 17:38 ` DJ Delorie
2002-01-08 3:02 ` Alan Modra
0 siblings, 2 replies; 13+ messages in thread
From: Alan Modra @ 2002-01-07 16:21 UTC (permalink / raw)
To: DJ Delorie; +Cc: levon, binutils
On Mon, Jan 07, 2002 at 07:07:04PM -0500, DJ Delorie wrote:
>
> Since Linux is specifically mentioned in libiberty.h, and linux is the
> one having the problem, I suppose it would be acceptable for the
> linux-specific case to do something different in libiberty.h.
>
> However, a better solution is to add the gcc-specific prototype
> detection logic to some common area, and teach projects to use it.
> Then, libiberty.h can default to "no prototype" unless the detection
> tells it what to do.
Why is it that __linux__ etc. means we disregard HAVE_DECL_BASENAME ?
How about the following change?
#if HAVE_DECL_BASENAME
/* Cool. */
#else
#if defined (__GNU_LIBRARY__ ) || defined (__linux__) || defined (__FreeBSD__) || defined (__OpenBSD__) || defined (__CYGWIN__) || defined (__CYGWIN32__)
extern char *basename PARAMS ((const char *));
#else
extern char *basename ();
# endif
#endif
--
Alan Modra
IBM OzLabs - Linux Technology Centre
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Problems with gcc + exceptions + -pedantic + libiberty.h
2002-01-07 16:21 ` Alan Modra
@ 2002-01-07 17:38 ` DJ Delorie
2002-01-07 20:28 ` Alan Modra
2002-01-08 3:02 ` Alan Modra
1 sibling, 1 reply; 13+ messages in thread
From: DJ Delorie @ 2002-01-07 17:38 UTC (permalink / raw)
To: amodra; +Cc: levon, binutils
> Why is it that __linux__ etc. means we disregard HAVE_DECL_BASENAME ?
The original problem is subdirectories that don't even test for the
decl. In those cases, HAVE_DECL_BASENAME is not set at all. Hence,
given an OS, we must try to guess what the right thing to do is. I
didn't add that code myself; I would have defaulted to *no* decl, and
force projects to adopt some sort of detection.
This code also breaks when included by a C++ source :-(
However, now that you've pointed it out, the existing logic is flawed
in that a defined HAVE_DECL_* doesn't override the os-based guess.
Patches welcome ;)
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Problems with gcc + exceptions + -pedantic + libiberty.h
2002-01-07 16:07 Problems with gcc + exceptions + -pedantic + libiberty.h John Levon
2002-01-07 16:16 ` DJ Delorie
@ 2002-01-07 18:30 ` Andrew Cagney
1 sibling, 0 replies; 13+ messages in thread
From: Andrew Cagney @ 2002-01-07 18:30 UTC (permalink / raw)
To: John Levon; +Cc: binutils
> 332 extern char *basename (__const char *__filename) __THROW;
BTW, is it actually used. GDB certainly doesn't. I think I removed all
uses from GCC.
enjoy,
Andrew
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Problems with gcc + exceptions + -pedantic + libiberty.h
2002-01-07 17:38 ` DJ Delorie
@ 2002-01-07 20:28 ` Alan Modra
2002-01-07 21:49 ` DJ Delorie
2002-01-08 10:25 ` John Levon
0 siblings, 2 replies; 13+ messages in thread
From: Alan Modra @ 2002-01-07 20:28 UTC (permalink / raw)
To: DJ Delorie; +Cc: binutils
On Mon, Jan 07, 2002 at 07:28:25PM -0500, DJ Delorie wrote:
>
> However, now that you've pointed it out, the existing logic is flawed
> in that a defined HAVE_DECL_* doesn't override the os-based guess.
> Patches welcome ;)
Here ya go.
* libiberty.h (basename): Don't declare if HAVE_DECL_BASENAME.
Index: include/libiberty.h
===================================================================
RCS file: /cvs/src/src/include/libiberty.h,v
retrieving revision 1.15
diff -u -p -r1.15 libiberty.h
--- libiberty.h 2001/10/23 15:31:55 1.15
+++ libiberty.h 2002/01/08 04:12:30
@@ -73,12 +73,12 @@ extern char **dupargv PARAMS ((char **))
declaration without arguments. If it is 0, we checked and failed
to find the declaration so provide a fully prototyped one. If it
is 1, we found it so don't provide any declaration at all. */
-#if defined (__GNU_LIBRARY__ ) || defined (__linux__) || defined (__FreeBSD__) || defined (__OpenBSD__) || defined (__CYGWIN__) || defined (__CYGWIN32__) || (defined (HAVE_DECL_BASENAME) && !HAVE_DECL_BASENAME)
+#if !HAVE_DECL_BASENAME
+#if defined (__GNU_LIBRARY__ ) || defined (__linux__) || defined (__FreeBSD__) || defined (__OpenBSD__) || defined (__CYGWIN__) || defined (__CYGWIN32__) || (defined (HAVE_DECL_BASENAME)
extern char *basename PARAMS ((const char *));
#else
-# if !defined (HAVE_DECL_BASENAME)
extern char *basename ();
-# endif
+#endif
#endif
/* A well-defined basename () that is always compiled in. */
--
Alan Modra
IBM OzLabs - Linux Technology Centre
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Problems with gcc + exceptions + -pedantic + libiberty.h
2002-01-07 20:28 ` Alan Modra
@ 2002-01-07 21:49 ` DJ Delorie
2002-01-08 11:23 ` John Levon
2002-06-23 22:08 ` Alan Modra
2002-01-08 10:25 ` John Levon
1 sibling, 2 replies; 13+ messages in thread
From: DJ Delorie @ 2002-01-07 21:49 UTC (permalink / raw)
To: amodra; +Cc: binutils, gcc-patches
Ok, minus the obvious typo. A similar patch for getopt.h is
preapproved. I think this leaves two problems remaining:
1. subdirs that don't yet test for a decl - should they get the ()
decl, or no decl?
2. C++ source shouldn't ever see the () decl, me thinks. It's inside
an extern "C" but I have this nagging feeling I've seen C++ sources
complain if they don't also see the real prototype.
And all those platform-specific things really bother me :-(
> Here ya go.
>
> * libiberty.h (basename): Don't declare if HAVE_DECL_BASENAME.
>
> Index: include/libiberty.h
> ===================================================================
> RCS file: /cvs/src/src/include/libiberty.h,v
> retrieving revision 1.15
> diff -u -p -r1.15 libiberty.h
> --- libiberty.h 2001/10/23 15:31:55 1.15
> +++ libiberty.h 2002/01/08 04:12:30
> @@ -73,12 +73,12 @@ extern char **dupargv PARAMS ((char **))
> declaration without arguments. If it is 0, we checked and failed
> to find the declaration so provide a fully prototyped one. If it
> is 1, we found it so don't provide any declaration at all. */
> -#if defined (__GNU_LIBRARY__ ) || defined (__linux__) || defined (__FreeBSD__) || defined (__OpenBSD__) || defined (__CYGWIN__) || defined (__CYGWIN32__) || (defined (HAVE_DECL_BASENAME) && !HAVE_DECL_BASENAME)
> +#if !HAVE_DECL_BASENAME
> +#if defined (__GNU_LIBRARY__ ) || defined (__linux__) || defined (__FreeBSD__) || defined (__OpenBSD__) || defined (__CYGWIN__) || defined (__CYGWIN32__) || (defined (HAVE_DECL_BASENAME)
> extern char *basename PARAMS ((const char *));
> #else
> -# if !defined (HAVE_DECL_BASENAME)
> extern char *basename ();
> -# endif
> +#endif
> #endif
>
> /* A well-defined basename () that is always compiled in. */
>
> --
> Alan Modra
> IBM OzLabs - Linux Technology Centre
>
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Problems with gcc + exceptions + -pedantic + libiberty.h
2002-01-07 16:21 ` Alan Modra
2002-01-07 17:38 ` DJ Delorie
@ 2002-01-08 3:02 ` Alan Modra
1 sibling, 0 replies; 13+ messages in thread
From: Alan Modra @ 2002-01-08 3:02 UTC (permalink / raw)
To: DJ Delorie; +Cc: levon, binutils
On Mon, Jan 07, 2002 at 07:07:04PM -0500, DJ Delorie wrote:
>
> Since Linux is specifically mentioned in libiberty.h, and linux is the
> one having the problem, I suppose it would be acceptable for the
> linux-specific case to do something different in libiberty.h.
>
> However, a better solution is to add the gcc-specific prototype
> detection logic to some common area, and teach projects to use it.
> Then, libiberty.h can default to "no prototype" unless the detection
> tells it what to do.
Why is it that __linux__ etc. means we disregard HAVE_DECL_BASENAME ?
How about the following change?
#if HAVE_DECL_BASENAME
/* Cool. */
#else
#if defined (__GNU_LIBRARY__ ) || defined (__linux__) || defined (__FreeBSD__) || defined (__OpenBSD__) || defined (__CYGWIN__) || defined (__CYGWIN32__)
extern char *basename PARAMS ((const char *));
#else
extern char *basename ();
# endif
#endif
--
Alan Modra
IBM OzLabs - Linux Technology Centre
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Problems with gcc + exceptions + -pedantic + libiberty.h
2002-01-07 20:28 ` Alan Modra
2002-01-07 21:49 ` DJ Delorie
@ 2002-01-08 10:25 ` John Levon
2002-01-08 14:10 ` DJ Delorie
1 sibling, 1 reply; 13+ messages in thread
From: John Levon @ 2002-01-08 10:25 UTC (permalink / raw)
To: amodra, binutils
On Tue, Jan 08, 2002 at 02:47:38PM +1030, Alan Modra wrote:
> On Mon, Jan 07, 2002 at 07:28:25PM -0500, DJ Delorie wrote:
> >
> > However, now that you've pointed it out, the existing logic is flawed
> > in that a defined HAVE_DECL_* doesn't override the os-based guess.
> > Patches welcome ;)
>
> Here ya go.
the patch is incomplete. Perhaps I should have mentioned it, but I also
have problems with asprintf() and vasprintf() from stdio.h when __USE_GNU is
enabled.
regards
john
--
"I went to set up a Yahoo ID for my dog. (Don't ask, but the DOG'S email was cluttering my inbox)."
- Ruthless Advisorette
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Problems with gcc + exceptions + -pedantic + libiberty.h
2002-01-07 21:49 ` DJ Delorie
@ 2002-01-08 11:23 ` John Levon
2002-01-08 12:52 ` DJ Delorie
2002-06-23 22:08 ` Alan Modra
1 sibling, 1 reply; 13+ messages in thread
From: John Levon @ 2002-01-08 11:23 UTC (permalink / raw)
To: gcc-patches, binutils; +Cc: dj
On Mon, Jan 07, 2002 at 11:28:47PM -0500, DJ Delorie wrote:
> 2. C++ source shouldn't ever see the () decl, me thinks. It's inside
> an extern "C" but I have this nagging feeling I've seen C++ sources
> complain if they don't also see the real prototype.
How about :
1) teaching GNU libc string.h to set HAVE_DECL_BASENAME
and
2) including string.h (+ stdio.h) in libiberty.h
That way the headers will "just work" in C++ without my application having to
worry about setting HAVE_DECL_BASENAME myself.
I'm not exactly fond of platform-specific hacks myself, but it would perhaps
reduce the complexity of the necessary autoconfigurey in my project to see if
c++ -pedantic is going to work in this case or not
regards
john
--
"I went to set up a Yahoo ID for my dog. (Don't ask, but the DOG'S email was cluttering my inbox)."
- Ruthless Advisorette
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Problems with gcc + exceptions + -pedantic + libiberty.h
2002-01-08 11:23 ` John Levon
@ 2002-01-08 12:52 ` DJ Delorie
0 siblings, 0 replies; 13+ messages in thread
From: DJ Delorie @ 2002-01-08 12:52 UTC (permalink / raw)
To: levon; +Cc: gcc-patches, binutils
> 1) teaching GNU libc string.h to set HAVE_DECL_BASENAME
We have no control over libc.
> 2) including string.h (+ stdio.h) in libiberty.h
What about older platforms that don't have string.h?
> That way the headers will "just work" in C++ without my application having to
> worry about setting HAVE_DECL_BASENAME myself.
Perhaps libiberty could provide a config.h that libiberty.h uses?
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Problems with gcc + exceptions + -pedantic + libiberty.h
2002-01-08 10:25 ` John Levon
@ 2002-01-08 14:10 ` DJ Delorie
0 siblings, 0 replies; 13+ messages in thread
From: DJ Delorie @ 2002-01-08 14:10 UTC (permalink / raw)
To: levon; +Cc: amodra, binutils
> the patch is incomplete. Perhaps I should have mentioned it, but I also
> have problems with asprintf() and vasprintf() from stdio.h when __USE_GNU is
> enabled.
That doesn't make the patch incomplete; he does solve the problem he
posted. If there are additional cases that need similar solutions,
they're similar but independent problems. They can be patched
independently.
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Problems with gcc + exceptions + -pedantic + libiberty.h
2002-01-07 21:49 ` DJ Delorie
2002-01-08 11:23 ` John Levon
@ 2002-06-23 22:08 ` Alan Modra
1 sibling, 0 replies; 13+ messages in thread
From: Alan Modra @ 2002-06-23 22:08 UTC (permalink / raw)
To: DJ Delorie; +Cc: binutils, gcc-patches
On Mon, Jan 07, 2002 at 11:28:47PM -0500, DJ Delorie wrote:
>
> Ok, minus the obvious typo. A similar patch for getopt.h is
> preapproved.
Somehow, I never got around to committing the change, and there are
enough other changes in my local trees that these got lost. Here's
what I finally committed to gcc mainline. binutils can wait for
your automatic merge.
include/ChangeLog
* libiberty.h (basename): Don't declare if HAVE_DECL_BASENAME.
* getopt.h (getopt): Don't declare if HAVE_DECL_GETOPT.
Index: include/getopt.h
===================================================================
RCS file: /cvs/gcc/gcc/include/getopt.h,v
retrieving revision 1.6
diff -u -p -r1.6 getopt.h
--- include/getopt.h 14 Mar 2001 19:44:38 -0000 1.6
+++ include/getopt.h 24 Jun 2002 04:51:24 -0000
@@ -105,16 +105,17 @@ struct option
declaration without arguments. If it is 0, we checked and failed
to find the declaration so provide a fully prototyped one. If it
is 1, we found it so don't provide any declaration at all. */
-#if defined (__GNU_LIBRARY__) || (defined (HAVE_DECL_GETOPT) && !HAVE_DECL_GETOPT)
+#if !HAVE_DECL_GETOPT
+#if defined (__GNU_LIBRARY__) || defined (HAVE_DECL_GETOPT)
/* Many other libraries have conflicting prototypes for getopt, with
differences in the consts, in stdlib.h. To avoid compilation
errors, only prototype getopt for the GNU C library. */
extern int getopt (int argc, char *const *argv, const char *shortopts);
-#else /* not __GNU_LIBRARY__ */
-# if !defined (HAVE_DECL_GETOPT)
+#else
extern int getopt ();
-# endif
-#endif /* __GNU_LIBRARY__ */
+#endif
+#endif /* !HAVE_DECL_GETOPT */
+
extern int getopt_long (int argc, char *const *argv, const char *shortopts,
const struct option *longopts, int *longind);
extern int getopt_long_only (int argc, char *const *argv,
Index: include/libiberty.h
===================================================================
RCS file: /cvs/gcc/gcc/include/libiberty.h,v
retrieving revision 1.27
diff -u -p -r1.27 libiberty.h
--- include/libiberty.h 28 Jan 2002 21:08:34 -0000 1.27
+++ include/libiberty.h 24 Jun 2002 04:51:25 -0000
@@ -73,12 +73,12 @@ extern char **dupargv PARAMS ((char **))
declaration without arguments. If it is 0, we checked and failed
to find the declaration so provide a fully prototyped one. If it
is 1, we found it so don't provide any declaration at all. */
-#if defined (__GNU_LIBRARY__ ) || defined (__linux__) || defined (__FreeBSD__) || defined (__OpenBSD__) || defined (__CYGWIN__) || defined (__CYGWIN32__) || (defined (HAVE_DECL_BASENAME) && !HAVE_DECL_BASENAME)
+#if !HAVE_DECL_BASENAME
+#if defined (__GNU_LIBRARY__ ) || defined (__linux__) || defined (__FreeBSD__) || defined (__OpenBSD__) || defined (__CYGWIN__) || defined (__CYGWIN32__) || defined (HAVE_DECL_BASENAME)
extern char *basename PARAMS ((const char *));
#else
-# if !defined (HAVE_DECL_BASENAME)
extern char *basename ();
-# endif
+#endif
#endif
/* A well-defined basename () that is always compiled in. */
--
Alan Modra
IBM OzLabs - Linux Technology Centre
^ permalink raw reply [flat|nested] 13+ messages in thread
end of thread, other threads:[~2002-06-24 5:08 UTC | newest]
Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-01-07 16:07 Problems with gcc + exceptions + -pedantic + libiberty.h John Levon
2002-01-07 16:16 ` DJ Delorie
2002-01-07 16:21 ` Alan Modra
2002-01-07 17:38 ` DJ Delorie
2002-01-07 20:28 ` Alan Modra
2002-01-07 21:49 ` DJ Delorie
2002-01-08 11:23 ` John Levon
2002-01-08 12:52 ` DJ Delorie
2002-06-23 22:08 ` Alan Modra
2002-01-08 10:25 ` John Levon
2002-01-08 14:10 ` DJ Delorie
2002-01-08 3:02 ` Alan Modra
2002-01-07 18:30 ` Andrew Cagney
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).