mity / acutest

Simple header-only C/C++ unit testing facility.
MIT License
347 stars 96 forks source link

Sign conversion warnings when compiling with -Wsign-conversion under clang #13

Closed xor-gate closed 6 years ago

xor-gate commented 7 years ago

I have copied latest master into my project, but I have very strict compiler flags. Here is the output:

/Users/jerry/go/src/github.com/xor-gate/eresp/tests/acutest.h:206:16: warning: implicit conversion changes signedness: 'int' to 'size_t'
      (aka 'unsigned long') [-Wsign-conversion]
        return printf("%s", buffer);
        ~~~~~~ ^~~~~~~~~~~~~~~~~~~~
/Users/jerry/go/src/github.com/xor-gate/eresp/tests/acutest.h:221:13: warning: implicit conversion changes signedness: 'int' to 'size_t'
      (aka 'unsigned long') [-Wsign-conversion]
        n = printf("%s", buffer);
          ~ ^~~~~~~~~~~~~~~~~~~~
/Users/jerry/go/src/github.com/xor-gate/eresp/tests/acutest.h:300:18: warning: implicit conversion changes signedness: 'int' to 'unsigned long'
      [-Wsign-conversion]
            n += printf("%s:%d: Check ", file, line);
              ~~ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/jerry/go/src/github.com/xor-gate/eresp/tests/acutest.h:304:14: warning: implicit conversion changes signedness: 'int' to 'unsigned long'
      [-Wsign-conversion]
        n += vprintf(fmt, args);
          ~~ ^~~~~~~~~~~~~~~~~~
/Users/jerry/go/src/github.com/xor-gate/eresp/tests/acutest.h:732:77: warning: implicit conversion changes signedness: 'int' to 'unsigned long'
      [-Wsign-conversion]
    tests__ = (const struct test__**) malloc(sizeof(const struct test__*) * test_list_size__);
                                                                          ~ ^~~~~~~~~~~~~~~~
/Users/jerry/go/src/github.com/xor-gate/eresp/tests/acutest.h:733:50: warning: implicit conversion changes signedness: 'int' to 'unsigned long'
      [-Wsign-conversion]
    test_flags__ = (char*) malloc(sizeof(char) * test_list_size__);
                                               ~ ^~~~~~~~~~~~~~~~
/Users/jerry/go/src/github.com/xor-gate/eresp/tests/acutest.h:738:52: warning: implicit conversion changes signedness: 'int' to 'unsigned long'
      [-Wsign-conversion]
    memset((void*) test_flags__, 0, sizeof(char) * test_list_size__);
                                                 ~ ^~~~~~~~~~~~~~~~
/usr/include/secure/_string.h:77:38: note: expanded from macro 'memset'
  __builtin___memset_chk (dest, val, len, __darwin_obsz0 (dest))
                                     ^~~
/Users/jerry/go/src/github.com/xor-gate/eresp/tests/reader.c:34:9: warning: missing field 'func' initializer [-Wmissing-field-initializers]
    { 0 }
        ^

For the last test list entry create a macro to have all fields initialized instead of incorrect {0}:

#define TEST_LIST_END {NULL, NULL}
mity commented 7 years ago

I don't have clang available anywhere in my reach right now. I fixed what gcc can see with -Wextra and -Wsign-conversion in the commit 704359ee6eaf8aa8f99720a0cf20f1338886b0be. If gcc missed something what clang can see, feel free to make PR.

About the {0}, I see adding some TEST_LIST_END macro as superfluous and I cannot see any benefit in having it. You may use { NULL, NULL} directly. It is IMO clear from the TEST_LIST description how such super-correct end record looks like.

xor-gate commented 7 years ago

You can enable clang for travis like this https://github.com/xor-gate/stlink2/blob/master/.travis.yml#L23-L24, dont forget to add clang to the installed packages like this: https://github.com/xor-gate/stlink2/blob/master/.travis.yml#L10-L13

mity commented 6 years ago

Should be fixed by 21845db79f22a6e15a42238613ea227317f34a7f.