On Thu, May 20, 2010 at 10:26 AM, Ian Lance Taylor <iant@xxxxxxxxxx> wrote: > Yixuan Huang <yixuan178@xxxxxxxxx> writes: > >> I wrote following code: >> #include <iostream> >> #include <string> >> #include <dirent.h> >> int main() >> { >> struct dirent **namelist; >> int numberOfProcDirs; >> numberOfProcDirs=scandir("/proc", &namelist, 0, alphasort); >> //std::string temp(std::string(namelist[0]->d_name)+std::string("fdsfds")); >> //std::string temp(std::string(namelist[0]->d_name)+std::string("fdsf")); >> // The error occured >> std::string temp(std::string(namelist[0]->d_name)+std::string("cfdada")); >> //std::string temp; >> //temp = std::string(namelist[0]->d_name)+std::string("cfdada"); >> return 0; >> } >> >> When compiled under g++ 3.2, it would report compile error. >> >> test.cpp: In function `int main()': >> test.cpp:12: syntax error before `->' token >> >> But code can compile under gcc 4. >> >> Is this a limitation for gcc 3.2 when I used "std::string >> temp(std::string(namelist[0]->d_name)+std::string("cfdada"));" to >> initialize value. > > This question is not appropriate for the mailing list > gcc@xxxxxxxxxxxx It would be appropriate for gcc-help@xxxxxxxxxxxx > Please take any followups to gcc-help. Thanks. > > gcc 3.2 is quite old. The C++ parser was completely rewritten in gcc > 3.4 to improve correctness. It is quite likely that this is simply a > bug in gcc 3.2. You can probably avoid the bug by using temporary > variables. Or possibly by adding extra parens, as in std::string temp((std::string(namelist[0]->d_name)+std::string("fdsf"))); to avoid the old/buggy parser trying to interpret this line as a function declaration. -- James