eliminated clang warnings

This commit is contained in:
Sergiu Deitsch 2021-12-21 10:51:41 +01:00 committed by Sergiu Deitsch
parent 9dc1107f88
commit 087ad5bf32
9 changed files with 39 additions and 16 deletions

View File

@ -31,7 +31,7 @@ jobs:
- name: Configure
env:
CXXFLAGS: -Wall -Wextra -Wpedantic -Wsign-conversion -Wtautological-compare -Werror ${{env.CXXFLAGS}}
CXXFLAGS: -Wall -Wextra -Wpedantic -Wsign-conversion -Wtautological-compare -Wformat-nonliteral -Wundef -Werror ${{env.CXXFLAGS}}
run: |
cmake -S . -B build_${{matrix.abi}} \
-DANDROID_ABI=${{matrix.abi}} \

View File

@ -67,7 +67,7 @@ jobs:
- name: Configure
env:
CXXFLAGS: -Wall -Wextra -Wsign-conversion -Wtautological-compare -Werror ${{env.CXXFLAGS}}
CXXFLAGS: -Wall -Wextra -Wsign-conversion -Wtautological-compare -Wformat-nonliteral -Wundef -Werror ${{env.CXXFLAGS}}
run: |
cmake -S . -B build_${{matrix.build_type}} \
-DBUILD_SHARED_LIBS=${{matrix.lib == 'shared'}} \

View File

@ -34,7 +34,7 @@ jobs:
- name: Configure
shell: bash
env:
CXXFLAGS: -Wall -Wextra -Wsign-conversion -Wtautological-compare -Werror ${{env.CXXFLAGS}}
CXXFLAGS: -Wall -Wextra -Wsign-conversion -Wtautological-compare -Wformat-nonliteral -Wundef -Werror ${{env.CXXFLAGS}}
run: |
cmake -S . -B build_${{matrix.build_type}} \
-DCMAKE_CXX_EXTENSIONS=OFF \

View File

@ -104,7 +104,7 @@ jobs:
- name: Configure
env:
CXXFLAGS: -Wall -Wextra -Wpedantic -Wsign-conversion -Wtautological-compare -Werror ${{env.CXXFLAGS}}
CXXFLAGS: -Wall -Wextra -Wpedantic -Wsign-conversion -Wtautological-compare -Wformat-nonliteral -Wundef -Werror ${{env.CXXFLAGS}}
run: |
if [[ ${{matrix.build_type}} == "Debug" ]]; then
export CXXFLAGS="--coverage ${CXXFLAGS}"

View File

@ -145,7 +145,11 @@ check_cxx_compiler_flag (-Wunnamed-type-template-args
HAVE_NO_UNNAMED_TYPE_TEMPLATE_ARGS)
cmake_push_check_state (RESET)
set (CMAKE_REQUIRED_LIBRARIES Threads::Threads)
if (Threads_FOUND)
set (CMAKE_REQUIRED_LIBRARIES Threads::Threads)
endif (Threads_FOUND)
check_cxx_symbol_exists (pthread_threadid_np "pthread.h" HAVE_PTHREAD_THREADID_NP)
cmake_pop_check_state ()

View File

@ -371,7 +371,7 @@ void TestRawLogging() {
RAW_LOG(ERROR, "%s%d%c%010d%s%1x", foo->c_str(), j, ' ', j, " ", j);
RAW_VLOG(0, "foo %d", j);
#ifdef NDEBUG
#if defined(NDEBUG)
RAW_LOG(INFO, "foo %d", j); // so that have same stderr to compare
#else
RAW_DLOG(INFO, "foo %d", j); // test RAW_DLOG in debug mode
@ -393,7 +393,7 @@ void TestRawLogging() {
RAW_VLOG(2, "vlog 2 on");
RAW_VLOG(3, "vlog 3 off");
#ifdef NDEBUG
#if defined(NDEBUG)
RAW_DCHECK(1 == 2, " RAW_DCHECK's shouldn't be compiled in normal mode");
#endif
@ -599,7 +599,7 @@ void TestCHECK() {
}
void TestDCHECK() {
#ifdef NDEBUG
#if defined(NDEBUG)
DCHECK( 1 == 2 ) << " DCHECK's shouldn't be compiled in normal mode";
#endif
DCHECK( 1 == 1 );
@ -1228,7 +1228,7 @@ static void MyCheck(bool a, bool b) {
TEST(DVLog, Basic) {
ScopedMockLog log;
#if NDEBUG
#if defined(NDEBUG)
// We are expecting that nothing is logged.
EXPECT_CALL(log, Log(_, _, _)).Times(0);
#else
@ -1279,7 +1279,7 @@ TEST(TestExitOnDFatal, ToBeOrNotToBe) {
// LOG(DFATAL) has severity FATAL if debugging, but is
// downgraded to ERROR if not debugging.
const LogSeverity severity =
#ifdef NDEBUG
#if defined(NDEBUG)
GLOG_ERROR;
#else
GLOG_FATAL;

View File

@ -348,7 +348,7 @@ void TestRawLogging() {
RAW_LOG(ERROR, "%s%d%c%010d%s%1x", foo->c_str(), j, ' ', j, " ", j);
RAW_VLOG(0, "foo %d", j);
#ifdef NDEBUG
#if defined(NDEBUG)
RAW_LOG(INFO, "foo %d", j); // so that have same stderr to compare
#else
RAW_DLOG(INFO, "foo %d", j); // test RAW_DLOG in debug mode
@ -370,7 +370,7 @@ void TestRawLogging() {
RAW_VLOG(2, "vlog 2 on");
RAW_VLOG(3, "vlog 3 off");
#ifdef NDEBUG
#if defined(NDEBUG)
RAW_DCHECK(1 == 2, " RAW_DCHECK's shouldn't be compiled in normal mode");
#endif
@ -594,7 +594,7 @@ void TestCHECK() {
}
void TestDCHECK() {
#ifdef NDEBUG
#if defined(NDEBUG)
DCHECK( 1 == 2 ) << " DCHECK's shouldn't be compiled in normal mode";
#endif
DCHECK( 1 == 1 );
@ -1316,7 +1316,7 @@ static void MyCheck(bool a, bool b) {
TEST(DVLog, Basic) {
ScopedMockLog log;
#if NDEBUG
#if defined(NDEBUG)
// We are expecting that nothing is logged.
EXPECT_CALL(log, Log(_, _, _)).Times(0);
#else
@ -1367,7 +1367,7 @@ TEST(TestExitOnDFatal, ToBeOrNotToBe) {
// LOG(DFATAL) has severity FATAL if debugging, but is
// downgraded to ERROR if not debugging.
const LogSeverity severity =
#ifdef NDEBUG
#if defined(NDEBUG)
GLOG_ERROR;
#else
GLOG_FATAL;

View File

@ -68,6 +68,16 @@
_START_GOOGLE_NAMESPACE_
#if defined(__GNUC__)
#define GLOG_ATTRIBUTE_FORMAT(archetype, stringIndex, firstToCheck) \
__attribute__((format(archetype, stringIndex, firstToCheck)))
#define GLOG_ATTRIBUTE_FORMAT_ARG(stringIndex) \
__attribute__((format_arg(stringIndex)))
#else
#define GLOG_ATTRIBUTE_FORMAT(archetype, stringIndex, firstToCheck)
#define GLOG_ATTRIBUTE_FORMAT_ARG(stringIndex)
#endif
// CAVEAT: vsnprintf called from *DoRawLog below has some (exotic) code paths
// that invoke malloc() and getenv() that might acquire some locks.
// If this becomes a problem we should reimplement a subset of vsnprintf
@ -76,6 +86,7 @@ _START_GOOGLE_NAMESPACE_
// Helper for RawLog__ below.
// *DoRawLog writes to *buf of *size and move them past the written portion.
// It returns true iff there was no overflow or error.
GLOG_ATTRIBUTE_FORMAT(printf, 3, 4)
static bool DoRawLog(char** buf, size_t* size, const char* format, ...) {
va_list ap;
va_start(ap, format);
@ -90,7 +101,14 @@ static bool DoRawLog(char** buf, size_t* size, const char* format, ...) {
// Helper for RawLog__ below.
inline static bool VADoRawLog(char** buf, size_t* size,
const char* format, va_list ap) {
#if defined(__GNUC__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wformat-nonliteral"
#endif
int n = vsnprintf(*buf, *size, format, ap);
#if defined(__GNUC__)
#pragma GCC diagnostic pop
#endif
if (n < 0 || static_cast<size_t>(n) > *size) return false;
*size -= static_cast<size_t>(n);
*buf += n;
@ -102,6 +120,7 @@ static bool crashed = false;
static CrashReason crash_reason;
static char crash_buf[kLogBufSize + 1] = { 0 }; // Will end in '\0'
GLOG_ATTRIBUTE_FORMAT(printf, 4, 5)
void RawLog__(LogSeverity severity, const char* file, int line,
const char* format, ...) {
if (!(FLAGS_logtostderr || severity >= FLAGS_stderrthreshold ||

View File

@ -71,7 +71,7 @@ static const char *TrySymbolize(void *pc) {
#if defined(__GNUC__) && !defined(__OPENCC__)
# if __GNUC__ >= 4
# define TEST_WITH_MODERN_GCC
# if __i386__ // always_inline isn't supported for x86_64 with GCC 4.1.0.
# if defined(__i386__) && __i386__ // always_inline isn't supported for x86_64 with GCC 4.1.0.
# undef always_inline
# define always_inline __attribute__((always_inline))
# define HAVE_ALWAYS_INLINE