Enable clang-specific warnings on the clang-cl build instead of just trying to be MSVC This also fixes the new warnings that are caught. These include: * Unreachable code after GTEST_SKIP (this is kind of ugly) * Some -Wundef warnings * A -Wshadow warning in vlog_config.cc PiperOrigin-RevId: 838046186 Change-Id: Ief48d6db2b8755d2173997d052560880593d5819
diff --git a/absl/base/config.h b/absl/base/config.h index e4518ca..a38c582 100644 --- a/absl/base/config.h +++ b/absl/base/config.h
@@ -755,7 +755,7 @@ #ifdef ABSL_INTERNAL_HAS_CXA_DEMANGLE #error ABSL_INTERNAL_HAS_CXA_DEMANGLE cannot be directly set #elif defined(OS_ANDROID) && (defined(__i386__) || defined(__x86_64__)) -#undef ABSL_INTERNAL_HAS_CXA_DEMANGLE +#define ABSL_INTERNAL_HAS_CXA_DEMANGLE 0 #elif defined(__GNUC__) #define ABSL_INTERNAL_HAS_CXA_DEMANGLE 1 #elif defined(__clang__) && !defined(_MSC_VER)
diff --git a/absl/container/btree_test.cc b/absl/container/btree_test.cc index a6438f5..1d2c2a6 100644 --- a/absl/container/btree_test.cc +++ b/absl/container/btree_test.cc
@@ -2048,10 +2048,7 @@ TEST(Btree, ExtractDoesntCauseExtraMoves) { #ifdef _MSC_VER - // This conditional is to avoid an unreachable code warning. - if (_MSC_VER > 0) { - GTEST_SKIP() << "This test fails on MSVC."; - } + GTEST_SKIP() << "This test fails on MSVC."; #endif using Set = absl::btree_set<MovableOnlyInstance>;
diff --git a/absl/copts/GENERATED_AbseilCopts.cmake b/absl/copts/GENERATED_AbseilCopts.cmake index b08c34c..32b97fc 100644 --- a/absl/copts/GENERATED_AbseilCopts.cmake +++ b/absl/copts/GENERATED_AbseilCopts.cmake
@@ -10,46 +10,6 @@ "/D_CRT_SECURE_NO_WARNINGS" "/D_SCL_SECURE_NO_WARNINGS" "/D_ENABLE_EXTENDED_ALIGNED_STORAGE" - "-Wmost" - "-Wextra" - "-Wc++98-compat-extra-semi" - "-Wcast-qual" - "-Wconversion" - "-Wdeprecated-pragma" - "-Wfloat-overflow-conversion" - "-Wfloat-zero-conversion" - "-Wfor-loop-analysis" - "-Wformat-security" - "-Wgnu-redeclared-enum" - "-Winfinite-recursion" - "-Winvalid-constexpr" - "-Wliteral-conversion" - "-Wmissing-declarations" - "-Wnullability-completeness" - "-Woverlength-strings" - "-Wpointer-arith" - "-Wself-assign" - "-Wshadow-all" - "-Wshorten-64-to-32" - "-Wsign-conversion" - "-Wstring-conversion" - "-Wtautological-overlap-compare" - "-Wtautological-unsigned-zero-compare" - "-Wthread-safety" - "-Wundef" - "-Wuninitialized" - "-Wunreachable-code" - "-Wunused-comparison" - "-Wunused-local-typedefs" - "-Wunused-result" - "-Wvla" - "-Wwrite-strings" - "-Wno-float-conversion" - "-Wno-implicit-float-conversion" - "-Wno-implicit-int-float-conversion" - "-Wno-unknown-warning-option" - "-Wno-unused-command-line-argument" - "-DNOMINMAX" ) list(APPEND ABSL_CLANG_CL_TEST_FLAGS @@ -59,43 +19,6 @@ "/D_CRT_SECURE_NO_WARNINGS" "/D_SCL_SECURE_NO_WARNINGS" "/D_ENABLE_EXTENDED_ALIGNED_STORAGE" - "-Wmost" - "-Wextra" - "-Wc++98-compat-extra-semi" - "-Wcast-qual" - "-Wconversion" - "-Wdeprecated-pragma" - "-Wfloat-overflow-conversion" - "-Wfloat-zero-conversion" - "-Wfor-loop-analysis" - "-Wformat-security" - "-Wgnu-redeclared-enum" - "-Winfinite-recursion" - "-Winvalid-constexpr" - "-Wliteral-conversion" - "-Wmissing-declarations" - "-Woverlength-strings" - "-Wpointer-arith" - "-Wself-assign" - "-Wshadow-all" - "-Wstring-conversion" - "-Wtautological-overlap-compare" - "-Wtautological-unsigned-zero-compare" - "-Wthread-safety" - "-Wundef" - "-Wuninitialized" - "-Wunreachable-code" - "-Wunused-comparison" - "-Wunused-local-typedefs" - "-Wunused-result" - "-Wvla" - "-Wwrite-strings" - "-Wno-float-conversion" - "-Wno-implicit-float-conversion" - "-Wno-implicit-int-float-conversion" - "-Wno-unknown-warning-option" - "-Wno-unused-command-line-argument" - "-DNOMINMAX" "-Wno-deprecated-declarations" "-Wno-implicit-int-conversion" "-Wno-missing-prototypes" @@ -161,7 +84,6 @@ list(APPEND ABSL_LLVM_FLAGS "-Wall" - "-Wmost" "-Wextra" "-Wc++98-compat-extra-semi" "-Wcast-qual" @@ -205,7 +127,6 @@ list(APPEND ABSL_LLVM_TEST_FLAGS "-Wall" - "-Wmost" "-Wextra" "-Wc++98-compat-extra-semi" "-Wcast-qual"
diff --git a/absl/copts/GENERATED_copts.bzl b/absl/copts/GENERATED_copts.bzl index 8c1d7a0..8d72190 100644 --- a/absl/copts/GENERATED_copts.bzl +++ b/absl/copts/GENERATED_copts.bzl
@@ -11,46 +11,6 @@ "/D_CRT_SECURE_NO_WARNINGS", "/D_SCL_SECURE_NO_WARNINGS", "/D_ENABLE_EXTENDED_ALIGNED_STORAGE", - "-Wmost", - "-Wextra", - "-Wc++98-compat-extra-semi", - "-Wcast-qual", - "-Wconversion", - "-Wdeprecated-pragma", - "-Wfloat-overflow-conversion", - "-Wfloat-zero-conversion", - "-Wfor-loop-analysis", - "-Wformat-security", - "-Wgnu-redeclared-enum", - "-Winfinite-recursion", - "-Winvalid-constexpr", - "-Wliteral-conversion", - "-Wmissing-declarations", - "-Wnullability-completeness", - "-Woverlength-strings", - "-Wpointer-arith", - "-Wself-assign", - "-Wshadow-all", - "-Wshorten-64-to-32", - "-Wsign-conversion", - "-Wstring-conversion", - "-Wtautological-overlap-compare", - "-Wtautological-unsigned-zero-compare", - "-Wthread-safety", - "-Wundef", - "-Wuninitialized", - "-Wunreachable-code", - "-Wunused-comparison", - "-Wunused-local-typedefs", - "-Wunused-result", - "-Wvla", - "-Wwrite-strings", - "-Wno-float-conversion", - "-Wno-implicit-float-conversion", - "-Wno-implicit-int-float-conversion", - "-Wno-unknown-warning-option", - "-Wno-unused-command-line-argument", - "-DNOMINMAX", ] ABSL_CLANG_CL_TEST_FLAGS = [ @@ -60,43 +20,6 @@ "/D_CRT_SECURE_NO_WARNINGS", "/D_SCL_SECURE_NO_WARNINGS", "/D_ENABLE_EXTENDED_ALIGNED_STORAGE", - "-Wmost", - "-Wextra", - "-Wc++98-compat-extra-semi", - "-Wcast-qual", - "-Wconversion", - "-Wdeprecated-pragma", - "-Wfloat-overflow-conversion", - "-Wfloat-zero-conversion", - "-Wfor-loop-analysis", - "-Wformat-security", - "-Wgnu-redeclared-enum", - "-Winfinite-recursion", - "-Winvalid-constexpr", - "-Wliteral-conversion", - "-Wmissing-declarations", - "-Woverlength-strings", - "-Wpointer-arith", - "-Wself-assign", - "-Wshadow-all", - "-Wstring-conversion", - "-Wtautological-overlap-compare", - "-Wtautological-unsigned-zero-compare", - "-Wthread-safety", - "-Wundef", - "-Wuninitialized", - "-Wunreachable-code", - "-Wunused-comparison", - "-Wunused-local-typedefs", - "-Wunused-result", - "-Wvla", - "-Wwrite-strings", - "-Wno-float-conversion", - "-Wno-implicit-float-conversion", - "-Wno-implicit-int-float-conversion", - "-Wno-unknown-warning-option", - "-Wno-unused-command-line-argument", - "-DNOMINMAX", "-Wno-deprecated-declarations", "-Wno-implicit-int-conversion", "-Wno-missing-prototypes", @@ -162,7 +85,6 @@ ABSL_LLVM_FLAGS = [ "-Wall", - "-Wmost", "-Wextra", "-Wc++98-compat-extra-semi", "-Wcast-qual", @@ -206,7 +128,6 @@ ABSL_LLVM_TEST_FLAGS = [ "-Wall", - "-Wmost", "-Wextra", "-Wc++98-compat-extra-semi", "-Wcast-qual",
diff --git a/absl/copts/copts.py b/absl/copts/copts.py index c1d1f4a..e6c4385 100644 --- a/absl/copts/copts.py +++ b/absl/copts/copts.py
@@ -41,13 +41,8 @@ "-Wno-unused-private-field", ] -# https://github.com/llvm/llvm-project/issues/102982 -# A list of LLVM base flags without -Wall. This is because clang-cl -# translates -Wall to -Weverything on Windows, mimicking MSVCs -# behavior. On most other platforms, -Wall is just a set of very good -# default flags. -ABSL_LLVM_BASE_FLAGS = [ - "-Wmost", +ABSL_LLVM_FLAGS = [ + "-Wall", "-Wextra", "-Wc++98-compat-extra-semi", "-Wcast-qual", @@ -94,8 +89,6 @@ "-DNOMINMAX", ] -ABSL_LLVM_FLAGS = ["-Wall"] + ABSL_LLVM_BASE_FLAGS - ABSL_LLVM_TEST_ADDITIONAL_FLAGS = [ "-Wno-deprecated-declarations", "-Wno-implicit-int-conversion", @@ -171,15 +164,9 @@ "ABSL_LLVM_TEST_FLAGS": GccStyleFilterAndCombine( ABSL_LLVM_FLAGS, ABSL_LLVM_TEST_ADDITIONAL_FLAGS ), - "ABSL_CLANG_CL_FLAGS": ( - MSVC_BIG_WARNING_FLAGS + MSVC_DEFINES + ABSL_LLVM_BASE_FLAGS - ), + "ABSL_CLANG_CL_FLAGS": MSVC_BIG_WARNING_FLAGS + MSVC_DEFINES, "ABSL_CLANG_CL_TEST_FLAGS": ( - MSVC_BIG_WARNING_FLAGS - + MSVC_DEFINES - + GccStyleFilterAndCombine( - ABSL_LLVM_BASE_FLAGS, ABSL_LLVM_TEST_ADDITIONAL_FLAGS - ) + MSVC_BIG_WARNING_FLAGS + MSVC_DEFINES + ABSL_LLVM_TEST_ADDITIONAL_FLAGS ), "ABSL_MSVC_FLAGS": ( MSVC_BIG_WARNING_FLAGS + MSVC_WARNING_FLAGS + MSVC_DEFINES
diff --git a/absl/debugging/internal/demangle.cc b/absl/debugging/internal/demangle.cc index a8d7511..5f62ebb 100644 --- a/absl/debugging/internal/demangle.cc +++ b/absl/debugging/internal/demangle.cc
@@ -28,7 +28,7 @@ #include "absl/base/config.h" #include "absl/debugging/internal/demangle_rust.h" -#ifdef ABSL_INTERNAL_HAS_CXA_DEMANGLE +#if ABSL_INTERNAL_HAS_CXA_DEMANGLE #include <cxxabi.h> #endif @@ -2941,7 +2941,7 @@ std::string out; int status = 0; char* demangled = nullptr; -#ifdef ABSL_INTERNAL_HAS_CXA_DEMANGLE +#if ABSL_INTERNAL_HAS_CXA_DEMANGLE demangled = abi::__cxa_demangle(mangled, nullptr, nullptr, &status); #endif if (status == 0 && demangled != nullptr) {
diff --git a/absl/debugging/stacktrace_test.cc b/absl/debugging/stacktrace_test.cc index 177db64..c1d3d84 100644 --- a/absl/debugging/stacktrace_test.cc +++ b/absl/debugging/stacktrace_test.cc
@@ -94,23 +94,15 @@ // This is a separate function to avoid inlining. ABSL_ATTRIBUTE_NOINLINE static void FixupNoFixupEquivalenceNoInline() { #if !ABSL_HAVE_ATTRIBUTE_WEAK - const char* kSkipReason = "Need weak symbol support"; -#elif defined(__riscv) - const char* kSkipReason = - "Skipping test on RISC-V due to pre-existing failure"; -#elif defined(_WIN32) - // TODO(b/434184677): Add support for fixups on Windows if needed - const char* kSkipReason = - "Skipping test on Windows due to lack of support for fixups"; -#else - const char* kSkipReason = nullptr; + GTEST_SKIP() << "Need weak symbol support"; #endif - - // This conditional is to avoid an unreachable code warning. - if (kSkipReason != nullptr) { - GTEST_SKIP() << kSkipReason; - } - +#if defined(__riscv) + GTEST_SKIP() << "Skipping test on RISC-V due to pre-existing failure"; +#endif +#if defined(_WIN32) + // TODO(b/434184677): Add support for fixups on Windows if needed + GTEST_SKIP() << "Skipping test on Windows due to lack of support for fixups"; +#endif bool can_rely_on_frame_pointers = false; if (!can_rely_on_frame_pointers) { GTEST_SKIP() << "Frame pointers are required, but not guaranteed in OSS"; @@ -241,19 +233,12 @@ TEST(StackTrace, FixupLowStackUsage) { #if !ABSL_HAVE_ATTRIBUTE_WEAK - const char* kSkipReason = "Skipping test on MSVC due to weak symbols"; -#elif defined(_WIN32) - // TODO(b/434184677): Add support for fixups on Windows if needed - const char* kSkipReason = - "Skipping test on Windows due to lack of support for fixups"; -#else - const char* kSkipReason = nullptr; + GTEST_SKIP() << "Skipping test on MSVC due to weak symbols"; #endif - - // This conditional is to avoid an unreachable code warning. - if (kSkipReason != nullptr) { - GTEST_SKIP() << kSkipReason; - } +#if defined(_WIN32) + // TODO(b/434184677): Add support for fixups on Windows if needed + GTEST_SKIP() << "Skipping test on Windows due to lack of support for fixups"; +#endif const Cleanup restore_state([enable_fixup = g_enable_fixup, fixup_calls = g_fixup_calls, @@ -291,19 +276,12 @@ TEST(StackTrace, CustomUnwinderPerformsFixup) { #if !ABSL_HAVE_ATTRIBUTE_WEAK - const char* kSkipReason = "Need weak symbol support"; -#elif defined(_WIN32) - // TODO(b/434184677): Add support for fixups on Windows if needed - const char* kSkipReason = - "Skipping test on Windows due to lack of support for fixups"; -#else - const char* kSkipReason = nullptr; + GTEST_SKIP() << "Need weak symbol support"; #endif - - // This conditional is to avoid an unreachable code warning. - if (kSkipReason != nullptr) { - GTEST_SKIP() << kSkipReason; - } +#if defined(_WIN32) + // TODO(b/434184677): Add support for fixups on Windows if needed + GTEST_SKIP() << "Skipping test on Windows due to lack of support for fixups"; +#endif constexpr int kSkip = 1; // Skip our own frame, whose return PCs won't match constexpr auto kStackCount = 1;
diff --git a/absl/hash/internal/low_level_hash_test.cc b/absl/hash/internal/low_level_hash_test.cc index b4fe872..c8573b1 100644 --- a/absl/hash/internal/low_level_hash_test.cc +++ b/absl/hash/internal/low_level_hash_test.cc
@@ -361,13 +361,9 @@ #if defined(ABSL_IS_BIG_ENDIAN) || !defined(ABSL_HAVE_INTRINSIC_INT128) || \ UINTPTR_MAX != UINT64_MAX constexpr uint64_t kGolden[kNumGoldenOutputs] = {}; - // This conditional is to avoid an unreachable code warning. - bool skip = true; - if (skip) { - GTEST_SKIP() - << "We only maintain golden data for little endian 64 bit systems with " - "128 bit intristics."; - } + GTEST_SKIP() + << "We only maintain golden data for little endian 64 bit systems with " + "128 bit intristics."; #elif defined(__SSE4_2__) && defined(__AES__) constexpr uint64_t kGolden[kNumGoldenOutputs] = { 0xd6bdb2c9ba5e55f2, 0xffd3e23d4115a8ae, 0x2c3218ef486127de,
diff --git a/absl/log/internal/vlog_config.cc b/absl/log/internal/vlog_config.cc index e9b4827..97665a5 100644 --- a/absl/log/internal/vlog_config.cc +++ b/absl/log/internal/vlog_config.cc
@@ -45,25 +45,13 @@ namespace log_internal { namespace { - -#ifdef _WIN32 -constexpr char kPathSeparators[] = "/\\"; -#else -constexpr char kPathSeparators[] = "/"; -#endif - bool ModuleIsPath(absl::string_view module_pattern) { - return module_pattern.find_first_of(kPathSeparators) != module_pattern.npos; +#ifdef _WIN32 + return module_pattern.find_first_of("/\\") != module_pattern.npos; +#else + return module_pattern.find('/') != module_pattern.npos; +#endif } - -absl::string_view Basename(absl::string_view file) { - auto sep = file.find_last_of(kPathSeparators); - if (sep != file.npos) { - file.remove_prefix(sep + 1); - } - return file; -} - } // namespace bool VLogSite::SlowIsEnabled(int stale_v, int level) { @@ -141,9 +129,21 @@ // parsing flags). We can't allocate in `VLOG`, so we treat null as empty // here and press on. if (!infos || infos->empty()) return current_global_v; + // Get basename for file + absl::string_view basename = file; + { + const size_t sep = basename.rfind('/'); + if (sep != basename.npos) { + basename.remove_prefix(sep + 1); +#ifdef _WIN32 + } else { + const size_t sep = basename.rfind('\\'); + if (sep != basename.npos) basename.remove_prefix(sep + 1); +#endif + } + } - absl::string_view stem = file; - absl::string_view stem_basename = Basename(stem); + absl::string_view stem = file, stem_basename = basename; { const size_t sep = stem_basename.find('.'); if (sep != stem_basename.npos) {