警告由于 ADL 而丢失 std:: 前缀
Warn against missing std:: prefixes due to ADL
当参数类型在该命名空间中时,可以省略 <algorithm>
的 std::
命名空间,这通常是这种情况。是否有发现此类遗漏的警告或 clang-tidy 规则?
#include <vector>
#include <algorithm>
std::vector<int> v;
for_each(v.begin(), v.end(), [](auto){});
return 0;
以上示例使用最新的 clang 和 -Wall、-Wextra 和 -Wpedantic 编译,不会发出任何诊断信息:
tidy 中有一个开放的变化可以用来标记这个:
[patch] Summary
This patch adds bugprone-unintended-adl
which flags uses of ADL that are not on the provided whitelist.
bugprone-unintended-adl
Finds usages of ADL (argument-dependent lookup), or potential ADL in the case of templates, that are not on the provided lists of allowed identifiers and namespaces. [...]
.. option:: IgnoreOverloadedOperators
If non-zero, ignores calls to overloaded operators using operator
syntax (e.g. a + b
), but not function call syntax (e.g.
operator+(a, b)
). Default is 1
.
.. option:: AllowedIdentifiers
Semicolon-separated list of names that the check ignores. Default
is
swap;make_error_code;make_error_condition;data;begin;end;rbegin;rend;crbegin;crend;size;ssize;empty
.
.. option:: AllowedNamespaces
Semicolon-separated list of namespace names (e.g. foo;bar::baz
).
If the check finds an unqualified call that resolves to a function
in a namespace in this list, the call is ignored. Default is an
empty list.
虽然自 2020 年 7 月以来似乎没有 activity 补丁,但如果 OP 对此感兴趣,OP 可以尝试恢复补丁。
当参数类型在该命名空间中时,可以省略 <algorithm>
的 std::
命名空间,这通常是这种情况。是否有发现此类遗漏的警告或 clang-tidy 规则?
#include <vector>
#include <algorithm>
std::vector<int> v;
for_each(v.begin(), v.end(), [](auto){});
return 0;
以上示例使用最新的 clang 和 -Wall、-Wextra 和 -Wpedantic 编译,不会发出任何诊断信息:
tidy 中有一个开放的变化可以用来标记这个:
[patch] Summary
This patch adds
bugprone-unintended-adl
which flags uses of ADL that are not on the provided whitelist.bugprone-unintended-adl
Finds usages of ADL (argument-dependent lookup), or potential ADL in the case of templates, that are not on the provided lists of allowed identifiers and namespaces. [...]
.. option::
IgnoreOverloadedOperators
If non-zero, ignores calls to overloaded operators using operator syntax (e.g.
a + b
), but not function call syntax (e.g.operator+(a, b)
). Default is1
... option::
AllowedIdentifiers
Semicolon-separated list of names that the check ignores. Default is
swap;make_error_code;make_error_condition;data;begin;end;rbegin;rend;crbegin;crend;size;ssize;empty
... option::
AllowedNamespaces
Semicolon-separated list of namespace names (e.g.
foo;bar::baz
). If the check finds an unqualified call that resolves to a function in a namespace in this list, the call is ignored. Default is an empty list.
虽然自 2020 年 7 月以来似乎没有 activity 补丁,但如果 OP 对此感兴趣,OP 可以尝试恢复补丁。