From: Marco Costalba Date: Mon, 4 Apr 2011 07:53:44 +0000 (+0200) Subject: Added -Wshadow option and fixed resulting warnings X-Git-Url: https://git.sesse.net/?p=stockfish;a=commitdiff_plain;h=04108d45414c70c796d9378b247207b574e22414 Added -Wshadow option and fixed resulting warnings No functional change. Signed-off-by: Marco Costalba --- diff --git a/src/Makefile b/src/Makefile index 549b7867..9b8d5982 100644 --- a/src/Makefile +++ b/src/Makefile @@ -228,11 +228,11 @@ endif 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) - CXXFLAGS += -Wno-long-long -Wextra + CXXFLAGS += -Wextra -Wshadow endif ifeq ($(comp),icc) diff --git a/src/book.cpp b/src/book.cpp index a918d043..d6dcf6cb 100644 --- a/src/book.cpp +++ b/src/book.cpp @@ -367,8 +367,8 @@ Book::~Book() { void Book::close() { - if (is_open()) - ifstream::close(); + if (bookFile.is_open()) + bookFile.close(); bookName = ""; } @@ -381,17 +381,17 @@ void Book::open(const string& fileName) { // 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 - if (!is_open()) + if (!bookFile.is_open()) 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); @@ -408,7 +408,7 @@ void Book::open(const string& fileName) { 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; @@ -512,11 +512,11 @@ BookEntry Book::read_entry(int idx) { 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; - if (!good()) + if (!bookFile.good()) { cerr << "Failed to read book entry at index " << idx << endl; exit(EXIT_FAILURE); diff --git a/src/book.h b/src/book.h index 53c8a7e1..55d212a8 100644 --- a/src/book.h +++ b/src/book.h @@ -38,9 +38,7 @@ struct BookEntry { 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(); @@ -60,14 +58,15 @@ private: 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 ;-) -template inline uint64_t Book::get_int() { return 256 * get_int() + get(); } -template<> inline uint64_t Book::get_int<1>() { return get(); } +template inline uint64_t Book::get_int() { return 256 * get_int() + bookFile.get(); } +template<> inline uint64_t Book::get_int<1>() { return bookFile.get(); } #endif // !defined(BOOK_H_INCLUDED) diff --git a/src/history.h b/src/history.h index c265777b..0f3fbc10 100644 --- a/src/history.h +++ b/src/history.h @@ -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; - 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 @@ -63,8 +63,8 @@ inline Value History::gain(Piece p, Square to) const { 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) diff --git a/src/position.cpp b/src/position.cpp index 8667d44b..48614fdf 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -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). -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. @@ -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; - isChess960 = c960; + chess960 = isChess960; 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)) - fen += isChess960 ? char(toupper(file_to_char(initialKRFile))) : 'K'; + fen += chess960 ? char(toupper(file_to_char(initialKRFile))) : 'K'; 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)) - fen += isChess960 ? file_to_char(initialKRFile) : 'k'; + fen += chess960 ? file_to_char(initialKRFile) : 'k'; if (can_castle_queenside(BLACK)) - fen += isChess960 ? file_to_char(initialQRFile) : 'q'; + fen += chess960 ? file_to_char(initialQRFile) : 'q'; } else fen += '-'; diff --git a/src/position.h b/src/position.h index 8bd70b16..a19911ab 100644 --- a/src/position.h +++ b/src/position.h @@ -303,7 +303,7 @@ private: int castleRightsMask[64]; StateInfo startState; File initialKFile, initialKRFile, initialQRFile; - bool isChess960; + bool chess960; 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 { - return isChess960; + return chess960; } inline bool Position::move_is_capture(Move m) const { diff --git a/src/ucioption.cpp b/src/ucioption.cpp index c0c1e281..bf9b5c0f 100644 --- a/src/ucioption.cpp +++ b/src/ucioption.cpp @@ -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. -void Option::set_value(const string& value) { +void Option::set_value(const string& v) { assert(!type.empty()); - if (value.empty()) + if (v.empty()) return; if ( (type == "check" || type == "button") - != (value == "true" || value == "false")) + != (v == "true" || v == "false")) 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; } - currentValue = value; + currentValue = v; } diff --git a/src/ucioption.h b/src/ucioption.h index ae7d392a..b9c16cd9 100644 --- a/src/ucioption.h +++ b/src/ucioption.h @@ -32,7 +32,7 @@ public: 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 T value() const; private: