gpt4 book ai didi

c++ - 警告由于 ADL 而丢失 std::prefixes

转载 作者:行者123 更新时间:2023-12-05 01:26:31 28 4
gpt4 key购买 nike

可以省略 std:: <algorithm> 的命名空间s 当参数类型在该 namespace 中时,通常是这种情况。是否有任何警告或 clang-tidy 规则可以发现此类遗漏?

#include <vector>
#include <algorithm>

std::vector<int> v;
for_each(v.begin(), v.end(), [](auto){});
return 0;

上面的示例,使用最新的 clang 和 -Wall、-Wextra 和 -Wpedantic 编译,不会发出任何诊断信息:

https://godbolt.org/z/dTsKbbEKe

最佳答案

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 operatorsyntax (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. Defaultis
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 functionin a namespace in this list, the call is ignored. Default is anempty list.

不过,自 2020 年 7 月以来,该补丁似乎没有任何事件,但如果 OP 对此感兴趣,则 OP 可以尝试恢复该补丁。

关于c++ - 警告由于 ADL 而丢失 std::prefixes,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70261360/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com