Skip to content

Commit

Permalink
Merge pull request #30759 from jbytheway/missing_declarations
Browse files Browse the repository at this point in the history
Add -Wmissing-declarations
  • Loading branch information
kevingranade authored May 23, 2019
2 parents ed96404 + 58f5393 commit 30f4e97
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 51 deletions.
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,9 @@ IF(MSVC)
add_definitions(-D_X86_)
endif()
ELSE()
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -Wall -Wextra -Woverloaded-virtual -Wpedantic -std=c++14")
SET(CATA_WARNINGS
"-Werror -Wall -Wextra -Woverloaded-virtual -Wpedantic -Wmissing-declarations")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CATA_WARNINGS} -std=c++14")
SET(CMAKE_CXX_FLAGS_DEBUG "-Og -g")
ENDIF()

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
# PROFILE is for use with gprof or a similar program -- don't bother generally.
# RELEASE_FLAGS is flags for release builds.
RELEASE_FLAGS =
WARNINGS = -Werror -Wall -Wextra -Woverloaded-virtual -Wpedantic
WARNINGS = -Werror -Wall -Wextra -Woverloaded-virtual -Wpedantic -Wmissing-declarations
# Uncomment below to disable warnings
#WARNINGS = -w
DEBUGSYMS = -g
Expand Down
76 changes: 38 additions & 38 deletions src/debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -822,17 +822,41 @@ std::string game_info::operating_system()
#endif
}

#if defined (__linux__) || defined(unix) || defined(__unix__) || defined(__unix) || ( defined(__APPLE__) && defined(__MACH__) ) || defined(BSD) // linux; unix; MacOs; BSD
/** Execute a command with the shell by using `popen()`.
* @param command The full command to execute.
* @note The output buffer is limited to 512 characters.
* @returns The result of the command (only stdout) or an empty string if there was a problem.
*/
static std::string shell_exec( const std::string &command )
{
std::vector<char> buffer( 512 );
std::string output;
try {
std::unique_ptr<FILE, decltype( &pclose )> pipe( popen( command.c_str(), "r" ), pclose );
if( pipe ) {
while( fgets( buffer.data(), buffer.size(), pipe.get() ) != nullptr ) {
output += buffer.data();
}
}
} catch( ... ) {
output = "";
}
return output;
}
#endif

#if defined (__ANDROID__)
/** Get a precise version number for Android systems.
* @note see:
* - https://stackoverflow.com/a/19777977/507028
* - https://github.com/pytorch/cpuinfo/blob/master/test/build.prop/galaxy-s7-us.log
* @returns If successful, a string containing the Android system version, otherwise an empty string.
*/
std::string android_version()
static std::string android_version()
{
std::string output;

#if defined (__ANDROID__)
// buffer used for the __system_property_get() function.
// note: according to android sources, it can't be greater than 92 chars (see 'PROP_VALUE_MAX' define in system_properties.h)
std::vector<char> buffer( 255 );
Expand All @@ -859,60 +883,36 @@ std::string android_version()
}
output.append( string_format( "%s: %s; ", entry.second, value ) );
}
#endif
return output;
}

#if defined (__linux__) || defined(unix) || defined(__unix__) || defined(__unix) || ( defined(__APPLE__) && defined(__MACH__) ) || defined(BSD) // linux; unix; MacOs; BSD
/** Execute a command with the shell by using `popen()`.
* @param command The full command to execute.
* @note The output buffer is limited to 512 characters.
* @returns The result of the command (only stdout) or an empty string if there was a problem.
*/
std::string shell_exec( const std::string &command )
{
std::vector<char> buffer( 512 );
std::string output;
try {
std::unique_ptr<FILE, decltype( &pclose )> pipe( popen( command.c_str(), "r" ), pclose );
if( pipe ) {
while( fgets( buffer.data(), buffer.size(), pipe.get() ) != nullptr ) {
output += buffer.data();
}
}
} catch( ... ) {
output = "";
}
return output;
}
#endif
#elif defined(BSD)

/** Get a precise version number for BSD systems.
* @note The code shells-out to call `uname -a`.
* @returns If successful, a string containing the Linux system version, otherwise an empty string.
*/
std::string bsd_version()
static std::string bsd_version()
{
std::string output;
#if defined(BSD)
output = shell_exec( "uname -a" );
if( !output.empty() ) {
// remove trailing '\n', if any.
output.erase( std::remove( output.begin(), output.end(), '\n' ),
output.end() );
}
#endif
return output;
}

#elif defined(__linux__)

/** Get a precise version number for Linux systems.
* @note The code shells-out to call `lsb_release -a`.
* @returns If successful, a string containing the Linux system version, otherwise an empty string.
*/
std::string linux_version()
static std::string linux_version()
{
std::string output;
#if defined(__linux__)
output = shell_exec( "lsb_release -a" );
if( !output.empty() ) {
// replace '\n' and '\t' in output.
Expand All @@ -927,18 +927,18 @@ std::string linux_version()
}
}
}
#endif
return output;
}

#elif defined(__APPLE__) && defined(__MACH__) && !defined(BSD)

