nlohmann / json

JSON for Modern C++
https://json.nlohmann.me
MIT License
42.18k stars 6.65k forks source link

`modernize-avoid-c-arrays` clang-tidy warning when using `NLOHMANN_JSON_SERIALIZE_ENUM` macro #3924

Open alzix opened 1 year ago

alzix commented 1 year ago

Description

clang-tidy emits a warning on a code using NLOHMANN_JSON_SERIALIZE_ENUM, this requires to to put no-lint comments on the usage code

Reproduction steps

run clang-tidy on the code using NLOHMANN_JSON_SERIALIZE_ENUM macro

Expected vs. actual results

expected no warnings

Minimal code example

++
enum class Foo {
  kFoo1,
  kFoo2
};
NLOHMANN_JSON_SERIALIZE_ENUM(
    Foo,
    {
        {Foo::kFoo1, "FOO1"},
        {Foo::kFoo2, "FOO2"},
    })

Error messages

| Clang-Tidy: Do not declare C-style arrays, use std::array<> instead

Compiler and operating system

Apple clang version 14.0.0, MacOS

Library version

v3.11.2

Validation

nlohmann commented 1 year ago

It's a false positive - we do not use arrays, but only braced initialization. And idea how to fix this?

avighnac commented 1 year ago

Sounds like a clang issue though, right?

nlohmann commented 1 year ago

I guess. The code surely does not define a C array.

alzix commented 1 year ago

how about static const std::pair<ENUM_TYPE, BasicJsonType> m[] = __VA_ARGS__; in https://github.com/nlohmann/json/blob/c71ecde505ebf236048a731c81ae8ecaf2b260a8/include/nlohmann/detail/macro_scope.hpp#L212