The Abseil C++ code is compiled using flags indicated within this guide. Our objective is to support as many warning flags as possible, to minimize the chance that your code will be impacted by flags that you may need in your development environment. However, given the plethora of possible compilation configurations, that is not always possible, and we’ve found some flags to be counter-productive.
This guide describes the warning flags we are using, per compiler. We do disable some flags to keep our code as noise-free as possible. Notes on flags that we do not support and have intentionally disabled are provided within this guide. Separately, some flags are also disabled within existing tests. In both cases, we will continue to work to reduce the number of flags we need to disable.
These flags (and flags sets) are defined in the Abseil code repository within the copts.bzl file.
At a high level, Abseil defines two sets of flags:
ABSL_TEST_COPTS includes all flags within
disables a number of them to avoid problems with certain tests. In general, you
ABSL_DEFAULT_COPTS as the canonical list of Abseil compiler
flags. We hope to harmonize these flag sets in the future.
ABSL_DEFAULT_COPTS contains one of the following flag sets,
depending on the compiler it is invoked under:
ABSL_GCC_FLAGSfor GNU gcc compilers
ABSL_LLVM_FLAGSfor Clang compilers
ABSL_MSVC_FLAGSfor Visual Studio/msvc compilers
These flag sets are documented below.
ABSL_GCC_FLAGS set of compiler flags has the following characteristics:
-Wextra. (Note that not “all” flags are contained with the GCC
-Wsign-comparebecause of the presence of signed and unsigned integer comparisons in our codebase (mostly between Abseil and the standard library).
ABSL_LLVM_FLAGS set of compiler flags is the most extensive set and
provides the most code analysis, which is why we recommend a Clang compiler.
The Clang compiler flag set has the following characteristics:
-Weverything. (Note that, like with GCC, not “all” flags are contained with the Clang
-Wconversionis disabled to turn off the overly-broad set of implicit conversion warnings. Many (but not all) of these implicit conversion warnings are later turned on.
-Wrange-loop-analysisis disabled because Clang’s implementation only ignores actual POD types; turning this warning on would require even small value types such as
absl::string_viewto be defined as const references within a range loop.
-Wglobal-constructorsis disabled because some low-level initialization abstractions (mostly internal) require them. In general, however, you should avoid global constructors.
-Wpackedare disabled because these flags are typically used as advisory warnings.
-Wgcc-compatis disabled because we want to use Clang-specific features in a Clang compilation branch and not get unnecessary warnings about GCC.
-Wextra-semiare disabled because they are still valid C++ code (and occur in cases of macro expansion).
-Wformat-literalis disabled because some of our logging code passes their literal arguments to helper functions as non-literal variables.
-Wswitch-enumsis disabled because it would break any users of existing enums, if additional enum entries were added.
ABSL_MSVC_FLAGS set of compiler flags is specific to MSVC/Visual Studio
and has the following characteristics:
\W3flag. (See Warning Levels).
/wd4005prevents warnings about macro redefinitions.
/wd4068prevents warnings on unknown pragmas.
/wd4244prevents warnings on implicit conversions.
/wd4267prevents warnings on conversion from
/wd4800prevents warnings on implicit conversion to type
/DNOMINMAXto prevent Windows overrides of
/DWIN32_LEAN_AND_MEANto reduce the amount of Windows-specific header files.
/D_CRT_SECURE_NO_WARNINGSto prevent Windows from complaining about standard C++ functions.