Skip to content

[clang-tidy] NOLINT not working in macros in clang-tidy-14 (regression) #55134

Closed
@paulaltin

Description

@paulaltin

Clang-tidy version 13 generates no warnings for this code:

#define CREATE_STRUCT(name)    \
struct name {	/* NOLINT */   \
    int a = 0;                 \
    int b;                     \
}; 				

CREATE_STRUCT(X)
CREATE_STRUCT(Y)
CREATE_STRUCT(Z)

when invoked as:

clang-tidy-13 test.cpp -checks=cppcoreguidelines-pro-type-member-init

Clang-tidy version 14 generates warnings on lines 7-9 when invoked the same way.

Activity

paulaltin

paulaltin commented on Apr 27, 2022

@paulaltin
ContributorAuthor

It appears from the summary of this patch that the intention is for "clang-tidy [to] look at the line of macro invocation and every line of macro definition for a NOLINT comment."

https://reviews.llvm.org/D24845

paulaltin

paulaltin commented on Apr 27, 2022

@paulaltin
ContributorAuthor

If anyone knows of a workaround for this (short of marking every use of the macro with NOLINT), I would be very grateful. Adding NOLINT to every line that uses the macro isn't possible in my case, but I can modify the macro definition.

llvmbot

llvmbot commented on Apr 27, 2022

@llvmbot
Member

@llvm/issue-subscribers-clang-tidy

firewave

firewave commented on Apr 27, 2022

@firewave

I encountered a similar issue with NOLINTNEXTLINE quite a while ago - see #46511.

paulaltin

paulaltin commented on Apr 28, 2022

@paulaltin
ContributorAuthor

@firewave – interesting, thanks for the info! Did you ever find a solution/workaround?

It looks like this issue is also specific to this check, and doesn't actually have anything to do with the macro having multiple lines – if I put the entire macro on one line the problem still occurs:

// NOLINTNEXTLINE
#define CREATE_STRUCT_ONELINE(name) struct name { int a = 0; int b; }; // NOLINT

Either of the NOLINTNEXTLINE and NOLINT comments were enough to suppress the warning in version 13, but neither works in version 14.

Other warnings can be suppressed as expected, even in multi-line macros, e.g. the NOLINT comment here works to suppress the readability-use-anyofallof warning in both versions:

#include <vector>

#define CREATE_FUNCTION(name)           \
bool name() {                           \
    std::vector<int> v;                 \
    for (auto el : v)  /* NOLINT */     \
        if (el != 0)                    \
            return false;               \
    return true;                        \
}

CREATE_FUNCTION(F)
changed the title [-][clang-tidy] NOLINT not working in multi-line macros in clang-tidy-14 (regression)[/-] [+][clang-tidy] NOLINT does not suppress cppcoreguidelines-pro-type-member-init warnings in clang-tidy-14 (regression)[/+] on Apr 28, 2022
changed the title [-][clang-tidy] NOLINT does not suppress cppcoreguidelines-pro-type-member-init warnings in clang-tidy-14 (regression)[/-] [+][clang-tidy] NOLINT does not suppress cppcoreguidelines-pro-type-member-init warnings in macros using clang-tidy-14 (regression)[/+] on Apr 28, 2022
Skylion007

Skylion007 commented on May 9, 2022

@Skylion007

I am encountering similar issues with google-explicit-constructor when trying to update clang-tidy to 14 for pybind11: https://github.com/pybind/pybind11/blob/2e331308d38a521c087e7fc0cfee227cd29f3f71/include/pybind11/pytypes.h#L1029 . NOLINTS are ignored. Interestingly, the 'bugprone-macro-*' NOLINT comments seem to work fine. Even NOLINTBEGIN NOLINTEND do not work when used in the multiline macro.

Skylion007

Skylion007 commented on May 9, 2022

@Skylion007

@paulaltin This implies the issue is not specific to this check, feel free to update the title.

changed the title [-][clang-tidy] NOLINT does not suppress cppcoreguidelines-pro-type-member-init warnings in macros using clang-tidy-14 (regression)[/-] [+][clang-tidy] NOLINT not working in macros in clang-tidy-14 (regression)[/+] on May 11, 2022
paulaltin

paulaltin commented on May 11, 2022

@paulaltin
ContributorAuthor

Checks known to have regressed in version 14:

  • cppcoreguidelines-pro-type-member-init
  • google-explicit-constructor

Checks known to have regressed in version 13:

  • google-explicit-constructor

Checks that were not working before version 13/14:

  • modernize-avoid-c-arrays
Skylion007

Skylion007 commented on May 11, 2022

@Skylion007

@paulaltin I have confirmed that the 'google-explicit ctor' seems to have actually regressed in version 13 as well (at least the latest minor release of it).

31 remaining items

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Development

    No branches or pull requests

      Participants

      @firewave@HighCommander4@Skylion007@EugeneZelenko@paulaltin

      Issue actions

        [clang-tidy] NOLINT not working in macros in clang-tidy-14 (regression) · Issue #55134 · llvm/llvm-project