Skip to content

Commit

Permalink
Merge pull request #688 from google/eliminate-warnings
Browse files Browse the repository at this point in the history
eliminate warnings
  • Loading branch information
sergiud committed Jul 23, 2021
2 parents 98e0e8c + 0b83bb2 commit f8c8e99
Show file tree
Hide file tree
Showing 21 changed files with 255 additions and 205 deletions.
10 changes: 7 additions & 3 deletions .github/workflows/macos-builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,19 @@ jobs:

- name: Configure
shell: bash
env:
CXXFLAGS: -Wall -Wextra -Wsign-conversion -Werror
run: |
if [[ ${{matrix.std}} == 98 ]]; then
export CXXFLAGS=-Werror=c++11-extensions
export CXXFLAGS="-Werror=c++11-extensions ${CXXFLAGS}"
fi
cmake -S . -B ${{runner.workspace}}/build_${{matrix.name}}_${{matrix.build_type}} \
-G "${{matrix.generator}}" \
-DCMAKE_CXX_EXTENSIONS=OFF \
-DCMAKE_CXX_FLAGS_DEBUG=-pedantic-errors \
-DCMAKE_CXX_FLAGS_RELEASE=-pedantic-errors \
-DCMAKE_CXX_STANDARD=${{matrix.std}} \
-DCMAKE_CXX_STANDARD_REQUIRED=ON \
-DCMAKE_CXX_EXTENSIONS=OFF
-DCMAKE_CXX_STANDARD_REQUIRED=ON
- name: Build
run: |
cmake --build ${{runner.workspace}}/build_${{matrix.name}}_${{matrix.build_type}} \
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/windows-builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ jobs:
- name: Configure build MinGW
if: ${{ startswith(matrix.config.name, 'MinGW-') }}
shell: powershell
env:
CXXFLAGS: -Wall -Wextra -Wpedantic -Wsign-conversion -Werror -Wno-error=variadic-macros -Wno-error=long-long
run: cmake -S . -B ${{runner.workspace}}/build_${{matrix.config.name}}_${{matrix.build_type}} -G "${{matrix.config.generator}}" -DCMAKE_CXX_STANDARD=${{matrix.config.std}} -DCMAKE_CXX_EXTENSIONS=OFF -DCMAKE_CXX_STANDARD_REQUIRED=ON -DCMAKE_BUILD_TYPE=${{matrix.build_type}}
- name: Build MinGW
if: ${{ startswith(matrix.config.name, 'MinGW-') }}
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ check_function_exists (fcntl HAVE_FCNTL)
check_function_exists (pread HAVE_PREAD)
check_function_exists (pwrite HAVE_PWRITE)
check_function_exists (sigaction HAVE_SIGACTION)
check_function_exists (sigaltstack HAVE_SIGALSTACK)
check_function_exists (sigaltstack HAVE_SIGALTSTACK)

# NOTE gcc does not fail if you pass a non-existent -Wno-* option as an
# argument. However, it will happily fail if you pass the corresponding -W*
Expand Down
10 changes: 5 additions & 5 deletions src/demangle.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@
// Note that we only have partial C++0x support yet.

#include <cstdio> // for NULL
#include "utilities.h"

#include "demangle.h"
#include "utilities.h"

#if defined(OS_WINDOWS)
#include <dbghelp.h>
#pragma comment(lib, "dbghelp")
#endif

_START_GOOGLE_NAMESPACE_
Expand Down Expand Up @@ -192,7 +192,7 @@ static bool StrPrefix(const char *str, const char *prefix) {
}

