public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [RFC PATCH v1] c: Do not warn about external declaration following inline definition
@ 2023-10-28 19:14 Barnabás Pőcze
  2023-10-30 18:01 ` Joseph Myers
  0 siblings, 1 reply; 4+ messages in thread
From: Barnabás Pőcze @ 2023-10-28 19:14 UTC (permalink / raw)
  To: gcc-patches

An external declaration following an inline definition is not redundant
because it forces the compiler to emit an external definition for the function.
That is,

  inline void f(void) { }
  [extern] void f(void);

should not trigger the

  redundant redeclaration of ...

warning.

gcc/c/ChangeLog:

	* c-decl.cc (diagnose_mismatched_decls): Add new
	case for Wredundant-decls suppression.
---
 gcc/c/c-decl.cc | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/gcc/c/c-decl.cc b/gcc/c/c-decl.cc
index 7a145bed281..e86f7950858 100644
--- a/gcc/c/c-decl.cc
+++ b/gcc/c/c-decl.cc
@@ -2592,7 +2592,12 @@ diagnose_mismatched_decls (tree newdecl, tree olddecl,
 	   && TREE_ASM_WRITTEN (olddecl) && !TREE_ASM_WRITTEN (newdecl))
       /* Don't warn about a variable definition following a declaration.  */
       && !(VAR_P (newdecl)
-	   && DECL_INITIAL (newdecl) && !DECL_INITIAL (olddecl)))
+	   && DECL_INITIAL (newdecl) && !DECL_INITIAL (olddecl))
+      /* Don't warn about external declaration following inline definition.  */
+      && !(TREE_CODE (newdecl) == FUNCTION_DECL
+	   && !DECL_INITIAL (newdecl) && !DECL_DECLARED_INLINE_P (newdecl)
+	   && DECL_EXTERNAL (newdecl) && DECL_INITIAL (olddecl)
+	   && DECL_DECLARED_INLINE_P (olddecl) && DECL_EXTERNAL (olddecl)))
     {
       warned = warning (OPT_Wredundant_decls, "redundant redeclaration of %q+D",
 			newdecl);
-- 
2.42.0



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

* Re: [RFC PATCH v1] c: Do not warn about external declaration following inline definition
  2023-10-28 19:14 [RFC PATCH v1] c: Do not warn about external declaration following inline definition Barnabás Pőcze
@ 2023-10-30 18:01 ` Joseph Myers
  2023-10-30 19:55   ` Barnabás Pőcze
  0 siblings, 1 reply; 4+ messages in thread
From: Joseph Myers @ 2023-10-30 18:01 UTC (permalink / raw)
  To: Barnabás Pőcze; +Cc: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 508 bytes --]

On Sat, 28 Oct 2023, Barnabás Pőcze wrote:

> An external declaration following an inline definition is not redundant
> because it forces the compiler to emit an external definition for the function.
> That is,
> 
>   inline void f(void) { }
>   [extern] void f(void);
> 
> should not trigger the
> 
>   redundant redeclaration of ...
> 
> warning.

This should add a testcase to the testsuite (that fails before and passes 
after the front-end change is made).

-- 
Joseph S. Myers
joseph@codesourcery.com

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

* Re: [RFC PATCH v1] c: Do not warn about external declaration following inline definition
  2023-10-30 18:01 ` Joseph Myers
@ 2023-10-30 19:55   ` Barnabás Pőcze
  2023-10-30 20:39     ` Joseph Myers
  0 siblings, 1 reply; 4+ messages in thread
From: Barnabás Pőcze @ 2023-10-30 19:55 UTC (permalink / raw)
  To: Joseph Myers; +Cc: gcc-patches

Hi


2023. október 30., hétfő 19:01 keltezéssel, Joseph Myers írta:

> On Sat, 28 Oct 2023, Barnabás Pőcze wrote:
> 
> > An external declaration following an inline definition is not redundant
> > because it forces the compiler to emit an external definition for the function.
> > That is,
> > 
> > inline void f(void) { }
> > [extern] void f(void);
> > 
> > should not trigger the
> > 
> > redundant redeclaration of ...
> > 
> > warning.
> 
> 
> This should add a testcase to the testsuite (that fails before and passes
> after the front-end change is made).

I did not want to commit more effort until I have some feedback.
I will most certainly add a test case if it turns out that the change
seems reasonable and has a chance of being accepted.


Regards,
Barnabás Pőcze

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

* Re: [RFC PATCH v1] c: Do not warn about external declaration following inline definition
  2023-10-30 19:55   ` Barnabás Pőcze
@ 2023-10-30 20:39     ` Joseph Myers
  0 siblings, 0 replies; 4+ messages in thread
From: Joseph Myers @ 2023-10-30 20:39 UTC (permalink / raw)
  To: Barnabás Pőcze; +Cc: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 1529 bytes --]

On Mon, 30 Oct 2023, Barnabás Pőcze wrote:

> Hi
> 
> 
> 2023. október 30., hétfő 19:01 keltezéssel, Joseph Myers írta:
> 
> > On Sat, 28 Oct 2023, Barnabás Pőcze wrote:
> > 
> > > An external declaration following an inline definition is not redundant
> > > because it forces the compiler to emit an external definition for the function.
> > > That is,
> > > 
> > > inline void f(void) { }
> > > [extern] void f(void);
> > > 
> > > should not trigger the
> > > 
> > > redundant redeclaration of ...
> > > 
> > > warning.
> > 
> > 
> > This should add a testcase to the testsuite (that fails before and passes
> > after the front-end change is made).
> 
> I did not want to commit more effort until I have some feedback.
> I will most certainly add a test case if it turns out that the change
> seems reasonable and has a chance of being accepted.

I agree that such a declaration is not redundant, and indeed serves a 
useful purpose, and so it's appropriate to avoid the warning in that case.  
Maybe also edit the documentation in invoke.texi to mention this case as 
not being diagnosed because not redundant.

Hopefully cases such as

inline void f(void) { }
void f(void);
void f(void);

do warn for the final declaration, because that one *is* redundant.  
Similarly, the changes should not affect warnings in the -fgnu89-inline 
case, because then a subsequent extern declaration has no effect on a 
prior inline definition.  Tests should include all these variations.

-- 
Joseph S. Myers
joseph@codesourcery.com

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

end of thread, other threads:[~2023-10-30 20:39 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-28 19:14 [RFC PATCH v1] c: Do not warn about external declaration following inline definition Barnabás Pőcze
2023-10-30 18:01 ` Joseph Myers
2023-10-30 19:55   ` Barnabás Pőcze
2023-10-30 20:39     ` Joseph 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).