From 05c47223c50b5dce77974e17e64671b5f007aa18 Mon Sep 17 00:00:00 2001 From: Marco Stornelli Date: Sat, 2 May 2020 15:26:54 +0200 Subject: [PATCH] Bug 562722 - Fix noexcept using implement method Change-Id: I3ac99f916883fa4be55af29e51b63bc8aa40a63f --- .../ImplementMethodRefactoringTest.java | 17 +++++++++++++++++ .../OverrideMethodsRefactoringTest.java | 2 +- .../ImplementMethodRefactoring.java | 8 ++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/implementmethod/ImplementMethodRefactoringTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/implementmethod/ImplementMethodRefactoringTest.java index 019ba9eff69..0bba6e7158a 100755 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/implementmethod/ImplementMethodRefactoringTest.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/implementmethod/ImplementMethodRefactoringTest.java @@ -919,4 +919,21 @@ public class ImplementMethodRefactoringTest extends RefactoringTestBase { public void testNamespaceAlreadyInDefinition_Bug434677() throws Exception { assertRefactoringSuccess(); } + + //A.h + // + //struct A { + // /*$*/void waldo() noexcept;/*$$*/ + //}; + + //A.cpp + //#include "A.h" + //==================== + //#include "A.h" + // + //void A::waldo() noexcept { + //} + public void testNoexpect_Bug562722() throws Exception { + assertRefactoringSuccess(); + } } diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/overridemethods/OverrideMethodsRefactoringTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/overridemethods/OverrideMethodsRefactoringTest.java index 5fcde1e927b..dff120aa23e 100755 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/overridemethods/OverrideMethodsRefactoringTest.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/overridemethods/OverrideMethodsRefactoringTest.java @@ -498,7 +498,7 @@ public class OverrideMethodsRefactoringTest extends RefactoringTestBase { // virtual void baseFunc() const noexcept; //}; // - //inline void X::baseFunc() const { + //inline void X::baseFunc() const noexcept { //} public void testWithNoExcept() throws Exception { selectedMethods = new String[] { "baseFunc()const" }; diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/implementmethod/ImplementMethodRefactoring.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/implementmethod/ImplementMethodRefactoring.java index f6bdc336959..6392909f163 100755 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/implementmethod/ImplementMethodRefactoring.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/implementmethod/ImplementMethodRefactoring.java @@ -38,6 +38,7 @@ import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.core.dom.ast.IASTTypeId; import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeclSpecifier; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTExpression; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamedTypeSpecifier; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName; @@ -357,6 +358,13 @@ public class ImplementMethodRefactoring extends CRefactoring { .addExceptionSpecificationTypeId(typeId == null ? null : typeId.copy(CopyStyle.withLocations)); } } + ICPPASTExpression noexceptExpression = functionDeclarator.getNoexceptExpression(); + if (noexceptExpression != null) { + createdMethodDeclarator.setNoexceptExpression( + noexceptExpression == ICPPASTFunctionDeclarator.NOEXCEPT_DEFAULT ? noexceptExpression + : (ICPPASTExpression) noexceptExpression.copy(CopyStyle.withLocations)); + } + IASTFunctionDefinition functionDefinition = nodeFactory.newFunctionDefinition(declSpecifier, createdMethodDeclarator, nodeFactory.newCompoundStatement()); functionDefinition.setParent(unit);