===================================================================
@@ -299,6 +299,10 @@ Wframe-address
C ObjC C++ ObjC++ Var(warn_frame_address) Warning LangEnabledBy(C ObjC C++ ObjC++,Wall)
Warn when __builtin_frame_address or __builtin_return_address is used unsafely.
+Wbuiltin-function-redefined
+C++ ObjC++ Var(warn_builtin_function_redefined) Warning LangEnabledBy(C++ ObjC++,Wall)
+Warn when a built-in function is redefined.
+
Wbuiltin-macro-redefined
C ObjC C++ ObjC++ CPP(warn_builtin_macro_redefined) CppReason(CPP_W_BUILTIN_MACRO_REDEFINED) Var(cpp_warn_builtin_macro_redefined) Init(1) Warning
Warn when a built-in preprocessor macro is undefined or redefined.
===================================================================
@@ -1502,6 +1502,14 @@ duplicate_decls (tree newdecl, tree olddecl, bool
}
else if (! same_type_p (TREE_VALUE (t1), TREE_VALUE (t2)))
break;
+ if (t1 || t2
+ || DECL_LANGUAGE (newdecl) != DECL_LANGUAGE (olddecl)
+ || ! same_type_p (TREE_TYPE (TREE_TYPE (olddecl)),
+ TREE_TYPE (TREE_TYPE (newdecl))))
+ warning_at (DECL_SOURCE_LOCATION (newdecl),
+ OPT_Wbuiltin_function_redefined,
+ "declaration of %q+#D conflicts with built-in "
+ "declaration %q#D", newdecl, olddecl);
}
else if ((DECL_EXTERN_C_P (newdecl)
&& DECL_EXTERN_C_P (olddecl))
@@ -1555,7 +1563,7 @@ duplicate_decls (tree newdecl, tree olddecl, bool
/* Whether or not the builtin can throw exceptions has no
bearing on this declarator. */
- TREE_NOTHROW (olddecl) = 0;
+ TREE_NOTHROW (olddecl) = TREE_NOTHROW (newdecl);
if (DECL_THIS_STATIC (newdecl) && !DECL_THIS_STATIC (olddecl))
{
===================================================================
@@ -256,8 +256,8 @@ Objective-C and Objective-C++ Dialects}.
-pedantic-errors @gol
-w -Wextra -Wall -Waddress -Waggregate-return @gol
-Wno-aggressive-loop-optimizations -Warray-bounds -Warray-bounds=@var{n} @gol
--Wno-attributes -Wbool-compare -Wno-builtin-macro-redefined @gol
--Wc90-c99-compat -Wc99-c11-compat @gol
+-Wno-attributes -Wbool-compare -Wbuiltin-function-redefined @gol
+-Wno-builtin-macro-redefined -Wc90-c99-compat -Wc99-c11-compat @gol
-Wc++-compat -Wc++11-compat -Wc++14-compat -Wcast-align -Wcast-qual @gol
-Wchar-subscripts -Wclobbered -Wcomment -Wconditionally-supported @gol
-Wconversion -Wcoverage-mismatch -Wno-cpp -Wdangling-else -Wdate-time @gol
@@ -5460,6 +5460,13 @@ unrecognized attributes, function attributes appli
etc. This does not stop errors for incorrect use of supported
attributes.
+@item -Wbuiltin-function-redefined @r{(C++ and Objective-C++ only)}
+@opindex Wbuiltin-function-redefined
+@opindex Wno-builtin-function-redefined
+Do warn if built-in functions are redefined. This option is only
+supported for C++ and Objective-C++. It is implied by @option{-Wall},
+which can be disabled with @option{-Wno-builtin-function-redefined}.
+
@item -Wno-builtin-macro-redefined
@opindex Wno-builtin-macro-redefined
@opindex Wbuiltin-macro-redefined
===================================================================
@@ -0,0 +1,14 @@
+// { dg-do compile }
+// { dg-options "-Wbuiltin-function-redefined -fdump-tree-eh" }
+
+extern "C"
+void fork () // { dg-warning "conflicts with built-in declaration" }
+__attribute__ ((__nothrow__));
+
+void bar () throw ()
+{
+ fork ();
+}
+
+// { dg-final { scan-tree-dump-not "eh_dispatch" "eh" } }
+// { dg-final { scan-tree-dump-not "resx" "eh" } }
===================================================================
@@ -2,6 +2,7 @@
/* { dg-do compile } */
/* { dg-options "-Wall" } */
+extern "C"
void *memcpy(void *dest, const void *src, __SIZE_TYPE__ n);
void f (void *dest, const void *src) {
memcpy (dest, src, 0);
===================================================================
@@ -2,9 +2,11 @@
// { dg-options "-W -Wall" }
typedef unsigned long size_t;
+extern "C" {
extern void* malloc (size_t);
extern void free (void*);
extern void* realloc (void*, size_t);
+}
struct vtable {
void* (* _malloc) (size_t);