stclib / STC

A modern, user friendly, generic, type-safe and fast C99 container library: String, Vector, Sorted and Unordered Map and Set, Deque, Forward List, Smart Pointers, Bitset and Random numbers.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Build fails with Clang on macOS < 10.16

barracuda156 opened this issue · comments

Example of failure on Catalina:

/usr/bin/clang  -I/opt/local/var/macports/build/_opt_bblocal_var_buildworker_ports_build_ports_devel_STC/STC/work/STC-4.2/include -pipe -Os -DNDEBUG -I/opt/local/include -isysroot/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk -arch x86_64 -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk -mmacosx-version-min=10.15 -std=gnu99 -MD -MT CMakeFiles/birthday.dir/misc/examples/birthday.c.o -MF CMakeFiles/birthday.dir/misc/examples/birthday.c.o.d -o CMakeFiles/birthday.dir/misc/examples/birthday.c.o -c /opt/local/var/macports/build/_opt_bblocal_var_buildworker_ports_build_ports_devel_STC/STC/work/STC-4.2/misc/examples/birthday.c
cd /opt/local/var/macports/build/_opt_bblocal_var_buildworker_ports_build_ports_devel_STC/STC/work/build && /opt/local/bin/cmake -E cmake_depends "Unix Makefiles" /opt/local/var/macports/build/_opt_bblocal_var_buildworker_ports_build_ports_devel_STC/STC/work/STC-4.2 /opt/local/var/macports/build/_opt_bblocal_var_buildworker_ports_build_ports_devel_STC/STC/work/STC-4.2 /opt/local/var/macports/build/_opt_bblocal_var_buildworker_ports_build_ports_devel_STC/STC/work/build /opt/local/var/macports/build/_opt_bblocal_var_buildworker_ports_build_ports_devel_STC/STC/work/build /opt/local/var/macports/build/_opt_bblocal_var_buildworker_ports_build_ports_devel_STC/STC/work/build/CMakeFiles/checkauto.dir/DependInfo.cmake --color=
make[2]: Leaving directory `/opt/local/var/macports/build/_opt_bblocal_var_buildworker_ports_build_ports_devel_STC/STC/work/build'
/Library/Developer/CommandLineTools/usr/bin/make  -f CMakeFiles/checkauto.dir/build.make CMakeFiles/checkauto.dir/build
make[2]: Entering directory `/opt/local/var/macports/build/_opt_bblocal_var_buildworker_ports_build_ports_devel_STC/STC/work/build'
/opt/local/var/macports/build/_opt_bblocal_var_buildworker_ports_build_ports_devel_STC/STC/work/STC-4.2/misc/examples/bits.c:12:48: warning: format specifies type 'long' but the argument has type 'int64_t' (aka 'long long') [-Wformat]
        printf("count %" c_ZI ", %" c_ZI "\n", cbits_count(&set), cbits_size(&set));
                      ~~~~~~~                  ^~~~~~~~~~~~~~~~~
/opt/local/var/macports/build/_opt_bblocal_var_buildworker_ports_build_ports_devel_STC/STC/work/STC-4.2/misc/examples/bits.c:16:45: warning: format specifies type 'long' but the argument has type 'int64_t' (aka 'long long') [-Wformat]
        printf("buf: %s: %" c_ZI "\n", buf, cbits_count(&s1));
                         ~~~~~~~            ^~~~~~~~~~~~~~~~
/opt/local/var/macports/build/_opt_bblocal_var_buildworker_ports_build_ports_devel_STC/STC/work/STC-4.2/misc/examples/bits2.c:15:47: warning: format specifies type 'long' but the argument has type 'int64_t' (aka 'long long') [-Wformat]
[  7%] Building C object CMakeFiles/checkauto.dir/lex.yy.c.o
    printf("buf: %s: count=%" c_ZI "\n", buf, Bits_count(&s1));
                           ~~~~~~~            ^~~~~~~~~~~~~~~
/usr/bin/clang   -pipe -Os -DNDEBUG -I/opt/local/include -isysroot/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk -arch x86_64 -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk -mmacosx-version-min=10.15 -std=gnu99 -MD -MT CMakeFiles/checkauto.dir/lex.yy.c.o -MF CMakeFiles/checkauto.dir/lex.yy.c.o.d -o CMakeFiles/checkauto.dir/lex.yy.c.o -c /opt/local/var/macports/build/_opt_bblocal_var_buildworker_ports_build_ports_devel_STC/STC/work/build/lex.yy.c
/opt/local/var/macports/build/_opt_bblocal_var_buildworker_ports_build_ports_devel_STC/STC/work/STC-4.2/misc/examples/arc_containers.c:70:13: error: declaration of non-local variable in 'for' loop
            c_forpair (name, year, Map, *i.ref->get)
            ^
/opt/local/var/macports/build/_opt_bblocal_var_buildworker_ports_build_ports_devel_STC/STC/work/STC-4.2/include/stc/ccommon.h:190:10: note: expanded from macro 'c_forpair'
    for (struct {C##_iter it; const C##_key* key; C##_mapped* val;} _ = {.it=C##_begin(&cnt)} \
         ^
/opt/local/var/macports/build/_opt_bblocal_var_buildworker_ports_build_ports_devel_STC/STC/work/STC-4.2/misc/examples/arc_containers.c:77:13: error: declaration of non-local variable in 'for' loop
            c_forpair (name, year, Map, *i.ref->get)
            ^
/opt/local/var/macports/build/_opt_bblocal_var_buildworker_ports_build_ports_devel_STC/STC/work/STC-4.2/include/stc/ccommon.h:190:10: note: expanded from macro 'c_forpair'
    for (struct {C##_iter it; const C##_key* key; C##_mapped* val;} _ = {.it=C##_begin(&cnt)} \
         ^
2 errors generated.
1 warning generated.
make[2]: *** [CMakeFiles/arc_containers.dir/misc/examples/arc_containers.c.o] Error 1
make[2]: Leaving directory `/opt/local/var/macports/build/_opt_bblocal_var_buildworker_ports_build_ports_devel_STC/STC/work/build'
make[1]: *** [CMakeFiles/arc_containers.dir/all] Error 2

Log from Catalina: https://build.macports.org/builders/ports-10.15_x86_64-builder/builds/147551/steps/install-port/logs/stdio
Log from Snow Leopard: https://build.macports.org/builders/ports-10.6_x86_64-builder/builds/160913/steps/install-port/logs/stdio

Build with GCC works, aside of the following issue (I had to simply delete that test case): #60

P. S. To keep track of relevant issues, one test fails: #61

Thanks, I currently work i on the dev43 branch so I forgot about the current master. Will fix it.

The errors in bits.c example are legitime, thanks.

The errors reported on c_forpair is a clang compiler bug which was reported here earlier, see one of the issues for details (anonymous struct in for-statement). You can use c_foreach instead in your code. c_forlist will have the same issue, but is not that often needed.

Closed as not an error, and can be avoided for old clang compilers by not using c_forpair.

Closed as not an error, and can be avoided for old clang compilers by not using c_forpair.

Well, we could try using a newer Clang. Which version of LLVM Clang will do?

The errors reported on c_forpair is a clang compiler bug which was reported here earlier, see one of the issues for details (anonymous struct in for-statement). You can use c_foreach instead in your code. c_forlist will have the same issue, but is not that often needed.

Tyge, while that makes sense, the problem is that it's actually STC itself that isn't compiling with this code.

How do we fix that?

Use clang 12 or newer: #18
STC does not use c_forpair, only the examples. Remove the ones which uses c_forpair and c_forlist.