[cfe-dev] clang++ bug or strict compliance?

Sebastian Redl sebastian.redl at getdesigned.at
Fri May 20 07:15:30 PDT 2011


On 20.05.2011, at 07:29, Jack Howarth wrote:

>   While building packages under fink using clang/clang++ 3.0svn, I ran into
> the following code fragment, derived from apt, which produces the error...
> 
> clang_bug.cc:15:8: error: redefinition of 'I' with a different type
>        char *I = S;
>              ^
> clang_bug.cc:8:25: note: previous definition is here
>      for (const char **I = Sections; *I != 0; I++)
>                        ^
> 4 errors generated.
> 
> under clang++ but is tolerated by clang, Apple's g++ 4.2.1, Apple's llvm-g++ 4.2.1 and
> FSF g++ 4.6.0. The code fragement is...
> 
>      int main(void) {
>      const char *Sections[] ={"Installed-Size",
>                            "Depends",
>                            "Pre-Depends",
>                            "Conflicts",
>                            "Replaces",0}; 
>      char S[1024];
>      for (const char **I = Sections; *I != 0; I++)
>      {
>        const char *Start;
>        const char *End;
>        extern char isspace(const char);
>        extern char tolower(const char);
> 
>        char *I = S;

Clang is right. A variable declared in a condition cannot be hidden by a variable in the immediately contained block.

Sebastian



More information about the cfe-dev mailing list