You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The following snippet fails to compile with Visual Studio 2017.1 and single-header doctest.h from v1.2.0.
I also see the same compiler error under VS 2015.3.
#include<thread>
#include"doctest.h"
It fails with the following compile error:
c:\path\to\doctest.h(830): error C2248: 'std::thread::id::id': cannot access private member declared in class 'std::thread::id'
c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.10.25017\include\thread(165): note: see declaration of 'std::thread::id::id'
c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.10.25017\include\thread(149): note: see declaration of 'std::thread::id'
c:\path\to\doctest.h(836): note: see reference to class template instantiation 'doctest::detail::has_insertion_operator_impl::has_insertion_operator<T>' being compiled
with
[
T=char
]
c:\path\to\doctest.h(1828): note: see reference to class template instantiation 'doctest::detail::has_insertion_operator<T>' being compiled
with
[
T=char
]
c:\path\to\doctest.h(1833): note: see reference to class template instantiation 'doctest::detail::StringStream<T>' being compiled
with
[
T=char
]
c:\path\to\doctest.h(1863): note: see reference to function template instantiation 'void doctest::detail::toStream<T>(std::ostream *,const T &)' being compiled
with
[
T=char
]
c:\path\to\doctest.h(1862): note: while compiling class template member function 'void doctest::detail::ContextBuilder::Capture<char>::toStream(std::ostream *) const'
c:\path\to\doctest.h(1869): note: see reference to class template instantiation 'doctest::detail::ContextBuilder::Capture<char>' being compiled
However, if I add #include <ostream> before including "doctest.h" it compiles fine.
It seems like it's missing the declaration of operator<<(std::ostream&, char) from <ostream>.
This means that when it's instantiating doctest::detail::has_insertion_operator<char> it's only finding the operator<<(std::ostream&, std::thread::id) overload and thus trying to convert the char value to a std::thread::id via the private constructor, which takes an unsigned int.
The doctest.h header includes standard headers inside a section guarded by #if defined(DOCTEST_CONFIG_IMPLEMENT) || !defined(DOCTEST_SINGLE_HEADER).
This means that if you're using the single-header version then unless you have defined either the DOCTEST_CONFIG_IMPLEMENTATION_IN_DLL or the DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN macro then doctest.h won't pull in any of the standard headers that define the built-in ostream operators.
I think doctest.h needs to #include <ostream> to get visibility of the std::ostream& operator<<(std::ostream&, char) overload as it's required by the ContextBuilder::Chunk type, which instantiates Capture<char>, which instantiates detail::toStream<T>(std::ostream&, const char&), which instantiates detail::StringStream<char>, which instantiates detail::has_insertion_operator<char>, which tries to sink a char value into a std::ostream.
Or am I missing something in how I'm using the library?
I've tried defining DOCTEST_CONFIG_USE_IOSFWD but this doesn't fix the problem (<iosfwd> doesn't declare operator<< overloads under MSVC).
The text was updated successfully, but these errors were encountered:
The following snippet fails to compile with Visual Studio 2017.1 and single-header doctest.h from v1.2.0.
I also see the same compiler error under VS 2015.3.
It fails with the following compile error:
However, if I add
#include <ostream>
before including"doctest.h"
it compiles fine.It seems like it's missing the declaration of
operator<<(std::ostream&, char)
from<ostream>
.This means that when it's instantiating
doctest::detail::has_insertion_operator<char>
it's only finding theoperator<<(std::ostream&, std::thread::id)
overload and thus trying to convert thechar
value to astd::thread::id
via the private constructor, which takes anunsigned int
.The
doctest.h
header includes standard headers inside a section guarded by#if defined(DOCTEST_CONFIG_IMPLEMENT) || !defined(DOCTEST_SINGLE_HEADER)
.This means that if you're using the single-header version then unless you have defined either the
DOCTEST_CONFIG_IMPLEMENTATION_IN_DLL
or theDOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
macro then doctest.h won't pull in any of the standard headers that define the built-in ostream operators.I think
doctest.h
needs to#include <ostream>
to get visibility of thestd::ostream& operator<<(std::ostream&, char)
overload as it's required by theContextBuilder::Chunk
type, which instantiatesCapture<char>
, which instantiatesdetail::toStream<T>(std::ostream&, const char&)
, which instantiatesdetail::StringStream<char>
, which instantiatesdetail::has_insertion_operator<char>
, which tries to sink achar
value into astd::ostream
.Or am I missing something in how I'm using the library?
I've tried defining
DOCTEST_CONFIG_USE_IOSFWD
but this doesn't fix the problem (<iosfwd>
doesn't declareoperator<<
overloads under MSVC).The text was updated successfully, but these errors were encountered: