Skip to content

[clang-tidy] Check request: bugprone-avoid-inline-constexpr-in-implementations #146612

@denzor200

Description

@denzor200

C++17 suggests us the possibility to use inline on constexpr variables, but when identical inline constexpr variables are defined in different translation units with different values, this violates the One Definition Rule (ODR) which manifests unpredictably (e.g., different values in different TUs).
Need a check to get rid from inline keyword on constexpr variables in source files.

BEFORE:

// foo.cpp
inline constexpr int MAX_SIZE = 1024;

AFTER:

// foo.cpp
constexpr int MAX_SIZE = 1024;

Scope

  • Applies only to sources (.cpp, .cxx, etc.), ignoring .h files.

Why bugprone-?

  • Runtime behaviour potentially affected due to unexpected constant's value selected in link time.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions