This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/85997] New: Bogus -Wvla warning from function array argument with size expression
- From: "kari.nurmela at iki dot fi" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Wed, 30 May 2018 11:26:25 +0000
- Subject: [Bug c/85997] New: Bogus -Wvla warning from function array argument with size expression
- Auto-submitted: auto-generated
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85997
Bug ID: 85997
Summary: Bogus -Wvla warning from function array argument with
size expression
Product: gcc
Version: 5.4.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: kari.nurmela at iki dot fi
Target Milestone: ---
If there is an array argument in a function definition or declaration that uses
a size expression (C99 6.7.5.3#7, Example 4, Example 5), gcc emits an "ISO C90
forbids variable length array" warning with -Wvla, even when there are no
variable length arrays involved. For example the function declaration
void print_array(unsigned count, int array[static count]);
gives "not_vla.c:3:1: warning: ISO C90 forbids variable length array "array"
[-Wvla]"
The "array" argument is not a variable-length array, the declaration just
states that the argument provides access to the first element of an array that
has at least "count" elements.
In a whole working example below two warnings are emitted when compiled with
-Wvla (function declaration, line 3, and definition, line 5):
#include <stdio.h>
void print_array(unsigned count, int array[static count]);
void print_array(unsigned count, int array[static count])
{
for (unsigned i = 0; i < count; ++i)
{
printf("%d ", array[i]);
}
printf("\n");
}
int main(void)
{
int array[5] = {1, 2, 3, 4, 5};
print_array(5, array);
// print_array(6, array);
// Error: array overflow. Since 6 and sizeof array are compile time const,
// this could emit a warning, but doesn't.
return 0;
}