diff options
author | Kadir Cetinkaya <kadircet@google.com> | 2019-10-01 14:08:51 +0000 |
---|---|---|
committer | Kadir Cetinkaya <kadircet@google.com> | 2019-10-01 14:08:51 +0000 |
commit | fd019ed54e36179d0b69d93822164ec2e5689e36 (patch) | |
tree | add4df2268e7c8e4ac3496a9584fd9649b5496f2 /clang/lib/AST/DeclTemplate.cpp | |
parent | b67c3b6cf0f039503d35ad91c1ababebe56e036f (diff) | |
download | bcm5719-llvm-fd019ed54e36179d0b69d93822164ec2e5689e36.tar.gz bcm5719-llvm-fd019ed54e36179d0b69d93822164ec2e5689e36.zip |
[clang] Make handling of unnamed template params similar to function params
Summary:
Clang uses the location identifier should be inserted for declarator
decls when a decl is unnamed. But for type template and template template
paramaters it uses the location of "typename/class" keyword, which makes it hard
for tooling to insert/change parameter names.
This change tries to unify these two cases by making template parameter
parsing and sourcerange operations similar to function params/declarator decls.
Reviewers: ilya-biryukov
Subscribers: arphaman, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D68143
llvm-svn: 373340
Diffstat (limited to 'clang/lib/AST/DeclTemplate.cpp')
-rw-r--r-- | clang/lib/AST/DeclTemplate.cpp | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/clang/lib/AST/DeclTemplate.cpp b/clang/lib/AST/DeclTemplate.cpp index 40c39c845db..c03ae22fb5d 100644 --- a/clang/lib/AST/DeclTemplate.cpp +++ b/clang/lib/AST/DeclTemplate.cpp @@ -510,8 +510,12 @@ SourceRange TemplateTypeParmDecl::getSourceRange() const { if (hasDefaultArgument() && !defaultArgumentWasInherited()) return SourceRange(getBeginLoc(), getDefaultArgumentInfo()->getTypeLoc().getEndLoc()); - else - return TypeDecl::getSourceRange(); + // TypeDecl::getSourceRange returns a range containing name location, which is + // wrong for unnamed template parameters. e.g: + // it will return <[[typename>]] instead of <[[typename]]> + else if (getDeclName().isEmpty()) + return SourceRange(getBeginLoc()); + return TypeDecl::getSourceRange(); } unsigned TemplateTypeParmDecl::getDepth() const { |