Skip to content

[clang-tidy] Check request: performance-use-inline-constexpr-in-headers #146179

@denzor200

Description

@denzor200

C++17 suggests us the possibility to use inline on constexpr variables, but pre-C++17 codebases (or code unaware of this rule) often omit inline in headers. This can silently bloat binaries and harm performance due to multiple symbol definitions.
Need a check to enforce inline on constexpr variables in header files.

BEFORE:

// header.h
constexpr int MAX_SIZE = 1024; 

AFTER:

// header.h
inline constexpr int MAX_SIZE = 1024; 

Scope

  • Applies only to headers (.h, .hpp, etc.), ignoring .cpp files.
  • Targets constexpr variables in global/namespace scope (not function locals).

Why performance-?

  • Binary size (reduces duplicate symbols).
  • Cache behavior (fewer redundant constants in memory).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions