mercredi 6 septembre 2017

Why gcc does not recognise auto in for loops (but clang does)

I tried a very simple example with auto and gcc -Wall -Werror causes error with gcc but not with clang

main.cc

unsigned int f(){
  return 5;
}
int main(){
  for (auto i = 0; i < f(); i++){};
    return 0;
}

clang++ (3.8.1)

clang++ -std=c++11 -Wall -Werror -o main main.cc

compiles it well.

g++ (6.3.0)

g++ -std=c++11 -Wall -Werror -o main main.cc 
main.cc: In function ‘int main()’:
main.cc:5:22: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare]
   for (auto i = 0; i < f(); i++){};
                    ~~^~~~~
cc1plus: all warnings being treated as errors

Why?

Aucun commentaire:

Enregistrer un commentaire