re PR c++/28991 (Static constructor emitted instead of initialized variable)
authorMark Mitchell <mark@codesourcery.com>
Mon, 11 Sep 2006 00:40:15 +0000 (00:40 +0000)
committerMark Mitchell <mmitchel@gcc.gnu.org>
Mon, 11 Sep 2006 00:40:15 +0000 (00:40 +0000)
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.
PR c++/289991
* g++.dg/init/static3.C: New test.

From-SVN: r116838

gcc/cp/ChangeLog
gcc/cp/cp-objcp-common.c
gcc/cp/cp-objcp-common.h
gcc/cp/cp-tree.h
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/init/static3.C [new file with mode: 0644]

index f565f4c8ac0be0860f547d48c210589e4a5c6b0b..bcb6dc8fe61eca6da5d93eef5c6804ea39e48191 100644 (file)
@@ -1,3 +1,10 @@
+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-09  Jason Merrill  <jason@redhat.com>
 
        PR c++/28996
index cb8369cb53b22fefecf4358a19e08a320b3cfd8d..f40be9696956ecf48c5bbab591303cb303454b89 100644 (file)
@@ -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 65eb6aedfa3650b16662a9f4467b7aa873523b30..f420d93b191f5849910c5e2cb2be17c9a14c11ae 100644 (file)
@@ -59,6 +59,8 @@ extern tree objcp_tsubst_copy_and_build (tree, tree, tsubst_flags_t,
 #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 f864487702758553452c152338cbc4057a701242..8f88976e78703352e506f49ee1d2eb2878df755a 100644 (file)
@@ -4519,6 +4519,7 @@ extern bool cp_var_mod_type_p                     (tree, tree);
 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 ebddaa604a028f22fa12c3180a35aa64266581b5..55c511ee075a0379448aab29e8c5708265aa1c53 100644 (file)
@@ -1,3 +1,8 @@
+2006-09-10  Mark Mitchell  <mark@codesourcery.com>
+
+       PR c++/28991
+       * g++.dg/init/static3.C: New test.
+
 2006-09-10  Andrew Pinski  <pinskia@physics.uc.edu>
 
        PR testsuite/29007
diff --git a/gcc/testsuite/g++.dg/init/static3.C b/gcc/testsuite/g++.dg/init/static3.C
new file mode 100644 (file)
index 0000000..a8e6216
--- /dev/null
@@ -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;
+}