Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gcc-11 and "declared with mismatched bound" warnings #79

Open
roblatham00 opened this issue Nov 8, 2021 · 3 comments
Open

gcc-11 and "declared with mismatched bound" warnings #79

roblatham00 opened this issue Nov 8, 2021 · 3 comments

Comments

@roblatham00
Copy link

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.

@codylico
Copy link

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.)

@roblatham00
Copy link
Author

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

@codylico
Copy link

codylico commented Nov 13, 2021 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants