File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -511,6 +511,14 @@ fn (v &Builder) only_compile_args(ccoptions CcompilerOptions) []string {
511511 all << '-Werror=implicit-function-declaration'
512512 }
513513 }
514+ } $else {
515+ // On non-Windows platforms, always add -Werror=implicit-function-declaration
516+ // to catch implicit function declarations at compile time
517+ if ccoptions.cc != .msvc {
518+ if ! v.pref.is_cstrict {
519+ all << '-Werror=implicit-function-declaration'
520+ }
521+ }
514522 }
515523 all << ccoptions.pre_args
516524 all << ccoptions.source_args
Original file line number Diff line number Diff line change 1+ // Test for implicit C function declaration detection
2+ // This test verifies that V correctly catches implicit C function declarations
3+
4+ module main
5+
6+ import os
7+
8+ // `test_imp_c_function.v` filename can't contains `implicit`
9+ const test_file = os.join_path (os.vtmp_dir (), 'test_imp_c_function.v' )
10+
11+ fn testsuite_begin () {
12+ os.rm (test_file) or {}
13+ // Test code that should fail due to implicit C function declaration
14+ test_code := 'module main
15+ fn C.custom_undeclared_function()
16+ fn main() {
17+ C.custom_undeclared_function()
18+ }
19+ '
20+ // Write the test code to the temporary file
21+ os.write_file (test_file, test_code) or {
22+ eprintln ('FAIL: Unable to write test file' )
23+ exit (1 )
24+ }
25+ }
26+
27+ fn testsuite_end () {
28+ os.rm (test_file) or { eprintln ('Warning: Unable to delete temporary file' ) }
29+ }
30+
31+ fn test_implicit_c_function_declaration () {
32+ result := os.execute ('v ${test_file} ' )
33+ assert result.exit_code != 0
34+ println (result.output)
35+ assert result.output.contains ('custom_undeclared_function' )
36+ // C4013 is for msvc
37+ assert result.output.contains ('implicit' ) || result.output.contains ('C4013' )
38+ }
You can’t perform that action at this time.
0 commit comments