1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-23 17:05:26 +02:00

Bug 515545 - NPE when using Extract Function in the presence of auto variable

Change-Id: Id13e7afadbd3c92f1ab5a1448b9851f2d0c7d4df
Signed-off-by: Marc-Andre Laperle <marc-andre.laperle@ericsson.com>
This commit is contained in:
Marc-Andre Laperle 2017-04-20 15:26:44 -04:00
parent 8da9b7a0b8
commit 765960cec6
2 changed files with 22 additions and 4 deletions

View file

@ -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<IASTDeclarator, LinkedList<IASTPointerOperator>> pointerOperatorMap = new HashMap<IASTDeclarator, LinkedList<IASTPointerOperator>>();
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;

View file

@ -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();
}
}