From: Jonathan Wakely <jwakely.gcc@gmail.com>
To: Liu Hao <lh_mouse@126.com>
Cc: Edward Diener <eldlistmailingz@tropicsoft.com>,
gcc-help <gcc-help@gcc.gnu.org>
Subject: Re: Function attributes and x32, x64
Date: Wed, 05 Feb 2020 09:52:00 -0000 [thread overview]
Message-ID: <CAH6eHdTWof6Qj6KmxxD-vcJii3Vrx2Mq+8Z2vc7U6WWiFFF6Vg@mail.gmail.com> (raw)
In-Reply-To: <f6ff7e64-9122-d7f3-d194-d09368840d75@126.com>
On Wed, 5 Feb 2020 at 03:31, Liu Hao <lh_mouse@126.com> wrote:
>
> 在 2020/2/4 上午2:37, Edward Diener 写道:
> > On 2/2/2020 8:11 AM, Liu Hao wrote:
> >> 在 2020/2/1 下午7:06, Edward Diener 写道:
> >>> Given the code:
> >>>
> >>> class cbase;
> >>> int main()
> >>> {
> >>> typedef int __attribute__ ((__stdcall__)) (cbase::* atype)();
> >>> typedef int __attribute__ ((__cdecl__)) (cbase::* btype)();
> >>> typedef int __attribute__ ((__fastcall__)) (cbase::* ctype)();
> >>> typedef int __attribute__ ((__thiscall__)) (cbase::* dtype)();
> >>> return 0;
> >>> }
> >>>
>
> > This does not make sense to me as the compiler seems to be objecting to
> > just having different pointer to member function types with different
> > calling conventions for the same class, as if all member functions for a
> > class must have the same calling conventions. Does gcc not allow
> > different calling conventions for different member functions of a class,
> > and, if so, where is this documented ?
> >
> >
>
> If I substitute the first typedef with an equivalent(?)
> using-declaration then I get a warning:
>
> ```
> test.cc: In function ‘int main()’:
> test.cc:5:65: warning: ‘__stdcall__’ attribute only applies to function
> types [-Wattributes]
> using atype = int __attribute__ ((__stdcall__)) (cbase::* )();
> ```
>
> It looks to me that in the typedef case, the stdcall attribute attaches
> to the `int`, not the (indirect) function type.
I think that's correct. The attribute grammar is confusing, but it
does apply to the return type as used above, and that's obviously
meaningless since 'int' has no calling convention.
> So long as GCC parses it
> as such, this eliminates the warning:
>
> ```
> typedef int ( __attribute__ ((__stdcall__ )) cbase::* atype)();
> // ^_______parenthesis_moved_______/
> ```
>
> The mangled names of these two types (which can be examined using
> `typeid(___).name`) don't differ, so I presume it is kind of a bug in
> intermediate representation.
>
>
> --
> Best regards,
> LH_Mouse
>
next prev parent reply other threads:[~2020-02-05 9:52 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-02-01 11:07 Edward Diener
2020-02-02 13:11 ` Liu Hao
2020-02-03 18:37 ` Edward Diener
2020-02-05 3:31 ` Liu Hao
2020-02-05 9:52 ` Jonathan Wakely [this message]
2020-02-06 2:03 ` Liu Hao
2020-02-04 17:41 ` Jonathan Wakely
2020-02-04 23:24 ` Edward Diener
2020-02-05 9:50 ` Jonathan Wakely
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAH6eHdTWof6Qj6KmxxD-vcJii3Vrx2Mq+8Z2vc7U6WWiFFF6Vg@mail.gmail.com \
--to=jwakely.gcc@gmail.com \
--cc=eldlistmailingz@tropicsoft.com \
--cc=gcc-help@gcc.gnu.org \
--cc=lh_mouse@126.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).