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.
MIT License
1.34k stars 73 forks source link

Build fails with Clang on macOS < 10.16 #62

Closed barracuda156 closed 1 year ago

barracuda156 commented 1 year ago

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): https://github.com/stclib/STC/issues/60

P. S. To keep track of relevant issues, one test fails: https://github.com/stclib/STC/issues/61

tylov commented 1 year ago

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

tylov commented 1 year ago

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.

tylov commented 1 year ago

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

barracuda156 commented 1 year ago

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?

mascguy commented 1 year ago

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?

tylov commented 1 year ago

Use clang 12 or newer: https://github.com/stclib/STC/issues/18 STC does not use c_forpair, only the examples. Remove the ones which uses c_forpair and c_forlist.