gccの15バグってませんか?
解決したいこと
明示的に引数を指定しない関数に引数を指定する
clangがCの仕様的に正しい動きだと思います
知見のある人ご意見ください
発生している問題・エラー
tyano@fedora:~$ cat test.c
void d(){}
int main(void) {d(1);return 0;}
tyano@fedora:~$ gcc test.c
test.c: In function ‘main’:
test.c:2:17: error: too many arguments to function ‘d’; expected 0, have 1
2 | int main(void) {d(1);return 0;}
| ^ ~
test.c:1:6: note: declared here
1 | void d(){}
| ^
tyano@fedora:~$ clang test.c
test.c:2:20: warning: too many arguments in call to 'd'
2 | int main(void) {d(1);return 0;}
| ~ ^
test.c:2:18: warning: passing arguments to 'd' without a prototype is deprecated in all versions of C and is not supported in C23 [-Wdeprecated-non-prototype]
2 | int main(void) {d(1);return 0;}
| ^
2 warnings generated.
該当するソースコード
tyano@fedora:~$ gcc --version
gcc (GCC) 15.0.1 20250313 (Red Hat 15.0.1-0)
Copyright (C) 2025 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
tyano@fedora:~$ clang --version
clang version 20.1.1 (Fedora 20.1.1-1.fc43)
Target: x86_64-redhat-linux-gnu
Thread model: posix
InstalledDir: /usr/lib64/llvm20/bin
Configuration file: /etc/clang/x86_64-redhat-linux-gnu-clang.cfg
自分で試したこと
voidを指定するとclangでもエラーになります
tyano@fedora:~$ cat test_void.c
void d(void){}
int main(void) {d(1);return 0;}
tyano@fedora:~$ gcc test_void.c
test_void.c: In function ‘main’:
test_void.c:2:17: error: too many arguments to function ‘d’; expected 0, have 1
2 | int main(void) {d(1);return 0;}
| ^ ~
test_void.c:1:6: note: declared here
1 | void d(void){}
| ^
tyano@fedora:~$ clang test_void.c
test_void.c:2:19: error: too many arguments to function call, expected 0, have 1
2 | int main(void) {d(1);return 0;}
| ~ ^
test_void.c:1:6: note: 'd' declared here
1 | void d(void){}
| ^
1 error generated.
これで何が問題かというと
GNUのライブラリ関連が./configure
でビルドエラーになるので
結構影響大きいと思うんですよね