This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
C++ PATCH: PR 28991
- From: Mark Mitchell <mark at codesourcery dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Sun, 10 Sep 2006 17:42:24 -0700
- Subject: C++ PATCH: PR 28991
- Reply-to: mark at codesourcery dot com
This patch fixes PR c++/28991, a recently-introduced regression
whereby we failed to statically initialize a function pointer whose
initializer was a static member function. Since BASELINKS can now
appear in an initializer, we need to let the middle-end know that they
can be staticp. (A BASELINK has no middle-end semantics; it is just a
front-end notation indicating how a particular function was named.)
Tested on x86_64-unknown-linux-gnu, applied on the mainline.
--
Mark Mitchell
CodeSourcery
mark@codesourcery.com
(650) 331-3385 x713
2006-09-10 Mark Mitchell <mark@codesourcery.com>
PR c++/28991
* cp-objcp-common.c (cxx_staticp): New function.
* cp-objcp-common.h (LANG_HOOOKS_STATICP): Use it.
* cp-tree.h (cxx_staticp): New function.
2006-09-10 Mark Mitchell <mark@codesourcery.com>
PR c++/289991
* g++.dg/init/static3.C: New test.
Index: gcc/cp/cp-objcp-common.c
===================================================================
--- gcc/cp/cp-objcp-common.c (revision 116832)
+++ gcc/cp/cp-objcp-common.c (working copy)
@@ -185,6 +185,21 @@ cxx_types_compatible_p (tree x, tree y)
return 0;
}
+tree
+cxx_staticp (tree arg)
+{
+ switch (TREE_CODE (arg))
+ {
+ case BASELINK:
+ return staticp (BASELINK_FUNCTIONS (arg));
+
+ default:
+ break;
+ }
+
+ return NULL_TREE;
+}
+
/* Stubs to keep c-opts.c happy. */
void
push_file_scope (void)
Index: gcc/cp/cp-objcp-common.h
===================================================================
--- gcc/cp/cp-objcp-common.h (revision 116832)
+++ gcc/cp/cp-objcp-common.h (working copy)
@@ -59,6 +59,8 @@ extern tree objcp_tsubst_copy_and_build
#define LANG_HOOKS_EXPAND_DECL c_expand_decl
#undef LANG_HOOKS_PARSE_FILE
#define LANG_HOOKS_PARSE_FILE c_common_parse_file
+#undef LANG_HOOKS_STATICP
+#define LANG_HOOKS_STATICP cxx_staticp
#undef LANG_HOOKS_DUP_LANG_SPECIFIC_DECL
#define LANG_HOOKS_DUP_LANG_SPECIFIC_DECL cxx_dup_lang_specific_decl
#undef LANG_HOOKS_SET_DECL_ASSEMBLER_NAME
Index: gcc/cp/cp-tree.h
===================================================================
--- gcc/cp/cp-tree.h (revision 116832)
+++ gcc/cp/cp-tree.h (working copy)
@@ -4519,6 +4519,7 @@ extern bool cp_var_mod_type_p (tree, t
extern void cxx_initialize_diagnostics (struct diagnostic_context *);
extern int cxx_types_compatible_p (tree, tree);
extern void init_shadowed_var_for_decl (void);
+extern tree cxx_staticp (tree);
/* in cp-gimplify.c */
extern int cp_gimplify_expr (tree *, tree *, tree *);
Index: gcc/testsuite/g++.dg/init/static3.C
===================================================================
--- gcc/testsuite/g++.dg/init/static3.C (revision 0)
+++ gcc/testsuite/g++.dg/init/static3.C (revision 0)
@@ -0,0 +1,26 @@
+// { dg-do run }
+
+struct T
+{
+ static void (*handler)();
+ static void func() {};
+};
+
+bool fail;
+
+struct S {
+ S() {
+ if (T::handler != T::func)
+ fail = true;
+ }
+};
+
+static S s;
+
+void (*T::handler)() = func;
+
+int main()
+{
+ if (fail)
+ return 1;
+}