diff --git a/cpp/ql/lib/semmle/code/cpp/UserType.qll b/cpp/ql/lib/semmle/code/cpp/UserType.qll index 439ed84e05e8..878754657b79 100644 --- a/cpp/ql/lib/semmle/code/cpp/UserType.qll +++ b/cpp/ql/lib/semmle/code/cpp/UserType.qll @@ -47,10 +47,16 @@ class UserType extends Type, Declaration, NameQualifyingElement, AccessHolder, @ else result = this.getADeclarationLocation() } + pragma[nomagic] + private TypeDeclarationEntry getADeclarationEntryBase() { + type_decls(underlyingElement(result), unresolveElement(this), _) + } + override TypeDeclarationEntry getADeclarationEntry() { - if type_decls(_, unresolveElement(this), _) - then type_decls(underlyingElement(result), unresolveElement(this), _) - else exists(Class t | this.(Class).isConstructedFrom(t) and result = t.getADeclarationEntry()) + pragma[only_bind_into](result) = pragma[only_bind_into](this).getADeclarationEntryBase() + or + not exists(this.getADeclarationEntryBase()) and + exists(Class t | this.(Class).isConstructedFrom(t) and result = t.getADeclarationEntry()) } override Location getADeclarationLocation() { result = this.getADeclarationEntry().getLocation() }