This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: PATCH: Reserve the __attributes__ for member function pointer type


On Mon, Aug 18, 2008 at 9:53 AM, Mark Mitchell <mark@codesourcery.com> wrote:
> The test case needs to be a proper DejaGNU testcase. See testsuite/g++.dg
> for examples. Thanks,

Ah-oh, a new patch containing test, I hope it is correct:

Patch:

diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c
--- a/gcc/cp/decl2.c
+++ b/gcc/cp/decl2.c
@@ -105,7 +105,7 @@
 tree
 build_memfn_type (tree fntype, tree ctype, cp_cv_quals quals)
 {
-  tree raises;
+  tree raises, attrs;
   int type_quals;

   if (fntype == error_mark_node || ctype == error_mark_node)
@@ -113,10 +113,13 @@

   type_quals = quals & ~TYPE_QUAL_RESTRICT;
   ctype = cp_build_qualified_type (ctype, type_quals);
-  fntype = build_method_type_directly (ctype, TREE_TYPE (fntype),
+  attrs = TYPE_ATTRIBUTES(fntype);
+  fntype = build_method_type_directly (ctype, TREE_TYPE(fntype),
                                       (TREE_CODE (fntype) == METHOD_TYPE
                                        ? TREE_CHAIN (TYPE_ARG_TYPES (fntype))
                                        : TYPE_ARG_TYPES (fntype)));
+  if (attrs)
+    fntype = build_type_attribute_variant (fntype, attrs);
   raises = TYPE_RAISES_EXCEPTIONS (fntype);
   if (raises)
     fntype = build_exception_variant (fntype, raises);
diff --git a/gcc/testsuite/g++.dg/ext/attribute-test-5.C
b/gcc/testsuite/g++.dg/ext/attribute-test-5.C
new file mode 100644
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ext/attribute-test-5.C
@@ -0,0 +1,23 @@
+// { dg-do run }
+// { dg-options "" }
+// PR c++/9381
+
+class Base{
+public:
+  Base(){};
+  ~Base(){};
+
+  __attribute__((__stdcall__)) virtual void func() { };
+};
+
+typedef void (__attribute__((__stdcall__)) Base::*Ptr)() ;
+
+int main(int argc, char ** argv){
+  Base objects[4];
+  Ptr ptrs = &Base::func;
+  for ( int i = 0; i < 4; i ++)
+    ((objects[i]).*ptrs)();  //Here will crash without the patch
+
+  return 0;
+}
+


gcc/cp/ChangeLog

2008-08-18  Bo Yang  <techrazy.yang@gmail.com>

     * decl2.c (build_memfn_type): Preserve the attributes of a member
     function by create a new type with attributes variant.


gcc/testsuite/ChangeLog

2008-08-18  Bo Yang  <techrazy.yang@gmail.com>

     * g++.dg/ext/attribute-test-5.C: Test pointer type to a member function
     with attribute associated.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]