Fix a template diffing problem were an '&' is unexpectedly printed in
authorRichard Trieu <rtrieu@google.com>
Tue, 22 Jul 2014 03:33:01 +0000 (03:33 +0000)
committerRichard Trieu <rtrieu@google.com>
Tue, 22 Jul 2014 03:33:01 +0000 (03:33 +0000)
a template argument.

llvm-svn: 213609

clang/lib/AST/ASTDiagnostic.cpp
clang/test/Misc/diag-template-diffing.cpp

index 2ee26fb..15e288a 100644 (file)
@@ -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() ==
index c43ed26..41cdca4 100644 (file)
@@ -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.