Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
25 changes: 25 additions & 0 deletions cxx-squid/src/test/resources/metrics/alias_in_template_func.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
template<typename Second>
struct A {
template<typename Third>
void foo(){
using type = void;
}
};

template<typename Fourth>
void bar(){
using type = void;
}

/*!
* \brief Commented
*/
template<typename Fourth>
void foobar(){
/*!
* \brief Commented (Not a doxygen comment)
*/
using type = void;

using second_type = double;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wichtounet would add also a positive test: same with comments.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@guwirth Good idea