summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2010-11-02 00:02:34 +0000
committerDouglas Gregor <dgregor@apple.com>2010-11-02 00:02:34 +0000
commite0f7a8ace9eb9c1d5f675b10f129267ce8a37f94 (patch)
treef0b5c71f277d059b8679e1abc40903f1d4aae239
parent5c86d22e672e8e29c62c4a8e08ef2e72f1e513c4 (diff)
downloadbcm5719-llvm-e0f7a8ace9eb9c1d5f675b10f129267ce8a37f94.tar.gz
bcm5719-llvm-e0f7a8ace9eb9c1d5f675b10f129267ce8a37f94.zip
When performing template argument deduction against a template-id,
only keep deduction results for successful deductions, so that they can be compared against each other. Fixes PR8462, from Richard Smith! llvm-svn: 117983
-rw-r--r--clang/lib/Sema/SemaTemplateDeduction.cpp11
-rw-r--r--clang/test/CXX/temp/temp.fct.spec/temp.deduct/temp.deduct.call/p3.cpp22
2 files changed, 31 insertions, 2 deletions
diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp b/clang/lib/Sema/SemaTemplateDeduction.cpp
index 855516cf10c..905e17e9c14 100644
--- a/clang/lib/Sema/SemaTemplateDeduction.cpp
+++ b/clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -721,6 +721,8 @@ DeduceTemplateArguments(Sema &S,
llvm::SmallVector<const RecordType *, 8> ToVisit;
ToVisit.push_back(RecordT);
bool Successful = false;
+ llvm::SmallVectorImpl<DeducedTemplateArgument> DeducedOrig(0);
+ DeducedOrig = Deduced;
while (!ToVisit.empty()) {
// Retrieve the next class in the inheritance hierarchy.
const RecordType *NextT = ToVisit.back();
@@ -738,9 +740,14 @@ DeduceTemplateArguments(Sema &S,
QualType(NextT, 0), Info, Deduced);
// If template argument deduction for this base was successful,
- // note that we had some success.
- if (BaseResult == Sema::TDK_Success)
+ // note that we had some success. Otherwise, ignore any deductions
+ // from this base class.
+ if (BaseResult == Sema::TDK_Success) {
Successful = true;
+ DeducedOrig = Deduced;
+ }
+ else
+ Deduced = DeducedOrig;
}
// Visit base classes
diff --git a/clang/test/CXX/temp/temp.fct.spec/temp.deduct/temp.deduct.call/p3.cpp b/clang/test/CXX/temp/temp.fct.spec/temp.deduct/temp.deduct.call/p3.cpp
index 19962c53490..3c22cf349c9 100644
--- a/clang/test/CXX/temp/temp.fct.spec/temp.deduct/temp.deduct.call/p3.cpp
+++ b/clang/test/CXX/temp/temp.fct.spec/temp.deduct/temp.deduct.call/p3.cpp
@@ -101,3 +101,25 @@ void test_f4(D d, E e, F f, G g) {
C<int, 1> *ci3c = f4c(&g);
int *ip1 = f4c(&f);
}
+
+// PR8462
+namespace N {
+ struct T0;
+ struct T1;
+
+ template<typename X, typename Y> struct B {};
+
+ struct J : B<T0,T0> {};
+ struct K : B<T1,T1> {};
+
+ struct D : J, K {};
+
+ template<typename X, typename Y> void F(B<Y,X>);
+
+ void test()
+ {
+ D d;
+ N::F<T0>(d); // Fails
+ N::F<T1>(d); // OK
+ }
+}
OpenPOWER on IntegriCloud