[cxx-interop] Fix test header to declare linkage for a implicit template #72522
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The header was defining a function, the function created a lambda, and the lambda was transformed into a
std::function
. This transformation is incorrect because the function scope does not have linkage, so the instantiated types will not have linkage either, causing the error below.Declaring the function
inline
forces each TU to have their own copies of the function, which avoids the instantiated templates from being in a different TU than the one using them.The header would not have worked in a normal C++ program, since none of the functions declare linkage, they would have been defined in each TU that included the header and it would fail linking as soon as two of those TU tried to be linked together. Declaring the functions
inline
avoids the problem (a more normal header, only with declarations, would also worked).