]> git.sesse.net Git - stockfish/commitdiff
Added -Wshadow option and fixed resulting warnings
authorMarco Costalba <mcostalba@gmail.com>
Mon, 4 Apr 2011 07:53:44 +0000 (09:53 +0200)
committerMarco Costalba <mcostalba@gmail.com>
Mon, 4 Apr 2011 11:11:01 +0000 (12:11 +0100)
No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
src/Makefile
src/book.cpp
src/book.h
src/history.h
src/position.cpp
src/position.h
src/ucioption.cpp
src/ucioption.h

index 549b7867cbd8d53ab15f31f0400ce65198d2b8fd..9b8d5982aff29fbd2a210cc16f4551c568a95854 100644 (file)
@@ -228,11 +228,11 @@ endif
 CXXFLAGS = -g -Wall -Wcast-qual -fno-exceptions -fno-rtti $(EXTRACXXFLAGS)
 
 ifeq ($(comp),gcc)
 CXXFLAGS = -g -Wall -Wcast-qual -fno-exceptions -fno-rtti $(EXTRACXXFLAGS)
 
 ifeq ($(comp),gcc)
-       CXXFLAGS += -ansi -pedantic -Wno-long-long -Wextra
+       CXXFLAGS += -ansi -pedantic -Wno-long-long -Wextra -Wshadow
 endif
 
 ifeq ($(comp),mingw)
 endif
 
 ifeq ($(comp),mingw)
-       CXXFLAGS += -Wno-long-long -Wextra
+       CXXFLAGS += -Wextra -Wshadow
 endif
 
 ifeq ($(comp),icc)
 endif
 
 ifeq ($(comp),icc)
