Przeglądaj źródła

Handle FriendDecl in DeclContextPrinter

This commit fixes a crash that occurs when -print-decl-contexts AST consumer
tries to print an unhandled declaration.

rdar://19467234

Differential Revision: https://reviews.llvm.org/D26964


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@290880 91177308-0d34-0410-b5e6-96231b3b80d8
Alex Lorenz 8 lat temu
rodzic
commit
a2c5a552d4

+ 7 - 0
lib/Frontend/ASTConsumers.cpp

@@ -478,6 +478,13 @@ void DeclContextPrinter::PrintDeclContext(const DeclContext* DC,
       Out << "<omp threadprivate> " << '"' << I << "\"\n";
       Out << "<omp threadprivate> " << '"' << I << "\"\n";
       break;
       break;
     }
     }
+    case Decl::Friend: {
+      Out << "<friend>";
+      if (const NamedDecl *ND = cast<FriendDecl>(I)->getFriendDecl())
+        Out << ' ' << *ND;
+      Out << "\n";
+      break;
+    }
     default:
     default:
       Out << "DeclKind: " << DK << '"' << I << "\"\n";
       Out << "DeclKind: " << DK << '"' << I << "\"\n";
       llvm_unreachable("decl unhandled");
       llvm_unreachable("decl unhandled");

+ 8 - 0
test/Coverage/cxx-language-features.inc

@@ -25,3 +25,11 @@ enum E1 { EC1 };
 template <E1 v> class C1 {};
 template <E1 v> class C1 {};
 template <E1 v> C1<v> f1() { return C1<v>(); }
 template <E1 v> C1<v> f1() { return C1<v>(); }
 void f2() { f1<EC1>(); }
 void f2() { f1<EC1>(); }
+
+// Friend declarations
+struct FriendlyStruct {
+  friend bool operator==(FriendlyStruct, FriendlyStruct) { return true; }
+  friend struct FriendedStruct;
+};
+
+struct FriendedStruct { };