summaryrefslogtreecommitdiffstats
path: root/lib/Sema/SemaTemplate.cpp
diff options
context:
space:
mode:
authorNico Weber <nicolasweber@gmx.de>2012-01-09 19:52:25 +0000
committerNico Weber <nicolasweber@gmx.de>2012-01-09 19:52:25 +0000
commitd1d512a9cd1923566a52e57b7e1e8ae65392f66b (patch)
tree54d9e6e43909f015be5ead255a4adb7e042f8d1f /lib/Sema/SemaTemplate.cpp
parenta33fd393d5255716e904fed021f87260095ed00a (diff)
Fix "note" of a duplicate explicit instantiation definition following a specialization.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@147798 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaTemplate.cpp')
-rw-r--r--lib/Sema/SemaTemplate.cpp29
1 files changed, 20 insertions, 9 deletions
diff --git a/lib/Sema/SemaTemplate.cpp b/lib/Sema/SemaTemplate.cpp
index 2527ac6a1c..b6babb6f75 100644
--- a/lib/Sema/SemaTemplate.cpp
+++ b/lib/Sema/SemaTemplate.cpp
@@ -5234,6 +5234,23 @@ static void StripImplicitInstantiation(NamedDecl *D) {
}
}
+/// \brief Compute the diagnostic location for an explicit instantiation
+// declaration or definition.
+static SourceLocation DiagLocForExplicitInstantiation(
+ NamedDecl* Decl, SourceLocation PointOfInstantiation) {
+ // Explicit instantiations following a specialization have no effect and
+ // hence no PointOfInstantiation. In that case, walk decl backwards
+ // until a valid name loc is found.
+ SourceLocation PrevDiagLoc = PointOfInstantiation;
+ for (NamedDecl *Prev = Decl; Prev && !PrevDiagLoc.isValid();
+ Prev = getPreviousDecl(Prev)) {
+ PrevDiagLoc = Prev->getLocation();
+ }
+ assert(PrevDiagLoc.isValid() &&
+ "Explicit instantiation without point of instantiation?");
+ return PrevDiagLoc;
+}
+
/// \brief Diagnose cases where we have an explicit template specialization
/// before/after an explicit template instantiation, producing diagnostics
/// for those cases where they are required and determining whether the
@@ -5348,14 +5365,8 @@ Sema::CheckSpecializationInstantiationRedecl(SourceLocation NewLoc,
// Explicit instantiations following a specialization have no effect and
// hence no PrevPointOfInstantiation. In that case, walk decl backwards
// until a valid name loc is found.
- SourceLocation PrevDiagLoc = PrevPointOfInstantiation;
- for (NamedDecl *Prev = PrevDecl; Prev && !PrevDiagLoc.isValid();
- Prev = getPreviousDecl(Prev)) {
- PrevDiagLoc = Prev->getLocation();
- }
- Diag(PrevDiagLoc, diag::note_explicit_instantiation_definition_here);
- assert(PrevDiagLoc.isValid() &&
- "Explicit instantiation without point of instantiation?");
+ Diag(DiagLocForExplicitInstantiation(PrevDecl, PrevPointOfInstantiation),
+ diag::note_explicit_instantiation_definition_here);
HasNoEffect = true;
return false;
}
@@ -5414,7 +5425,7 @@ Sema::CheckSpecializationInstantiationRedecl(SourceLocation NewLoc,
// in a program,
Diag(NewLoc, diag::err_explicit_instantiation_duplicate)
<< PrevDecl;
- Diag(PrevPointOfInstantiation,
+ Diag(DiagLocForExplicitInstantiation(PrevDecl, PrevPointOfInstantiation),
diag::note_previous_explicit_instantiation);
HasNoEffect = true;
return false;