Skip to content

Commit

Permalink
Turn on the -Wmissing-declarations warning and move all detected glob…
Browse files Browse the repository at this point in the history
…al functions to the anonymous namespace (#9048)
  • Loading branch information
oleg-derevenetz authored Aug 18, 2024
1 parent 0b7700f commit 88b97f0
Show file tree
Hide file tree
Showing 22 changed files with 5,897 additions and 5,858 deletions.
1 change: 1 addition & 0 deletions android/app/jni/Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ FHEROES2_C_WARN_OPTIONS := \
FHEROES2_CPP_WARN_OPTIONS := \
-Wctor-dtor-privacy \
-Wextra-semi \
-Wmissing-declarations \
-Woverloaded-virtual \
-Wsuggest-override

Expand Down
3 changes: 2 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ set(
)
set(
GNU_CXX_WARN_OPTS
${GNU_CC_WARN_OPTS} -Wctor-dtor-privacy -Wextra-semi -Woverloaded-virtual -Wsuggest-override
${GNU_CC_WARN_OPTS} -Wctor-dtor-privacy -Wextra-semi -Wmissing-declarations -Woverloaded-virtual
-Wsuggest-override
)
set(
MSVC_CC_WARN_OPTS
Expand Down
5 changes: 2 additions & 3 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,12 @@ CCFLAGS := $(CCFLAGS) -DFHEROES2_DATA="$(FHEROES2_DATA)"
endif

# TODO: Add -Wconversion -Wsign-conversion flags once we fix all the corresponding code smells
# TODO: Add -Wmissing-declarations once there will be no more functions that are used only within a single module,
# TODO: but are not declared static (and are not placed in an anonymous namespace)
# TODO: Add -Wdouble-promotion -Wold-style-cast -Wswitch-default flags once SDL headers can be compiled with them
CCWARNOPTS := -pedantic -Wall -Wextra -Wcast-align -Wcast-qual -Wfloat-conversion -Wfloat-equal -Wredundant-decls \
-Wshadow -Wundef -Wunused
CFLAGS := $(CFLAGS) $(CCWARNOPTS)
CXXFLAGS := $(CXXFLAGS) $(CCWARNOPTS) -Wctor-dtor-privacy -Wextra-semi -Woverloaded-virtual -Wsuggest-override
CXXFLAGS := $(CXXFLAGS) $(CCWARNOPTS) -Wctor-dtor-privacy -Wextra-semi -Wmissing-declarations -Woverloaded-virtual \
-Wsuggest-override

ifdef FHEROES2_STRICT_COMPILATION
CCFLAGS := $(CCFLAGS) -Werror
Expand Down
7,795 changes: 3,896 additions & 3,899 deletions src/fheroes2/agg/agg_image.cpp

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/fheroes2/battle/battle_board.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ int Battle::Board::GetDirection( const int32_t index1, const int32_t index2 )
return CENTER;
}

for ( direction_t dir = TOP_LEFT; dir < CENTER; ++dir ) {
for ( CellDirection dir = TOP_LEFT; dir < CENTER; ++dir ) {
if ( isValidDirection( index1, dir ) && index2 == GetIndexDirection( index1, dir ) ) {
return dir;
}
Expand Down Expand Up @@ -729,7 +729,7 @@ Battle::Indexes Battle::Board::GetAroundIndexes( const int32_t center )
Indexes result;
result.reserve( 6 );

for ( direction_t dir = TOP_LEFT; dir < CENTER; ++dir ) {
for ( CellDirection dir = TOP_LEFT; dir < CENTER; ++dir ) {
if ( !isValidDirection( center, dir ) ) {
continue;
}
Expand Down
8 changes: 4 additions & 4 deletions src/fheroes2/battle/battle_board.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ namespace Battle
{
class Unit;

inline direction_t & operator++( direction_t & d )
inline CellDirection & operator++( CellDirection & d )
{
return d = ( CENTER == d ? TOP_LEFT : direction_t( d << 1 ) );
return d = ( CENTER == d ? TOP_LEFT : CellDirection( d << 1 ) );
}
inline direction_t & operator--( direction_t & d )
inline CellDirection & operator--( CellDirection & d )
{
return d = ( TOP_LEFT == d ? CENTER : direction_t( d >> 1 ) );
return d = ( TOP_LEFT == d ? CENTER : CellDirection( d >> 1 ) );
}

using Indexes = std::vector<int32_t>;
Expand Down
2 changes: 1 addition & 1 deletion src/fheroes2/battle/battle_cell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ void Battle::Cell::SetArea( const fheroes2::Rect & area )
_coord[6] = { infl * _pos.x, infl * _pos.y + infl * _pos.height - infl * ( _pos.height - cellHeightVerSide ) / 2 };
}

Battle::direction_t Battle::Cell::GetTriangleDirection( const fheroes2::Point & dst ) const
Battle::CellDirection Battle::Cell::GetTriangleDirection( const fheroes2::Point & dst ) const
{
const fheroes2::Point pt( infl * dst.x, infl * dst.y );

Expand Down
4 changes: 2 additions & 2 deletions src/fheroes2/battle/battle_cell.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ namespace Battle
{
class Unit;

enum direction_t
enum CellDirection : int
{
UNKNOWN = 0x00,
TOP_LEFT = 0x01,
Expand Down Expand Up @@ -72,7 +72,7 @@ namespace Battle
const Unit * GetUnit() const;
Unit * GetUnit();

direction_t GetTriangleDirection( const fheroes2::Point & dst ) const;
CellDirection GetTriangleDirection( const fheroes2::Point & dst ) const;

bool isPositionIncludePoint( const fheroes2::Point & pt ) const;

Expand Down
Loading

0 comments on commit 88b97f0

Please sign in to comment.