public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* c++/10364: compile error using vector, comma operator and for loop
@ 2003-04-09 19:36 pdemarco
  0 siblings, 0 replies; 5+ messages in thread
From: pdemarco @ 2003-04-09 19:36 UTC (permalink / raw)
  To: gcc-gnats


>Number:         10364
>Category:       c++
>Synopsis:       compile error using vector, comma operator and for loop
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Apr 09 19:36:01 UTC 2003
>Closed-Date:
>Last-Modified:
>Originator:     Me
>Release:        g++ (GCC) 3.2 (mingw special 20020817-1)
>Organization:
>Environment:
Windows 2000
>Description:
Here is a strange little bug where the addition of a comma operator kills the compile.  Below it works with 2 ints.
Regards.
--Paul

#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main()
{
#ifndef FAILS_COMPILE
	std::vector<string>::iterator oCMIter;
	std::vector<string> bites;

	for ( int iI = 3, oCMIter = bites.begin();
				oCMIter != bites.end();
				oCMIter++, iI++ )
	{
		cout << "hello" << endl;
	}
#else
	// works
	int iOne;
	for ( int iI = 3, iOne = 0; iOne < 10; iOne++, iI++ )
	{
		cout << "hello" << endl;
	}
#endif

	return 0;
}
>How-To-Repeat:
g++ foo.cpp
>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: c++/10364: compile error using vector, comma operator and for loop
@ 2003-04-09 20:58 bangerth
  0 siblings, 0 replies; 5+ messages in thread
From: bangerth @ 2003-04-09 20:58 UTC (permalink / raw)
  To: gcc-bugs, gcc-prs, nobody, pdemarco

Synopsis: compile error using vector, comma operator and for loop

State-Changed-From-To: open->closed
State-Changed-By: bangerth
State-Changed-When: Wed Apr  9 20:58:58 2003
State-Changed-Why:
    Not a bug

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=10364


^ permalink raw reply	[flat|nested] 5+ messages in thread

* RE: c++/10364: compile error using vector, comma operator and for loop
@ 2003-04-09 20:36 DeMarco, Paul
  0 siblings, 0 replies; 5+ messages in thread
From: DeMarco, Paul @ 2003-04-09 20:36 UTC (permalink / raw)
  To: nobody; +Cc: gcc-prs

The following reply was made to PR c++/10364; it has been noted by GNATS.

From: "DeMarco, Paul" <pdemarco@ppg.com>
To: 'Phil Edwards' <phil@jaj.com>
Cc: gcc-gnats@gcc.gnu.org
Subject: RE: c++/10364: compile error using vector, comma operator and for
	 loop
