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

Compile failure with WinRT on 2.4.5 #465

Closed
bnason-nf opened this issue Feb 4, 2021 · 5 comments
Closed

Compile failure with WinRT on 2.4.5 #465

bnason-nf opened this issue Feb 4, 2021 · 5 comments

Comments

@bnason-nf
Copy link
Contributor

Hi,

I just updated to version 2.4.5, and the Windows UWP build using doctest gets this compile error:

doctest\doctest/doctest.h(3070,41): error C2482: 'tlsLaneIdx': dynamic initialization of thread local data not allowed in WinRT code
doctest\doctest/doctest.h(3068): message : while compiling class template member function 'std::atomic<int> &doctest::detail::MultiLaneAtomic<int>::myAtomic(void) noexcept'
doctest\doctest/doctest.h(3025): message : see reference to function template instantiation 'std::atomic<int> &doctest::detail::MultiLaneAtomic<int>::myAtomic(void) noexcept' being compiled
doctest\doctest/doctest.h(3084): message : see reference to class template instantiation 'doctest::detail::MultiLaneAtomic<int>' being compiled

This error is documented here:
https://docs.microsoft.com/en-us/cpp/error-messages/compiler-errors-1/compiler-error-c2482

It's trivial to avoid the error by splitting the declaration and the assignment, but I'm not sure this code is doing what you intend since the variable isn't static, or maybe I'm misunderstanding.

Thanks,
Benbuck

@onqtam
Copy link
Member

onqtam commented Feb 4, 2021

Hi,

thread_local implies static when used in function-scope so that code should be fine.

Regarding your problem - the documentation you link to states that A static expression is required to initialize __declspec(thread) or thread_local data in these runtime environments. so I guess the problem is that laneCounter++ % DOCTEST_MULTI_LANE_ATOMICS_THREAD_LANES is not a static expression and that's not permitted in that environment.

What you could do is simply define DOCTEST_CONFIG_NO_MULTI_LANE_ATOMICS before including the framework header. Perhaps the framework can detect Windows UWP and define that by itself - I'm open for PRs :)

Let me know if this helps!

@bnason-nf
Copy link
Contributor Author

Hi Viktor,

Defining DOCTEST_CONFIG_NO_MULTI_LANE_ATOMICS does avoid the problem. I'm not sure what the actual solution would be if you wanted to support that feature under WinRT, but the workaround is sufficient for my needs.

Thanks,
Benbuck

@onqtam
Copy link
Member

onqtam commented Feb 18, 2021

Seems that other people are having problems with this as well: jupyter-xeus/cpp-terminal#88

Assuming there is a macro to detect WinRT (something like __cplusplus_winrt or anything mentioned here) it should be possible to simply add

#ifdef SOME_WINRT_MACRO
#define DOCTEST_CONFIG_NO_MULTI_LANE_ATOMICS
#endif

But someone else should test this as I don't have access to a Windows machine atm.

@bnason-nf
Copy link
Contributor Author

Hi @onqtam,

This seems to be the right way to do the ifdef:

#if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_APP)
#define DOCTEST_CONFIG_NO_MULTI_LANE_ATOMICS
#endif

Would that be something you would be willing to add into doctest itself?

Thanks,
Benbuck

onqtam added a commit that referenced this issue Mar 21, 2021
@onqtam
Copy link
Member

onqtam commented Mar 21, 2021

Thanks! fixed in the dev branch

@onqtam onqtam closed this as completed Mar 21, 2021
onqtam added a commit that referenced this issue Mar 22, 2021
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