From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 25854 invoked by alias); 20 Nov 2002 11:06:05 -0000 Mailing-List: contact gcc-prs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-prs-owner@gcc.gnu.org Received: (qmail 25831 invoked by uid 71); 20 Nov 2002 11:06:04 -0000 Resent-Date: 20 Nov 2002 11:06:04 -0000 Resent-Message-ID: <20021120110604.25829.qmail@sources.redhat.com> Resent-From: gcc-gnats@gcc.gnu.org (GNATS Filer) Resent-Cc: gcc-prs@gcc.gnu.org, gcc-bugs@gcc.gnu.org, rmathew@hotmail.com Resent-Reply-To: gcc-gnats@gcc.gnu.org, rmathew@hotmail.com Received: (qmail 21724 invoked by uid 61); 20 Nov 2002 10:57:04 -0000 Message-Id: <20021120105704.21723.qmail@sources.redhat.com> Date: Thu, 28 Nov 2002 07:31:00 -0000 From: rmathew@hotmail.com Reply-To: rmathew@hotmail.com To: gcc-gnats@gcc.gnu.org Cc: rmathew@hotmail.com X-Send-Pr-Version: gnatsweb-2.9.3 (1.1.1.1.2.31) X-GNATS-Notify: rmathew@hotmail.com Subject: c++/8656: Unable to assign function with __attribute__ and pointer return type to an appropriate variable X-SW-Source: 2002-11/txt/msg01099.txt.bz2 List-Id: >Number: 8656 >Category: c++ >Synopsis: Unable to assign function with __attribute__ and pointer return type to an appropriate variable >Confidential: no >Severity: serious >Priority: medium >Responsible: unassigned >State: open >Class: rejects-legal >Submitter-Id: net >Arrival-Date: Wed Nov 20 03:06:03 PST 2002 >Closed-Date: >Last-Modified: >Originator: rmathew@hotmail.com >Release: GCC 3.2 >Organization: >Environment: MinGW, Cygwin and Linux(x86) (and possibly other x86-32 targets) >Description: Consider the following source code saved in file "bar.c": --------------------------- 8< --------------------------- extern int * (__attribute__((stdcall)) *fooPtr)( void); int * __attribute__((stdcall)) myFn01( void) { return 0; } void snafu( void) { fooPtr = myFn01; } --------------------------- 8< --------------------------- Running "g++ -c bar.c" gives: --------------------------- 8< --------------------------- bar.c: In function `void snafu()': bar.c:7: invalid conversion from `int*(*)()' to `int*(*)()' --------------------------- 8< --------------------------- However, running "gcc -c bar.c" creates no such problems. With reference to the source code given above, here're a few more observations: 1. This problem is not shown by the 2.95.3 g++. 2. If the definition of myFn01 above is changed to a declaration or if a declaration for the same is added before it, the problem disappears. 3. The problem appears only if the return type is of the kind "xyz *" - if there's a "typedef int *intptr;" and we use "intptr" instead of "int *" for myFn01, the problem disappears. 4. The problem can also be circumvented by putting the attribute and the function name together in parentheses like "int * (__attribute__((stdcall)) myFn01)( void)". 5. The problem does not come if all the "stdcall" instances are replaced by "cdecl", but it reappears if they are replaced by "fastcall". 6. Both Borland C/C++ 5.5 and MSVC++ 6.2 compile this code perfectly (after using the MS equivalent "__stdcall"). Lastly, this looks very similar to PR 6626, but IMHO is different - the syntax and semantics are perfectly valid in this case as far as I can see. >How-To-Repeat: Just save the sample code given above as file "bar.c" (or whatever) and run "g++ -c" on it. >Fix: >Release-Note: >Audit-Trail: >Unformatted: