From 40ea264c25250abf6f209183167448475c33fc19 Mon Sep 17 00:00:00 2001 From: Eli Friedman Date: Tue, 18 Dec 2012 23:32:47 +0000 Subject: [PATCH] Fix a crash in diagnostic printing when a template class type is diff'ed against itself. PR14489. llvm-svn: 170474 --- clang/lib/AST/ASTDiagnostic.cpp | 7 ++++++- clang/test/Misc/diag-template-diffing.cpp | 12 ++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/clang/lib/AST/ASTDiagnostic.cpp b/clang/lib/AST/ASTDiagnostic.cpp index 31c1fbf..a61abf7 100644 --- a/clang/lib/AST/ASTDiagnostic.cpp +++ b/clang/lib/AST/ASTDiagnostic.cpp @@ -1125,7 +1125,12 @@ class TemplateDiff { TemplateDecl *FromTD, *ToTD; Tree.GetNode(FromTD, ToTD); - assert(Tree.HasChildren() && "Template difference not found in diff tree."); + if (!Tree.HasChildren()) { + // If we're dealing with a template specialization with zero + // arguments, there are no children; special-case this. + OS << FromTD->getNameAsString() << "<>"; + return; + } Qualifiers FromQual, ToQual; Tree.GetNode(FromQual, ToQual); diff --git a/clang/test/Misc/diag-template-diffing.cpp b/clang/test/Misc/diag-template-diffing.cpp index 7d01f46..e7a8048 100644 --- a/clang/test/Misc/diag-template-diffing.cpp +++ b/clang/test/Misc/diag-template-diffing.cpp @@ -800,6 +800,18 @@ namespace PR14342 { // CHECK-ELIDE-NOTREE: error: no viable conversion from 'X<[...], 2>' to 'X<[...], 3UL>' } +namespace PR14489 { + // The important thing here is that the diagnostic diffs a template specialization + // with no arguments against itself. (We might need a different test if this + // diagnostic changes). + template + struct VariableList { + void ConnectAllToAll(VariableList<>& params = VariableList<>()) { + } + }; + // CHECK-ELIDE-NOTREE: non-const lvalue reference to type 'VariableList<>' cannot bind to a temporary of type 'VariableList<>' +} + // CHECK-ELIDE-NOTREE: {{[0-9]*}} errors generated. // CHECK-NOELIDE-NOTREE: {{[0-9]*}} errors generated. // CHECK-ELIDE-TREE: {{[0-9]*}} errors generated. -- 2.7.4