From: Richard Trieu Date: Wed, 3 Apr 2013 02:22:12 +0000 (+0000) Subject: Fix a crasher in Template Diffing. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=fa3d2758653113cd2b5fff06f8ff22eeb669c044;p=clang Fix a crasher in Template Diffing. When support was added for declaration arguments, the case of variadic declaration arguments was not supported. This patch fixes that problem by not crashing when certain ValueDecl's are null. Patch by Olivier Goffart! git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@178610 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/AST/ASTDiagnostic.cpp b/lib/AST/ASTDiagnostic.cpp index 419152de04..c2c24925eb 100644 --- a/lib/AST/ASTDiagnostic.cpp +++ b/lib/AST/ASTDiagnostic.cpp @@ -944,7 +944,8 @@ class TemplateDiff { if (!HasToValueDecl && ToExpr) ToValueDecl = GetValueDecl(ToIter, ToExpr); Tree.SetNode(FromValueDecl, ToValueDecl); - Tree.SetSame(FromValueDecl->getCanonicalDecl() == + Tree.SetSame(FromValueDecl && ToValueDecl && + FromValueDecl->getCanonicalDecl() == ToValueDecl->getCanonicalDecl()); Tree.SetDefault(FromIter.isEnd() && FromValueDecl, ToIter.isEnd() && ToValueDecl); diff --git a/test/Misc/diag-template-diffing.cpp b/test/Misc/diag-template-diffing.cpp index fd331139a8..f27f8b67e2 100644 --- a/test/Misc/diag-template-diffing.cpp +++ b/test/Misc/diag-template-diffing.cpp @@ -958,6 +958,45 @@ namespace DependentDefault { } } +namespace VariadicDefault { + int i1, i2, i3; + template struct A {}; + template struct B {}; + template struct C {}; + + void test() { + A<> a1; + A<5, 6, 7> a2; + A<1, 2> a3; + a2 = a1; + // CHECK-ELIDE-NOTREE: no viable overloaded '=' + // CHECK-ELIDE-NOTREE: no known conversion from 'A<[...], (no argument), (no argument)>' to 'A<[...], 6, 7>' + a3 = a1; + // CHECK-ELIDE-NOTREE: no viable overloaded '=' + // CHECK-ELIDE-NOTREE: no known conversion from 'A<(default) 5, (no argument)>' to 'A<1, 2>' + + B<> b1; + B b2; + B b3; + b2 = b1; + // CHECK-ELIDE-NOTREE: no viable overloaded '=' + // CHECK-ELIDE-NOTREE: no known conversion from 'B<[...], (no argument), (no argument)>' to 'B<[...], i2, i3>' + b3 = b1; + // CHECK-ELIDE-NOTREE: no viable overloaded '=' + // CHECK-ELIDE-NOTREE: no known conversion from 'B<(default) i1, (no argument)>' to 'B' + + C<> c1; + C c2; + C c3; + c2 = c1; + // CHECK-ELIDE-NOTREE: no viable overloaded '=' + // CHECK-ELIDE-NOTREE: no known conversion from 'C<[...], (no argument)>' to 'C<[...], void>' + c3 = c1; + // CHECK-ELIDE-NOTREE: no viable overloaded '=' + // CHECK-ELIDE-NOTREE: no known conversion from 'C<(default) void, (no argument)>' to 'C' + } +} + // CHECK-ELIDE-NOTREE: {{[0-9]*}} errors generated. // CHECK-NOELIDE-NOTREE: {{[0-9]*}} errors generated. // CHECK-ELIDE-TREE: {{[0-9]*}} errors generated.