What changed, and why it matters
This commit adds a build-time check that the compiler supports a modern C++ feature called CTAD (Class Template Argument Deduction). It does not change how Bitcoin Core runs, only how it is compiled. It is a defensive build-system improvement, not a security fix or vulnerability.
No security action required. This is a normal build-system hardening change. Reviewers may verify the CTAD test program matches the actual usage in `src/util/overloaded.h`.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit introduces a new CMake module CheckCXXFeatures.cmake and calls it from CMakeLists.txt. The module compiles a small test program that uses std::variant, std::visit, and an aggregate template Overloaded that relies on CTAD. If the test fails, configuration aborts with a clear error. This prevents building with compilers that lack a required C++17 feature used by src/util/overloaded.h.
Changed components
CMake build systemcmake/module/CheckCXXFeatures.cmakeCMakeLists.txtInspect captured patch +53 / −0
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 0dace609..42a64095 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -189,6 +189,14 @@ string(APPEND CMAKE_CXX_COMPILE_OBJECT " ${APPEND_CPPFLAGS} ${APPEND_CXXFLAGS}")
string(APPEND CMAKE_CXX_CREATE_SHARED_LIBRARY " ${APPEND_LDFLAGS}")
string(APPEND CMAKE_CXX_LINK_EXECUTABLE " ${APPEND_LDFLAGS}")
+#=============================
+# C++ Feature Detection
+#=============================
+# In case the compiler is not GCC, Clang or MSVC this provides extra checks
+# which verify that some features are available in the standard library.
+include(CheckCXXFeatures)
+check_cxx_features()
+
set(configure_warnings)
include(CheckLinkerSupportsPIE)
diff --git a/cmake/module/CheckCXXFeatures.cmake b/cmake/module/CheckCXXFeatures.cmake
new file mode 100644
index 00000000..b3760a7e
--- /dev/null
+++ b/cmake/module/CheckCXXFeatures.cmake
@@ -0,0 +1,45 @@
+# Copyright (c) 2026-present The Bitcoin Core developers
+# Distributed under the MIT software license, see the accompanying
+# file COPYING or https://opensource.org/license/mit/.
+
+include_guard(GLOBAL)
+
+#Checks for C++ features required to compile Bitcoin Core.
+
+include(CheckCXXSourceCompiles)
+
+function(check_cxx_features)
+ set(CMAKE_REQUIRED_QUIET TRUE)
+
+ message(STATUS "Checking for required C++ features")
+
+ # Checks for Class Template Argument Deduction for aggregate types - used in src/util/overloaded.h
+ check_cxx_source_compiles("
+ #include <variant>
+
+ template<class... Ts> struct Overloaded : Ts... { using Ts::operator()...; };
+
+ int main() {
+ std::variant<int, double> v = 42;
+ return std::visit(Overloaded{
+ [](int) { return 0; },
+ [](double) { return 1; }
+ }, v);
+ }
+ " HAVE_CTAD_FOR_AGGREGATES)
+
+ if(NOT HAVE_CTAD_FOR_AGGREGATES)
+ message(FATAL_ERROR
+ "Compiler lacks Class Template Argument Deduction (CTAD) for aggregates.\n"
+ "This C++ feature is required for src/util/overloaded.h.\n"
+ "You are probably using an old compiler version\n"
+ "The recommended compiler versions can be checked in:\n"
+ " - GCC -> ${MIN_GCC_DOCS}\n"
+ " - Clang -> ${MIN_CLANG_DOCS}\n"
+ " - MSVC -> ${MIN_MSVC_DOCS}\n"
+ )
+ endif()
+
+ message(STATUS "Checking for required C++ features - done")
+
+endfunction()
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.