diff --git a/cxx-squid/src/main/java/org/sonar/cxx/visitors/AbstractCxxPublicApiVisitor.java b/cxx-squid/src/main/java/org/sonar/cxx/visitors/AbstractCxxPublicApiVisitor.java index c70695734f..d19f32028a 100644 --- a/cxx-squid/src/main/java/org/sonar/cxx/visitors/AbstractCxxPublicApiVisitor.java +++ b/cxx-squid/src/main/java/org/sonar/cxx/visitors/AbstractCxxPublicApiVisitor.java @@ -2,17 +2,17 @@ * Sonar C++ Plugin (Community) * Copyright (C) 2011-2016 SonarOpenCommunity * http://github.com/SonarOpenCommunity/sonar-cxx - * + * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 3 of the License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. @@ -502,6 +502,15 @@ private void visitMemberDeclarator(AstNode node) { } private void visitAliasDeclaration(AstNode aliasDeclNode) { + AstNode parent = aliasDeclNode.getFirstAncestor( + CxxGrammarImpl.functionDefinition, + CxxGrammarImpl.classSpecifier); + + // An alias declaration inside a function is not part of the public API + if (parent != null && parent.getType() == CxxGrammarImpl.functionDefinition){ + return; + } + if (isPublicApiMember(aliasDeclNode)) { logDebug("AliasDeclaration"); diff --git a/cxx-squid/src/test/java/org/sonar/cxx/CxxPublicApiVisitorTest.java b/cxx-squid/src/test/java/org/sonar/cxx/CxxPublicApiVisitorTest.java index 9096694276..18de641fe2 100644 --- a/cxx-squid/src/test/java/org/sonar/cxx/CxxPublicApiVisitorTest.java +++ b/cxx-squid/src/test/java/org/sonar/cxx/CxxPublicApiVisitorTest.java @@ -137,6 +137,11 @@ public void template() throws IOException { testFile("src/test/resources/metrics/template.h", 9, 4, true); } + @Test + public void alias_function_template() throws IOException { + testFile("src/test/resources/metrics/alias_in_template_func.h", 4, 3, false); + } + @Test public void unnamed_class() throws IOException { testFile("src/test/resources/metrics/unnamed_class.h", 3, 1, false); diff --git a/cxx-squid/src/test/resources/metrics/alias_in_template_func.h b/cxx-squid/src/test/resources/metrics/alias_in_template_func.h new file mode 100644 index 0000000000..3f1ac736f9 --- /dev/null +++ b/cxx-squid/src/test/resources/metrics/alias_in_template_func.h @@ -0,0 +1,25 @@ +template +struct A { + template + void foo(){ + using type = void; + } +}; + +template +void bar(){ + using type = void; +} + +/*! + * \brief Commented + */ +template +void foobar(){ + /*! + * \brief Commented (Not a doxygen comment) + */ + using type = void; + + using second_type = double; +}