From 855ce8dd9dbcaa1a01f1fb5ba4b851f337b2b91e Mon Sep 17 00:00:00 2001 From: Matthew Gretton-Dann Date: Fri, 16 Aug 2019 15:46:58 +0100 Subject: [PATCH] C++: Add support for UsingEntry.getEnclosingElement --- cpp/ql/src/semmle/code/cpp/Element.qll | 3 ++- cpp/ql/test/library-tests/usings/Usings2.expected | 7 +++++++ cpp/ql/test/library-tests/usings/Usings2.ql | 6 ++++++ 3 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 cpp/ql/test/library-tests/usings/Usings2.expected create mode 100644 cpp/ql/test/library-tests/usings/Usings2.ql diff --git a/cpp/ql/src/semmle/code/cpp/Element.qll b/cpp/ql/src/semmle/code/cpp/Element.qll index f3ca8b3f657..771c3a24895 100644 --- a/cpp/ql/src/semmle/code/cpp/Element.qll +++ b/cpp/ql/src/semmle/code/cpp/Element.qll @@ -206,7 +206,8 @@ class Element extends ElementBase { namequalifiers(underlyingElement(this), unresolveElement(result), _, _) or initialisers(underlyingElement(this), unresolveElement(result), _, _) or exprconv(unresolveElement(result), underlyingElement(this)) or - param_decl_bind(underlyingElement(this),_,unresolveElement(result)) + param_decl_bind(underlyingElement(this),_,unresolveElement(result)) or + using_container(unresolveElement(result),underlyingElement(this)) } /** Gets the closest `Element` enclosing this one. */ diff --git a/cpp/ql/test/library-tests/usings/Usings2.expected b/cpp/ql/test/library-tests/usings/Usings2.expected new file mode 100644 index 00000000000..bb23b50e41a --- /dev/null +++ b/cpp/ql/test/library-tests/usings/Usings2.expected @@ -0,0 +1,7 @@ +| templates.cpp:9:5:9:14 | using c | file://:0:0:0:0 | std | +| usings.cpp:8:1:8:11 | using nf | file://:0:0:0:0 | (global namespace) | +| usings.cpp:9:1:9:17 | using namespace N | file://:0:0:0:0 | (global namespace) | +| usings.cpp:18:3:18:13 | using bf | usings.cpp:16:8:16:8 | D | +| usings.cpp:21:5:21:14 | using gf | usings.cpp:20:13:23:3 | { ... } | +| usings.cpp:34:3:34:20 | using tbf | usings.cpp:32:8:32:9 | TD | +| usings.cpp:42:5:42:22 | using foo | usings.cpp:41:11:41:15 | nsbar | diff --git a/cpp/ql/test/library-tests/usings/Usings2.ql b/cpp/ql/test/library-tests/usings/Usings2.ql new file mode 100644 index 00000000000..0278f1fafaa --- /dev/null +++ b/cpp/ql/test/library-tests/usings/Usings2.ql @@ -0,0 +1,6 @@ +import cpp + +from UsingEntry ue, Element e +where + e = ue.getEnclosingElement() +select ue, e