abolz/Drachennest

size of array ‘altStackMem’ is not an integral constant-expression

Opened this issue · 0 comments

Problem

I get the following error when compiling the tests:

In file included from /usr/include/signal.h:328,
                 from /home/projects/c/Drachennest/test/catch.hpp:6456,
                 from /home/projects/c/Drachennest/test/catch_main.cc:2:
/home/projects/c/Drachennest/test/catch.hpp:6631:45: error: size of array ‘altStackMem’ is not an integral constant-expression
 6631 |     char FatalConditionHandler::altStackMem[SIGSTKSZ] = {};
      |                                             ^~~~~~~~

I saw this notice for glibc 2.34, which seems relevant to the issue:

12 * Add _SC_MINSIGSTKSZ and _SC_SIGSTKSZ. When _SC_SIGSTKSZ_SOURCE or
13 _GNU_SOURCE are defined, MINSIGSTKSZ and SIGSTKSZ are no longer
14 constant on Linux. MINSIGSTKSZ is redefined to sysconf(_SC_MINSIGSTKSZ)
15 and SIGSTKSZ is redefined to sysconf (_SC_SIGSTKSZ).

So this problem is bound to creep in projects using those #defines.

Steps to reproduce

git clone https://github.com/abolz/Drachennest.git
cd Drachennest/
mkdir build
cd build/
cmake ..
cd test
cmake --build .

Work-around

diff --git a/test/catch.hpp b/test/catch.hpp
index 1106e46..cdbe953 100644
--- a/test/catch.hpp
+++ b/test/catch.hpp
@@ -6628,6 +6628,11 @@ namespace Catch {
     bool FatalConditionHandler::isSet = false;
     struct sigaction FatalConditionHandler::oldSigActions[sizeof(signalDefs)/sizeof(SignalDefs)] = {};
     stack_t FatalConditionHandler::oldSigStack = {};
+
+// FIXME: temporary fix
+# undef SIGSTKSZ
+# define SIGSTKSZ _SC_SIGSTKSZ
+
     char FatalConditionHandler::altStackMem[SIGSTKSZ] = {};
 
 } // namespace Catch

Environment

ldd (GNU libc) 2.36
gcc (GCC) 12.2.0
Linux manj 5.15.74-3-MANJARO x86_64 GNU/Linux

Other info

Trying to compile everything in build shows many other errors that I didn't investigate.

The first was:

[ 85%] Building CXX object bench/CMakeFiles/bench_dtoa.dir/bench_dtoa.cc.o
/home/projects/c/Drachennest/bench/bench_dtoa.cc:177:22: error: ‘JenkinsRandom random’ redeclared as different kind of entity
  177 | static JenkinsRandom random;
      |                      ^~~~~~
In file included from /usr/include/c++/12.2.0/cstdlib:75,
                 from /usr/include/c++/12.2.0/bits/stl_algo.h:69,
                 from /usr/include/c++/12.2.0/algorithm:61,
                 from /home/projects/c/Drachennest/ext/google_benchmark/include/benchmark/benchmark.h:172,
                 from /home/projects/c/Drachennest/bench/bench_dtoa.cc:1:
/usr/include/stdlib.h:402:17: note: previous declaration ‘long int random()’
  402 | extern long int random (void) __THROW;
      |                 ^~~~~~