From 3fd6a8de7da58bd021fdba28732c2029499acbc4 Mon Sep 17 00:00:00 2001 From: Ian Lynagh Date: Mon, 3 Sep 2018 13:17:06 +0100 Subject: [PATCH] C++: Fix the definition of GlobalNamespace.getADeclaration() Globals can still have declarations in declaration statements. We already rule out local variables etc via the isTopLevel check, so we don't need to consider DeclStmt. --- cpp/ql/src/semmle/code/cpp/Namespace.qll | 5 ----- .../test/library-tests/namespaces/namespaces/decls.expected | 2 +- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/cpp/ql/src/semmle/code/cpp/Namespace.qll b/cpp/ql/src/semmle/code/cpp/Namespace.qll index 603be7dcfb3..cd93175b796 100644 --- a/cpp/ql/src/semmle/code/cpp/Namespace.qll +++ b/cpp/ql/src/semmle/code/cpp/Namespace.qll @@ -190,11 +190,6 @@ class GlobalNamespace extends Namespace { override Declaration getADeclaration() { suppressWarningForUnused(this) and - not exists(DeclStmt d | - d.getADeclaration() = result and - not result instanceof Function - ) and - not exists(ConditionDeclExpr cde | cde.getVariable() = result) and result.isTopLevel() and not namespacembrs(_, unresolveElement(result)) } diff --git a/cpp/ql/test/library-tests/namespaces/namespaces/decls.expected b/cpp/ql/test/library-tests/namespaces/namespaces/decls.expected index 6855bf65f9a..16f6b2bc855 100644 --- a/cpp/ql/test/library-tests/namespaces/namespaces/decls.expected +++ b/cpp/ql/test/library-tests/namespaces/namespaces/decls.expected @@ -5,9 +5,9 @@ | file://:0:0:0:0 | (global namespace) | file://:0:0:0:0 | operator= | __va_list_tag::operator= | false | | file://:0:0:0:0 | (global namespace) | file://:0:0:0:0 | overflow_arg_area | __va_list_tag::overflow_arg_area | false | | file://:0:0:0:0 | (global namespace) | file://:0:0:0:0 | reg_save_area | __va_list_tag::reg_save_area | false | +| file://:0:0:0:0 | (global namespace) | namespaces.cpp:40:5:40:13 | globalInt | globalInt | true | | file://:0:0:0:0 | (global namespace) | namespaces.cpp:42:6:42:18 | globalIntUser | globalIntUser | true | | file://:0:0:0:0 | | file://:0:0:0:0 | auto | | false | -| file://:0:0:0:0 | | namespaces.cpp:40:5:40:13 | globalInt | | true | | file://:0:0:0:0 | B | namespaces.cpp:32:7:32:7 | x | B::x | true | | namespaces.cpp:11:13:11:13 | C::D | file://:0:0:0:0 | p#0 | | false | | namespaces.cpp:11:13:11:13 | C::D | file://:0:0:0:0 | p#0 | | false |