473,467 Members | 1,612 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Bug in compiler?

In my compiler, the following works and does as expected:

#include <iterator>
#include <iostream>
#include <vector>
#include <algorithm>

int main()
{
using namespace std;
istream_iterator<char> inBegin(cin);
istream_iterator<char> inEnd;
vector<char> vec( inBegin, inEnd );
copy( vec.begin(), vec.end(), ostream_iterator<char>(cout, ", ") );
cout << '\n';
}

Whereas the following doesn't compile:

#include <iterator>
#include <iostream>
#include <vector>
#include <algorithm>

int main()
{
using namespace std;
vector<char> vec( istream_iterator<char>(cin),
istream_iterator<char>() );
copy( vec.begin(), vec.end(), ostream_iterator<char>(cout, ", ") );
cout << '\n';
}

main.cpp:11: error: request for member `begin' in
`vec(std::istream_iterator<char, char, std::char_traits<char>,
ptrdiff_t>, std::istream_iterator<char, char, std::char_traits<char>,
ptrdiff_t> (*)())', which is of non-aggregate type `std::vector<char,
std::allocator<char> > ()(std::istream_iterator<char, char,
std::char_traits<char>, ptrdiff_t>, std::istream_iterator<char, char,
std::char_traits<char>, ptrdiff_t> (*)())'

Is this a bug in the compiler, or something else?

--
Magic depends on tradition and belief. It does not welcome observation,
nor does it profit by experiment. On the other hand, science is based
on experience; it is open to correction by observation and experiment.
Feb 8 '06 #1
7 1379

"Daniel T." <po********@earthlink.net> wrote in message
news:po******************************@news.east.ea rthlink.net...
#include <iterator>
#include <iostream>
#include <vector>
#include <algorithm>

int main()
{
using namespace std;
vector<char> vec( istream_iterator<char>(cin),
istream_iterator<char>() );
The above line changes to:
vector<char> vec( istream_iterator<char>(cin), (istream_iterator<char>()) );
copy( vec.begin(), vec.end(), ostream_iterator<char>(cout, ", ") );
cout << '\n';
}
Is this a bug in the compiler, or something else?


No, the extra set of parenthesis is required.

Regards,
Sumit.
--
Sumit Rajan <su****@msdc.hcltech.com>
Feb 8 '06 #2

"Sumit Rajan" <su*********@gmail.com> wrote in message
news:44************@individual.net...

"Daniel T." <po********@earthlink.net> wrote in message
news:po******************************@news.east.ea rthlink.net...
#include <iterator>
#include <iostream>
#include <vector>
#include <algorithm>

int main()
{
using namespace std;
vector<char> vec( istream_iterator<char>(cin),
istream_iterator<char>() );


The above line changes to:
vector<char> vec( istream_iterator<char>(cin),
(istream_iterator<char>()) );
copy( vec.begin(), vec.end(), ostream_iterator<char>(cout, ", ") );
cout << '\n';
}


Is this a bug in the compiler, or something else?


No, the extra set of parenthesis is required.


Sorry, I should have explained further.

This is because the compiler could consider vec to be a function declaration
of a function that returns a vector<char>. It would take two parameters --
the first one being an istream_iterator<char> and the second one being a
unnamed function type taking no arguments and returning an
istream_iterator<char>.

Regards,
Sumit.
--
Sumit Rajan <su****@msdc.hcltech.com>
Feb 8 '06 #3
In article <44************@individual.net>,
"Sumit Rajan" <su*********@gmail.com> wrote:
"Daniel T." <po********@earthlink.net> wrote in message
news:po******************************@news.east.ea rthlink.net...
#include <iterator>
#include <iostream>
#include <vector>
#include <algorithm>

int main()
{
using namespace std;
vector<char> vec( istream_iterator<char>(cin),
istream_iterator<char>() );


The above line changes to:
vector<char> vec( istream_iterator<char>(cin), (istream_iterator<char>()) );
copy( vec.begin(), vec.end(), ostream_iterator<char>(cout, ", ") );
cout << '\n';
}


Is this a bug in the compiler, or something else?


No, the extra set of parenthesis is required.


Still doesn't work...

int main()
{
using namespace std;
vector<char> vec( istream_iterator<char>(cin),
(istream_iterator<char>()) ); // extra parens
copy( vec.begin(), vec.end(), ostream_iterator<char>(cout, ", ") );
cout << '\n';
}