index a918d043b619e6915a483400398445c1eeb96d88..d6dcf6cb3c8bd84798c5551ef92396f0b051c901 100644 (file)
@@ -367,8 +367,8 @@ Book::~Book() {
 
 void Book::close() {
 
 
 void Book::close() {
 
-  if (is_open())
-      ifstream::close();
+  if (bookFile.is_open())
+      bookFile.close();
 
   bookName = "";
 }
 
   bookName = "";
 }
@@ -381,17 +381,17 @@ void Book::open(const string& fileName) {
   // Close old file before opening the new
   close();
 
   // Close old file before opening the new
   close();
 
-  ifstream::open(fileName.c_str(), ifstream::in | ifstream::binary);
+  bookFile.open(fileName.c_str(), ifstream::in | ifstream::binary);
 
   // Silently return when asked to open a non-exsistent file
 
   // Silently return when asked to open a non-exsistent file
-  if (!is_open())
+  if (!bookFile.is_open())
       return;
 
   // Get the book size in number of entries
       return;
 
   // Get the book size in number of entries
-  seekg(0, ios::end);
-  bookSize = long(tellg()) / sizeof(BookEntry);
+  bookFile.seekg(0, ios::end);
+  bookSize = long(bookFile.tellg()) / sizeof(BookEntry);
 
 
-  if (!good())
+  if (!bookFile.good())
   {
       cerr << "Failed to open book file " << fileName << endl;
       exit(EXIT_FAILURE);
   {
       cerr << "Failed to open book file " << fileName << endl;
       exit(EXIT_FAILURE);
@@ -408,7 +408,7 @@ void Book::open(const string& fileName) {
 
 Move Book::get_move(const Position& pos, bool findBestMove) {
 
 
 Move Book::get_move(const Position& pos, bool findBestMove) {
 
-  if (!is_open() || bookSize == 0)
+  if (!bookFile.is_open() || bookSize == 0)
       return MOVE_NONE;
 
   BookEntry entry;
       return MOVE_NONE;
 
   BookEntry entry;
@@ -512,11 +512,11 @@ BookEntry Book::read_entry(int idx) {
 
   BookEntry e;
 
 
   BookEntry e;
 
-  seekg(idx * sizeof(BookEntry), ios_base::beg);
+  bookFile.seekg(idx * sizeof(BookEntry), ios_base::beg);
 
   *this >> e.key >> e.move >> e.count >> e.learn;
 
 
   *this >> e.key >> e.move >> e.count >> e.learn;
 
-  if (!good())
+  if (!bookFile.good())
   {
       cerr << "Failed to read book entry at index " << idx << endl;
       exit(EXIT_FAILURE);
   {
       cerr << "Failed to read book entry at index " << idx << endl;
       exit(EXIT_FAILURE);
index 53c8a7e1be01b81c6caaa46efbd0ef2365ac2500..55d212a88634b03e00ebad286ad2f5a3aa868b4f 100644 (file)
@@ -38,9 +38,7 @@ struct BookEntry {
   uint32_t learn;
 };
 
   uint32_t learn;
 };
 
-class Book : private std::ifstream {
-  Book(const Book&); // just decleared..
-  Book& operator=(const Book&); // ..to avoid a warning
+class Book {
 public:
   Book();
   ~Book();
 public:
   Book();
   ~Book();
@@ -60,14 +58,15 @@ private:
   BookEntry read_entry(int idx);
   int find_entry(uint64_t key);
 
   BookEntry read_entry(int idx);
   int find_entry(uint64_t key);
 
+  std::ifstream bookFile;
   std::string bookName;
   int bookSize;
   RKISS RKiss;
 };
 
 // Yes, we indulge a bit here ;-)
   std::string bookName;
   int bookSize;
   RKISS RKiss;
 };
 
 // Yes, we indulge a bit here ;-)
-template<int n> inline uint64_t Book::get_int() { return 256 * get_int<n-1>() + get(); }
-template<> inline uint64_t Book::get_int<1>() { return get(); }
+template<int n> inline uint64_t Book::get_int() { return 256 * get_int<n-1>() + bookFile.get(); }
+template<> inline uint64_t Book::get_int<1>() { return bookFile.get(); }
 
 
 #endif // !defined(BOOK_H_INCLUDED)
 
 
 #endif // !defined(BOOK_H_INCLUDED)
index c265777b42a6c4d0bcf60485aae9d80a64625f43..0f3fbc10405e8789219c2af0ff1d294ec1263522 100644 (file)
@@ -37,7 +37,7 @@ public:
   Value value(Piece p, Square to) const;
   void update(Piece p, Square to, Value bonus);
   Value gain(Piece p, Square to) const;
   Value value(Piece p, Square to) const;
   void update(Piece p, Square to, Value bonus);
   Value gain(Piece p, Square to) const;
-  void update_gain(Piece p, Square to, Value gain);
+  void update_gain(Piece p, Square to, Value g);
 
   static const Value MaxValue = Value(1 << 29); // To avoid an overflow
 
 
   static const Value MaxValue = Value(1 << 29); // To avoid an overflow
 
@@ -63,8 +63,8 @@ inline Value History::gain(Piece p, Square to) const {
   return maxGains[p][to];
 }
 
   return maxGains[p][to];
 }
 
-inline void History::update_gain(Piece p, Square to, Value gain) {
-  maxGains[p][to] = Max(gain, maxGains[p][to] - 1);
+inline void History::update_gain(Piece p, Square to, Value g) {
+  maxGains[p][to] = Max(g, maxGains[p][to] - 1);
 }
 
 #endif // !defined(HISTORY_H_INCLUDED)
 }
 
 #endif // !defined(HISTORY_H_INCLUDED)
index 8667d44bfce718500aadc73cd16fe8db34d72763..48614fdfa14d4303e64525f02d5f789e81b3f248 100644 (file)
@@ -160,7 +160,7 @@ void Position::detach() {
 /// string. This function is not very robust - make sure that input FENs are
 /// correct (this is assumed to be the responsibility of the GUI).
 
 /// string. This function is not very robust - make sure that input FENs are
 /// correct (this is assumed to be the responsibility of the GUI).
 
-void Position::from_fen(const string& fen, bool c960) {
+void Position::from_fen(const string& fen, bool isChess960) {
 /*
    A FEN string defines a particular position using only the ASCII character set.
 
 /*
    A FEN string defines a particular position using only the ASCII character set.
 
@@ -255,7 +255,7 @@ void Position::from_fen(const string& fen, bool c960) {
   castleRightsMask[make_square(initialQRFile, RANK_1)] ^= WHITE_OOO;
   castleRightsMask[make_square(initialQRFile, RANK_8)] ^= BLACK_OOO;
 
   castleRightsMask[make_square(initialQRFile, RANK_1)] ^= WHITE_OOO;
   castleRightsMask[make_square(initialQRFile, RANK_8)] ^= BLACK_OOO;
 
-  isChess960 = c960;
+  chess960 = isChess960;
   find_checkers();
 
   st->key = compute_key();
   find_checkers();
 
   st->key = compute_key();
@@ -368,16 +368,16 @@ const string Position::to_fen() const {
   if (st->castleRights != CASTLES_NONE)
   {
       if (can_castle_kingside(WHITE))
   if (st->castleRights != CASTLES_NONE)
   {
       if (can_castle_kingside(WHITE))
-          fen += isChess960 ? char(toupper(file_to_char(initialKRFile))) : 'K';
+          fen += chess960 ? char(toupper(file_to_char(initialKRFile))) : 'K';
 
       if (can_castle_queenside(WHITE))
 
       if (can_castle_queenside(WHITE))
-          fen += isChess960 ? char(toupper(file_to_char(initialQRFile))) : 'Q';
+          fen += chess960 ? char(toupper(file_to_char(initialQRFile))) : 'Q';
 
       if (can_castle_kingside(BLACK))
 
       if (can_castle_kingside(BLACK))
-          fen += isChess960 ? file_to_char(initialKRFile) : 'k';
+          fen += chess960 ? file_to_char(initialKRFile) : 'k';
 
       if (can_castle_queenside(BLACK))
 
       if (can_castle_queenside(BLACK))
-          fen += isChess960 ? file_to_char(initialQRFile) : 'q';
+          fen += chess960 ? file_to_char(initialQRFile) : 'q';
   } else
       fen += '-';
 
   } else
       fen += '-';
 
index 8bd70b1643f3d47f6d530b0a091692e63de5dde6..a19911ab6035a5efb5013471e4d903b7d66e75a7 100644 (file)
@@ -303,7 +303,7 @@ private:
   int castleRightsMask[64];
   StateInfo startState;
   File initialKFile, initialKRFile, initialQRFile;
   int castleRightsMask[64];
   StateInfo startState;
   File initialKFile, initialKRFile, initialQRFile;
-  bool isChess960;
+  bool chess960;
   int startPosPlyCounter;
   int threadID;
   int64_t nodes;
   int startPosPlyCounter;
   int threadID;
   int64_t nodes;
@@ -524,7 +524,7 @@ inline bool Position::has_pawn_on_7th(Color c) const {
 }
 
 inline bool Position::is_chess960() const {
 }
 
 inline bool Position::is_chess960() const {
-  return isChess960;
+  return chess960;
 }
 
 inline bool Position::move_is_capture(Move m) const {
 }
 
 inline bool Position::move_is_capture(Move m) const {
index c0c1e281e8af92e4c2016dae724761150703b4cf..bf9b5c0f59d5a7b53f4fd554e68f5cb889346639 100644 (file)
@@ -159,23 +159,23 @@ Option::Option(int def, int minv, int maxv) : type("spin"), idx(Options.size()),
 /// the GUI to check for option's limits, but we could receive the new value
 /// directly from the user by teminal window. So let's check the bounds anyway.
 
 /// the GUI to check for option's limits, but we could receive the new value
 /// directly from the user by teminal window. So let's check the bounds anyway.
 
-void Option::set_value(const string& value) {
+void Option::set_value(const string& v) {
 
   assert(!type.empty());
 
 
   assert(!type.empty());
 
-  if (value.empty())
+  if (v.empty())
       return;
 
   if (   (type == "check" || type == "button")
       return;
 
   if (   (type == "check" || type == "button")
-      != (value == "true" || value == "false"))
+      != (v == "true" || v == "false"))
       return;
 
   if (type == "spin")
   {
       return;
 
   if (type == "spin")
   {
-      int v = atoi(value.c_str());
-      if (v < minValue || v > maxValue)
+      int val = atoi(v.c_str());
+      if (val < minValue || val > maxValue)
           return;
   }
 
           return;
   }
 
-  currentValue = value;
+  currentValue = v;
 }
 }
index ae7d392a01d8e52fc4942f18c540a3383f58a30b..b9c16cd913dab970780fc38f04966f209c388103 100644 (file)
@@ -32,7 +32,7 @@ public:
   Option(bool defaultValue, std::string type = "check");
   Option(int defaultValue, int minValue, int maxValue);
 
   Option(bool defaultValue, std::string type = "check");
   Option(int defaultValue, int minValue, int maxValue);
 
-  void set_value(const std::string& value);
+  void set_value(const std::string& v);
   template<typename T> T value() const;
 
 private:
   template<typename T> T value() const;
 
 private: