From da336e88abc18baf2f765c39831c52dbd8d5d812 Mon Sep 17 00:00:00 2001 From: Richard Trieu Date: Tue, 22 Jul 2014 03:33:01 +0000 Subject: [PATCH] Fix a template diffing problem were an '&' is unexpectedly printed in a template argument. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@213609 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/AST/ASTDiagnostic.cpp | 32 +++++++++++++++++++++++------ test/Misc/diag-template-diffing.cpp | 16 +++++++++++++++ 2 files changed, 42 insertions(+), 6 deletions(-) diff --git a/lib/AST/ASTDiagnostic.cpp b/lib/AST/ASTDiagnostic.cpp index 2ee26fb7a7..15e288acb9 100644 --- a/lib/AST/ASTDiagnostic.cpp +++ b/lib/AST/ASTDiagnostic.cpp @@ -991,12 +991,32 @@ class TemplateDiff { if (!HasToValueDecl && ToExpr) ToValueDecl = GetValueDecl(ToIter, ToExpr); QualType ArgumentType = DefaultNTTPD->getType(); - bool FromAddressOf = FromValueDecl && - !ArgumentType->isReferenceType() && - !FromValueDecl->getType()->isArrayType(); - bool ToAddressOf = ToValueDecl && - !ArgumentType->isReferenceType() && - !ToValueDecl->getType()->isArrayType(); + bool FromAddressOf = false; + if (FromValueDecl) { + if (FromExpr) { + if (UnaryOperator *UO = dyn_cast(FromExpr)) { + if (UO->getOpcode() == UO_AddrOf) + FromAddressOf = true; + } + } else { + if (!ArgumentType->isReferenceType()) { + FromAddressOf = true; + } + } + } + bool ToAddressOf = false; + if (ToValueDecl) { + if (ToExpr) { + if (UnaryOperator *UO = dyn_cast(ToExpr)) { + if (UO->getOpcode() == UO_AddrOf) { + ToAddressOf = true; + } + } + } else { + if (!ArgumentType->isReferenceType()) + ToAddressOf = true; + } + } Tree.SetNode(FromValueDecl, ToValueDecl, FromAddressOf, ToAddressOf); Tree.SetSame(FromValueDecl && ToValueDecl && FromValueDecl->getCanonicalDecl() == diff --git a/test/Misc/diag-template-diffing.cpp b/test/Misc/diag-template-diffing.cpp index c43ed263c6..41cdca4712 100644 --- a/test/Misc/diag-template-diffing.cpp +++ b/test/Misc/diag-template-diffing.cpp @@ -1105,6 +1105,22 @@ using F = C<21 + 21>; } } +namespace AddressOf { +template +struct S {}; + +template +struct Wrapper {}; + +template +Wrapper MakeWrapper(); +int global; +constexpr int * ptr = nullptr; +Wrapper> W = MakeWrapper>(); +// Don't print an extra '&' for 'ptr' +// CHECK-ELIDE-NOTREE: no viable conversion from 'Wrapper>' to 'Wrapper>' +} + // CHECK-ELIDE-NOTREE: {{[0-9]*}} errors generated. // CHECK-NOELIDE-NOTREE: {{[0-9]*}} errors generated. // CHECK-ELIDE-TREE: {{[0-9]*}} errors generated. -- 2.40.0