Changeset View
Standalone View
clang-tools-extra/clang-tidy/bugprone/UnintendedADLCheck.h
- This file was added.
//===--- UnintendedADLCheck.h - clang-tidy ----------------------*- C++ -*-===// | |||||
// | |||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | |||||
// See https://llvm.org/LICENSE.txt for license information. | |||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | |||||
// | |||||
//===----------------------------------------------------------------------===// | |||||
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_UNINTENDEDADLCHECK_H | |||||
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_UNINTENDEDADLCHECK_H | |||||
#include "../ClangTidyCheck.h" | |||||
#include <string> | |||||
#include <vector> | |||||
Eugene.Zelenko: Unnecessary empty line. | |||||
namespace clang { | |||||
namespace tidy { | |||||
namespace bugprone { | |||||
/// Finds usages of ADL (argument-dependent lookup), or potential ADL in the | |||||
/// case of templates, that are not on the provided whitelist. | |||||
/// | |||||
/// For the user-facing documentation see: | |||||
/// http://clang.llvm.org/extra/clang-tidy/checks/bugprone-unintended-adl.html | |||||
class UnintendedADLCheck : public ClangTidyCheck { | |||||
const bool IgnoreOverloadedOperators; | |||||
const std::vector<std::string> Whitelist; | |||||
aaron.ballmanUnsubmitted I'd prefer a more descriptive name for this (and the user-facing option + documentation). How about AllowedIdentifiers or ADLEnabledIdentifiers or some such? aaron.ballman: I'd prefer a more descriptive name for this (and the user-facing option + documentation). How… | |||||
Not Done ReplyInline ActionsI think we should always ignore operators. I don't see value in having a mode where every comparison triggers this warning. EricWF: I think we should always ignore operators. I don't see value in having a mode where every… | |||||
Not Done ReplyInline ActionsI think there's value in that mode, for library writers (not libc++) who really care about finding every unintentional ADL in their whole library. The standard library is designed not-to-work with types like [Holder<Incomplete>](https://quuxplusone.github.io/blog/2019/09/26/uglification-doesnt-stop-adl/), but someone else's library might be designed to work even in that case, and then they'd want to hear about ADL lookups for things like operator,. Besides, it's just 1 extra line of code in the patch, isn't it? However, I now think I may not understand how this check works. I thought it looked for unqualified calls (even in templates) that "may" use ADL, but now that I look again at the tests, it seems to trigger only on concrete calls (in concrete template instantiations) that "do" use ADL, which sounds still useful but much less comprehensive than I had thought. I think it would catch template<class T> void foo(T t) { t, 0; } struct S { friend void operator,(S, int); }; template void foo(S); but not template<class T> void foo(T t) { t, 0; } struct S { friend void operator,(S, int); }; template void foo(int); or template<class T> void foo(T t) { t, 0; } is that right? Quuxplusone: I think there's value in that mode, for library writers (not libc++) who really care about… | |||||
@Quuxplusone your initial understanding was right; the check fires on both templates that "may" use ADL as well as concrete instantiations that "do." There are tests for both, but I see now that I failed to add tests for the "may" case for operators, which I'll do. logan-5: @Quuxplusone your initial understanding was right; the check fires on both templates that "may"… | |||||
public: | |||||
UnintendedADLCheck(StringRef Name, ClangTidyContext *Context); | |||||
void registerMatchers(ast_matchers::MatchFinder *Finder) override; | |||||
void check(const ast_matchers::MatchFinder::MatchResult &Result) override; | |||||
void storeOptions(ClangTidyOptions::OptionMap &Opts) override; | |||||
}; | |||||
} // namespace bugprone | |||||
} // namespace tidy | |||||
} // namespace clang | |||||
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_UNINTENDEDADLCHECK_H |
Unnecessary empty line.