r305799 - D31187: Fix removal of out-of-line definitions.

Vassil Vassilev via cfe-commits cfe-commits at lists.llvm.org
Tue Jun 20 07:59:58 PDT 2017

Author: vvassilev
Date: Tue Jun 20 09:59:57 2017
New Revision: 305799

URL: http://llvm.org/viewvc/llvm-project?rev=305799&view=rev
D31187: Fix removal of out-of-line definitions.


struct MyClass {
  void f() {}
MyClass::f(){} // expected error redefinition of f. #1

Some clients (eg. cling) need to call removeDecl for the redefined (#1) decl.

This patch enables us to remove the lookup entry is registered in the semantic
decl context and not in the primary decl context of the lexical decl context
where we currently are trying to remove it from.

It is not trivial to test this piece and writing a full-blown unit test seems
too much.


Modified: cfe/trunk/lib/AST/DeclBase.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclBase.cpp?rev=305799&r1=305798&r2=305799&view=diff
--- cfe/trunk/lib/AST/DeclBase.cpp (original)
+++ cfe/trunk/lib/AST/DeclBase.cpp Tue Jun 20 09:59:57 2017
@@ -1352,7 +1352,7 @@ void DeclContext::removeDecl(Decl *D) {
     // Remove only decls that have a name
     if (!ND->getDeclName()) return;
-    auto *DC = this;
+    auto *DC = D->getDeclContext();
     do {
       StoredDeclsMap *Map = DC->getPrimaryContext()->LookupPtr;
       if (Map) {

More information about the cfe-commits mailing list