adishavit / argh

Argh! A minimalist argument handler.
BSD 3-Clause "New" or "Revised" License
1.33k stars 93 forks source link

Uncompileable with clang 14 #66

Closed KOLANICH closed 2 years ago

KOLANICH commented 3 years ago
In file included from ../argh_tests.cpp:4:
../doctest.h:4403:33: error: variable length array declaration not allowed at file scope
        static char             altStackMem[SIGSTKSZ];
                                ^           ~~~~~~~~
In file included from ../argh_tests.cpp:4:
../doctest.h:4453:36: error: variable length array declaration not allowed at file scope
    char    FatalConditionHandler::altStackMem[SIGSTKSZ] = {};
                                   ^           ~~~~~~~~
adishavit commented 3 years ago

Pinging @onqtam.
This seems to be related to doctest.

onqtam commented 2 years ago

I just tried using clang trunk (couldn't find 14) on godbolt and it compiles a simple example without problem: https://godbolt.org/z/dve19fb3d

What's your OS? What compiler options are you using?

KOLANICH commented 2 years ago

Ubuntu 21.10 To get clang 14 you can follow the instructions on https://apt.llvm.org/

onqtam commented 2 years ago

any clue why it doesn't happen with clang trunk and why there's no clang 14 in godbolt?

adishavit commented 2 years ago

@mattgodbolt?

FabioLolix commented 2 years ago

Hello, I'm on Arch Linux and I'm making the pkgbuilds for this software for both stable release and latest git commit, it currently fail with any combination of compiler and source I've tested

v1.3.1 with GCC 11.2.0

[ 50%] Building CXX object CMakeFiles/argh_example.dir/example.cpp.o
In file included from /usr/include/signal.h:328,
                 from /usr/include/c++/11.2.0/csignal:42,
                 from /home/fabio/Dev/Github/PKGBUILD-AUR_fix/a/argh/src/argh-1.3.1/doctest.h:3241,
                 from /home/fabio/Dev/Github/PKGBUILD-AUR_fix/a/argh/src/argh-1.3.1/argh_tests.cpp:4:
/home/fabio/Dev/Github/PKGBUILD-AUR_fix/a/argh/src/argh-1.3.1/doctest.h:4403:45: error: size of array ‘altStackMem’ is not an integral constant-expression
 4403 |         static char             altStackMem[SIGSTKSZ];
      |                                             ^~~~~~~~
/home/fabio/Dev/Github/PKGBUILD-AUR_fix/a/argh/src/argh-1.3.1/doctest.h:4453:48: error: size of array ‘altStackMem’ is not an integral constant-expression
 4453 |     char    FatalConditionHandler::altStackMem[SIGSTKSZ] = {};
      |                                                ^~~~~~~~
/home/fabio/Dev/Github/PKGBUILD-AUR_fix/a/argh/src/argh-1.3.1/argh_tests.cpp: In function ‘void _DOCTEST_ANON_FUNC_28()’:

argh-gcc11

v1.3.1 with Clang 13

 50%] Building CXX object CMakeFiles/argh_tests.dir/argh_tests.cpp.o
In file included from /home/fabio/Dev/Github/PKGBUILD-AUR_fix/a/argh/src/argh-1.3.1/argh_tests.cpp:4:
/home/fabio/Dev/Github/PKGBUILD-AUR_fix/a/argh/src/argh-1.3.1/doctest.h:4403:45: warning: variable length arrays are a C99 feature [-Wvla-extension]
        static char             altStackMem[SIGSTKSZ];
                                            ^~~~~~~~
/usr/include/bits/sigstksz.h:28:19: note: expanded from macro 'SIGSTKSZ'
# define SIGSTKSZ sysconf (_SC_SIGSTKSZ)
                  ^~~~~~~~~~~~~~~~~~~~~~
