diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2016-12-23 01:30:39 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2016-12-23 01:30:39 +0000 |
commit | 593d6a168f45745d335e27afa86eee4479cbbcbe (patch) | |
tree | ad2e81f3ba4ee3d6d56315ce6b4d612c30c65998 /clang/lib/Sema/SemaOverload.cpp | |
parent | fcd33149b48885ab8e4ca4ffb6977bce5be2e623 (diff) | |
download | bcm5719-llvm-593d6a168f45745d335e27afa86eee4479cbbcbe.tar.gz bcm5719-llvm-593d6a168f45745d335e27afa86eee4479cbbcbe.zip |
When merging two deduced non-type template arguments for the same parameter,
fail the merge if the arguments have different types (except if one of them was
deduced from an array bound, in which case take the type from the other).
This is correct because (except in the array bound case) the type of the
template argument in each deduction must match the type of the parameter, so at
least one of the two deduced arguments must have a mismatched type.
This is necessary because we would otherwise lose the type information for the
discarded template argument in the merge, and fail to diagnose the mismatch.
In order to power this, we now properly retain the type of a deduced non-type
template argument deduced from a declaration, rather than giving it the type of
the template parameter; we'll convert it to the template parameter type when
checking the deduced arguments.
llvm-svn: 290399
Diffstat (limited to 'clang/lib/Sema/SemaOverload.cpp')
-rw-r--r-- | clang/lib/Sema/SemaOverload.cpp | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp index 5252e6a26c9..626a6ca9815 100644 --- a/clang/lib/Sema/SemaOverload.cpp +++ b/clang/lib/Sema/SemaOverload.cpp @@ -9593,9 +9593,25 @@ static void DiagnoseBadDeduction(Sema &S, NamedDecl *Found, Decl *Templated, int which = 0; if (isa<TemplateTypeParmDecl>(ParamD)) which = 0; - else if (isa<NonTypeTemplateParmDecl>(ParamD)) + else if (isa<NonTypeTemplateParmDecl>(ParamD)) { + // Deduction might have failed because we deduced arguments of two + // different types for a non-type template parameter. + // FIXME: Use a different TDK value for this. + QualType T1 = + DeductionFailure.getFirstArg()->getNonTypeTemplateArgumentType(); + QualType T2 = + DeductionFailure.getSecondArg()->getNonTypeTemplateArgumentType(); + if (!S.Context.hasSameType(T1, T2)) { + S.Diag(Templated->getLocation(), + diag::note_ovl_candidate_inconsistent_deduction_types) + << ParamD->getDeclName() << *DeductionFailure.getFirstArg() << T1 + << *DeductionFailure.getSecondArg() << T2; + MaybeEmitInheritedConstructorNote(S, Found); + return; + } + which = 1; - else { + } else { which = 2; } |