From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 21067 invoked by alias); 3 Feb 2020 18:37:08 -0000 Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org Received: (qmail 21058 invoked by uid 89); 3 Feb 2020 18:37:07 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=0.9 required=5.0 tests=BAYES_00,FORGED_MUA_MOZILLA,KAM_NUMSUBJECT,KAM_SHORT,SPF_PASS autolearn=no version=3.3.1 spammy=Diener, diener, ctype, dtype X-HELO: ciao.gmane.io Received: from ciao.gmane.io (HELO ciao.gmane.io) (159.69.161.202) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 03 Feb 2020 18:37:06 +0000 Received: from list by ciao.gmane.io with local (Exim 4.92) (envelope-from ) id 1iygam-000Bhx-Hr for gcc-help@gcc.gnu.org; Mon, 03 Feb 2020 19:37:04 +0100 To: gcc-help@gcc.gnu.org From: Edward Diener Subject: Re: Function attributes and x32, x64 Date: Mon, 03 Feb 2020 18:37:00 -0000 Message-ID: References: <29e08084.e493.17006075515.Coremail.lh_mouse@126.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.4.2 In-Reply-To: <29e08084.e493.17006075515.Coremail.lh_mouse@126.com> X-IsSubscribed: yes X-SW-Source: 2020-02/txt/msg00029.txt.bz2 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; >>     } >> >> >> If I compile this for x64 (-m64) in gcc-9.2 I receive no errors or >> warnings. Yet >> https://gcc.gnu.org/onlinedocs/gcc/x86-Function-Attributes.html tells me >> that all four are only for x86-32 targets. Is the documentation wrong, >> is this a bug in gcc-9.2, or have I missed something ? > > Are you compiling for Windows targets? If you target x64 Windows then > it's likely that such attributes are accepted but ignored in line with > MS compilers. On Windows in a 64-bit compile the attributes are ignored. On Linux in a 64-bit compile the attributes are ignored but at least there are indeed warning messages saying so. But the do9c should explain this. In both Windows and Linux in a 32-bit compile I get messages such as: test_calling_conventions.cpp: In function 'int main()': test_calling_conventions.cpp:5:62: error: stdcall and cdecl attributes are not compatible 5 | typedef int __attribute__ ((__cdecl__)) (cbase::* btype)(); | ^ test_calling_conventions.cpp:6:65: error: fastcall and cdecl attributes are not compatible 6 | typedef int __attribute__ ((__fastcall__)) (cbase::* ctype)(); | ^ test_calling_conventions.cpp:6:65: error: fastcall and stdcall attributes are not compatible test_calling_conventions.cpp:7:65: error: stdcall and thiscall attributes are not compatible 7 | typedef int __attribute__ ((__thiscall__)) (cbase::* dtype)(); | ^ test_calling_conventions.cpp:7:65: error: fastcall and thiscall attributes are not compatible test_calling_conventions.cpp:7:65: error: cdecl and thiscall attributes are not compatible 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 ?