static void InitState(State *state, const char *mangled,
char *out, int out_size) {
char *out, size_t out_size) {
state->mangled_cur = mangled;
state->out_cur = out;
state->out_begin = out;
Expand Down Expand Up @@ -1323,7 +1323,7 @@ static bool ParseTopLevelMangledName(State *state) {
#endif

// The demangler entry point.
bool Demangle(const char *mangled, char *out, int out_size) {
bool Demangle(const char *mangled, char *out, size_t out_size) {
#if defined(OS_WINDOWS)
// When built with incremental linking, the Windows debugger
// library provides a more complicated `Symbol->Name` with the
Expand All @@ -1339,7 +1339,7 @@ bool Demangle(const char *mangled, char *out, int out_size) {
if (lparen) {
// Extract the string `(?...)`
const char *rparen = strchr(lparen, ')');
size_t length = rparen - lparen - 1;
size_t length = static_cast<size_t>(rparen - lparen) - 1;
strncpy(buffer, lparen + 1, length);
buffer[length] = '\0';
mangled = buffer;
Expand Down
2 changes: 1 addition & 1 deletion src/demangle.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ _START_GOOGLE_NAMESPACE_
// Demangle "mangled". On success, return true and write the
// demangled symbol name to "out". Otherwise, return false.
// "out" is modified even if demangling is unsuccessful.
bool GOOGLE_GLOG_DLL_DECL Demangle(const char *mangled, char *out, int out_size);
bool GOOGLE_GLOG_DLL_DECL Demangle(const char *mangled, char *out, size_t out_size);

_END_GOOGLE_NAMESPACE_

Expand Down
72 changes: 39 additions & 33 deletions src/glog/logging.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
// Pretty much everybody needs to #include this file so that they can
// log various happenings.
//
#ifndef _LOGGING_H_
#define _LOGGING_H_
#ifndef GLOG_LOGGING_H
#define GLOG_LOGGING_H

#if @ac_cv_cxx11_chrono@ && __cplusplus >= 201103L
#include <chrono>
Expand Down Expand Up @@ -605,8 +605,14 @@ GOOGLE_GLOG_DLL_DECL bool IsGoogleLoggingInitialized();
// Shutdown google's logging library.
GOOGLE_GLOG_DLL_DECL void ShutdownGoogleLogging();

#if defined(__GNUC__)
typedef void (*logging_fail_func_t)() __attribute__((noreturn));
#else
typedef void (*logging_fail_func_t)();
#endif

// Install a function which will be called after LOG(FATAL).
GOOGLE_GLOG_DLL_DECL void InstallFailureFunction(void (*fail_func)());
GOOGLE_GLOG_DLL_DECL void InstallFailureFunction(logging_fail_func_t fail_func);

// Enable/Disable old log cleaner.
GOOGLE_GLOG_DLL_DECL void EnableLogCleaner(int overdue_days);
Expand Down Expand Up @@ -1004,22 +1010,22 @@ PLOG_IF(FATAL, GOOGLE_PREDICT_BRANCH_NOT_TAKEN((invocation) == -1)) \
#define LOG_PREVIOUS_TIME LOG_EVERY_N_VARNAME(previousTime_, __LINE__)

#if defined(__has_feature)
#define _GLOG_HAS_FEATURE(...) __has_feature(__VA_ARGS__)
#else
#define _GLOG_HAS_FEATURE(...) 0
# if __has_feature(thread_sanitizer)
# define GLOG_SANITIZE_THREAD 1
# endif
#endif

#if _GLOG_HAS_FEATURE(thread_sanitizer) || __SANITIZE_THREAD__
#define _GLOG_SANITIZE_THREAD 1
#if !defined(GLOG_SANITIZE_THREAD) && defined(__SANITIZE_THREAD__) && __SANITIZE_THREAD__
# define GLOG_SANITIZE_THREAD 1
#endif

#if defined(_GLOG_SANITIZE_THREAD)
#define _GLOG_IFDEF_THREAD_SANITIZER(X) X
#if defined(GLOG_SANITIZE_THREAD)
#define GLOG_IFDEF_THREAD_SANITIZER(X) X
#else
#define _GLOG_IFDEF_THREAD_SANITIZER(X)
#define GLOG_IFDEF_THREAD_SANITIZER(X)
#endif

#if defined(_GLOG_SANITIZE_THREAD)
#if defined(GLOG_SANITIZE_THREAD)
} // namespace google

// We need to identify the static variables as "benign" races
Expand All @@ -1038,9 +1044,9 @@ namespace google {
#define SOME_KIND_OF_LOG_EVERY_T(severity, seconds) \
GLOG_CONSTEXPR std::chrono::nanoseconds LOG_TIME_PERIOD = std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::duration<double>(seconds)); \
static std::atomic<int64> LOG_PREVIOUS_TIME_RAW; \
_GLOG_IFDEF_THREAD_SANITIZER( \
GLOG_IFDEF_THREAD_SANITIZER( \
AnnotateBenignRaceSized(__FILE__, __LINE__, &LOG_TIME_PERIOD, sizeof(int64), "")); \
_GLOG_IFDEF_THREAD_SANITIZER( \
GLOG_IFDEF_THREAD_SANITIZER( \
AnnotateBenignRaceSized(__FILE__, __LINE__, &LOG_PREVIOUS_TIME_RAW, sizeof(int64), "")); \
const auto LOG_CURRENT_TIME = std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::steady_clock::now().time_since_epoch()); \
const auto LOG_PREVIOUS_TIME = LOG_PREVIOUS_TIME_RAW.load(std::memory_order_relaxed); \
Expand Down Expand Up @@ -1083,9 +1089,9 @@ namespace google {

#if @ac_cv_cxx11_atomic@ && __cplusplus >= 201103L
#define SOME_KIND_OF_LOG_EVERY_N(severity, n, what_to_do) \
static std::atomic<int> LOG_OCCURRENCES(0), LOG_OCCURRENCES_MOD_N(0); \
_GLOG_IFDEF_THREAD_SANITIZER(AnnotateBenignRaceSized(__FILE__, __LINE__, &LOG_OCCURRENCES, sizeof(int), "")); \
_GLOG_IFDEF_THREAD_SANITIZER(AnnotateBenignRaceSized(__FILE__, __LINE__, &LOG_OCCURRENCES_MOD_N, sizeof(int), "")); \
static std::atomic<unsigned> LOG_OCCURRENCES(0), LOG_OCCURRENCES_MOD_N(0); \
GLOG_IFDEF_THREAD_SANITIZER(AnnotateBenignRaceSized(__FILE__, __LINE__, &LOG_OCCURRENCES, sizeof(int), "")); \
GLOG_IFDEF_THREAD_SANITIZER(AnnotateBenignRaceSized(__FILE__, __LINE__, &LOG_OCCURRENCES_MOD_N, sizeof(int), "")); \
++LOG_OCCURRENCES; \
if (++LOG_OCCURRENCES_MOD_N > n) LOG_OCCURRENCES_MOD_N -= n; \
if (LOG_OCCURRENCES_MOD_N == 1) \
Expand All @@ -1094,9 +1100,9 @@ namespace google {
&what_to_do).stream()

#define SOME_KIND_OF_LOG_IF_EVERY_N(severity, condition, n, what_to_do) \
static std::atomic<int> LOG_OCCURRENCES(0), LOG_OCCURRENCES_MOD_N(0); \
_GLOG_IFDEF_THREAD_SANITIZER(AnnotateBenignRaceSized(__FILE__, __LINE__, &LOG_OCCURRENCES, sizeof(int), "")); \
_GLOG_IFDEF_THREAD_SANITIZER(AnnotateBenignRaceSized(__FILE__, __LINE__, &LOG_OCCURRENCES_MOD_N, sizeof(int), "")); \
static std::atomic<unsigned> LOG_OCCURRENCES(0), LOG_OCCURRENCES_MOD_N(0); \
GLOG_IFDEF_THREAD_SANITIZER(AnnotateBenignRaceSized(__FILE__, __LINE__, &LOG_OCCURRENCES, sizeof(int), "")); \
GLOG_IFDEF_THREAD_SANITIZER(AnnotateBenignRaceSized(__FILE__, __LINE__, &LOG_OCCURRENCES_MOD_N, sizeof(int), "")); \
++LOG_OCCURRENCES; \
if ((condition) && \
((LOG_OCCURRENCES_MOD_N=(LOG_OCCURRENCES_MOD_N + 1) % n) == (1 % n))) \
Expand All @@ -1105,9 +1111,9 @@ namespace google {
&what_to_do).stream()

#define SOME_KIND_OF_PLOG_EVERY_N(severity, n, what_to_do) \
static std::atomic<int> LOG_OCCURRENCES(0), LOG_OCCURRENCES_MOD_N(0); \
_GLOG_IFDEF_THREAD_SANITIZER(AnnotateBenignRaceSized(__FILE__, __LINE__, &LOG_OCCURRENCES, sizeof(int), "")); \
_GLOG_IFDEF_THREAD_SANITIZER(AnnotateBenignRaceSized(__FILE__, __LINE__, &LOG_OCCURRENCES_MOD_N, sizeof(int), "")); \
static std::atomic<unsigned> LOG_OCCURRENCES(0), LOG_OCCURRENCES_MOD_N(0); \
GLOG_IFDEF_THREAD_SANITIZER(AnnotateBenignRaceSized(__FILE__, __LINE__, &LOG_OCCURRENCES, sizeof(int), "")); \
GLOG_IFDEF_THREAD_SANITIZER(AnnotateBenignRaceSized(__FILE__, __LINE__, &LOG_OCCURRENCES_MOD_N, sizeof(int), "")); \
++LOG_OCCURRENCES; \
if (++LOG_OCCURRENCES_MOD_N > n) LOG_OCCURRENCES_MOD_N -= n; \
if (LOG_OCCURRENCES_MOD_N == 1) \
Expand All @@ -1116,8 +1122,8 @@ namespace google {
&what_to_do).stream()

#define SOME_KIND_OF_LOG_FIRST_N(severity, n, what_to_do) \
static std::atomic<int> LOG_OCCURRENCES(0); \
_GLOG_IFDEF_THREAD_SANITIZER(AnnotateBenignRaceSized(__FILE__, __LINE__, &LOG_OCCURRENCES, sizeof(int), "")); \
static std::atomic<unsigned> LOG_OCCURRENCES(0); \
GLOG_IFDEF_THREAD_SANITIZER(AnnotateBenignRaceSized(__FILE__, __LINE__, &LOG_OCCURRENCES, sizeof(int), "")); \
if (LOG_OCCURRENCES <= n) \
++LOG_OCCURRENCES; \
if (LOG_OCCURRENCES <= n) \
Expand Down Expand Up @@ -1173,7 +1179,7 @@ namespace google {
#else

#define SOME_KIND_OF_LOG_EVERY_N(severity, n, what_to_do) \
static int LOG_OCCURRENCES = 0, LOG_OCCURRENCES_MOD_N = 0; \
static unsigned LOG_OCCURRENCES = 0, LOG_OCCURRENCES_MOD_N = 0; \
__sync_add_and_fetch(&LOG_OCCURRENCES, 1); \
if (__sync_add_and_fetch(&LOG_OCCURRENCES_MOD_N, 1) > n) \
__sync_sub_and_fetch(&LOG_OCCURRENCES_MOD_N, n); \
Expand All @@ -1183,7 +1189,7 @@ namespace google {
&what_to_do).stream()

#define SOME_KIND_OF_LOG_IF_EVERY_N(severity, condition, n, what_to_do) \
static int LOG_OCCURRENCES = 0, LOG_OCCURRENCES_MOD_N = 0; \
static unsigned LOG_OCCURRENCES = 0, LOG_OCCURRENCES_MOD_N = 0; \
__sync_add_and_fetch(&LOG_OCCURRENCES, 1); \
if ((condition) && \
(__sync_add_and_fetch(&LOG_OCCURRENCES_MOD_N, 1) || true) && \
Expand All @@ -1194,7 +1200,7 @@ namespace google {
&what_to_do).stream()

#define SOME_KIND_OF_PLOG_EVERY_N(severity, n, what_to_do) \
static int LOG_OCCURRENCES = 0, LOG_OCCURRENCES_MOD_N = 0; \
static unsigned LOG_OCCURRENCES = 0, LOG_OCCURRENCES_MOD_N = 0; \
__sync_add_and_fetch(&LOG_OCCURRENCES, 1); \
if (__sync_add_and_fetch(&LOG_OCCURRENCES_MOD_N, 1) > n) \
__sync_sub_and_fetch(&LOG_OCCURRENCES_MOD_N, n); \
Expand All @@ -1204,7 +1210,7 @@ namespace google {
&what_to_do).stream()

#define SOME_KIND_OF_LOG_FIRST_N(severity, n, what_to_do) \
static int LOG_OCCURRENCES = 0; \
static unsigned LOG_OCCURRENCES = 0; \
if (LOG_OCCURRENCES <= n) \
__sync_add_and_fetch(&LOG_OCCURRENCES, 1); \
if (LOG_OCCURRENCES <= n) \
Expand Down Expand Up @@ -1412,7 +1418,7 @@ class GOOGLE_GLOG_DLL_DECL LogStreamBuf : public std::streambuf {
}

// Legacy public ostrstream method.
size_t pcount() const { return pptr() - pbase(); }
size_t pcount() const { return static_cast<size_t>(pptr() - pbase()); }
char* pbase() const { return std::streambuf::pbase(); }
};

Expand Down Expand Up @@ -1860,7 +1866,7 @@ class GOOGLE_GLOG_DLL_DECL Logger {
virtual void Write(bool force_flush,
time_t timestamp,
const char* message,
int message_len) = 0;
size_t message_len) = 0;

// Flush any buffered messages
virtual void Flush() = 0;
Expand Down Expand Up @@ -1961,7 +1967,7 @@ GOOGLE_GLOG_DLL_DECL void InstallFailureSignalHandler();
// is the size of the message. You should not expect the data is
// terminated with '\0'.
GOOGLE_GLOG_DLL_DECL void InstallFailureWriter(
void (*writer)(const char* data, int size));
void (*writer)(const char* data, size_t size));

@ac_google_end_namespace@

Expand All @@ -1970,4 +1976,4 @@ GOOGLE_GLOG_DLL_DECL void InstallFailureWriter(
#pragma pop_macro("GFLAGS_DLL_DECLARE_FLAG")
#endif // defined(GLOG_GFLAGS_DLL_DECLARE_FLAG_WAS_DEFINED)

#endif // _LOGGING_H_
#endif // GLOG_LOGGING_H
25 changes: 17 additions & 8 deletions src/glog/raw_logging.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
// acquire any locks, and can therefore be used by low-level memory
// allocation and synchronization code.

#ifndef BASE_RAW_LOGGING_H_
#define BASE_RAW_LOGGING_H_
#ifndef GLOG_RAW_LOGGING_H
#define GLOG_RAW_LOGGING_H

#include <ctime>

Expand All @@ -52,6 +52,11 @@
# endif
#endif

#if defined(__GNUC__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wvariadic-macros"
#endif

// This is similar to LOG(severity) << format... and VLOG(level) << format..,
// but
// * it is to be used ONLY by low-level modules that can't use normal LOG()
Expand Down Expand Up @@ -88,7 +93,7 @@

// The following STRIP_LOG testing is performed in the header file so that it's
// possible to completely compile out the logging code and the log messages.
#if STRIP_LOG == 0
#if !defined(STRIP_LOG) || STRIP_LOG == 0
#define RAW_VLOG(verboselevel, ...) \
do { \
if (VLOG_IS_ON(verboselevel)) { \
Expand All @@ -99,28 +104,28 @@
#define RAW_VLOG(verboselevel, ...) RawLogStub__(0, __VA_ARGS__)
#endif // STRIP_LOG == 0

#if STRIP_LOG == 0
#if !defined(STRIP_LOG) || STRIP_LOG == 0
#define RAW_LOG_INFO(...) @ac_google_namespace@::RawLog__(@ac_google_namespace@::GLOG_INFO, \
__FILE__, __LINE__, __VA_ARGS__)
#else
#define RAW_LOG_INFO(...) @ac_google_namespace@::RawLogStub__(0, __VA_ARGS__)
#endif // STRIP_LOG == 0

#if STRIP_LOG <= 1
#if !defined(STRIP_LOG) || STRIP_LOG <= 1
#define RAW_LOG_WARNING(...) @ac_google_namespace@::RawLog__(@ac_google_namespace@::GLOG_WARNING, \
__FILE__, __LINE__, __VA_ARGS__)
#else
#define RAW_LOG_WARNING(...) @ac_google_namespace@::RawLogStub__(0, __VA_ARGS__)
#endif // STRIP_LOG <= 1

#if STRIP_LOG <= 2
#if !defined(STRIP_LOG) || STRIP_LOG <= 2
#define RAW_LOG_ERROR(...) @ac_google_namespace@::RawLog__(@ac_google_namespace@::GLOG_ERROR, \
__FILE__, __LINE__, __VA_ARGS__)
#else
#define RAW_LOG_ERROR(...) @ac_google_namespace@::RawLogStub__(0, __VA_ARGS__)
#endif // STRIP_LOG <= 2

#if STRIP_LOG <= 3
#if !defined(STRIP_LOG) || STRIP_LOG <= 3
#define RAW_LOG_FATAL(...) @ac_google_namespace@::RawLog__(@ac_google_namespace@::GLOG_FATAL, \
__FILE__, __LINE__, __VA_ARGS__)
#else
Expand Down Expand Up @@ -160,6 +165,10 @@

#endif // NDEBUG

#if defined(__GNUC__)
#pragma GCC diagnostic pop
#endif

// Stub log function used to work around for unused variable warnings when
// building with STRIP_LOG > 0.
static inline void RawLogStub__(int /* ignored */, ...) {
Expand All @@ -177,4 +186,4 @@ GOOGLE_GLOG_DLL_DECL void RawLog__(LogSeverity severity,

@ac_google_end_namespace@

#endif // BASE_RAW_LOGGING_H_
#endif // GLOG_RAW_LOGGING_H
Loading

0 comments on commit f8c8e99

Please sign in to comment.