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

compilation issue in MSVC when defining DOCTEST_THREAD_LOCAL to static #458

Closed
apanloco opened this issue Jan 17, 2021 · 4 comments
Closed

Comments

@apanloco
Copy link

Description

define DOCTEST_THREAD_LOCAL to static:

#define DOCTEST_THREAD_LOCAL static
#define DOCTEST_CONFIG_IMPLEMENT
#include <doctest/doctest.h>

Steps to reproduce

build

Extra information

  • doctest version: v2.4.4 (conan.io)
  • Operating System: Windows 10
  • Compiler+version: Visual Studio Version 16.8.3

The reason is this place

#ifdef DOCTEST_PLATFORM_WINDOWS
    struct DebugOutputWindowReporter : public ConsoleReporter
    {
        DOCTEST_THREAD_LOCAL static std::ostringstream oss;

        DebugOutputWindowReporter(const ContextOptions& co)
                : ConsoleReporter(co, oss) {}

where static is, probably by accident, put after DOCTEST_THREAD_LOCAL

in other places it looks like this:

    DOCTEST_THREAD_LOCAL std::ostringstream DebugOutputWindowReporter::oss;

or

    DOCTEST_THREAD_LOCAL std::ostringstream g_oss; // NOLINT(cert-err58-cpp)

etc...

but this particular case is DOCTEST_PLATFORM_WINDOWS-only.

thanks!

@apanloco apanloco changed the title compiler issues in MSVC when defining DOCTEST_THREAD_LOCAL to static compilation issue in MSVC when defining DOCTEST_THREAD_LOCAL to static Jan 17, 2021
@onqtam
Copy link
Member

onqtam commented Jan 17, 2021

The reason that thread local there is static is that it's a class member and in all other cases the thread locals are globals and thus they don't need static. If you want to simply not have thread locals because you don't have access to a fully conformant C++11 compiler or you won't be doing anything from multiple threads you can simply define DOCTEST_THREAD_LOCAL without giving it a value - you don't have to set it to static. Let me know if this helps.

@apanloco
Copy link
Author

that works well for me
i got the inspiration from this commit: 21f2504
what would the difference be, anything i should keep in mind?

@onqtam
Copy link
Member

onqtam commented Jan 17, 2021

there's another commit after the one you linked where I'm removing the static from the define - I guess I must have realized that I cannot simply set it to static: b031dd0

@apanloco
Copy link
Author

thanks for the help!

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