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/AST/TemplateBase.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/AST/TemplateBase.cpp')
-rw-r--r-- | clang/lib/AST/TemplateBase.cpp | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/clang/lib/AST/TemplateBase.cpp b/clang/lib/AST/TemplateBase.cpp index b1c88f93b6a..099f939c7a7 100644 --- a/clang/lib/AST/TemplateBase.cpp +++ b/clang/lib/AST/TemplateBase.cpp @@ -243,6 +243,31 @@ Optional<unsigned> TemplateArgument::getNumTemplateExpansions() const { return None; } +QualType TemplateArgument::getNonTypeTemplateArgumentType() const { + switch (getKind()) { + case TemplateArgument::Null: + case TemplateArgument::Type: + case TemplateArgument::Template: + case TemplateArgument::TemplateExpansion: + case TemplateArgument::Pack: + return QualType(); + + case TemplateArgument::Integral: + return getIntegralType(); + + case TemplateArgument::Expression: + return getAsExpr()->getType(); + + case TemplateArgument::Declaration: + return getParamTypeForDecl(); + + case TemplateArgument::NullPtr: + return getNullPtrType(); + } + + llvm_unreachable("Invalid TemplateArgument Kind!"); +} + void TemplateArgument::Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context) const { ID.AddInteger(getKind()); |