diff options
author | Aaron Ballman <aaron@aaronballman.com> | 2024-06-04 13:32:11 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-06-04 13:32:11 -0400 |
commit | e5f7123dfef3a80937d088d846ddb3b2bb1869b9 (patch) | |
tree | 0791b3e51594baac8b1d27677960081f5c778ecd /clang/docs | |
parent | 7dc84e225e11e37925db6f4f08269f447d2f2347 (diff) | |
download | llvm-e5f7123dfef3a80937d088d846ddb3b2bb1869b9.zip llvm-e5f7123dfef3a80937d088d846ddb3b2bb1869b9.tar.gz llvm-e5f7123dfef3a80937d088d846ddb3b2bb1869b9.tar.bz2 |
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.
Diffstat (limited to 'clang/docs')
-rw-r--r-- | clang/docs/ReleaseNotes.rst | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 99580c0..39a9013 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -207,6 +207,9 @@ C++23 Feature Support - Implemented `P1774R8: Portable assumptions <https://wg21.link/P1774R8>`_. - Implemented `P2448R2: Relaxing some constexpr restrictions <https://wg21.link/P2448R2>`_. + Note, the ``-Winvalid-constexpr`` diagnostic is now disabled in C++23 mode, + but can be explicitly specified to retain the old diagnostic checking + behavior. - Added a ``__reference_converts_from_temporary`` builtin, completing the necessary compiler support for `P2255R2: Type trait to determine if a reference binds to a temporary <https://wg21.link/P2255R2>`_. @@ -323,6 +326,17 @@ Non-comprehensive list of changes in this release - Builtins ``__builtin_shufflevector()`` and ``__builtin_convertvector()`` may now be used within constant expressions. +- When compiling a constexpr function, Clang will check to see whether the + function can *never* be used in a constant expression context and issues a + diagnostic under the ``-Winvalid-constexpr`` diagostic flag (which defaults + to an error). This check can be expensive because the mere presence of a + function marked ``constexpr`` will cause us to undergo constant expression + evaluation, even if the function is not called within the translation unit + being compiled. Due to the expense, Clang no longer checks constexpr function + bodies when the function is defined in a system header file or when + ``-Winvalid-constexpr`` is not enabled for the function definition, which + should result in mild compile-time performance improvements. + New Compiler Flags ------------------ - ``-fsanitize=implicit-bitfield-conversion`` checks implicit truncation and |