Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

__cdecl implies extern "C" for functions in C++ code #18

Open
dmik opened this issue Dec 5, 2015 · 1 comment
Open

__cdecl implies extern "C" for functions in C++ code #18

dmik opened this issue Dec 5, 2015 · 1 comment

Comments

@dmik
Copy link
Collaborator

dmik commented Dec 5, 2015

It seems that gcc 4.x.x for OS/2 causes functions to be declared using extern "C" semantics when they have __attribute__((__cdecl__)) attached to them. E.g. for this declaration in C++ context

void __attribute__((__cdecl__)) foo (void **v);

the resulting assembler name (signature) will be _foo instead of __Z3fooPPv (which is the case if _cdecl gets removed). This is not the case with gcc 3.x.x for OS/2 or with gcc 4.x.x on other platforms (e.g. OS X) and looks like a regression of my change that made functions declared as _System in C++ context imply extern "C" (for compatibility with IBM VAC).

Frankly saying there are not many places where it breaks things, but one known case is VirtualBox. The RTCALL calling convention there is defined as __cdecl on OS/2 which causes all functions declared with RTCALL (and with RTDECL which implicitly uses it) to get C signatures instead of C++ ones. For some functions defined in C++ context this brings obvious problems, e.g. for overloaded operators that have the same name by definition (like operator+) but different sets of arguments. This eventually results in several functions with the same signature and the following compiler error:

In file included from D:/Coding/vbox/trunk/src/VBox/Runtime/common/string/ministring.cpp:34:0:
D:/Coding/vbox/trunk/include/iprt/cpp/ministring.h:1024:79: error: conflicting declaration of C function 'const RTCString operator+(const RTCString&, const char*)'
 RTDECL(const RTCString) operator+(const RTCString &a_rstr1, const char *a_psz2);
                                                                               ^
D:/Coding/vbox/trunk/include/iprt/cpp/ministring.h:1013:25: note: previous declaration 'const RTCString operator+(const RTCString&, const RTCString&)'
 RTDECL(const RTCString) operator+(const RTCString &a_rstr1, const RTCString &a_rstr2);
                         ^
D:/Coding/vbox/trunk/include/iprt/cpp/ministring.h:1035:79: error: conflicting declaration of C function 'const RTCString operator+(const char*, const RTCString&)'
 RTDECL(const RTCString) operator+(const char *a_psz1, const RTCString &a_rstr2);
                                                                               ^
D:/Coding/vbox/trunk/include/iprt/cpp/ministring.h:1024:25: note: previous declaration 'const RTCString operator+(const RTCString&, const char*)'
 RTDECL(const RTCString) operator+(const RTCString &a_rstr1, const char *a_psz2);
                         ^
D:/Coding/vbox/trunk/include/iprt/cpp/ministring.h:1035:79: error: conflicting declaration of C function 'const RTCString operator+(const char*, const RTCString&)'
 RTDECL(const RTCString) operator+(const char *a_psz1, const RTCString &a_rstr2);
                                                                               ^
D:/Coding/vbox/trunk/include/iprt/cpp/ministring.h:1013:25: note: previous declaration 'const RTCString operator+(const RTCString&, const RTCString&)'
 RTDECL(const RTCString) operator+(const RTCString &a_rstr1, const RTCString &a_rstr2);
@dmik
Copy link
Collaborator Author

dmik commented Dec 5, 2015

I need to review my _System patch. For the time being we have to avoid using explicit _cdecl with global functions defined in C++ context.

@dmik dmik changed the title _cdecl implies extern "C" for functions in C++ code __cdecl implies extern "C" for functions in C++ code Dec 6, 2015
valerius2k pushed a commit to valerius2k/vbox that referenced this issue Jun 5, 2022
This is temporary, see psmedley/gcc#18
for details.


git-svn-id: http://svn.netlabs.org/repos/vbox/trunk@18 8b531da7-8337-e511-8bd3-62de69f6b5d0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant