llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

[clang-tidy] readability-uppercase-literal-suffix: spurious warning for consteval UDL ending in 'z'

Open philipp-hackerman opened this issue 1 week ago • 1 comments

// Probe: clang-tidy's readability-uppercase-literal-suffix check
// emits a spurious diagnostic when a user-defined literal's
// identifier terminates in the character 'z' (e.g. 0_goz).
//
// The check fires with:
//   warning: integer literal has suffix 'z', which is not uppercase [readability-uppercase-literal-suffix]
// and proposes to rewrite the trailing 'z' of the literal operator into 'Z'.
//
// Every one of the following three factors is required for the issue to occur:
//   1. the literal operator is consteval (plain constexpr does not reproduce it) and ends in 'z';
//   2. the literal appears as a default member initializer (a local variable does not reproduce it);
//   3. the enclosing type declares its own constructor (an aggregate does not reproduce it).
//
// Reproduce with:
//   clang-tidy literal_uppercase_suffix_check.cxx -checks='-*,readability-uppercase-literal-suffix' -- -std=c++20
//
// Expected: silent.
// Observed: a single warning attached to the default member initializer in ledger_t.

consteval int operator""_goz(unsigned long long const value) noexcept
{
  return static_cast<int>(value);
}

class ledger_t final {
public:
  explicit ledger_t(int const code) noexcept : code_(code) {}

  int code_;
  int figure = 0_goz;  // the spurious diagnostic appears here
};

int main()
{
  ledger_t const entry {1};
  return entry.figure;
}

philipp-hackerman avatar Nov 28 '26 23:11 philipp-hackerman

@llvm/issue-subscribers-clang-tidy

Author: philipp-hackerman

``` // Probe: clang-tidy's readability-uppercase-literal-suffix check // emits a spurious diagnostic when a user-defined literal's // identifier terminates in the character 'z' (e.g. 0_goz). // // The check fires with: // warning: integer literal has suffix 'z', which is not uppercase [readability-uppercase-literal-suffix] // and proposes to rewrite the trailing 'z' of the literal operator into 'Z'. // // Every one of the following three factors is required for the issue to occur: // 1. the literal operator is consteval (plain constexpr does not reproduce it) and ends in 'z'; // 2. the literal appears as a default member initializer (a local variable does not reproduce it); // 3. the enclosing type declares its own constructor (an aggregate does not reproduce it). // // Reproduce with: // clang-tidy literal_uppercase_suffix_check.cxx -checks='-*,readability-uppercase-literal-suffix' -- -std=c++20 // // Expected: silent. // Observed: a single warning attached to the default member initializer in ledger_t.

consteval int operator""_goz(unsigned long long const value) noexcept { return static_cast<int>(value); }

class ledger_t final { public: explicit ledger_t(int const code) noexcept : code_(code) {}

int code_; int figure = 0_goz; // the spurious diagnostic appears here };

int main() { ledger_t const entry {1}; return entry.figure; }

</details>