r213609 - Fix a template diffing problem were an '&' is unexpectedly printed in
Richard Trieu
rtrieu at google.com
Mon Jul 21 20:33:01 PDT 2014
Author: rtrieu
Date: Mon Jul 21 22:33:01 2014
New Revision: 213609
URL: http://llvm.org/viewvc/llvm-project?rev=213609&view=rev
Log:
Fix a template diffing problem were an '&' is unexpectedly printed in
a template argument.
Modified:
cfe/trunk/lib/AST/ASTDiagnostic.cpp
cfe/trunk/test/Misc/diag-template-diffing.cpp
Modified: cfe/trunk/lib/AST/ASTDiagnostic.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTDiagnostic.cpp?rev=213609&r1=213608&r2=213609&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ASTDiagnostic.cpp (original)
+++ cfe/trunk/lib/AST/ASTDiagnostic.cpp Mon Jul 21 22:33:01 2014
@@ -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<UnaryOperator>(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<UnaryOperator>(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() ==
Modified: cfe/trunk/test/Misc/diag-template-diffing.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Misc/diag-template-diffing.cpp?rev=213609&r1=213608&r2=213609&view=diff
==============================================================================
--- cfe/trunk/test/Misc/diag-template-diffing.cpp (original)
+++ cfe/trunk/test/Misc/diag-template-diffing.cpp Mon Jul 21 22:33:01 2014
@@ -1105,6 +1105,22 @@ using F = C<21 + 21>;
}
}
+namespace AddressOf {
+template <int*>
+struct S {};
+
+template <class T>
+struct Wrapper {};
+
+template <class T>
+Wrapper<T> MakeWrapper();
+int global;
+constexpr int * ptr = nullptr;
+Wrapper<S<ptr>> W = MakeWrapper<S<&global>>();
+// Don't print an extra '&' for 'ptr'
+// CHECK-ELIDE-NOTREE: no viable conversion from 'Wrapper<S<&global>>' to 'Wrapper<S<ptr>>'
+}
+
// CHECK-ELIDE-NOTREE: {{[0-9]*}} errors generated.
// CHECK-NOELIDE-NOTREE: {{[0-9]*}} errors generated.
// CHECK-ELIDE-TREE: {{[0-9]*}} errors generated.
More information about the cfe-commits
mailing list