Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with using lambdas in tests in gcc #49

Closed
kostic2000 opened this issue Feb 12, 2017 · 2 comments
Closed

Issue with using lambdas in tests in gcc #49

kostic2000 opened this issue Feb 12, 2017 · 2 comments

Comments

@kostic2000
Copy link

I have come across an issue where two test cases in separate source files, that happen to acquire the same name (due to COUNTER macro being per compilation unit), and using lambdas inside them are compiled (or linked) incorrectly. The issue is certainly in either gcc or the linker (or both) and relates to how it handles inline functions.
In this particular case the issue is in macro DOCTEST_CREATE_AND_REGISTER_FUNCTION. It forwards declares the function as static, and then implements it as inline, but without "static". The fix is in either defining the function as static inline, or just forget about inline (after all the name is going ot be unique within a compilation unit, inline seems unnecessary here).

I have managed to reproduce the compiler(or linker) bug without doctest, I can supply more details if interested. But in this particular case, when two modules declare static functions of the same name, and then define them as inline without "static", and also both declare and call a lambda inside, both functions will end up calling the same lambda (from one of the functions, the other one will not be in the executable at all).

I can create and submit a PR with a fix, but it is as simple as changing
inline void f()
to either
static inline void f()
or
static void f()

This is line 1188 in the latest version at the time of writing.

@onqtam
Copy link
Member

onqtam commented Feb 18, 2017

Thanks for reporting this! That inline there was a remnant from the early development of doctest.

This happened only under linux - there was no problem using MinGW-w64 under windows.

So this is currently in the dev branch - but I'll release 1.1.4 soon with this fix

@onqtam onqtam closed this as completed in 88955d3 Feb 18, 2017
@kostic2000
Copy link
Author

kostic2000 commented Feb 19, 2017 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants