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

Jack Howarth howarth at bromo.med.uc.edu
Fri May 20 06:29:50 PDT 2011


   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



More information about the cfe-dev mailing list