This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
C++: warn about implicit declarations of built-in functions
- To: gcc-patches at gcc dot gnu dot org
- Subject: C++: warn about implicit declarations of built-in functions
- From: Zack Weinberg <zack at wolery dot cumb dot org>
- Date: Sat, 27 May 2000 21:31:18 -0700
- Cc: mark at codesourcery dot com
The C++ compiler currently does not issue implicit declaration
warnings for functions that are recognized specially, such as strcpy.
This patch corrects the problem.
It will cause a large number of regressions in the C++ test suite,
which is crawling with implicit declarations of builtins. I will send
a separate patch for that.
This is analogous to the patch I sent last week to fix the same
problem in the C and ObjC front ends, but completely independent.
zw
* cp-tree.h (DECL_ANTICIPATED): New macro.
Document new use of DECL_LANG_FLAG_7.
* decl.c (builtin_function): Set DECL_ANTICIPATED on builtins
in the user namespace.
* lex.c (do_identifier): If the identifier's declaration has
DECL_ANTICIPATED on, it has not yet been declared. But do not
replace it with an ordinary implicit declaration.
* tinfo2.cc: Include stdlib.h.
===================================================================
Index: cp/cp-tree.h
--- cp/cp-tree.h 2000/05/26 21:05:04 1.463
+++ cp/cp-tree.h 2000/05/28 04:26:01
@@ -101,6 +101,7 @@ Boston, MA 02111-1307, USA. */
5: DECL_INTERFACE_KNOWN.
6: DECL_THIS_STATIC (in VAR_DECL or FUNCTION_DECL).
7: DECL_DEAD_FOR_LOCAL (in VAR_DECL).
+ DECL_ANTICIPATED (in FUNCTION_DECL).
Usage of language-independent fields in a language-dependent manner:
@@ -2461,6 +2462,10 @@ extern int flag_new_for_scope;
scope) declared in a local scope. */
#define DECL_LOCAL_FUNCTION_P(NODE) \
DECL_LANG_FLAG_0 (FUNCTION_DECL_CHECK (NODE))
+
+/* Nonzero if NODE is a FUNCTION_DECL for a built-in function, and we have
+ not yet seen a prototype for that function. */
+#define DECL_ANTICIPATED(NODE) DECL_LANG_FLAG_7 (FUNCTION_DECL_CHECK (NODE))
/* This _DECL represents a compiler-generated entity. */
#define SET_DECL_ARTIFICIAL(NODE) (DECL_ARTIFICIAL (NODE) = 1)
===================================================================
Index: cp/decl.c
--- cp/decl.c 2000/05/26 21:05:05 1.614
+++ cp/decl.c 2000/05/28 04:26:04
@@ -6769,6 +6769,12 @@ builtin_function (name, type, code, clas
if (libname)
DECL_ASSEMBLER_NAME (decl) = get_identifier (libname);
make_function_rtl (decl);
+
+ /* Warn if a function in the namespace for users
+ is used without an occasion to consider it declared. */
+ if (name[0] != '_' || name[1] != '_')
+ DECL_ANTICIPATED (decl) = 1;
+
return decl;
}
===================================================================
Index: cp/lex.c
--- cp/lex.c 2000/05/14 08:44:48 1.197
+++ cp/lex.c 2000/05/28 04:26:05
@@ -3315,8 +3315,9 @@ do_identifier (token, parsing, args)
id = lookup_name (token, 0);
return error_mark_node;
}
-
- if (!id)
+
+ if (!id || (TREE_CODE (id) == FUNCTION_DECL
+ && DECL_ANTICIPATED (id)))
{
if (current_template_parms)
return build_min_nt (LOOKUP_EXPR, token);
@@ -3328,7 +3329,16 @@ do_identifier (token, parsing, args)
}
else if (in_call && ! flag_strict_prototype)
{
- id = implicitly_declare (token);
+ if (!id)
+ id = implicitly_declare (token);
+ else
+ {
+ /* Implicit declaration of built-in function. Don't
+ change the built-in declaration, but don't let this
+ go by silently, either. */
+ cp_pedwarn ("implicit declaration of function `%D'", token);
+ DECL_ANTICIPATED (id) = 0; /* only issue this warning once */
+ }
}
else if (current_function_decl == 0)
{
===================================================================
Index: cp/tinfo2.cc
--- cp/tinfo2.cc 2000/05/25 11:49:33 1.24
+++ cp/tinfo2.cc 2000/05/28 04:26:05
@@ -28,6 +28,7 @@
// the GNU General Public License.
#include <stddef.h>
+#include <stdlib.h> // for abort
#include "tinfo.h"
#include "new" // for placement new