diff --git a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ExtractMethod.rts b/core/org.eclipse.cdt.ui.tests/resources/refactoring/ExtractMethod.rts index 171658a9b1e..eb7509328cc 100644 --- a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ExtractMethod.rts +++ b/core/org.eclipse.cdt.ui.tests/resources/refactoring/ExtractMethod.rts @@ -2706,3 +2706,49 @@ int Test::calculateStuff() { return result; } +//!Bug#281564 Extract Function fails when catching an unnamed exception +//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest +//@.config +filename=main.cpp +methodname=exp +//@main.cpp + +int myFunc() { +return 5; +} + +int main() { + +int a = 0; +/*$*/try { + a = myFunc(); + } + catch(const int & ){ + a = 3; + }/*$$*/ + return a; +} + +//= + +int myFunc() { +return 5; +} + +void exp(int & a) +{ + try { + a = myFunc(); + } + catch(const int & ){ + a = 3; + } +} + +int main() { + +int a = 0; + exp(a); + return a; +} + diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/NodeContainer.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/NodeContainer.java index 6dcea881798..72e0053b44b 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/NodeContainer.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/NodeContainer.java @@ -207,9 +207,12 @@ public class NodeContainer { } public boolean isDeclarationInScope() { - int declOffset = declaration.getFileLocation().getNodeOffset(); - return declOffset >= getStartOffset() - && declOffset <= getEndOffset(); + if(declaration.toCharArray().length > 0) { + int declOffset = declaration.getFileLocation().getNodeOffset(); + return declOffset >= getStartOffset() + && declOffset <= getEndOffset(); + } + return true; } @Override