This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: gcc 3.2 compile issue when initialize value
- From: James Dennett <james dot dennett at gmail dot com>
- To: gcc-help at gcc dot gnu dot org
- Cc: Yixuan Huang <yixuan178 at gmail dot com>
- Date: Thu, 20 May 2010 21:35:21 -0700
- Subject: Re: gcc 3.2 compile issue when initialize value
- References: <AANLkTimciUxAHf0QZjBzTXZL_pCpKU48BulvaHlYCQjf@mail.gmail.com> <mcrzkzu1o39.fsf@dhcp-172-17-9-151.mtv.corp.google.com>
On Thu, May 20, 2010 at 10:26 AM, Ian Lance Taylor <iant@google.com> wrote:
> 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.
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