Avoid adding qualifiers before C++ operators declared in a non-class context
Reviewed By: tom-anders
Differential Revision: https://reviews.llvm.org/D137494
if (!visibleContext(T->getDeclContext())
->Equals(TargetDirective->getNominatedNamespace()))
return;
+ // Avoid adding qualifiers before operators, e.g.
+ // using namespace std;
+ // cout << "foo"; // Must not changed to std::cout std:: << "foo"
+ // FIXME: User-defined literals are not handled
+ if (T->isInIdentifierNamespace(
+ Decl::IdentifierNamespace::IDNS_NonMemberOperator))
+ return;
}
SourceLocation Loc = Ref.NameLoc;
if (Loc.isMacroID()) {
int main() {
std::vector V;
}
+ )cpp"},
+ {// Does not qualify operators declared in a non-class context
+ R"cpp(
+ namespace ns {
+ struct Foo {};
+ void operator+(const Foo &, int) {}
+ }
+ using namespace n^s;
+ int main() {
+ Foo foo;
+ foo + 10;
+ }
+ )cpp",
+ R"cpp(
+ namespace ns {
+ struct Foo {};
+ void operator+(const Foo &, int) {}
+ }
+
+ int main() {
+ ns::Foo foo;
+ foo + 10;
+ }
)cpp"}};
for (auto C : Cases)
EXPECT_EQ(C.second, apply(C.first)) << C.first;