[Bug c/105180] New: K&R style definition does not evaluate array size
gcc at emil dot codes
gcc-bugzilla@gcc.gnu.org
Wed Apr 6 14:33:51 GMT 2022
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105180
Bug ID: 105180
Summary: K&R style definition does not evaluate array size
Product: gcc
Version: 11.2.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: gcc at emil dot codes
Target Milestone: ---
GCC doesn't evaluates the size of an array when declared as a parameter in K&R
style declaration.
Example program:
#include <stdio.h>
int crime(s, c)
char *s;
char c[static printf("%s\n", s)];
{
return 0;
}
int accomplice(s) char *s;
{
return crime(s, s);
}
int main(void)
{
return accomplice("Hello");
}
This should print "Hello\n". When using an ANSI definition, it does, but in
K&R-style, nothing is printed, `printf` isn't evaluated at all.
According to godbolt's compiler explorer, it is a regression which appeared
after GCC 4.6.4 and before or in GCC 4.7.1
It works correctly in clang but not in modern GCC.
More information about the Gcc-bugs
mailing list