Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions vlib/v/builder/cc.v
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,14 @@ fn (v &Builder) only_compile_args(ccoptions CcompilerOptions) []string {
all << '-Werror=implicit-function-declaration'
}
}
} $else {
// On non-Windows platforms, always add -Werror=implicit-function-declaration
// to catch implicit function declarations at compile time
if ccoptions.cc != .msvc {
if !v.pref.is_cstrict {
all << '-Werror=implicit-function-declaration'
}
}
}
all << ccoptions.pre_args
all << ccoptions.source_args
Expand Down
38 changes: 38 additions & 0 deletions vlib/v/tests/implicit_function_declaration_test.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Test for implicit C function declaration detection
// This test verifies that V correctly catches implicit C function declarations

module main

import os

// `test_imp_c_function.v` filename can't contains `implicit`
const test_file = os.join_path(os.vtmp_dir(), 'test_imp_c_function.v')

fn testsuite_begin() {
os.rm(test_file) or {}
// Test code that should fail due to implicit C function declaration
test_code := 'module main
fn C.custom_undeclared_function()
fn main() {
C.custom_undeclared_function()
}
'
// Write the test code to the temporary file
os.write_file(test_file, test_code) or {
eprintln('FAIL: Unable to write test file')
exit(1)
}
}

fn testsuite_end() {
os.rm(test_file) or { eprintln('Warning: Unable to delete temporary file') }
}

fn test_implicit_c_function_declaration() {
result := os.execute('v ${test_file}')
assert result.exit_code != 0
println(result.output)
assert result.output.contains('custom_undeclared_function')
// C4013 is for msvc
assert result.output.contains('implicit') || result.output.contains('C4013')
}
Loading