From e5f7123dfef3a80937d088d846ddb3b2bb1869b9 Mon Sep 17 00:00:00 2001 From: Aaron Ballman Date: Tue, 4 Jun 2024 13:32:11 -0400 Subject: Disable constexpr function body checking in more situations (#94347) Before C++23, we would check a constexpr function body to diagnose if the function can never be evaluated in a constant expression context. This was previously required standards behavior, but C++23 relaxed the restrictions with P2448R2. While this checking is useful, it is also quite expensive, especially in pathological cases (see #92924 for an example), because it means the mere presence of a constexpr function definition will require constant evaluation even if the function is not used within the TU. Clang suppresses diagnostics in system headers by default and system headers (like STL implementations) can be full of constexpr function bodies. Now we suppress the check for a diagnostic if the function definition is in a system header or if the `-Winvalid-constexpr` diagnostic is disabled. This should have some mild compile time performance improvements. Also, the previous implementation would disable the diagnostic in C++23 mode entirely. Due to the benefit of the check, this patch now makes it possible to enable the diagnostic explicitly in C++23 mode. --- clang/lib/Frontend/CompilerInvocation.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'clang/lib/Frontend/CompilerInvocation.cpp') diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp index 14ee02c..58694e5 100644 --- a/clang/lib/Frontend/CompilerInvocation.cpp +++ b/clang/lib/Frontend/CompilerInvocation.cpp @@ -2407,6 +2407,9 @@ void CompilerInvocationBase::GenerateDiagnosticArgs( // This option is automatically generated from UndefPrefixes. if (Warning == "undef-prefix") continue; + // This option is automatically generated from CheckConstexprFunctionBodies. + if (Warning == "invalid-constexpr" || Warning == "no-invalid-constexpr") + continue; Consumer(StringRef("-W") + Warning); } -- cgit v1.1