Skip to main content
aboutsummaryrefslogtreecommitdiffstats
path: root/codan
diff options
context:
space:
mode:
Diffstat (limited to 'codan')
-rw-r--r--codan/org.eclipse.cdt.codan.checkers/OSGI-INF/l10n/bundle.properties4
-rw-r--r--codan/org.eclipse.cdt.codan.checkers/plugin.xml15
-rw-r--r--codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/DecltypeAutoChecker.java45
-rw-r--r--codan/org.eclipse.cdt.codan.core.tests/src/org/eclipse/cdt/codan/core/internal/checkers/DecltypeAutoCheckerTest.java171
-rw-r--r--codan/org.eclipse.cdt.codan.core.tests/src/org/eclipse/cdt/codan/core/tests/AutomatedIntegrationSuite.java2
5 files changed, 237 insertions, 0 deletions
diff --git a/codan/org.eclipse.cdt.codan.checkers/OSGI-INF/l10n/bundle.properties b/codan/org.eclipse.cdt.codan.checkers/OSGI-INF/l10n/bundle.properties
index c5ebf9beed5..a478e7851e1 100644
--- a/codan/org.eclipse.cdt.codan.checkers/OSGI-INF/l10n/bundle.properties
+++ b/codan/org.eclipse.cdt.codan.checkers/OSGI-INF/l10n/bundle.properties
@@ -127,3 +127,7 @@ problem.description.UnusedStaticFunctionProblem = Finds static functions which c
problem.messagePattern.UnusedStaticFunctionProblem = Unused static function ''{0}''
problem.name.UnusedStaticFunctionProblem = Unused static function
+checker.name.DecltypeAutoChecker = Invalid 'decltype(auto)' specifier checker
+problem.name.DecltypeAutoProblem = Invalid 'decltype(auto)' specifier
+problem.messagePattern.DecltypeAutoProblem = Combining 'decltype(auto)' with other type specifiers is not allowed
+problem.description.DecltypeAutoProblem = This rule will flag 'decltype(auto)' if combined with other type specifiers
diff --git a/codan/org.eclipse.cdt.codan.checkers/plugin.xml b/codan/org.eclipse.cdt.codan.checkers/plugin.xml
index b4b1e025c35..7d44acf36d0 100644
--- a/codan/org.eclipse.cdt.codan.checkers/plugin.xml
+++ b/codan/org.eclipse.cdt.codan.checkers/plugin.xml
@@ -424,5 +424,20 @@
name="Nesting comments">
</problem>
</checker>
+ <checker
+ class="org.eclipse.cdt.codan.internal.checkers.DecltypeAutoChecker"
+ id="org.eclipse.cdt.codan.internal.checkers.DecltypeAutoChecker"
+ name="%checker.name.DecltypeAutoChecker">
+ <problem
+ category="org.eclipse.cdt.codan.core.categories.ProgrammingProblems"
+ defaultEnabled="true"
+ defaultSeverity="Error"
+ description="%problem.description.DecltypeAutoProblem"
+ id="org.eclipse.cdt.codan.internal.checkers.DecltypeAutoProblem"
+ markerType="org.eclipse.cdt.codan.core.codanProblem"
+ messagePattern="%problem.messagePattern.DecltypeAutoProblem"
+ name="%problem.name.DecltypeAutoProblem">
+ </problem>
+ </checker>
</extension>
</plugin>
diff --git a/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/DecltypeAutoChecker.java b/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/DecltypeAutoChecker.java
new file mode 100644
index 00000000000..f071bbe217b
--- /dev/null
+++ b/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/DecltypeAutoChecker.java
@@ -0,0 +1,45 @@
+/*******************************************************************************
+ * Copyright (c) 2017 Institute for Software, HSR Hochschule fuer Technik
+ * Rapperswil, University of applied sciences.
+ * 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
+ *******************************************************************************/
+package org.eclipse.cdt.codan.internal.checkers;
+
+import org.eclipse.cdt.codan.core.cxx.model.AbstractIndexAstChecker;
+import org.eclipse.cdt.core.dom.ast.ASTVisitor;
+import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
+import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTSimpleDeclSpecifier;
+
+public class DecltypeAutoChecker extends AbstractIndexAstChecker {
+ public static final String ERR_ID = "org.eclipse.cdt.codan.internal.checkers.DecltypeAutoProblem"; //$NON-NLS-1$
+
+ @Override
+ public boolean runInEditor() {
+ return true;
+ }
+
+ @Override
+ public void processAst(IASTTranslationUnit ast) {
+ ast.accept(new ASTVisitor() {
+ {
+ shouldVisitDeclSpecifiers = true;
+ }
+
+ @Override
+ public int visit(IASTDeclSpecifier specifier) {
+ if (specifier instanceof ICPPASTSimpleDeclSpecifier) {
+ if (((ICPPASTSimpleDeclSpecifier) specifier).getType() == ICPPASTSimpleDeclSpecifier.t_decltype_auto) {
+ if (specifier.isConst() || specifier.isVolatile()) {
+ reportProblem(ERR_ID, specifier);
+ }
+ }
+ }
+ return PROCESS_CONTINUE;
+ }
+ });
+ }
+}
diff --git a/codan/org.eclipse.cdt.codan.core.tests/src/org/eclipse/cdt/codan/core/internal/checkers/DecltypeAutoCheckerTest.java b/codan/org.eclipse.cdt.codan.core.tests/src/org/eclipse/cdt/codan/core/internal/checkers/DecltypeAutoCheckerTest.java
new file mode 100644
index 00000000000..3af9c505b04
--- /dev/null
+++ b/codan/org.eclipse.cdt.codan.core.tests/src/org/eclipse/cdt/codan/core/internal/checkers/DecltypeAutoCheckerTest.java
@@ -0,0 +1,171 @@
+/*******************************************************************************
+ * Copyright (c) 2017 Institute for Software, HSR Hochschule fuer Technik
+ * Rapperswil, University of applied sciences.
+ * 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
+ *******************************************************************************/
+package org.eclipse.cdt.codan.core.internal.checkers;
+
+import org.eclipse.cdt.codan.core.tests.CheckerTestCase;
+import org.eclipse.cdt.codan.internal.checkers.DecltypeAutoChecker;
+
+/**
+ * Test for {@link DecltypeAutoChecker} class
+ */
+public class DecltypeAutoCheckerTest extends CheckerTestCase {
+
+ public static final String ERR_ID = DecltypeAutoChecker.ERR_ID;
+
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+ enableProblems(ERR_ID);
+ }
+
+ @Override
+ public boolean isCpp() {
+ return true;
+ }
+
+ // int i { 42 }
+ // decltype(i) k = i;
+ public void testDecltypeExpressionVariable() throws Exception {
+ loadCodeAndRun(getAboveComment());
+ checkNoErrorsOfKind(ERR_ID);
+ }
+
+ // int i { 42 }
+ // decltype(i) volatile k = i;
+ public void testDecltypeExpressionVolatileVariable() throws Exception {
+ loadCodeAndRun(getAboveComment());
+ checkNoErrorsOfKind(ERR_ID);
+ }
+
+ // int i { 42 }
+ // decltype(i) const k = i;
+ public void testDecltypeExpressionConstVariable() throws Exception {
+ loadCodeAndRun(getAboveComment());
+ checkNoErrorsOfKind(ERR_ID);
+ }
+
+ // int i { 42 }
+ // decltype(i) const volatile k = i;
+ public void testDecltypeExpressionCVVariable() throws Exception {
+ loadCodeAndRun(getAboveComment());
+ checkNoErrorsOfKind(ERR_ID);
+ }
+
+ // decltype(auto) i { 42 };
+ public void testDecltypeAutoVariable() throws Exception {
+ loadCodeAndRun(getAboveComment());
+ checkNoErrorsOfKind(ERR_ID);
+ }
+
+ // decltype(auto) const i { 42 };
+ public void testDecltypeAutoConstVariable() throws Exception {
+ loadCodeAndRun(getAboveComment());
+ checkErrorLine(1, ERR_ID);
+ }
+
+ // decltype(auto) volatile i { 42 };
+ public void testDecltypeAutoVolatileVariable() throws Exception {
+ loadCodeAndRun(getAboveComment());
+ checkErrorLine(1, ERR_ID);
+ }
+
+ // decltype(auto) const volatile i { 42 };
+ public void testDecltypeAutoCVVariable() throws Exception {
+ loadCodeAndRun(getAboveComment());
+ checkErrorLine(1, ERR_ID);
+ }
+
+ // void foo() {
+ // decltype(auto) const i { 42 };
+ // }
+ public void testDecltypeAutoConstVariablInsideFunction() throws Exception {
+ loadCodeAndRun(getAboveComment());
+ checkErrorLine(2, ERR_ID);
+ }
+
+ // void foo() {
+ // decltype(auto) volatile i { 42 };
+ // }
+ public void testDecltypeAutoVolatileVariableInsideFunction() throws Exception {
+ loadCodeAndRun(getAboveComment());
+ checkErrorLine(2, ERR_ID);
+ }
+
+ // void foo() {
+ // decltype(auto) const volatile i { 42 };
+ // }
+ public void testDecltypeAutoCVVariableInsideFunction() throws Exception {
+ loadCodeAndRun(getAboveComment());
+ checkErrorLine(2, ERR_ID);
+ }
+
+ // decltype(auto) foo() {
+ // return 42;
+ // }
+ public void testDecltypeAutoReturnType() throws Exception {
+ loadCodeAndRun(getAboveComment());
+ checkNoErrorsOfKind(ERR_ID);
+ }
+
+ // decltype(auto) const foo() {
+ // return 42;
+ // }
+ public void testDecltypeAutoConstReturnType() throws Exception {
+ loadCodeAndRun(getAboveComment());
+ checkErrorLine(1, ERR_ID);
+ }
+
+ // decltype(auto) volatile foo() {
+ // return 42;
+ // }
+ public void testDecltypeAutoVolatileReturnType() throws Exception {
+ loadCodeAndRun(getAboveComment());
+ checkErrorLine(1, ERR_ID);
+ }
+
+ // decltype(auto) const volatile foo() {
+ // return 42;
+ // }
+ public void testDecltypeAutoCVReturnType() throws Exception {
+ loadCodeAndRun(getAboveComment());
+ checkErrorLine(1, ERR_ID);
+ }
+
+ // auto foo() -> decltype(auto) {
+ // return 42;
+ // }
+ public void testDecltypeAutoTrailingReturnType() throws Exception {
+ loadCodeAndRun(getAboveComment());
+ checkNoErrorsOfKind(ERR_ID);
+ }
+
+ // auto foo() -> decltype(auto) const {
+ // return 42;
+ // }
+ public void testDecltypeAutoConstTrailingReturnType() throws Exception {
+ loadCodeAndRun(getAboveComment());
+ checkErrorLine(1, ERR_ID);
+ }
+
+ // auto foo() -> decltype(auto) volatile {
+ // return 42;
+ // }
+ public void testDecltypeAutoVolatileTrailingReturnType() throws Exception {
+ loadCodeAndRun(getAboveComment());
+ checkErrorLine(1, ERR_ID);
+ }
+
+ // auto foo() -> decltype(auto) const volatile {
+ // return 42;
+ // }
+ public void testDecltypeAutoCVTrailingReturnType() throws Exception {
+ loadCodeAndRun(getAboveComment());
+ checkErrorLine(1, ERR_ID);
+ }
+}
diff --git a/codan/org.eclipse.cdt.codan.core.tests/src/org/eclipse/cdt/codan/core/tests/AutomatedIntegrationSuite.java b/codan/org.eclipse.cdt.codan.core.tests/src/org/eclipse/cdt/codan/core/tests/AutomatedIntegrationSuite.java
index 71bf0ca2620..57560947458 100644
--- a/codan/org.eclipse.cdt.codan.core.tests/src/org/eclipse/cdt/codan/core/tests/AutomatedIntegrationSuite.java
+++ b/codan/org.eclipse.cdt.codan.core.tests/src/org/eclipse/cdt/codan/core/tests/AutomatedIntegrationSuite.java
@@ -19,6 +19,7 @@ import org.eclipse.cdt.codan.core.internal.checkers.CatchByReferenceTest;
import org.eclipse.cdt.codan.core.internal.checkers.ClassMembersInitializationCheckerTest;
import org.eclipse.cdt.codan.core.internal.checkers.CommentCheckerLineTests;
import org.eclipse.cdt.codan.core.internal.checkers.CommentCheckerNestedTests;
+import org.eclipse.cdt.codan.core.internal.checkers.DecltypeAutoCheckerTest;
import org.eclipse.cdt.codan.core.internal.checkers.FormatStringCheckerTest;
import org.eclipse.cdt.codan.core.internal.checkers.NonVirtualDestructorCheckerTest;
import org.eclipse.cdt.codan.core.internal.checkers.ProblemBindingCheckerTest;
@@ -66,6 +67,7 @@ public class AutomatedIntegrationSuite extends TestSuite {
suite.addTestSuite(CaseBreakCheckerTest.class);
suite.addTestSuite(CatchByReferenceTest.class);
suite.addTestSuite(ClassMembersInitializationCheckerTest.class);
+ suite.addTestSuite(DecltypeAutoCheckerTest.class);
suite.addTestSuite(FormatStringCheckerTest.class);
suite.addTestSuite(NonVirtualDestructorCheckerTest.class);
suite.addTestSuite(ProblemBindingCheckerTest.class);

Back to the top