This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
PATCH: new flag to say when things are instantiated
- To: gcc-bugs at gcc dot gnu dot org
- Subject: PATCH: new flag to say when things are instantiated
- From: Brendan Kehoe <brendan at zen dot org>
- Date: Wed, 08 Nov 2000 20:13:02 +0000
- Reply-To: Brendan Kehoe <brendan at zen dot org>
I've found this feature to be particularly helpful in some situations. By
making it possible for users to know precisely when the compiler is doing
something for them, it can both help new C++ developers grasp the language
better, and also help you know when seemingly obscure bugs happen due to a
random instantiation you didn't know about.
Ok?
B
2000-11-08 Brendan Kehoe <brendan@zen.org>
* decl2.c (warn_instantiations): New variable.
(lang_decode_option): Set it for -Winstantiations.
* pt.c (instantiate_decl): If WARN_INSTANTIATIONS, tell the user
when an instantiatiation has taken place.
(instantiate_class_template): Likewise for classes.
* lang-options.h: Add -Winstantiations/-Wno-instantiations.
Index: cp-tree.h
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cp/cp-tree.h,v
retrieving revision 1.539
diff -u -p -r1.539 cp-tree.h
--- cp-tree.h 2000/10/31 08:43:16 1.539
+++ cp-tree.h 2000/11/08 16:58:02
@@ -3202,6 +3205,10 @@ extern int warn_multichar;
declared in a templatized class. This behavior is warned about with
flag_guiding_decls in do_friend. */
extern int warn_nontemplate_friend;
+
+/* Nonzero means warn when each variable, function, or type is
instantiated. */
+
+extern int warn_instantiations;
/* in c-common.c */
extern void declare_function_name PARAMS ((void));
Index: lang-options.h
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cp/lang-options.h,v
retrieving revision 1.36
diff -u -p -r1.36 lang-options.h
--- lang-options.h 2000/06/06 20:11:40 1.36
+++ lang-options.h 2000/11/08 16:58:19
@@ -135,6 +137,8 @@ DEFINE_LANG_NAME ("C++")
{ "-Wold-style-cast", "Warn if a C style cast is used in a program" },
{ "-Wno-old-style-cast", "" },
{ "-Wnon-template-friend", "" },
+ { "-Winstantiations", "Warn on the instantiation of each variable,
function, and type" },
+ { "-Wno-instantiations", "" },
{ "-Wno-non-template-friend", "Don't warn when non-templatized
friend functions are declared within a template" },
{ "-Wdeprecated", "" },
{ "-Wno-deprecated", "Don't announce deprecation of compiler
features" },
Index: pt.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cp/pt.c,v
retrieving revision 1.475
diff -u -p -r1.475 pt.c
--- pt.c 2000/11/07 22:49:57 1.475
+++ pt.c 2000/11/08 16:59:00
@@ -5119,6 +5119,9 @@ instantiate_class_template (type)
TYPE_BEING_DEFINED (type) = 0;
repo_template_used (type);
+ if (warn_instantiations)
+ cp_warning ("instantiated template class `%#T'", type);
+
/* Now that the class is complete, instantiate default arguments for
any member functions. We don't do this earlier because the
default arguments may reference members of the class. */
@@ -9675,6 +9678,9 @@ instantiate_decl (d, defer_ok)
DECL_NOT_REALLY_EXTERN (d) = 1;
}
cp_finish_decl (d, DECL_INITIAL (d), NULL_TREE, 0);
+
+ if (warn_instantiations)
+
cp_warning ("instantiated variable `%#D'", d);
}
else if (TREE_CODE (d) == FUNCTION_DECL)
{
@@ -9707,6 +9713,9 @@ instantiate_decl (d, defer_ok)
/* Finish the function. */
expand_body (finish_function (0));
+
+ if (warn_instantiations)
+
cp_warning ("instantiated function `%#D'", d);
}
/* We're not deferring instantiation any more. */
Index: decl2.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cp/decl2.c,v
retrieving revision 1.409
diff -u -p -u -2 -p -r1.409 decl2.c
--- decl2.c 2000/11/08 14:03:29 1.409
+++ decl2.c 2000/11/08 17:06:13
@@ -346,4 +357,8 @@ int warn_multichar = 1;
int warn_nontemplate_friend = 1;
+/* Nonzero means warn when each variable, function, or type is
instantiated. */
+
+int warn_instantiations = 0;
+
/* Nonzero means complain about deprecated features. */
@@ -774,4 +795,6 @@ lang_decode_option (argc, argv)
else if (!strcmp (p, "non-template-friend"))
warn_nontemplate_friend = setting;
+ else if (!strcmp (p, "instantiations"))
+
warn_instantiations = setting;
else if (!strcmp (p, "deprecated"))
warn_deprecated = setting;
--
Brendan Kehoe
CTO of Nobie.com (http://www.nobie.com/)
-- Finally true Net marketing in .ie