/** Get a precise version number for MacOs systems.
* @note The code shells-out to call `sw_vers` with various options.
* @returns If successful, a string containing the MacOS system version, otherwise an empty string.
*/
std::string mac_os_version()
static std::string mac_os_version()
{
std::string output;
#if defined(__APPLE__) && defined(__MACH__) && !defined(BSD)
std::vector<std::pair<std::string, std::string>> commands = {
{ "sw_vers -productName", "Name" },
{ "sw_vers -productVersion", "Version" },
Expand All @@ -956,20 +956,20 @@ std::string mac_os_version()
}
output.append( string_format( "%s: %s; ", entry.second, command_result ) );
}
#endif
return output;
}

#elif defined (_WIN32)

/** Get a precise version number for Windows systems.
* @note Since Windows 10 all version-related APIs lie about the underlying system if the application is not Manifested (see VerifyVersionInfoA
* or GetVersionEx documentation for further explanation). In this function we use the registry or the native RtlGetVersion which both
* report correct versions and are compatible down to XP.
* @returns If successful, a string containing the Windows system version number, otherwise an empty string.
*/
std::string windows_version()
static std::string windows_version()
{
std::string output;
#if defined (_WIN32)
HKEY handle_key;
bool success = RegOpenKeyExA( HKEY_LOCAL_MACHINE, R"(SOFTWARE\Microsoft\Windows NT\CurrentVersion)",
0,
Expand Down Expand Up @@ -1026,9 +1026,9 @@ std::string windows_version()
}
}
}
#endif
return output;
}
#endif // Various OS define tests

std::string game_info::operating_system_version()
{
Expand Down
14 changes: 7 additions & 7 deletions src/wincurse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ static int TERMINAL_HEIGHT;
// Declare this locally, because it's not generally cross-compatible in cursesport.h
LRESULT CALLBACK ProcessMessages( HWND__ *hWnd, std::uint32_t Msg, WPARAM wParam, LPARAM lParam );

std::wstring widen( const std::string &s )
static std::wstring widen( const std::string &s )
{
if( s.empty() ) {
// MultiByteToWideChar can not handle this case
Expand All @@ -76,7 +76,7 @@ std::wstring widen( const std::string &s )
}

// Registers, creates, and shows the Window!!
bool WinCreate()
static bool WinCreate()
{
// Get current process handle
WindowINST = GetModuleHandle( 0 );
Expand Down Expand Up @@ -128,7 +128,7 @@ bool WinCreate()
}

// Unregisters, releases the DC if needed, and destroys the window.
void WinDestroy()
static void WinDestroy()
{
if( ( WindowDC != NULL ) && ( ReleaseDC( WindowHandle, WindowDC ) == 0 ) ) {
WindowDC = 0;
Expand All @@ -142,7 +142,7 @@ void WinDestroy()
}

// Creates a backbuffer to prevent flickering
void create_backbuffer()
static void create_backbuffer()
{
if( WindowDC != NULL ) {
ReleaseDC( WindowHandle, WindowDC );
Expand Down Expand Up @@ -207,7 +207,7 @@ static void begin_alt_code()
alt_buffer_len = 0;
}

void add_alt_code( char c )
static void add_alt_code( char c )
{
// Not exactly how it works, but acceptable
if( c >= '0' && c <= '9' ) {
Expand Down Expand Up @@ -534,7 +534,7 @@ void cata_cursesport::curses_drawwindow( const catacurses::window &w )
}

// Check for any window messages (keypress, paint, mousemove, etc)
void CheckMessages()
static void CheckMessages()
{
MSG msg;
while( PeekMessage( &msg, 0, 0, 0, PM_REMOVE ) ) {
Expand Down Expand Up @@ -636,7 +636,7 @@ void catacurses::init_interface()
}

// A very accurate and responsive timer (NEVER use GetTickCount)
uint64_t GetPerfCount()
static uint64_t GetPerfCount()
{
uint64_t Count;
QueryPerformanceCounter( ( PLARGE_INTEGER )&Count );
Expand Down
2 changes: 1 addition & 1 deletion tests/test_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ static option_overrides_t extract_option_overrides( std::vector<const char *> &a
return ret;
}

std::string extract_user_dir( std::vector<const char *> &arg_vec )
static std::string extract_user_dir( std::vector<const char *> &arg_vec )
{
std::string option_user_dir = extract_argument( arg_vec, "--user-dir=" );
if( option_user_dir.empty() ) {
Expand Down
6 changes: 3 additions & 3 deletions tools/format/getpost.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ THE SOFTWARE.
#include <map>
#include <new>

std::string urlDecode( std::string str )
inline std::string urlDecode( std::string str )
{
std::string temp;
int i;
Expand Down Expand Up @@ -60,7 +60,7 @@ std::string urlDecode( std::string str )
return temp;
}

void initializeGet( std::map <std::string, std::string> &Get )
inline void initializeGet( std::map <std::string, std::string> &Get )
{
std::string tmpkey, tmpvalue;
std::string *tmpstr = &tmpkey;
Expand Down Expand Up @@ -92,7 +92,7 @@ void initializeGet( std::map <std::string, std::string> &Get )
}
}

void initializePost( std::map <std::string, std::string> &Post )
inline void initializePost( std::map <std::string, std::string> &Post )
{
std::string tmpkey, tmpvalue;
std::string *tmpstr = &tmpkey;
Expand Down

0 comments on commit 30f4e97

Please sign in to comment.