C++ Standards Supported by Abseil C++: Requirements and Compatibility
Abseil C++ requires C++17 as its minimum supported language standard and optionally enables C++20 and C++23 features when available.
The Abseil C++ library (abseil/abseil-cpp) is a collection of C++ library code designed to augment the C++ standard library. Understanding which C++ standards supported by Abseil are required helps developers configure their build systems correctly and take advantage of modern language features.
Minimum C++ Standard Requirement
Abseil C++ strictly requires C++17 as the baseline language version. The project no longer supports C++14 or earlier standards.
According to the repository's README.md (lines 4-5), the code is explicitly declared as "compliant to C++17". This requirement is reinforced throughout the codebase via implementation comments. For example, absl/types/variant.h contains the comment "Now that C++17 is required" at line 20, indicating the library has transitioned from polyfill implementations to standard library facilities. Similar comments appear in absl/types/optional.h (line 20) and absl/strings/string_view.h (lines 20-21), confirming that fundamental types like absl::optional and absl::string_view now rely on C++17's std::optional and std::string_view.
Evidence from Source Documentation
The C++17 requirement is documented in several key header files:
absl/types/variant.h(line 20): Contains implementation notes stating C++17 is now requiredabsl/strings/string_view.h(lines 20-21): Documents the transition to standardstd::string_viewabsl/types/optional.h(line 20): References the C++17 requirement for optional types
These comments reflect the library's architectural decision to depend on C++17's guaranteed language features and standard library components.
Optional Support for C++20 and C++23
While C++17 is mandatory, Abseil C++ uses conditional compilation to leverage C++20 and C++23 features when the compiler supports them. The library uses preprocessor checks like __cplusplus >= 202002L to detect standard versions and enable enhanced functionality.
C++20 Feature Detection
In absl/types/span.h (lines 33-34), the codebase uses preprocessor guards to handle constexpr std::span features available in C++20:
#if __cplusplus >= 202002L
// C++20 specific constexpr handling
#endif
Abseil also detects C++20's three-way comparison operator (<=>) and enhanced constexpr capabilities, enabling more compile-time evaluations when building with -std=c++20 or higher.
C++23 Considerations
When compiled with C++23, Abseil can utilize newer standard library features such as std::ranges. However, these are strictly optional optimizations—the library maintains full functionality under pure C++17 compilation.
Build System Configuration
Both CMake and Bazel build configurations enforce the C++17 minimum requirement.
The top-level CMakeLists.txt sets CMAKE_CXX_STANDARD to 17 or higher, ensuring the compiler flag -std=c++17 is applied. Similarly, the Bazel build rules in BUILD.bazel configure copts to specify C++17 as the compilation standard. Attempting to build with an older standard results in compilation errors due to missing language features.
Code Examples
The following example compiles under the required C++17 standard:
#include "absl/strings/string_view.h"
#include "absl/status/status.h"
absl::Status DoWork(absl::string_view input) {
if (input.empty()) return absl::InvalidArgumentError("empty");
return absl::OkStatus();
}
This code uses absl::string_view, which since the C++17 requirement has become an alias for std::string_view.
For projects using C++20, Abseil enables additional features:
#if __cplusplus >= 202002L
#include <compare>
#include "absl/types/optional.h"
absl::optional<int> CompareValues(int a, int b) {
if (auto cmp = (a <=> b); cmp == std::strong_ordering::less) {
return a;
}
return b;
}
#endif
The second snippet activates only when the compiler reports C++20 support, demonstrating Abseil's forward compatibility strategy.
Summary
- C++17 is required: Abseil C++ requires C++17 as the minimum language standard, as documented in
README.mdand implementation headers likeabsl/types/variant.h. - C++20 is optional: The library detects C++20 via
__cplusplus >= 202002Land enables additional constexpr and comparison features. - C++23 support: Newer standards are supported opportunistically but not required.
- Build enforcement: Both CMake (
CMAKE_CXX_STANDARD) and Bazel configurations enforce the C++17 minimum.
Frequently Asked Questions
Does Abseil support C++14 or earlier standards?
No. Abseil C++ explicitly requires C++17 as the minimum version. Header files such as absl/types/optional.h and absl/types/variant.h contain comments indicating that C++17 is now required, and the library relies on standard library features like std::string_view and std::optional that were introduced in C++17.
Can I use Abseil with C++20 or C++23?
Yes. Abseil C++ is compatible with C++20 and C++23. When you compile with these newer standards, Abseil detects them using preprocessor checks like __cplusplus >= 202002L and enables enhanced features such as three-way comparison operators and extended constexpr support. However, C++17 remains the baseline requirement.
How does Abseil detect which C++ standard is being used?
Abseil uses the predefined preprocessor macro __cplusplus to detect the C++ standard version. For example, in absl/types/span.h (lines 33-34), the code checks #if __cplusplus >= 202002L to conditionally enable C++20-specific features. This allows the library to maintain backward compatibility while taking advantage of newer language features when available.
What build configuration is needed to compile Abseil?
You must configure your build system to use at least C++17. In CMake, this means setting CMAKE_CXX_STANDARD to 17 or higher in your CMakeLists.txt. For Bazel builds, ensure your toolchain specifies -std=c++17 or newer. The Abseil repository's own CMakeLists.txt enforces this minimum requirement automatically.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →