clang++ bug or strict compliance?

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++)
                        ^
clang_bug.cc:19:21: error: assigning to 'const char *' from incompatible type 'char'
               *I++ = tolower(*Start);
                    ^ ~~~~~~~~~~~~~~~
clang_bug.cc:21:22: error: assigning to 'const char *' from incompatible type 'char'
                *I++ = '=';
                     ^ ~~~
clang_bug.cc:23:22: error: assigning to 'const char *' from incompatible type 'char'
                *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;
        for (; Start != End; Start++)
           {
             if (isspace(*Start) == 0)
               *I++ = tolower(*Start);
             if (*Start == '<' && Start[1] != '<' && Start[1] != '=')
                *I++ = '=';
             if (*Start == '>' && Start[1] != '>' && Start[1] != '=')
                *I++ = '=';
           }
      }
}

and is compiled simply as 'clang++ -c clang_bug.cc'. I have to currently
patch this as...

--- clang_bug.cc.orig 2011-05-20 09:24:16.000000000 -0400
+++ clang_bug.cc 2011-05-20 09:25:19.000000000 -0400
@@ -12,15 +12,15 @@
         extern char isspace(const char);
         extern char tolower(const char);

- char *I = S;
+ char *J = S;
         for (; Start != End; Start++)
            {
              if (isspace(*Start) == 0)
- *I++ = tolower(*Start);
+ *J++ = tolower(*Start);
              if (*Start == '<' && Start[1] != '<' && Start[1] != '=')
- *I++ = '=';
+ *J++ = '=';
              if (*Start == '>' && Start[1] != '>' && Start[1] != '=')
- *I++ = '=';
+ *J++ = '=';
      }
       }
}

for clang++ to accept this. This additional strictness doesn't seem to be described
on the clang web site at http://clang.llvm.org/compatibility.html. Is this expected
behavior or should I open a PR?
       Jack

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

Sebastian

While building packages under fink using clang/clang++ 3.0svn, I ran into
the following code fragment, derived from apt, which produces the error...

(snip)

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

Sebastian

Comeau C++ agrees:

Comeau C/C++ 4.3.10.1 (Oct 6 2008 11:28:09) for ONLINE_EVALUATION_BETA2
Copyright 1988-2008 Comeau Computing. All rights reserved.
MODE:strict errors C++ C++0x_extensions

"ComeauTest.c", line 15: error: "I", declared in for-loop
initialization, may not be
          redeclared in this scope
         char *I = S;
               ^

"ComeauTest.c", line 16: warning: variable "Start" is used before its
value is set
         for (; Start != End; Start++)
                ^

"ComeauTest.c", line 16: warning: variable "End" is used before its value is set
         for (; Start != End; Start++)
                         ^