main.cpp:27: error: parse error before `)' token

The error points to the vector<char> line...
--
Magic depends on tradition and belief. It does not welcome observation,
nor does it profit by experiment. On the other hand, science is based
on experience; it is open to correction by observation and experiment.
Feb 8 '06 #4

"Daniel T." <po********@earthlink.net> wrote in message
news:po******************************@news.east.ea rthlink.net...
Still doesn't work...

int main()
{
using namespace std;
vector<char> vec( istream_iterator<char>(cin),
(istream_iterator<char>()) ); // extra parens
copy( vec.begin(), vec.end(), ostream_iterator<char>(cout, ", ") );
cout << '\n';
}


Can you tell me which compiler you are using? I've managed to compile it
using VC++ 8.0, Comeau C++ , mingw 3.4.2 and VC++ 7.1.

Regards,
Sumit.
--
Sumit Rajan <su****@msdc.hcltech.com>
Feb 8 '06 #5
Daniel T. wrote:
In article <44************@individual.net>,
"Sumit Rajan" <su*********@gmail.com> wrote:

"Daniel T." <po********@earthlink.net> wrote in message
news:po******************************@news.east. earthlink.net...
#include <iterator>
#include <iostream>
#include <vector>
#include <algorithm>

int main()
{
using namespace std;
vector<char> vec( istream_iterator<char>(cin),
istream_iterator<char>() );


The above line changes to:
vector<char> vec( istream_iterator<char>(cin), (istream_iterator<char>()) );

copy( vec.begin(), vec.end(), ostream_iterator<char>(cout, ", ") );
cout << '\n';
}


Is this a bug in the compiler, or something else?


No, the extra set of parenthesis is required.

Still doesn't work...

int main()
{
using namespace std;
vector<char> vec( istream_iterator<char>(cin),
(istream_iterator<char>()) ); // extra parens
copy( vec.begin(), vec.end(), ostream_iterator<char>(cout, ", ") );
cout << '\n';
}

main.cpp:27: error: parse error before `)' token

The error points to the vector<char> line...


Are you sure? I just tested your code with Comeau online and it compiles
fine. The only difference from the originally posted code is the added
parentheses around the second argument passed to construct 'vec' object.

Could it be you're using a faulty compiler?

V
--
Please remove capital As from my address when replying by mail
Feb 8 '06 #6
In article <44************@individual.net>,
"Sumit Rajan" <su*********@gmail.com> wrote:
"Daniel T." <po********@earthlink.net> wrote in message
news:po******************************@news.east.ea rthlink.net...
Still doesn't work...

int main()
{
using namespace std;
vector<char> vec( istream_iterator<char>(cin),
(istream_iterator<char>()) ); // extra parens
copy( vec.begin(), vec.end(), ostream_iterator<char>(cout, ", ") );
cout << '\n';
}


Can you tell me which compiler you are using? I've managed to compile it
using VC++ 8.0, Comeau C++ , mingw 3.4.2 and VC++ 7.1.


I'm using apples Xcode IDE which uses GCC 3.3 on the back-end.

--
Magic depends on tradition and belief. It does not welcome observation,
nor does it profit by experiment. On the other hand, science is based
on experience; it is open to correction by observation and experiment.
Feb 8 '06 #7

Daniel T. wrote:
Can you tell me which compiler you are using? I've managed to compile it
using VC++ 8.0, Comeau C++ , mingw 3.4.2 and VC++ 7.1.


I'm using apples Xcode IDE which uses GCC 3.3 on the back-end.


<OT>

gcc's standard conformance got much better starting with gcc 3.4.

Quoting from http://gcc.gnu.org/gcc-3.4/changes.html:

"G++ is now much closer to full conformance to the ISO/ANSI C++
standard. This means, among other things, that a lot of invalid
constructs which used to be accepted in previous versions will now be
rejected. It is very likely that existing C++ code will need to be
fixed. This document lists some of the most common issues. A
hand-written recursive-descent C++ parser has replaced the YACC-derived
C++ parser from previous GCC releases. The new parser contains much
improved infrastructure needed for better parsing of C++ source codes,
handling of extensions, and clean separation (where possible) between
proper semantics analysis and parsing. The new parser fixes many bugs
that were found in the old parser."

Sounds like it's time for you to upgrade.

</OT>

Best regards,

Tom

Feb 8 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Jeff Epler | last post by:
Hello. Recently, Generator Comprehensions were mentioned again on python-list. I have written an implementation for the compiler module. To try it out, however, you must be able to rebuild...
13
by: Bryan Parkoff | last post by:
You may notice that switch (...) is much faster than function that can gain a big improved performance because it only use JMP instruction however function is required to use CALL, PUSH, and POP...
10
by: Bjorn | last post by:
I'm using interfaces in C++ by declaring classes with only pure virtual methods. If then someone wants to implement the interface they needs to inherit from the class. If the implementing class...
7
by: Tao Wang | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi, I saw cuj's conformance roundup, but the result is quite old. I think many people like me want to know newer c++ standard conformance test...
14
by: joshc | last post by:
I'm writing some C to be used in an embedded environment and the code needs to be optimized. I have a question about optimizing compilers in general. I'm using GCC for the workstation and Diab...
16
by: pj | last post by:
(Was originally, probably wrongly, posted to the vc subgroup.) (This doesn't appear to be a c# problem, but a problem with a bug in the Visual Studio c# compiler, but, any help will be welcome...)...
0
by: rollasoc | last post by:
Hi, I seem to be getting a compiler error Internal Compiler Error (0xc0000005 at address 535DB439): likely culprit is 'BIND'. An internal error has occurred in the compiler. To work around...
3
by: Mark Rockman | last post by:
------ Build started: Project: USDAver2, Configuration: Debug .NET ------ Preparing resources... Updating references... Performing main compilation... error CS0583: Internal Compiler Error...
6
by: toton | last post by:
Hi, Anyone have a link to comparative study of different C++ compilers and how much they conform to C++ language standard? Most of the big platforms I know have GCC which well supports C++...
41
by: Miroslaw Makowiecki | last post by:
Where can I download Comeau compiler as a trial version? Thanks in advice.
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.