Closed jwnimmer-tri closed 5 months ago
This was giving a lot of compilation warnings during unit tests, all along the lines of this:
In file included from /Users/pgoulart/projects/clarabel/Clarabel.cpp/include/Clarabel:6:
/Users/pgoulart/projects/clarabel/Clarabel.cpp/include/cpp/DefaultSettings.h:300:25: warning: 'clarabel_DefaultSettings_f64_default' has C-linkage specified, but returns incomplete type 'DefaultSettings<double>' which could be incompatible with C [-Wreturn-type-c-linkage]
DefaultSettings<double> clarabel_DefaultSettings_f64_default();
The issue appear to be that the template instantiations make the compiler accept things like this.
Happy to remerge this if we can resolve the warnings.
Thanks for the feedback! I learned something new about C++ today.
When I have time to circle back to this, I'll work on developing a working patch, and open a new PR.
I know of no reason why explicit template instantiations should ever appear in a header file: code that includes the header file will already implicitly instantiate any templates that it uses. (See https://en.cppreference.com/w/cpp/language/class_template.) The effect of the instantiations is only to copy unnecessary object code into every translation unit that calls this library.
In any case, for trivial wrapper structs it's always better to use function inlining anyway; for performance, we don't actually want to be jumping through extern functions when dealing with these wrappers.