OSDN Git Service

C++: Fix a crash in debug builds when rewriting functions.
authorChristian Kamm <christian.d.kamm@nokia.com>
Tue, 25 Oct 2011 09:28:51 +0000 (11:28 +0200)
committerChristian Kamm <christian.d.kamm@nokia.com>
Tue, 25 Oct 2011 09:32:18 +0000 (11:32 +0200)
Change-Id: I35266b69d1cc433c4d9176cc849efd03ea1cc1cd
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
src/libs/3rdparty/cplusplus/Symbol.cpp
src/libs/3rdparty/cplusplus/Symbol.h
src/libs/cplusplus/CppRewriter.cpp

index b7caa00..b6216f0 100644 (file)
@@ -237,6 +237,11 @@ void Symbol::setScope(Scope *scope)
     _scope = scope;
 }
 
+void Symbol::resetScope()
+{
+    _scope = 0;
+}
+
 Namespace *Symbol::enclosingNamespace() const
 {
     for (Scope *s = _scope; s; s = s->enclosingScope()) {
index 3423120..a995f43 100644 (file)
@@ -291,6 +291,7 @@ public:
     Block *enclosingBlock() const;
 
     void setScope(Scope *enclosingScope); // ### make me private
+    void resetScope(); // ### make me private
     void setSourceLocation(unsigned sourceLocation, TranslationUnit *translationUnit); // ### make me private
 
     void visitSymbol(SymbolVisitor *visitor);
index ba975b3..8948b92 100644 (file)
@@ -151,6 +151,9 @@ public:
                 newArg->setName(rewrite->rewriteName(arg->name()));
                 newArg->setType(rewrite->rewriteType(arg->type()));
 
+                // the copy() call above set the scope to 'type'
+                // reset it to 0 before adding addMember to avoid assert
+                newArg->resetScope();
                 funTy->addMember(newArg);
             }