Skip to main content
summaryrefslogtreecommitdiffstats
path: root/codan
diff options
context:
space:
mode:
authorSergey Prigogin2015-04-03 17:12:28 -0400
committerSergey Prigogin2015-04-06 17:35:03 -0400
commit711ec8df95456d971ee3c6e6c0eeff586cdc6ba1 (patch)
tree0da018e688c9bab5e70476019d8ffb06538c8b86 /codan
parentd702a8f9474364f96a35aebaffebbeb2d3533520 (diff)
downloadorg.eclipse.cdt-711ec8df95456d971ee3c6e6c0eeff586cdc6ba1.tar.gz
org.eclipse.cdt-711ec8df95456d971ee3c6e6c0eeff586cdc6ba1.tar.xz
org.eclipse.cdt-711ec8df95456d971ee3c6e6c0eeff586cdc6ba1.zip
Bug 461538 - "noreturn" attribute in destructor is not accounted for
Change-Id: Ia3c3bdfdb26ff18092fd20be02f178ebb71848bb Signed-off-by: Sergey Prigogin <eclipse.sprigogin@gmail.com>
Diffstat (limited to 'codan')
-rw-r--r--codan/org.eclipse.cdt.codan.core.cxx/src/org/eclipse/cdt/codan/core/cxx/CxxAstUtils.java38
-rw-r--r--codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/internal/checkers/ReturnCheckerTest.java24
2 files changed, 50 insertions, 12 deletions
diff --git a/codan/org.eclipse.cdt.codan.core.cxx/src/org/eclipse/cdt/codan/core/cxx/CxxAstUtils.java b/codan/org.eclipse.cdt.codan.core.cxx/src/org/eclipse/cdt/codan/core/cxx/CxxAstUtils.java
index 443b5c3cd9..ff9f109611 100644
--- a/codan/org.eclipse.cdt.codan.core.cxx/src/org/eclipse/cdt/codan/core/cxx/CxxAstUtils.java
+++ b/codan/org.eclipse.cdt.codan.core.cxx/src/org/eclipse/cdt/codan/core/cxx/CxxAstUtils.java
@@ -1,14 +1,15 @@
/*******************************************************************************
- * Copyright (c) 2009, 2012 Alena Laskavaia, Tomasz Wesolowski
+ * Copyright (c) 2009, 2015 Alena Laskavaia, 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
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * Alena Laskavaia - initial API and implementation
- * Tomasz Wesolowski - extension
- * Marc-Andre Laperle
+ * Alena Laskavaia - initial API and implementation
+ * Tomasz Wesolowski - extension
+ * Marc-Andre Laperle
+ * Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.codan.core.cxx;
@@ -31,6 +32,7 @@ import org.eclipse.cdt.core.dom.ast.IASTFunctionCallExpression;
import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
import org.eclipse.cdt.core.dom.ast.IASTIdExpression;
+import org.eclipse.cdt.core.dom.ast.IASTImplicitName;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTNode.CopyStyle;
@@ -90,6 +92,27 @@ public final class CxxAstUtils {
}
}
+ private static class NoReturnImplicitCallFinder extends ASTVisitor {
+ boolean noReturn;
+
+ NoReturnImplicitCallFinder() {
+ shouldVisitImplicitNames = true;
+ shouldVisitImplicitDestructorNames = true;
+ }
+
+ @Override
+ public int visit(IASTName name) {
+ if (name instanceof IASTImplicitName) {
+ IBinding binding = name.resolveBinding();
+ if (binding instanceof IFunction && ((IFunction) binding).isNoReturn()) {
+ noReturn = true;
+ return PROCESS_ABORT;
+ }
+ }
+ return PROCESS_CONTINUE;
+ }
+ }
+
// Not instantiatable. All methods are static.
private CxxAstUtils() {
}
@@ -378,6 +401,11 @@ public final class CxxAstUtils {
}
public static boolean isExitStatement(IASTNode statement) {
+ NoReturnImplicitCallFinder noReturnFinder = new NoReturnImplicitCallFinder();
+ statement.accept(noReturnFinder);
+ if (noReturnFinder.noReturn)
+ return true;
+
if (!(statement instanceof IASTExpressionStatement))
return false;
IASTExpression expression = ((IASTExpressionStatement) statement).getExpression();
@@ -388,7 +416,7 @@ public final class CxxAstUtils {
IASTName name = ((IASTIdExpression) functionNameExpression).getName();
IBinding binding = name.resolveBinding();
- if (binding != null && binding instanceof IFunction && ((IFunction) binding).isNoReturn()) {
+ if (binding instanceof IFunction && ((IFunction) binding).isNoReturn()) {
return true;
}
}
diff --git a/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/internal/checkers/ReturnCheckerTest.java b/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/internal/checkers/ReturnCheckerTest.java
index eb495ea176..cfe7cc23f0 100644
--- a/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/internal/checkers/ReturnCheckerTest.java
+++ b/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/internal/checkers/ReturnCheckerTest.java
@@ -303,17 +303,27 @@ public class ReturnCheckerTest extends CheckerTestCase {
checkSampleAbove();
}
-
-//void f() __attribute__((noreturn));
-//
-//int test() {
-// f();
-//}
-
+ // void f() __attribute__((noreturn));
+ //
+ // int test() {
+ // f();
+ // }
public void testNoReturn() {
checkSampleAbove();
}
+ // struct A {
+ // A();
+ // ~A() __attribute__((noreturn));
+ // };
+ //
+ // int test() {
+ // A();
+ // }
+ public void testNoReturnInDestructor_461538() throws Exception {
+ checkSampleAboveCpp();
+ }
+
// int try1() {
// try {
// return 5;

Back to the top