]> granicus.if.org Git - clang/commitdiff
D31187: Fix removal of out-of-line definitions.
authorVassil Vassilev <v.g.vassilev@gmail.com>
Tue, 20 Jun 2017 14:59:57 +0000 (14:59 +0000)
committerVassil Vassilev <v.g.vassilev@gmail.com>
Tue, 20 Jun 2017 14:59:57 +0000 (14:59 +0000)
Consider:

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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@305799 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/DeclBase.cpp

index 032a20afa8343cf4a8ad092ea81fd4d1b6cec971..77ba6cf445dda9ccc8fdfaccd6f33ded106e47c9 100644 (file)
@@ -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) {