Skip to content

[clang-tidy] [Modules] Avoid duplicated checkings #145628

@ChuanqiXu9

Description

@ChuanqiXu9

Reproducer:

// RUN: rm -fr %t
// RUN: mkdir %t
// RUN: split-file %s %t
// RUN: mkdir %t/tmp
//
// RUN: %check_clang_tidy -std=c++20 -check-suffix=DEFAULT %t/a.cpp \
// RUN:   cppcoreguidelines-narrowing-conversions %t/a.cpp -- \
// RUN:   -config='{}'

// RUN: %clang -std=c++20 -x c++-module %t/a.cpp --precompile -o %t/a.pcm

// RUN: %check_clang_tidy -std=c++20 -check-suffix=DEFAULT %t/use.cpp \
// RUN:   cppcoreguidelines-narrowing-conversions %t/a.cpp -- \
// RUN:   -config='{}' -- -fmodule-file=a=%t/a.pcm 

//--- a.cpp
export module a;
export void most_narrowing_is_not_ok() {
  int i;
  long long ui;
  i = ui;
  // CHECK-MESSAGES-DEFAULT: :[[@LINE-1]]:7: warning: narrowing conversion from 'long long' to signed type 'int' is implementation-defined [cppcoreguidelines-narrowing-conversions]
}

//--- use.cpp
import a;
void use() {
  most_narrowing_is_not_ok();
}
CHECK-MESSAGES-DEFAULT:
}

In this example, we don't hope we see any warning from use.cpp. But now we can see:

1 warning generated.
Suppressed 1 warnings (1 in non-user code).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.

Although technically we can filter the warnings, but what we want is to avoid checking decls from imported modules. This can save a lot of times.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions