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