diff --git a/CMakeLists.txt b/CMakeLists.txt index 4e83018c401b3..2c1443daf5d5d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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() diff --git a/Makefile b/Makefile index daf3e07e178c2..533710fc720ea 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/src/debug.cpp b/src/debug.cpp index 6bf29dccde8ee..4b0356966d19b 100644 --- a/src/debug.cpp +++ b/src/debug.cpp @@ -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 buffer( 512 ); + std::string output; + try { + std::unique_ptr 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 buffer( 255 ); @@ -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 buffer( 512 ); - std::string output; - try { - std::unique_ptr 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. @@ -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> commands = { { "sw_vers -productName", "Name" }, { "sw_vers -productVersion", "Version" }, @@ -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, @@ -1026,9 +1026,9 @@ std::string windows_version() } } } -#endif return output; } +#endif // Various OS define tests std::string game_info::operating_system_version() { diff --git a/src/wincurse.cpp b/src/wincurse.cpp index 02f39bd313209..fd8fbfa19e53b 100644 --- a/src/wincurse.cpp +++ b/src/wincurse.cpp @@ -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 @@ -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 ); @@ -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; @@ -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 ); @@ -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' ) { @@ -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 ) ) { @@ -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 ); diff --git a/tests/test_main.cpp b/tests/test_main.cpp index e830dbca7dba6..39ad2c8354228 100644 --- a/tests/test_main.cpp +++ b/tests/test_main.cpp @@ -212,7 +212,7 @@ static option_overrides_t extract_option_overrides( std::vector &a return ret; } -std::string extract_user_dir( std::vector &arg_vec ) +static std::string extract_user_dir( std::vector &arg_vec ) { std::string option_user_dir = extract_argument( arg_vec, "--user-dir=" ); if( option_user_dir.empty() ) { diff --git a/tools/format/getpost.h b/tools/format/getpost.h index 87365fb4708e4..3e584cb837db8 100644 --- a/tools/format/getpost.h +++ b/tools/format/getpost.h @@ -31,7 +31,7 @@ THE SOFTWARE. #include #include -std::string urlDecode( std::string str ) +inline std::string urlDecode( std::string str ) { std::string temp; int i; @@ -60,7 +60,7 @@ std::string urlDecode( std::string str ) return temp; } -void initializeGet( std::map &Get ) +inline void initializeGet( std::map &Get ) { std::string tmpkey, tmpvalue; std::string *tmpstr = &tmpkey; @@ -92,7 +92,7 @@ void initializeGet( std::map &Get ) } } -void initializePost( std::map &Post ) +inline void initializePost( std::map &Post ) { std::string tmpkey, tmpvalue; std::string *tmpstr = &tmpkey;