Skip to content

Commit 64338b0

Browse files
committed
Element::getEnclosingElement: Skip macro information.
Previously, we would try to find an element enclosing each macro access. This is not in general well-defined, especially in the context of template instantiations -- macros are a lexing-time concept, and don't map cleanly onto AST elements.
1 parent 9d2dd97 commit 64338b0

File tree

1 file changed

+2
-17
lines changed

1 file changed

+2
-17
lines changed

cpp/ql/src/semmle/code/cpp/Element.qll

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,6 @@ class Element extends @element {
154154
namequalifiers(this, result, _, _) or
155155
initialisers(this, result, _, _) or
156156
exprconv(result, this) or
157-
this = result.(MacroAccess).getParentInvocation() or
158-
result = this.(MacroInvocation).getExpr() or // macroinvocation -> outer Expr
159157
param_decl_bind(this,_,result)
160158
}
161159

@@ -165,17 +163,6 @@ class Element extends @element {
165163
(
166164
not exists(getEnclosingElementPref()) and
167165
(
168-
// macroinvocation -> all enclosed elements
169-
inmacroexpansion(result, this)
170-
or
171-
macrolocationbind(
172-
this.(MacroInvocation),
173-
result.(VariableDeclarationEntry).getLocation())
174-
or
175-
macrolocationbind(
176-
this.(MacroInvocation),
177-
result.(FunctionDeclarationEntry).getLocation())
178-
or
179166
this = result.(Class).getAMember()
180167
or
181168
result = exprEnclosingElement(this)
@@ -225,8 +212,7 @@ private predicate isFromTemplateInstantiationRec(Element e, Element instantiatio
225212
instantiation.(Variable).isConstructedFrom(_) and
226213
e = instantiation
227214
or
228-
isFromTemplateInstantiationRec(e.getEnclosingElement(), instantiation) and
229-
not e instanceof MacroAccess
215+
isFromTemplateInstantiationRec(e.getEnclosingElement(), instantiation)
230216
}
231217

232218
private predicate isFromUninstantiatedTemplateRec(Element e, Element template) {
@@ -239,8 +225,7 @@ private predicate isFromUninstantiatedTemplateRec(Element e, Element template) {
239225
is_variable_template(template) and
240226
e = template
241227
or
242-
isFromUninstantiatedTemplateRec(e.getEnclosingElement(), template) and
243-
not e instanceof MacroAccess
228+
isFromUninstantiatedTemplateRec(e.getEnclosingElement(), template)
244229
}
245230

246231
/**

0 commit comments

Comments
 (0)