public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [C PATCH] Don't output warning twice (PR c/63626)
@ 2014-10-23 11:29 Marek Polacek
  2014-10-23 16:53 ` Joseph S. Myers
  0 siblings, 1 reply; 2+ messages in thread
From: Marek Polacek @ 2014-10-23 11:29 UTC (permalink / raw)
  To: Joseph S. Myers, GCC Patches

At present, we print the "inline function ... declared but never
defined" warning twice.  The reason for that is that this warning
is being printed in pop_scope, which is called when popping file
scope (c_common_parse_file->pop_file_scope), and when popping
external scope (c_write_global_declarations).  I think we should
not print this warning when popping the external scope.
We don't have to worry about nested functions here.

Writing a proper testcase is a little bit tricky, but I hope what
I did would work fine.

Bootstrapped/regtested on x86_64-linux, ok for trunk?

2014-10-23  Marek Polacek  <polacek@redhat.com>

	PR c/63626
	* c-decl.c (pop_scope): Don't print warning in external_scope.

	* gcc.dg/pr63626.c: New test.

diff --git gcc/c/c-decl.c gcc/c/c-decl.c
index b18da48..7d1840e 100644
--- gcc/c/c-decl.c
+++ gcc/c/c-decl.c
@@ -1182,7 +1182,8 @@ pop_scope (void)
 		 with an inline function specifier ... shall also be defined
 		 in the same translation unit."  */
 	      if (!flag_gnu89_inline
-		  && !lookup_attribute ("gnu_inline", DECL_ATTRIBUTES (p)))
+		  && !lookup_attribute ("gnu_inline", DECL_ATTRIBUTES (p))
+		  && scope != external_scope)
 		pedwarn (input_location, 0,
 			 "inline function %q+D declared but never defined", p);
 	      DECL_EXTERNAL (p) = 1;
diff --git gcc/testsuite/gcc.dg/pr63626.c gcc/testsuite/gcc.dg/pr63626.c
index e69de29..1f03818 100644
--- gcc/testsuite/gcc.dg/pr63626.c
+++ gcc/testsuite/gcc.dg/pr63626.c
@@ -0,0 +1,8 @@
+/* PR c/63626 */
+/* { dg-do compile } */
+/* { dg-options "" } */
+
+/* Test that we don't output the warning twice.  */
+
+inline int foo (void); /* { dg-bogus "inline function.*inline function" } */
+/* { dg-warning "inline function .foo. declared but never defined" "" { target *-*-* } 7 } */

	Marek

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [C PATCH] Don't output warning twice (PR c/63626)
  2014-10-23 11:29 [C PATCH] Don't output warning twice (PR c/63626) Marek Polacek
@ 2014-10-23 16:53 ` Joseph S. Myers
  0 siblings, 0 replies; 2+ messages in thread
From: Joseph S. Myers @ 2014-10-23 16:53 UTC (permalink / raw)
  To: Marek Polacek; +Cc: GCC Patches

On Thu, 23 Oct 2014, Marek Polacek wrote:

> At present, we print the "inline function ... declared but never
> defined" warning twice.  The reason for that is that this warning
> is being printed in pop_scope, which is called when popping file
> scope (c_common_parse_file->pop_file_scope), and when popping
> external scope (c_write_global_declarations).  I think we should
> not print this warning when popping the external scope.
> We don't have to worry about nested functions here.
> 
> Writing a proper testcase is a little bit tricky, but I hope what
> I did would work fine.
> 
> Bootstrapped/regtested on x86_64-linux, ok for trunk?
> 
> 2014-10-23  Marek Polacek  <polacek@redhat.com>
> 
> 	PR c/63626
> 	* c-decl.c (pop_scope): Don't print warning in external_scope.
> 
> 	* gcc.dg/pr63626.c: New test.

OK.

-- 
Joseph S. Myers
joseph@codesourcery.com

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2014-10-23 16:39 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-10-23 11:29 [C PATCH] Don't output warning twice (PR c/63626) Marek Polacek
2014-10-23 16:53 ` Joseph S. Myers

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).