This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: gcc 3.2 compile issue when initialize value
Yixuan Huang <yixuan178@gmail.com> 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@gcc.gnu.org. It would be appropriate for gcc-help@gcc.gnu.org.
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.
Ian