/home/fabio/Dev/Github/PKGBUILD-AUR_fix/a/argh/src/argh-1.3.1/doctest.h:4403:45: note: non-constexpr function 'sysconf' cannot be used in a constant expression
/usr/include/bits/sigstksz.h:28:19: note: expanded from macro 'SIGSTKSZ'
# define SIGSTKSZ sysconf (_SC_SIGSTKSZ)
                  ^
/usr/include/unistd.h:640:17: note: declared here
extern long int sysconf (int __name) __THROW;
                ^
In file included from /home/fabio/Dev/Github/PKGBUILD-AUR_fix/a/argh/src/argh-1.3.1/argh_tests.cpp:4:
/home/fabio/Dev/Github/PKGBUILD-AUR_fix/a/argh/src/argh-1.3.1/doctest.h:4403:33: error: variable length array declaration not allowed at file scope
        static char             altStackMem[SIGSTKSZ];
                                ^           ~~~~~~~~
/home/fabio/Dev/Github/PKGBUILD-AUR_fix/a/argh/src/argh-1.3.1/doctest.h:4453:48: warning: variable length arrays are a C99 feature [-Wvla-extension]
    char    FatalConditionHandler::altStackMem[SIGSTKSZ] = {};
                                               ^~~~~~~~
/usr/include/bits/sigstksz.h:28:19: note: expanded from macro 'SIGSTKSZ'
# define SIGSTKSZ sysconf (_SC_SIGSTKSZ)
                  ^~~~~~~~~~~~~~~~~~~~~~
/home/fabio/Dev/Github/PKGBUILD-AUR_fix/a/argh/src/argh-1.3.1/doctest.h:4453:48: note: non-constexpr function 'sysconf' cannot be used in a constant expression
/usr/include/bits/sigstksz.h:28:19: note: expanded from macro 'SIGSTKSZ'
# define SIGSTKSZ sysconf (_SC_SIGSTKSZ)
                  ^
/usr/include/unistd.h:640:17: note: declared here
extern long int sysconf (int __name) __THROW;
                ^
In file included from /home/fabio/Dev/Github/PKGBUILD-AUR_fix/a/argh/src/argh-1.3.1/argh_tests.cpp:4:
/home/fabio/Dev/Github/PKGBUILD-AUR_fix/a/argh/src/argh-1.3.1/doctest.h:4453:36: error: variable length array declaration not allowed at file scope
    char    FatalConditionHandler::altStackMem[SIGSTKSZ] = {};
                                   ^           ~~~~~~~~
/home/fabio/Dev/Github/PKGBUILD-AUR_fix/a/argh/src/argh-1.3.1/argh_tests.cpp:415:24: warning: ISO C++11 does not allow conversion from string literal to 'char *' [-Wwritable-strings]
      char* argv[] = { "0", "-a", "1", "-b", "2", "3", "4" };

argh-clang13

v1.3.1 with GCC 10.3.0

[ 50%] Building CXX object CMakeFiles/argh_tests.dir/argh_tests.cpp.o
In file included from /home/fabio/Dev/Github/PKGBUILD-AUR_fix/a/argh/src/argh-1.3.1/argh_tests.cpp:4:
/home/fabio/Dev/Github/PKGBUILD-AUR_fix/a/argh/src/argh-1.3.1/doctest.h:4403:53: error: array bound is not an integer constant before ‘]’ token
 4403 |         static char             altStackMem[SIGSTKSZ];
      |                                                     ^
/home/fabio/Dev/Github/PKGBUILD-AUR_fix/a/argh/src/argh-1.3.1/doctest.h: In constructor ‘doctest::detail::FatalConditionHandler::FatalConditionHandler()’:
/home/fabio/Dev/Github/PKGBUILD-AUR_fix/a/argh/src/argh-1.3.1/doctest.h:4422:33: error: ‘altStackMem’ was not declared in this scope
 4422 |             sigStack.ss_sp    = altStackMem;
      |                                 ^~~~~~~~~~~
