munit icon indicating copy to clipboard operation
munit copied to clipboard

gcc-11 and "declared with mismatched bound" warnings

Open roblatham00 opened this issue 4 years ago • 3 comments

munit hits some new warnings in gcc-11:

  CC       tests/unit-tests/munit/munit.o
../tests/unit-tests/munit/munit.c:1836:47: warning: argument 4 of type ‘char * const[argc + 1]’ declared with mismatched bound ‘argc + 1’ [-Wvla-parameter]
 1836 |                         int argc, char* const argv[MUNIT_ARRAY_PARAM(argc + 1)],
      |                                   ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from ../tests/unit-tests/munit/munit.c:118:
../tests/unit-tests/munit/munit.h:478:51: note: previously declared as ‘char * const[argc + 1]’ with bound ‘argc + 1’
  478 |                             int argc, char* const argv[MUNIT_ARRAY_PARAM(argc + 1)],
      |                                       ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../tests/unit-tests/munit/munit.c:2053:40: warning: argument 4 of type ‘char * const[argc + 1]’ declared with mismatched bound ‘argc + 1’ [-Wvla-parameter]
 2053 |                  int argc, char* const argv[MUNIT_ARRAY_PARAM(argc + 1)]) {
      |                            ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from ../tests/unit-tests/munit/munit.c:118:
../tests/unit-tests/munit/munit.h:463:86: note: previously declared as ‘char * const[argc + 1]’ with bound ‘argc + 1’
  463 | int munit_suite_main(const MunitSuite* suite, void* user_data, int argc, char* const argv[MUNIT_ARRAY_PARAM(argc + 1)]);
      |                                                                          ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

I do not yet understand why argc + 1 would be different from argc +1 . Still happens even if I remove MUNIT_ARRAY_PARAM -- which of course it does because on my platform that macro does nothing.

roblatham00 avatar Nov 08 '21 20:11 roblatham00

It seems like other people have been running into similar problems in other code bases:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101605 https://stackoverflow.com/questions/68488777/vla-warning-for-exactly-matching-prototype https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101585

It seems like a faulty -Wvla-parameter, now enabled in GCC 11 as part of -Wall, is to blame. To clarify, have you tried removing the whole MUNIT_ARRAY_PARAM(argc + 1) expression, or only just the MUNIT_ARRAY_PARAM? (MUNIT_ARRAY_PARAM is a function macro.)

codylico avatar Nov 10 '21 14:11 codylico

To clarify, have you tried removing the whole MUNIT_ARRAY_PARAM(argc + 1) expression, or only just the MUNIT_ARRAY_PARAM? (MUNIT_ARRAY_PARAM is a function macro.)

Lines such as

int
munit_suite_main_custom(const MunitSuite* suite, void* user_data,
                        int argc, char* const argv[MUNIT_ARRAY_PARAM(argc + 1)],
                        const MunitArgument arguments[]) {

I rewrote as

int
munit_suite_main_custom(const MunitSuite* suite, void* user_data,
                        int argc, char* const argv[(argc + 1)],
                        const MunitArgument arguments[]) {

and got the same warning

roblatham00 avatar Nov 10 '21 15:11 roblatham00

How about removing the whole thing (i.e. char* const argv[MUNIT_ARRAY_PARAM(argc + 1)] -> char* const argv[])? Did you try this?

codylico avatar Nov 13 '21 00:11 codylico