Bug 122888

Summary: rust/ast/rust-fmt.h: templates through extern "C" linkage ?
Product: gcc Reporter: David Binderman <dcb314>
Component: rustAssignee: Not yet assigned to anyone <unassigned>
Status: UNCONFIRMED ---    
Severity: normal CC: dkm, gcc-rust, pep
Priority: P3    
Version: 16.0   
Target Milestone: ---   
See Also: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125823
Host: Target:
Build: Known to work:
Known to fail: Last reconfirmed:

Description David Binderman 2025-11-27 12:35:29 UTC
A compile of rust trunk with clang produces the following:

trunk/gcc/rust/ast/rust-fmt.h:403:15: warning: 'clone_pieces' has C-linkage specified, but returns incomplete type 'FFIVec<Piece>' which could be incompatible with C [-Wreturn-type-c-linkage]
trunk/gcc/rust/ast/rust-fmt.h:406:15: warning: 'clone_pieces' has C-linkage specified, but returns incomplete type 'FFIVec<Piece>' which could be incompatible with C [-Wreturn-type-c-linkage]

Source code is

extern "C" {

FFIVec<Piece> collect_pieces (RustHamster input, bool append_newline,
                  ParseMode parse_mode);

FFIVec<Piece> clone_pieces (const FFIVec<Piece> &);

} // extern "C"

I don't think C understands C++ templates. Suggest code rework.
Comment 1 Andreas Schwab 2025-11-27 12:50:02 UTC
// TODO: Should we instead make an FFIVector struct?
type PieceVec<'a> = ffi::FFIVec<ffi::Piece<'a>>;