This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PING] Re: [PATCH] c/66516 - missing diagnostic on taking the address of a builtin function
- From: Joseph Myers <joseph at codesourcery dot com>
- To: Martin Sebor <msebor at gmail dot com>
- Cc: Jason Merrill <jason at redhat dot com>, Jakub Jelinek <jakub at redhat dot com>, Marek Polacek <polacek at redhat dot com>, Gcc Patch List <gcc-patches at gcc dot gnu dot org>
- Date: Fri, 28 Aug 2015 20:09:55 +0000
- Subject: Re: [PING] Re: [PATCH] c/66516 - missing diagnostic on taking the address of a builtin function
- Authentication-results: sourceware.org; auth=none
- References: <5587432A dot 9000602 at redhat dot com> <20150622144010 dot GK10139 at redhat dot com> <5588BD78 dot 4030607 at gmail dot com> <20150623101829 dot GQ10139 at redhat dot com> <20150623102909 dot GK10247 at tucnak dot redhat dot com> <55897735 dot 1040509 at redhat dot com> <5590965B dot 6030103 at gmail dot com> <alpine dot DEB dot 2 dot 10 dot 1507021411440 dot 29415 at digraph dot polyomino dot org dot uk> <55985EE0 dot 3060802 at gmail dot com> <55A483E8 dot 7060708 at gmail dot com> <55A52443 dot 10800 at redhat dot com> <55A54DBF dot 7080702 at gmail dot com> <55B84AAA dot 7040503 at redhat dot com> <55E0BD94 dot 2060105 at gmail dot com>
On Fri, 28 Aug 2015, Martin Sebor wrote:
> I ran into one regression in the gcc.dg/lto/pr54702_1.c test.
> The file takes the address of malloc without declaring it, and
> after calling it first. The code is invalid but GCC compiles it
> due to a bug. I raised it in c/67386 -- missing diagnostic on
> a use of an undeclared function, and suppressed the error by
But that PR isn't a bug - the code is working exactly as it's meant to (an
implicit declaration acts exactly like an explicit declaration "int func
();" in the nearest containing scope). The declaration has an
incompatible type, it's true, but GCC deliberately allows that with a
warning.
What if (a) you use a built-in function that returns int, instead of
malloc, and (b) use -std=gnu89, so the implicit declaration isn't even an
extension? Then you have something that's completely valid, including
taking the address of the implicitly declared function.
--
Joseph S. Myers
joseph@codesourcery.com