/home/fabio/Dev/Github/PKGBUILD-AUR_fix/a/argh/src/argh-1.3.1/doctest.h: At global scope:
/home/fabio/Dev/Github/PKGBUILD-AUR_fix/a/argh/src/argh-1.3.1/doctest.h:4453:56: error: array bound is not an integer constant before ‘]’ token
 4453 |     char    FatalConditionHandler::altStackMem[SIGSTKSZ] = {};
      |                                                        ^
/home/fabio/Dev/Github/PKGBUILD-AUR_fix/a/argh/src/argh-1.3.1/argh_tests.cpp: In function ‘void _DOCTEST_ANON_FUNC_28()’:
/home/fabio/Dev/Github/PKGBUILD-AUR_fix/a/argh/src/argh-1.3.1/argh_tests.cpp:415:24: warning: ISO C++ forbids converting a string constant to ‘char*’ [-Wwrite-strings]
  415 |       char* argv[] = { "0", "-a", "1", "-b", "2", "3", "4" };
      |                        ^~~

argh-gcc10

v1.3.1.r17.g01b6a4a with GCC 11.2.0

[ 50%] Building CXX object CMakeFiles/argh_tests.dir/argh_tests.cpp.o
[ 50%] Building CXX object CMakeFiles/argh_example.dir/example.cpp.o
In file included from /usr/include/signal.h:328,
                 from /usr/include/c++/11.2.0/csignal:42,
                 from /home/fabio/Dev/Github/PKGBUILD-AUR_fix/a/argh-git/src/argh/doctest.h:3241,
                 from /home/fabio/Dev/Github/PKGBUILD-AUR_fix/a/argh-git/src/argh/argh_tests.cpp:4:
/home/fabio/Dev/Github/PKGBUILD-AUR_fix/a/argh-git/src/argh/doctest.h:4403:45: error: size of array ‘altStackMem’ is not an integral constant-expression
 4403 |         static char             altStackMem[SIGSTKSZ];
      |                                             ^~~~~~~~
/home/fabio/Dev/Github/PKGBUILD-AUR_fix/a/argh-git/src/argh/doctest.h:4453:48: error: size of array ‘altStackMem’ is not an integral constant-expression
 4453 |     char    FatalConditionHandler::altStackMem[SIGSTKSZ] = {};
      |                                                ^~~~~~~~
/home/fabio/Dev/Github/PKGBUILD-AUR_fix/a/argh-git/src/argh/argh_tests.cpp: In lambda function:
/home/fabio/Dev/Github/PKGBUILD-AUR_fix/a/argh-git/src/argh/argh_tests.cpp:730:27: warning: declaration of ‘cmdl’ shadows a previous local [-Wshadow]
  730 |    [](argh::parser const& cmdl)
      |       ~~~~~~~~~~~~~~~~~~~~^~~~
/home/fabio/Dev/Github/PKGBUILD-AUR_fix/a/argh-git/src/argh/argh_tests.cpp:720:17: note: shadowed declaration is here
  720 |    const parser cmdl(argv);
      |                 ^~~~
[ 75%] Linking CXX executable argh_example
[ 75%] Built target argh_example
make[2]: *** [CMakeFiles/argh_tests.dir/build.make:76: CMakeFiles/argh_tests.dir/argh_tests.cpp.o] Errore 1

argh-git-gcc11

onqtam commented 2 years ago

oh, it just clicked for me - argh is using a very old version of doctest where indeed SIGSTKSZ is a problem. It's been fixed long ago - I'd suggest updating to version 2.4.6 from 1 year ago within the argh repository: https://github.com/doctest/doctest/blob/2.4.6/doctest/doctest.h

I don't recommend the newer versions (2.4.7/2.4.8/dev) because of this problem: https://github.com/adishavit/argh/issues/72 (it will be fixed eventually too).

adishavit commented 2 years ago

Thanks @onqtam. I pushed version 2.4.6. @KOLANICH LMK if the problem is fixed.

FabioLolix commented 2 years ago

For me has been fixed

KOLANICH commented 2 years ago

Yeah, it has solved the problem. Thank you.