http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56498
Bug #: 56498 Summary: invalid declaration of string iterator on comma separated list Classification: Unclassified Product: gcc Version: 4.7.2 Status: UNCONFIRMED Severity: minor Priority: P3 Component: c++ AssignedTo: unassig...@gcc.gnu.org ReportedBy: hgkam...@hotmail.com Trying to declare and initialize two iterators in a comma separated list results in an invalid declaration error. workaround, declare the iterator before the for statement. a.cpp: In function ‘bool ispalindrome(std::string&)’: a.cpp:7:37: error: invalid declaration of ‘std::basic_string<char>::reverse_iterator’ a.cpp:7:62: error: expected ‘;’ before ‘i2’ a.cpp:7:62: error: ‘i2’ was not declared in this scope a.cpp:7:89: error: expected ‘)’ before ‘;’ token a.cpp:7:92: error: ‘i1’ was not declared in this scope a.cpp:7:98: error: ‘i2’ was not declared in this scope a.cpp:7:102: error: expected ‘;’ before ‘)’ token #include <iostream> #include <string> using namespace std; bool ispalindrome(string &s){ // replace with below line to see the error. // for(string::iterator i1=s.begin(),string::reverse_iterator i2=s.rbegin() ; i1!=s.end(); i1++, i2++) { string::reverse_iterator i2=s.rbegin(); for(string::iterator i1=s.begin() ; i1!=s.end(); i1++, i2++) { if (*i1!=*i2) return false; } return true; } int main() { string s; cin >> s ; if (ispalindrome(s)) { cout << "First\n"; }else{ cout << "Second\n"; } return 0; }