mardi 24 avril 2012

Warning gcc

Un warning bizarre de gcc. En cherchant sur la mailing list, il existe un bug similaire qui a été résolu par le passé, mais on dirait que celui là courrait encore dans gcc 4.4 (corrigé en revanche dans 4.6). Ce cas assez tordu cause un warning se plaignant que certains chemins n'ont pas de return:

// test.cpp
// Compile with:
// g++ -c test.cpp -O0 -o test -W -Wall

// Compiling with -O3 fixes the warning

#include 
#include 
 
int a()
{
  std::string str; // Removing this line fixes the warning
  int state = 1;
  if(state != 1 && state != 2) // Only having 1 condition fixes the warning
  {
    throw std::runtime_error("abc");
    //return 0; // Replacing the throw by return 0 fixes the warning
  }
  else
  {
    return 0;
  }
}

Aucun commentaire: