diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/DeclarationGeneratorImpl.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/DeclarationGeneratorImpl.java index c365fd332e5..a65005d9cd2 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/DeclarationGeneratorImpl.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/DeclarationGeneratorImpl.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010, 2016 Tomasz Wesolowski + * Copyright (c) 2010, 2017 Tomasz Wesolowski * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -134,12 +134,12 @@ public class DeclarationGeneratorImpl extends DeclarationGenerator { public IASTDeclarator createDeclaratorFromType(IType type, char[] name, boolean changeInitialFunctionToFuncPtr) { IASTDeclarator returnedDeclarator = null; + IASTName newName = name != null ? factory.newName(name) : factory.newName(); try { // Addition of pointer operators has to be in reverse order, so it's deferred until // the end. Map> pointerOperatorMap = new HashMap>(); - IASTName newName = name != null ? factory.newName(name) : factory.newName(); // If the type is an array of something, create a declaration of a pointer to something // instead (to allow assignment, etc). @@ -220,7 +220,7 @@ public class DeclarationGeneratorImpl extends DeclarationGenerator { // Fallback if (returnedDeclarator == null) { - returnedDeclarator = factory.newDeclarator(factory.newName(name)); + returnedDeclarator = factory.newDeclarator(newName); } return returnedDeclarator; diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/extractfunction/ExtractFunctionRefactoringTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/extractfunction/ExtractFunctionRefactoringTest.java index 6b30e36e1d1..2c0e0122b2c 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/extractfunction/ExtractFunctionRefactoringTest.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/extractfunction/ExtractFunctionRefactoringTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2014 Institute for Software, HSR Hochschule fuer Technik + * Copyright (c) 2008, 2017 Institute for Software, HSR Hochschule fuer Technik * Rapperswil, University of applied sciences and others * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -4721,4 +4721,22 @@ public class ExtractFunctionRefactoringTest extends RefactoringTestBase { public void testExtractArrayInitializer_Bug412380() throws Exception { assertRefactoringSuccess(); } + + //main.cpp + //int main() { + // auto var = 1; + // /*$*/var;/*$$*/ + //} + //==================== + //void extracted(int var) { + // var; + //} + // + //int main() { + // auto var = 1; + // extracted(var); + //} + public void testExtractWithAutoVar() throws Exception { + assertRefactoringSuccess(); + } }