Skip to content

PR for llvm/llvm-project#55717 #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion clang-tools-extra/clang-tidy/NoLintDirectiveHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ bool NoLintDirectiveHandler::Impl::diagHasNoLintInMacro(
return true;
if (!DiagLoc.isMacroID())
return false;
DiagLoc = SrcMgr.getImmediateMacroCallerLoc(DiagLoc);
DiagLoc = SrcMgr.getImmediateExpansionRange(DiagLoc).getBegin();
}
return false;
}
Expand Down
4 changes: 4 additions & 0 deletions clang-tools-extra/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,10 @@ Improvements to clang-tidy

- Added support for external plugin checks with `-load`.

- Fixed a regression introduced in clang-tidy 14.0.0, which prevented NOLINTs
from suppressing diagnostics associated with macro arguments. This fixes
`Issue 55134 <https://github.com/llvm/llvm-project/issues/55134>`_.

New checks
^^^^^^^^^^

Expand Down
21 changes: 19 additions & 2 deletions clang-tools-extra/test/clang-tidy/infrastructure/nolint.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// REQUIRES: static-analyzer
// RUN: %check_clang_tidy %s google-explicit-constructor,clang-diagnostic-unused-variable,clang-analyzer-core.UndefinedBinaryOperatorResult,modernize-avoid-c-arrays,cppcoreguidelines-avoid-c-arrays %t -- -extra-arg=-Wunused-variable -- -I%S/Inputs/nolint
// RUN: %check_clang_tidy %s google-explicit-constructor,clang-diagnostic-unused-variable,clang-analyzer-core.UndefinedBinaryOperatorResult,modernize-avoid-c-arrays,cppcoreguidelines-avoid-c-arrays,cppcoreguidelines-pro-type-member-init %t -- -extra-arg=-Wunused-variable -- -I%S/Inputs/nolint

#include "trigger_warning.h"
void I(int& Out) {
Expand Down Expand Up @@ -96,6 +96,23 @@ MACRO_NOARG // NOLINT
#define MACRO_NOLINT class G { G(int i); }; // NOLINT
MACRO_NOLINT

// Check that we can suppress diagnostics about macro arguments (as opposed to
// diagnostics about the macro contents itself).
#define MACRO_SUPPRESS_DIAG_FOR_ARG_1(X) \
class X { \
X(int i); /* NOLINT(google-explicit-constructor) */ \
};

MACRO_SUPPRESS_DIAG_FOR_ARG_1(G1)

#define MACRO_SUPPRESS_DIAG_FOR_ARG_2(X) \
struct X { /* NOLINT(cppcoreguidelines-pro-type-member-init) */ \
int a = 0; \
int b; \
};

MACRO_SUPPRESS_DIAG_FOR_ARG_2(G2)

#define DOUBLE_MACRO MACRO(H) // NOLINT
DOUBLE_MACRO

Expand All @@ -116,4 +133,4 @@ int array2[10]; // NOLINT(cppcoreguidelines-avoid-c-arrays)
int array3[10]; // NOLINT(cppcoreguidelines-avoid-c-arrays,modernize-avoid-c-arrays)
int array4[10]; // NOLINT(*-avoid-c-arrays)

// CHECK-MESSAGES: Suppressed 34 warnings (34 NOLINT)
// CHECK-MESSAGES: Suppressed 36 warnings (36 NOLINT)