Skip to content

New warning with Clang for non-header only mode #318

Closed
@mwinterb

Description

@mwinterb

All usages of "Data" in format.h trigger a new warning in clang, -Wundefined-var-template.

The fix is easy enough, after "typedef BasicData<> Data;", add:

#ifndef FMT_HEADER_ONLY
extern template struct BasicData<void>;
#endif

But I don't have access to enough compilers to identify the necessary feature test for extern template support, so I don't feel comfortable submitting a PR. GCC's C++11 status page just says "Yes" (going back to at least 4.3). Clang reports 2.9. I think MSVC has had support for them for "ages", possibly as far back as VS 2003, before they were standard. Intel is at least 11.1. Curiously, Visual Studio 2015's intellisense compiler complains 'extern template' cannot follow explicit instantiation of class "fmt::internal::BasicData<void>", which would suggest possibly this instead:

#ifndef FMT_HEADER_ONLY
#ifndef __INTELLISENSE__
extern template struct BasicData<void>;
#endif
#endif

Since it's a clang-only warning, one option would be to just use FMT_HAS_FEATURE, but I can't find a relevant feature test listed here:
http://clang.llvm.org/docs/LanguageExtensions.html#checks-for-standard-language-features
Another cheap option would be just be a check for __clang__ being defined, but that would prevent prevent working with a pre-2.9 Clang.

The warning was added to clang here http://reviews.llvm.org/rL266719 and discussed here http://reviews.llvm.org/D12326

Sorry, this is far too many words for a simple thing, I just didn't feel comfortable submitting a PR for something I was pretty certain wouldn't work everywhere, and I don't have enough experience supporting multiple compilers at once to make an optimal choice.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions