Differential D72282 Diff 240691 clang-tools-extra/test/clang-tidy/checkers/bugprone-unintended-adl-operators.cpp
Changeset View
Changeset View
Standalone View
Standalone View
clang-tools-extra/test/clang-tidy/checkers/bugprone-unintended-adl-operators.cpp
- This file was added.
// RUN: %check_clang_tidy -std=c++14-or-later %s bugprone-unintended-adl %t -- \ | |||||
// RUN: -config='{CheckOptions: [ \ | |||||
// RUN: {key: bugprone-unintended-adl.IgnoreOverloadedOperators, value: 0}, \ | |||||
// RUN: ]}' -- | |||||
namespace aspace { | |||||
struct A {}; | |||||
} // namespace aspace | |||||
namespace ops { | |||||
struct Stream { | |||||
} stream; | |||||
Stream &operator<<(Stream &s, int) { | |||||
return s; | |||||
} | |||||
Stream &operator<<(Stream &s, aspace::A) { | |||||
return s; | |||||
} | |||||
template <typename IStream> | |||||
IStream &operator>>(IStream &s, int) { | |||||
return s; | |||||
} | |||||
template <typename IStream> | |||||
IStream &operator>>(IStream &s, aspace::A) { | |||||
return s; | |||||
} | |||||
void smooth_operator(Stream); | |||||
} // namespace ops | |||||
void ops_test() { | |||||
ops::stream << 5; | |||||
// CHECK-MESSAGES: [[@LINE-1]]:3: warning: expression calls 'ops::operator<<' through ADL [bugprone-unintended-adl] | |||||
operator<<(ops::stream, 5); | |||||
// CHECK-MESSAGES: [[@LINE-1]]:3: warning: expression calls 'ops::operator<<' through ADL [bugprone-unintended-adl] | |||||
ops::stream << aspace::A(); | |||||
// CHECK-MESSAGES: [[@LINE-1]]:3: warning: expression calls 'ops::operator<<' through ADL [bugprone-unintended-adl] | |||||
operator<<(ops::stream, aspace::A()); | |||||
// CHECK-MESSAGES: [[@LINE-1]]:3: warning: expression calls 'ops::operator<<' through ADL [bugprone-unintended-adl] | |||||
ops::stream >> aspace::A(); | |||||
// CHECK-MESSAGES: [[@LINE-1]]:3: warning: expression calls 'ops::operator>>' through ADL [bugprone-unintended-adl] | |||||
operator>>(ops::stream, aspace::A()); | |||||
// CHECK-MESSAGES: [[@LINE-1]]:3: warning: expression calls 'ops::operator>>' through ADL [bugprone-unintended-adl] | |||||
smooth_operator(ops::stream); | |||||
// CHECK-MESSAGES: [[@LINE-1]]:3: warning: expression calls 'ops::smooth_operator' through ADL [bugprone-unintended-adl] | |||||
} |