open-watcom / open-watcom-v2

Open Watcom V2.0 - Source code repository, Wiki, Latest Binary build, Archived builds including all installers for download.
Other
991 stars 163 forks source link

cout cannot accept string objects #749

Open doctorjei opened 3 years ago

doctorjei commented 3 years ago

When compiling for a DOS target (maybe others?), in both the DOS version and WINNT version of WATCOM, cout fails when passed a C++ string object.

Example:

(teststr.cpp)

#include <string>
#include <iostream>

int main()
{
    std::cout << std::string("Foo");
    return 0;
}

Compile with "wcl teststr.cpp" or "wpp teststr.cpp".

Expected result: Compiles program that prints "Foo"

Actual result: Compiler error:

teststr.cpp(7): Note! N717: col(15) left operand type is 'std::ostream __watcall (lvalue)'
teststr.cpp(7): Note! N718: col(15) right operand type is 'std::basic_string<char,std::char_traits<char>,std::allocator<char>>'
teststr.cpp: 106 lines, included 6081, no warnings, 1 error
jmalak commented 3 years ago

Sorry, my knowledge of C++ is small. Probably this construct is enabled in some higher standard of C++. I think Open Watcom C++ support C++98 standard with some extension.

doctorjei commented 3 years ago

Sorry, my markup was bad, so "#include <string>" was missing.

Yeah, I am sure it wasn't in Open Watcom C++ old version. If you want me to mark this as a "feature", I can. I'm even happy to try to fix this. It's actually not too hard a fix - I don't know the code base so well, but I know C++ standards pretty well. If there is anyone who works on the standard library, and can help me navigate, I can submit a pull request. :)

jmalak commented 3 years ago

You are welcome to any contribution to OW.

Now nobody is working on C++ compiler and standard library, due to very old standard support. There is some limitations by design of C++ compiler. I can help you with some basic information and OW build system C++ compiler sources are in bld/pluplus/c, bld/plusplus/a and bld/plusplus/h C++ run-time libraries are in bld/cpplib divided by appropriate class to subdirectories with cpp and h sudirectory for iostream classes it is bld/cpplib/iostream/cpp and bld/cpplib/iostream/h

jmalak commented 3 years ago

Anyway there are regression tests in bld/plustest subdirectory C++ compiler is little bit broken by previous changes from contributors (some I fixed but not all). There is problem with regard to "this" operator and floating-point constants folding that you get some bug from testing.

doctorjei commented 3 years ago

Of course that is what I did. :) I don't mind pitching in on these sorts of small issues (I will try to squeeze in some time to fix this one in particular). I wouldn't exactly call the string class new - it's C++98 after all! :) (But probably after the open sourcing of OW I'm guessing.)

I can get around these issues myself, but it was a head scratcher at first. I'd just like to help make it better, whether via bug reports or other means.

jmalak commented 3 years ago

Thanks. Any help is welcome.

pchapin commented 2 years ago

I have been involved with the Open Watcom C++ standard library, and I am the author of Open Watcom's standard string template.

As I recall, and it has been a while, this particular feature was left unimplemented in anticipation of overhauling the IOStreams library to make it more modern. The idea was that it didn't make sense to mix standard strings with an ancient IOStreams library. However, that overhaul has not happened (yet), so it is long overdue to patch this issue.

I'd be happy to assist with navigating the C++ library headers, etc., if you are still interested in contributing. Finally doing that IOStreams overhaul would be nice, but there are compiler limitations that hold that back. Anyway, that's probably a bigger project than you were thinking about!