Repository navigation
Inline functions in several headers to fix ODR violations - #360
Conversation
|
Thanks @fearn-e. There are certainly more of these lurking. I think I will make a new test that does as you suggest and just builds two TUs that include all of core. Then we can catch at test time (clang tidy will also pick these up in most cases too) |
|
Note that function templates shouldn't need to be inlined. I'll give this a proper review when I have time. |
|
@tremblap I did not yet because I wasn't 100% sure this was the right way to go about things in the first place! It's been a while since I committed something outside of my own acorex bubble 😅 Now that I do, I could add something to the examples folder that has multiple TUs in it. In fact, what I'm making for the OF tutorial could probably go in the examples folder anyway. And I wouldn't mind doing the test case @weefuzzy, that's still a blind spot for me. And it does indeed look like function templates don't need the inline keyword, as they |
987c6aa to
2dd8ba4
Compare
|
Haven't written a proper test, but did a quick and dirty run through everything in I'm not sure what the situation is with |
|
Excellent, many thanks for going above and beyond. It's highly unlikely that |
|
@weefuzzy do we want to 'rebase and merge' here, or 'squash and merge' |
squash and merge |
As per issue #9 and PR #20 that fixed it, there are more functions that produce LNK2005 errors when including their header files in more than one TU, as FluCoMa is set as an INTERFACE library in the
CMakeLists.txt.ScalerUtils.hpp,DistanceFuncs.hpp,KMeans.hpp-- all have a few instances of this.FluidJSON.hppis littered with the error on every singlecheck_json,to_json, andfrom_json.A build can be forced through with /FORCE:MULTIPLE, and considering the definitions will be identical in this case, shouldn't cause any undefined behaviour at runtime. However, adding
inlineto all the offending functions is a simple fix and, as far as I can tell, should generally be what is done for an interface library.On a sidenote; This seemingly doesn't come up that often, I'd guess because the default FluCoMa examples contain only one TU per .exe target, so these functions are never defined more than once there. But I am surprised to not see any more bug reports about this in the 5 years since that last PR #20!
There's likely more of these present in the codebase, but it could be checked by going through and including every header file in two different TUs.