adtools / amigaos-gcc-2.95.3

gcc 2.95.3 with support for AmigaOS/m68k
GNU General Public License v2.0
7 stars 4 forks source link

__VA_ARGS__ broken in g++: badly punctuated parameter list in `#define' #8

Open sezero opened 7 years ago

sezero commented 7 years ago
$ cat test.c
#include <proto/dos.h>

$ m68k-amigaos-g++ -O2 -Wall -c test.c
In file included from /opt/m68k-amigaos/lib/gcc-lib/m68k-amigaos/2.95.3/../../../../m68k-amigaos/include/../ndk/include/proto/dos.h:13,
                 from test.c:1:
/opt/m68k-amigaos/lib/gcc-lib/m68k-amigaos/2.95.3/../../../../m68k-amigaos/include/../ndk/include/inline/dos.h:157: badly punctuated parameter list in `#define'
/opt/m68k-amigaos/lib/gcc-lib/m68k-amigaos/2.95.3/../../../../m68k-amigaos/include/../ndk/include/inline/dos.h:262: badly punctuated parameter list in `#define'
/opt/m68k-amigaos/lib/gcc-lib/m68k-amigaos/2.95.3/../../../../m68k-amigaos/include/../ndk/include/inline/dos.h:271: badly punctuated parameter list in `#define'
/opt/m68k-amigaos/lib/gcc-lib/m68k-amigaos/2.95.3/../../../../m68k-amigaos/include/../ndk/include/inline/dos.h:372: badly punctuated parameter list in `#define'
/opt/m68k-amigaos/lib/gcc-lib/m68k-amigaos/2.95.3/../../../../m68k-amigaos/include/../ndk/include/inline/dos.h:453: badly punctuated parameter list in `#define'
/opt/m68k-amigaos/lib/gcc-lib/m68k-amigaos/2.95.3/../../../../m68k-amigaos/include/../ndk/include/inline/dos.h:570: badly punctuated parameter list in `#define'
/opt/m68k-amigaos/lib/gcc-lib/m68k-amigaos/2.95.3/../../../../m68k-amigaos/include/../ndk/include/inline/dos.h:687: badly punctuated parameter list in `#define'

Relevant part of inline/dos.h, around line 157:

#ifndef NO_INLINE_STDARG
#define AllocDosObjectTags(___type, ___tags, ...) \
    ({_sfdc_vararg _tags[] = { ___tags, __VA_ARGS__ }; AllocDosObjectTagList((___type), (const struct TagItem *) _tags); })
#endif /* !NO_INLINE_STDARG */
cahirwpz commented 6 years ago

According to "Badly punctuated parameter list in #define" blog post, the problem could be fixed by replacing:

#define AllocDosObjectTags(___type, ___tags, ...) \
    ({_sfdc_vararg _tags[] = { ___tags, __VA_ARGS__ }; AllocDosObjectTagList((___type), (const struct TagItem *) _tags); })

... with:

#define AllocDosObjectTags(___type, ___tags, ARGS...) \
    ({_sfdc_vararg _tags[] = { ___tags, ##ARGS }; AllocDosObjectTagList((___type), (const struct TagItem *) _tags); })

This could be achieved by modifying function_start in sfdc.

cahirwpz commented 6 years ago

Another quick fix is to pass -Wp,-std=gnu9x to g++ which makes sure C++ compiler uses "more recent" preprecessor features. As __VA_ARGS__ works with newer C++ standard I'm in favour of not changing sfdc, but rather supplying default option to the preprocessor when running in C++ mode (-lang-c++ option). However I'd have to reach out to C++ guys to verify if such a change won't break something fundamentally.

EDIT: I could modify -lang-c++ settings with opts->c9x = 1.

cahirwpz commented 6 years ago

@sezero Any opinion on that topic? I'm leaning towards latter option.

sezero commented 6 years ago

-Wp,-std=gnu9x (but not -std=gnu9x alone) does workaround the issue for me.

sezero commented 2 years ago

Applied your suggested change to my fork as https://github.com/sezero/amigaos-gcc-2.95.3/commit/53b3955284694f7dbe99db4da5e0a8148d7bd4a9