This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: PATCH: Reserve the __attributes__ for member function pointer type
- From: "Bo Yang" <techrazy dot yang at gmail dot com>
- To: "Mark Mitchell" <mark at codesourcery dot com>
- Cc: gcc-patches at gcc dot gnu dot org, "Jakub Jelinek" <jakub at redhat dot com>, pinskia at gmail dot com
- Date: Mon, 18 Aug 2008 09:17:29 +0800
- Subject: Re: PATCH: Reserve the __attributes__ for member function pointer type
- References: <a47d5c0807302107o6ce10a99n3048aa004faee3f7@mail.gmail.com> <48914B88.10201@gnu.org> <a47d5c0807302327k57d9f97fs423ab81bcca608a2@mail.gmail.com> <20080731074327.GI8133@devserv.devel.redhat.com> <a47d5c0807310118h1a11113cs2dac1a6348460fe5@mail.gmail.com> <20080731083108.GJ8133@devserv.devel.redhat.com> <a47d5c0807310154h349556e5qf5a9df98f1dd71ad@mail.gmail.com> <4899F410.8070207@codesourcery.com> <a47d5c0808170133u63ad32d7ua8267112031a3f50@mail.gmail.com> <48A8524E.6020400@codesourcery.com>
On Mon, Aug 18, 2008 at 12:31 AM, Mark Mitchell <mark@codesourcery.com> wrote:
> Bo Yang wrote:
>
>> 2008-08-17 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.
>
> This looks much better. However, your patch does not include new tests for
> the testsuite to verify that the bug has been fixed. Please add those and
> resubmit.
Do you mean like the following?
Changelog
2008-08-17 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.
Code
diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c
--- a/gcc/cp/decl2.c
+++ b/gcc/cp/decl2.c
@@ -107,7 +107,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)
@@ -115,10 +115,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);
The test case:
class Base{
public:
Base(){};
~Base(){};
__attribute__((__stdcall__)) virtual void test() { };
};
typedef void (__attribute__((__stdcall__)) Base::* test)() ;
int main(int argc, char ** argv){
Base children[4];
test md = &Base::test;
for ( int i = 0; i < 4; i ++)
((children[i]).*md)();
return 0;
}