summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn McCall <rjmccall@apple.com>2010-03-24 08:27:58 +0000
committerJohn McCall <rjmccall@apple.com>2010-03-24 08:27:58 +0000
commit1f0479e3d724b5025d2bba2d25d7650b5f9a35bd (patch)
treece2d6f4e2d056112dda46b931e3b012d14157cea
parent816d75b7012ac9fabbe134579ba1a1dba80a5f4f (diff)
downloadbcm5719-llvm-1f0479e3d724b5025d2bba2d25d7650b5f9a35bd.tar.gz
bcm5719-llvm-1f0479e3d724b5025d2bba2d25d7650b5f9a35bd.zip
Correct that last fixit: if the user wrote
template <> friend void foo(int); we need to change it to friend void foo<>(int); or else the user won't get the template specialization they obviously want. llvm-svn: 99390
-rw-r--r--clang/lib/Sema/SemaDecl.cpp19
1 files changed, 17 insertions, 2 deletions
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 1435a8f7212..e802018c9f8 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -2921,9 +2921,24 @@ Sema::ActOnFunctionDeclarator(Scope* S, Declarator& D, DeclContext* DC,
// C++0x [temp.expl.spec]p20 forbids "template<> void foo(int);".
if (isFriend && isFunctionTemplateSpecialization) {
- SourceRange Range = TemplateParams->getSourceRange();
+ // We want to remove the "template<>", found here.
+ SourceRange RemoveRange = TemplateParams->getSourceRange();
+
+ // If we remove the template<> and the name is not a
+ // template-id, we're actually silently creating a problem:
+ // the friend declaration will refer to an untemplated decl,
+ // and clearly the user wants a template specialization. So
+ // we need to insert '<>' after the name.
+ SourceLocation InsertLoc;
+ if (D.getName().getKind() != UnqualifiedId::IK_TemplateId) {
+ InsertLoc = D.getName().getSourceRange().getEnd();
+ InsertLoc = PP.getLocForEndOfToken(InsertLoc);
+ }
+
Diag(D.getIdentifierLoc(), diag::err_template_spec_decl_friend)
- << Name << Range << CodeModificationHint::CreateRemoval(Range);
+ << Name << RemoveRange
+ << CodeModificationHint::CreateRemoval(RemoveRange)
+ << CodeModificationHint::CreateInsertion(InsertLoc, "<>");
}
}
OpenPOWER on IntegriCloud