Comments (10)
@Snaipe, can you please make a more self-contained example (with main
instantiating a &ofstream
and then expected/actual outputs)? I will pass it along to some concerned folks. :)
from criterion.
@am11 I managed to come up with a self-contained example after a bit of tweaking around.
The issue arises only when:
- the stream class is inherited.
- the variable is typed as a reference of the inherited type (using a reference to
std::fstream
, for instance, works).
It seems to be a problem with the overload resolution picking up operator<<
for const void *
before the one for const char *
.
GCC & Clang seem to both handle the resolution gracefuly.
from criterion.
@Snaipe, thanks! On compiling with g++ 4.9, I am getting:
sh-4.3$ g++ --std=c++0x -o main *.cpp
main.cpp: In instantiation of 'my_basic_fstream<CharT>::my_basic_fstream(FILE*) [with CharT = char; FILE = _IO_FILE]':
main.cpp:21:13: required from 'static my_basic_fstream<CharT>& get_file_stream_<CharT>::call(FILE*) [with CharT = char; FILE = _IO_FILE]'
main.cpp:28:36: required from here
main.cpp:11:64: error: no matching function for call to 'std::basic_fstream<char>::basic_fstream(FILE*&)'
my_basic_fstream(std::FILE *f) : std::basic_fstream<char>(f) {}
^
main.cpp:11:64: note: candidates are:
In file included from main.cpp:3:0:
/usr/include/c++/4.9.2/fstream:834:7: note: std::basic_fstream<_CharT, _Traits>::basic_fstream(const string&, std::ios_base::openmode) [with _CharT = char; _Traits = std::char_tra
its<char>; std::string = std::basic_string<char>; std::ios_base::openmode = std::_Ios_Openmode]
basic_fstream(const std::string& __s,
^
/usr/include/c++/4.9.2/fstream:834:7: note: no known conversion for argument 1 from 'FILE* {aka _IO_FILE*}' to 'const string& {aka const std::basic_string<char>&}'
/usr/include/c++/4.9.2/fstream:819:7: note: std::basic_fstream<_CharT, _Traits>::basic_fstream(const char*, std::ios_base::openmode) [with _CharT = char; _Traits = std::char_trait
s<char>; std::ios_base::openmode = std::_Ios_Openmode]
basic_fstream(const char* __s,
^
/usr/include/c++/4.9.2/fstream:819:7: note: no known conversion for argument 1 from 'FILE* {aka _IO_FILE*}' to 'const char*'
/usr/include/c++/4.9.2/fstream:806:7: note: std::basic_fstream<_CharT, _Traits>::basic_fstream() [with _CharT = char; _Traits = std::char_traits<char>]
basic_fstream()
^
/usr/include/c++/4.9.2/fstream:806:7: note: candidate expects 0 arguments, 1 provided
from criterion.
I have further simplified the example with https://gist.github.com/am11/5341b87ce9eb6bdf2d15; added some comments. Removing one (apparently) unrelated and unused code line makes it compile and pass with VCR. But Clang and GCC failed due to same issue (that they give with the original example): missing function signature std::basic_fstream
which takes std::File*
.
from criterion.
@am11 the sample is using a MSVC-specific constructor (the one taking a FILE*), I did not make the GCC/Clang specific version because it did not happen on both of them.
I added a version which is GCC/Clang compatible, but it's not that interesting to be honest.
from criterion.
@Snaipe, I agree its looks like spaghetti now.
Nonetheless, I will proceed with reporting to VC team and cross-reference the issue here. FWIW, we reported some bugs after VS2015 RTM (released 29.07.2015) and they have fixed for VS2015 Update 1 (currently unreleased). For some reason their webcompiler site is down: http://webcompiler.cloudapp.net/, otherwise we could verify this one right away.
Thank you for this effort!
from criterion.
x-ref: https://connect.microsoft.com/VisualStudio/feedback/details/1816111.
from criterion.
@am11 I just reread the snippet you linked, but I think that the solution you provide to make it pass is a bit unfortunate: *unused_stream actively invokes undefined behaviour (you dereference a null smart pointer), and, well, the apparent "good" behaviour could be the result of an optimisation based on the fact that *unused_stream is invalid.
from criterion.
@Snaipe, I have received a reply (via private email) from VC team member (Stephan T. Lavavej aka STL):
I've reduced this and I believe it is a compiler bug. Here's a library-free repro:
C:\Temp>type meow.cpp
namespace Std { template <class Elem> struct CharTraits { }; template <class Elem, class Traits = CharTraits<Elem>> struct BasicOstream { void operator<<(const void *) = delete; }; template <class Traits> void operator<<(BasicOstream<char, Traits>&, const char *) = delete; } template <typename CharT> struct MyOstream : Std::BasicOstream<char> { }; MyOstream<char> * stream; #ifdef AVOID_TEMPLATE MyOstream<char>& call() { #else template <typename RandomT = double> MyOstream<char>& call() { #endif stream = new MyOstream<char>(); return *stream; } int main() { MyOstream<char>& f = call(); f << "Foo"; }C:\Temp>cl /EHsc /nologo /W4 meow.cpp
meow.cpp
meow.cpp(26): error C2280: 'void Std::BasicOstream<char,Std::CharTraits>::operator <<(const void *)': attempting t
o reference a deleted function
with [ Elem=char ]
meow.cpp(5): note: see declaration of 'Std::BasicOstream<char,Std::CharTraits>::operator <<'
with [ Elem=char ]
C:\Temp>cl /EHsc /nologo /W4 /DAVOID_TEMPLATE meow.cpp
meow.cpp
meow.cpp(26): error C2280: 'void Std::operator <<Std::CharTraits(Std::BasicOstream<Elem,Std::CharTraits> &
,const char *)': attempting to reference a deleted function
with [ Elem=char
meow.cpp(8): note: see declaration of 'Std::operator <<'
AVOID_TEMPLATE shouldn't affect the result of overload resolution, but it does. I'll pass this along to the compiler team.
from criterion.
Awesome.
In the meantime, I guess I can remove the template on call
(we use CharT = char anyways) since it's affecting resolution.
from criterion.
Related Issues (20)
- cannot import name 'TemporaryDirectory' from 'proto' (unknown location) HOT 1
- Can't compile on openSUSE HOT 37
- gt assertion misbehaves in new assertion API
- Testing on Slackware
- v2.4.2 preparation HOT 3
- Include debugbreak and klib in source zip file HOT 4
- How can i get started using this library ? HOT 2
- Failed to compile with criterion HOT 2
- failed to override main function on Ubuntu 22.04 HOT 3
- v2.4.2-rc tarball size is huge HOT 1
- How to use Criterion tests with code coverage? HOT 2
- pre-installed klib is never found by meson because it doesn't install cmake or pkgconfig files HOT 4
- Memory leak when using array type tags HOT 2
- `--show-skipped` tests option HOT 1
- Compilation fails with clang-16: incompatible function pointer types initializing 'cookie_read_function_t *' (aka 'long (*)(void *, char *, unsigned long)') with an expression of type 'cr_retcount (void *, char *, cr_count)' (aka 'int (void *, char *, int)')
- How to build it? HOT 2
- Redirections for `stdout` require buffering to be disabled for assertions like `cr_assert_stdout_eq_str` to pass.
- `cr_assert_std[out|err]_eq_str` doesn't show both values
- Writing output after asserting redirected output causes a crash. HOT 1
- libgit2 has been updated to version 1.7.0 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from criterion.