summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPawel Wodnicki <pawel@32bitmicro.com>2012-11-28 23:44:46 +0000
committerPawel Wodnicki <pawel@32bitmicro.com>2012-11-28 23:44:46 +0000
commit81bdf6606e4bfedadebba2a4b8d1cce3815edb6e (patch)
treec283786bb95c87f24720b85fde1132cf61302a33
parent1ada42cb99756622dcf8d21d385c89554bd72868 (diff)
downloadclang-81bdf6606e4bfedadebba2a4b8d1cce3815edb6e.tar.gz
clang-81bdf6606e4bfedadebba2a4b8d1cce3815edb6e.tar.bz2
clang-81bdf6606e4bfedadebba2a4b8d1cce3815edb6e.tar.xz
Merging r168818: into the 3.2 release branch.
PR13098: If we're instantiating an overloaded binary operator and we could determine which member function would be the callee from within the template definition, don't pass that function as a "non-member function" to CreateOverloadedBinOp. Instead, just rely on it to select the member function for itself. git-svn-id: https://llvm.org/svn/llvm-project/cfe/branches/release_32@168830 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Sema/TreeTransform.h7
-rw-r--r--test/SemaTemplate/instantiate-overload-candidates.cpp31
2 files changed, 37 insertions, 1 deletions
diff --git a/lib/Sema/TreeTransform.h b/lib/Sema/TreeTransform.h
index 5b5122f5b0..294d742446 100644
--- a/lib/Sema/TreeTransform.h
+++ b/lib/Sema/TreeTransform.h
@@ -9179,7 +9179,12 @@ TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
// IsAcceptableNonMemberOperatorCandidate for each of these?
Functions.append(ULE->decls_begin(), ULE->decls_end());
} else {
- Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
+ // If we've resolved this to a particular non-member function, just call
+ // that function. If we resolved it to a member function,
+ // CreateOverloaded* will find that function for us.
+ NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
+ if (!isa<CXXMethodDecl>(ND))
+ Functions.addDecl(ND);
}
// Add any functions found via argument-dependent lookup.
diff --git a/test/SemaTemplate/instantiate-overload-candidates.cpp b/test/SemaTemplate/instantiate-overload-candidates.cpp
index 5b7e60dccf..d29460eb28 100644
--- a/test/SemaTemplate/instantiate-overload-candidates.cpp
+++ b/test/SemaTemplate/instantiate-overload-candidates.cpp
@@ -19,3 +19,34 @@ template <typename T> S_<NoDefinition>::type f(T*, NoDefinition*); // expected-n
void test(int x) {
f(&x, 0);
}
+
+// Ensure that we instantiate an overloaded function if it's selected by
+// overload resolution when initializing a function pointer.
+template<typename T> struct X {
+ static T f() { T::error; } // expected-error {{has no members}}
+ static T f(bool);
+};
+void (*p)() = &X<void>().f; // expected-note {{instantiation of}}
+
+namespace PR13098 {
+ struct A {
+ A(int);
+ void operator++() {}
+ void operator+(int) {}
+ void operator+(A) {}
+ void operator[](int) {}
+ void operator[](A) {}
+ };
+ struct B : A {
+ using A::operator++;
+ using A::operator+;
+ using A::operator[];
+ };
+ template<typename T> void f(B b) {
+ ++b;
+ b + 0;
+ b[0];
+ }
+ template void f<void>(B);
+}
+