Skip to content

Build errors under gcc 16 #1333

Closed
Closed

Description

@ivankra

I ran into these build failures under gcc 16:

$ make
cmake -B build -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr/local
-- The C compiler identification is GNU 16.0.1
...
[ 22%] Building C object CMakeFiles/qjs.dir/quickjs.c.o
/src/quickjs.c: In function ‘js_default_module_normalize_name’:
/src/quickjs.c:29087:7: error: assignment discards ‘const’ qualifier from pointer target type [-Werror=discarded-qualifiers]
29087 |     p = strrchr(base_name, '/');
      |       ^
In function ‘js_bigint_sign’,
    inlined from ‘js_bigint_get_si_sat’ at /src/quickjs.c:12114:13,
    inlined from ‘js_binary_logic_slow’ at /src/quickjs.c:15091:25:
/src/quickjs.c:12106:18: error: ‘buf2’ may be used uninitialized [-Werror=maybe-uninitialized]
12106 |     return a->tab[a->len - 1] >> (JS_LIMB_BITS - 1);
      |            ~~~~~~^~~~~~~~~~~~
/src/quickjs.c: In function ‘js_binary_logic_slow’:
/src/quickjs.c:15071:27: note: ‘buf2’ declared here
15071 |         JSBigIntBuf buf1, buf2;
      |                           ^~~~
In function ‘js_bigint_sign’,
    inlined from ‘js_bigint_get_si_sat’ at /src/quickjs.c:12114:13,
    inlined from ‘js_binary_logic_slow’ at /src/quickjs.c:15091:25:
/src/quickjs.c:12106:18: error: ‘buf2’ may be used uninitialized [-Werror=maybe-uninitialized]
12106 |     return a->tab[a->len - 1] >> (JS_LIMB_BITS - 1);
      |            ~~~~~~^~~~~~~~~~~~
/src/quickjs.c: In function ‘js_binary_logic_slow’:
/src/quickjs.c:15071:27: note: ‘buf2’ declared here
15071 |         JSBigIntBuf buf1, buf2;
      |                           ^~~~

Using latest Debian's gcc build: 16.0.1 20260208 (experimental) [trunk r16-7394-gd93c8a679b2] (Debian 16-20260208-1)

Activity

  1. bnoordhuis commented on Feb 9, 2026

    @bnoordhuis
    Contributor

    The first warning is because you're compiling quickjs as a C23 project (which it isn't - yet):

    /src/quickjs.c:29087:7: error: assignment discards ‘const’ qualifier from pointer target type [-Werror=discarded-qualifiers]
    29087 |     p = strrchr(base_name, '/');
    

    strrchr's pre-C23 prototype is char *strrchr(const char *, int) but the error message implies gcc thinks it's the C23 prototype where the return type is the type of the first argument (relevant search engine keywords: qchar c23)

    The others are false positives. Not sure why gcc gets confused.

  2. ivankra commented on Feb 10, 2026

    @ivankra
    ContributorAuthor

    Oh yes, looks like gcc 16 is switching to C23 as the default - https://www.phoronix.com/news/GCC-Prepares-std-gnu23-Default

    cmake passes -std=gnu11 flag to gcc, but it doesn't affect that warning, which becomes an error due to -Werror:

    /usr/bin/gcc-16 -DQUICKJS_NG_BUILD -D_GNU_SOURCE -I/src -O3 -DNDEBUG -std=gnu11 -fvisibility=hidden -Wall -Werror -Wextra -Wformat=2 -Wno-implicit-fallthrough -Wno-sign-compare -Wno-missing-field-initializers -Wno-unused-parameter -Wno-unused-but-set-variable -Wno-unused-result -Wno-stringop-truncation -Wno-array-bounds -funsigned-char -MD -MT CMakeFiles/qjs.dir/quickjs.c.o -MF CMakeFiles/qjs.dir/quickjs.c.o.d -o CMakeFiles/qjs.dir/quickjs.c.o -c /src/quickjs.c

    I guess this could be intentional on gcc's part, standard doesn't mandate warnings. -Werror makes the compiler behave stricter than the standard prescribes. quickjs has the same discarded-qualifiers warning and without -Werror in its Makefile it compiles fine.

    Not sure maybe-uninitialized warnings - quickjs doesn't have that one.

  3. bnoordhuis commented on Feb 10, 2026

    @bnoordhuis
    Contributor

    We shouldn't be setting -Werror except in CI or developer builds. I'll file a new issue for that.

    The strrchr warning is simple to fix. I'll open a pull request for that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions