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

Does not compile on Ubuntu Linux 20.04 g++ 9.4.0 #37

Open
ifrguy opened this issue Aug 26, 2022 · 1 comment
Open

Does not compile on Ubuntu Linux 20.04 g++ 9.4.0 #37

ifrguy opened this issue Aug 26, 2022 · 1 comment
Labels
compiling issue issue preventing a successful compilation

Comments

@ifrguy
Copy link

ifrguy commented Aug 26, 2022

OS:
Distributor ID: Ubuntu
Description: Ubuntu 20.04.4 LTS
Release: 20.04
Codename: focal

Arch:
x86_64

g++ (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0
Compile command: g++ -o jtc -Wall -std=c++17 -Ofast jtc.cpp

Compiler output see attached file
jtc.err.gz

@ldn-softdev
Copy link
Owner

ldn-softdev commented Aug 28, 2022

Interesting. It looks like the version of gcc you use pre-processes the concatenation token ## in a different way than prior versions (I'm talking of the version of GCC and not of C++ standard).

Namely, considering this macro definition (where the error is seen most of the time):

#define __DBG_0_ARG__() __dbg__     /* DBG(): access to debug object */
#define __DBG_1_ARG__(X)            /* DBG(N) {..}: debug operator, prints debug indention */\
    if( __dbg__(X) ) \
     TLOCK(__dbg__.mutex()) \
      if( __dbg__(X, __func__) )                                // now print the prompt
#define __DBG_2_ARG__(O, X)         /* DBG(F, N) {..}: using debug operator from F */\
    if( O.__dbg__(X) ) \
     TLOCK(O.__dbg__.mutex()) \
      if( O.__dbg__(X, __func__) )                              // now print the prompt
#define __DBG_4TH_ARG__(arg1, arg2, arg3, arg4, ...) arg4
#define __DBG_CHOOSER__(ARGS...) \
    __DBG_4TH_ARG__(dummy, ##ARGS, __DBG_2_ARG__, __DBG_1_ARG__, __DBG_0_ARG__)
#define DBG(ARGS...) __DBG_CHOOSER__(ARGS)(ARGS)

the line :
454 | template<class X> Debug(X &x) { x.DBG().severity(x); };
must result in resolving DBG() into the token __DBG_0_ARG__, while the error indicates that it resolved into the token __DBG_1_ARG__ instead.

This means, that the argument substitution in the line
__DBG_4TH_ARG__(dummy, ##ARGS, __DBG_2_ARG__, __DBG_1_ARG__, __DBG_0_ARG__)
resulted in 5 arguments, whereas it's expected to be expanded into 4 arguments (given token ## and the empty argument ARGS).

It could be a change in the macro behavior in the newer c++ compilers or a peculiar behavior of this gcc version. I'd need to take more time to experiment with different compiler versions, and perhaps rewrite some macros, given c++20 introduced new __VA_OPT__ macro to handle similar expansions I do in DBG macro.

@ldn-softdev ldn-softdev added the compiling issue issue preventing a successful compilation label Aug 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiling issue issue preventing a successful compilation
Projects
None yet
Development

No branches or pull requests

2 participants