Standard library bug (?)

Standard library bug (?)

Post by Dave Bryan » Fri, 23 Apr 1999 04:00:00



/* The following code generates a compiler error in one of the standard
include libraries.
I am compiling it with Code Warrior IDE version 3.2, Standard Console
C++ PPC.

I am a little confused by this one...

David. */

#include<iostream>
#include<vector.h>

using namespace std;  //introduces namespace std

class myclass {
        public:
                myclass();
                ~myclass();

Quote:};

myclass::myclass() {
        vector<int> dummy(1,1);

Quote:}

myclass::~myclass() { }

int main()
{      

        return 0;

Quote:}

 
 
 

Standard library bug (?)

Post by Howard Hinna » Fri, 23 Apr 1999 04:00:00




> /* The following code generates a compiler error in one of the standard
> include libraries.
> I am compiling it with Code Warrior IDE version 3.2, Standard Console
> C++ PPC.

> I am a little confused by this one...

> David. */

> #include<iostream>
> #include<vector.h>

> using namespace std;  //introduces namespace std

> class myclass {
>         public:
>                 myclass();
>                 ~myclass();
> };

> myclass::myclass() {
>         vector<int> dummy(1,1);
> }

> myclass::~myclass() { }

> int main()
> {      

>         return 0;
> }

The compiler is mistaking (1, 1) as a pair of input iterators instead of
size and initial value (though this is a lib problem, not a compiler
problem).  The C++ standard changed in Nov. '97 (then a draft) to fix this
problem.  By Dec. '98 Metrowerks had implemented this fix.  If you
download the free patch "Pro 4.1 MacOS Compiler 2.2.1 & MSL 4.1.05 for
Mac" on the Metrowerks web site, that ought to fix this problem.

Alternatively you could modify your code like this as a work around:

         vector<int> dummy(size_t(1),1);

A third alternative would be to disable member templates in the lib by
commenting out MSIPL_MEMBER_TEMPLATE in mcompile.h and recompile your C++
lib.

-Howard

 
 
 

1. CWP5 Standard C++ I/O Libraries bug?

I run into these line of code:

using namespace std; // for semplicity's sake
...
ifstream in_file("a_file");
// check on file opening OK
cout << in_file.rdbuf();
cout << "some message" << endl;
...
The ouput was:
file content properly displayed, but "some message" was missing!

Trying to understand why, I inserted some diagnostic code;
...
ios::iostate ios1 = in_file.rdstate();
ios::iostate ios2 = cout.rdstate();
cout << ios1 << endl;
cout << ios2 << endl;

        cout << in_file.rdbuf();

ios1 = in_file.rdstate();
ios2 = cout.rdstate();
cout.clear();  
cout << ios1 << endl;
cout << ios2 << endl;

        cout << "some message" << endl;
        ....    

The ouput was:
0               // OK!  in_file's failbit, badbit, eofbit all cleared
0               // OK!  cout's   failbit, badbit, eofbit all cleared
file content properly displayed
0               // ?? in_file's failbit, badbit,eofbit all cleared
        //      shouldn't be failbit and eofbit set?
4               // ?? cout's  failbit set, badbit and eofbit cleared
                //       shouldn't be failbit cleared too?
some message

I took a look at the standard and found a reference in
27.6.2.5.3                                              [lib.ostream.inserters]
subsections 5 up to 9 that seem to confirm that CWP5
implemantation of rdbuf() is buggy because it appears
to always call setstate(failbit). Am I wrong?

Best regards, Aldo.

2. Problem: printing Postscript files on HP LJ IIP connected to Sparc10

3. New Metrowerks Standard Library i/o problem?

4. TCP/UDP ports for Microsoft netmeeting

5. Need Help with Standard Library Wierdness

6. Determinizing non-deterministic finite automata

7. Including the Standard Library as a sub-project

8. In-Proc COM server and passing back strings...

9. Standard Template Library

10. Why does The C++ Standard Library page 203 example not compile?

11. standard 'c' library that sets errno

12. standard library algorithm: unique_copy

13. Standard Components library?