Date: Wed, 9 Apr 2003 16:28:55 -0400 

 Shamed.
 I mis-copied the bites.begin()  as bites.begin
 
 :(
 
 -----Original Message-----
 From: Phil Edwards [mailto:phil@jaj.com]
 Sent: Wednesday, April 09, 2003 4:11 PM
 To: DeMarco, Paul
 Cc: gcc-gnats@gcc.gnu.org
 Subject: Re: c++/10364: compile error using vector, comma operator and
 for loop
 
 
 On Wed, Apr 09, 2003 at 07:34:56PM -0000, pdemarco@ppg.com wrote:
 > Here is a strange little bug where the addition of a comma operator kills the compile.  Below it works with 2 ints.
 > Regards.
 > --Paul
 > 
 
 You didn't include the error messages you received.  Here's my guess:
 
 
 > 	std::vector<string>::iterator oCMIter;
 > 	std::vector<string> bites;
 > 
 > 	for ( int iI = 3, oCMIter = bites.begin();
 > 				oCMIter != bites.end();
 > 				oCMIter++, iI++ )
 > 	{
 > 		cout << "hello" << endl;
 > 	}
 
 Buggy code.  The 'init' statement in a for loop can only be a simple
 declaration or an expression.
 
 "int iI = 3, oCMIter = bites.begin();" declares two integers, one
 called iI (initialized to 3) and another called oCMIter, initialized to
 bites.begin().  But there's no conversion from an iterator (the return
 value from bites.begin()) to an integer (the oCMIter being defined and
 initialized), so you get an error.
 
 The std::vector<string>::iterator oCMIter outside the for loop is shadowed
 by the int oCMIter inside the loop.  You would get a shadowing warning,
 /if/ it were legal code.
 
 Move the iI declaration out of the for-init-statement.  That way it becomes
 an expression instead of a declaration:
 
   	std::vector<string>::iterator oCMIter;
   	std::vector<string> bites;
     int iI;
   
   	for ( iI = 3, oCMIter = bites.begin(); ...
 
 
 Phil
 
 -- 
 To err is human; to forgive is simply not our policy.
     - MIT Assassination Club


^ permalink raw reply	[flat|nested] 5+ messages in thread

* RE: c++/10364: compile error using vector, comma operator and for loop
@ 2003-04-09 20:26 DeMarco, Paul
  0 siblings, 0 replies; 5+ messages in thread
From: DeMarco, Paul @ 2003-04-09 20:26 UTC (permalink / raw)
  To: nobody; +Cc: gcc-prs

The following reply was made to PR c++/10364; it has been noted by GNATS.

From: "DeMarco, Paul" <pdemarco@ppg.com>
To: 'Phil Edwards' <phil@jaj.com>
Cc: gcc-gnats@gcc.gnu.org
Subject: RE: c++/10364: compile error using vector, comma operator and for
	 loop
Date: Wed, 9 Apr 2003 16:25:05 -0400 

 Phil,
 	My error message was something like that..
 
 Here's another similar problem without the "for".  With two examples in it.  One with a string & one with vector assignment.
 I've even used parenthesis to ensure my intentions are explicit.  This is prefectly valid C++ code.
 
 #include <iostream>
 #include <string>
 #include <vector>
 
 using namespace std;
 
 int main()
 {
 	std::vector<string>::iterator oCMIter;
 	std::vector<string> bites;
 	int iI;
 	string sYes;
 	(iI = 3) , ( oCMIter = bites.begin );	// This WON'T COMPILE
 	(iI = 3), ( sYes = "Yes" );				// this works fine.
 
 	return 0;
 }
 
 My Error message was:
 foo.cpp: In function `int main()':
 foo.cpp:13: no match for `__gnu_cxx::__normal_iterator<std::string*,
    std::vector<std::string, std::allocator<std::string> > >& = <unknown type>'
    operator
 D:/MinGW/include/c++/3.2/bits/stl_iterator.h:571: candidates are:
    __gnu_cxx::__normal_iterator<std::string*, std::vector<std::string,
    std::allocator<std::string> > >& __gnu_cxx::__normal_iterator<std::string*,
    std::vector<std::string, std::allocator<std::string> > >::operator=(const
    __gnu_cxx::__normal_iterator<std::string*, std::vector<std::string,
    std::allocator<std::string> > >&)
 
 Thanks,
 	-- Paul
 
 
 -----Original Message-----
 From: Phil Edwards [mailto:phil@jaj.com]
 Sent: Wednesday, April 09, 2003 4:11 PM
 To: DeMarco, Paul
 Cc: gcc-gnats@gcc.gnu.org
 Subject: Re: c++/10364: compile error using vector, comma operator and
 for loop
 
 
 On Wed, Apr 09, 2003 at 07:34:56PM -0000, pdemarco@ppg.com wrote:
 > Here is a strange little bug where the addition of a comma operator kills the compile.  Below it works with 2 ints.
 > Regards.
 > --Paul
 > 
 
 You didn't include the error messages you received.  Here's my guess:
 
 
 > 	std::vector<string>::iterator oCMIter;
 > 	std::vector<string> bites;
 > 
 > 	for ( int iI = 3, oCMIter = bites.begin();
 > 				oCMIter != bites.end();
 > 				oCMIter++, iI++ )
 > 	{
 > 		cout << "hello" << endl;
 > 	}
 
 Buggy code.  The 'init' statement in a for loop can only be a simple
 declaration or an expression.
 
 "int iI = 3, oCMIter = bites.begin();" declares two integers, one
 called iI (initialized to 3) and another called oCMIter, initialized to
 bites.begin().  But there's no conversion from an iterator (the return
 value from bites.begin()) to an integer (the oCMIter being defined and
 initialized), so you get an error.
 
 The std::vector<string>::iterator oCMIter outside the for loop is shadowed
 by the int oCMIter inside the loop.  You would get a shadowing warning,
 /if/ it were legal code.
 
 Move the iI declaration out of the for-init-statement.  That way it becomes
 an expression instead of a declaration:
 
   	std::vector<string>::iterator oCMIter;
   	std::vector<string> bites;
     int iI;
   
   	for ( iI = 3, oCMIter = bites.begin(); ...
 
 
 Phil
 
 -- 
 To err is human; to forgive is simply not our policy.
     - MIT Assassination Club


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: c++/10364: compile error using vector, comma operator and for loop
@ 2003-04-09 20:16 Phil Edwards
  0 siblings, 0 replies; 5+ messages in thread
From: Phil Edwards @ 2003-04-09 20:16 UTC (permalink / raw)
  To: nobody; +Cc: gcc-prs

The following reply was made to PR c++/10364; it has been noted by GNATS.

From: Phil Edwards <phil@jaj.com>
To: pdemarco@ppg.com
Cc: gcc-gnats@gcc.gnu.org
Subject: Re: c++/10364: compile error using vector, comma operator and for loop
Date: Wed, 9 Apr 2003 16:10:52 -0400

 On Wed, Apr 09, 2003 at 07:34:56PM -0000, pdemarco@ppg.com wrote:
 > Here is a strange little bug where the addition of a comma operator kills the compile.  Below it works with 2 ints.
 > Regards.
 > --Paul
 > 
 
 You didn't include the error messages you received.  Here's my guess:
 
 
 > 	std::vector<string>::iterator oCMIter;
 > 	std::vector<string> bites;
 > 
 > 	for ( int iI = 3, oCMIter = bites.begin();
 > 				oCMIter != bites.end();
 > 				oCMIter++, iI++ )
 > 	{
 > 		cout << "hello" << endl;
 > 	}
 
 Buggy code.  The 'init' statement in a for loop can only be a simple
 declaration or an expression.
 
 "int iI = 3, oCMIter = bites.begin();" declares two integers, one
 called iI (initialized to 3) and another called oCMIter, initialized to
 bites.begin().  But there's no conversion from an iterator (the return
 value from bites.begin()) to an integer (the oCMIter being defined and
 initialized), so you get an error.
 
 The std::vector<string>::iterator oCMIter outside the for loop is shadowed
 by the int oCMIter inside the loop.  You would get a shadowing warning,
 /if/ it were legal code.
 
 Move the iI declaration out of the for-init-statement.  That way it becomes
 an expression instead of a declaration:
 
   	std::vector<string>::iterator oCMIter;
   	std::vector<string> bites;
     int iI;
   
   	for ( iI = 3, oCMIter = bites.begin(); ...
 
 
 Phil
 
 -- 
 To err is human; to forgive is simply not our policy.
     - MIT Assassination Club


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2003-04-09 20:58 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-04-09 19:36 c++/10364: compile error using vector, comma operator and for loop pdemarco
2003-04-09 20:16 Phil Edwards
2003-04-09 20:26 DeMarco, Paul
2003-04-09 20:36 DeMarco, Paul
2003-04-09 20:58 bangerth

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).