@@ -393,18 +393,23 @@ class Function extends Declaration, ControlFlowNode, AccessHolder, @function {
393393
394394 /** Gets a function that overloads this one. */
395395 Function getAnOverload ( ) {
396- result .getName ( ) = getName ( ) and
397- result .getNamespace ( ) = getNamespace ( ) and
398- result != this and
399- // If this function is declared in a class, only consider other
400- // functions from the same class. Conversely, if this function is not
401- // declared in a class, only consider other functions not declared in a
402- // class.
403396 (
404- if exists ( getDeclaringType ( ) )
405- then result .getDeclaringType ( ) = getDeclaringType ( )
406- else not exists ( result .getDeclaringType ( ) )
397+ // If this function is declared in a class, only consider other
398+ // functions from the same class.
399+ exists ( string name , Namespace namespace , Class declaringType |
400+ candGetAnOverloadMember ( name , namespace , declaringType , this ) and
401+ candGetAnOverloadMember ( name , namespace , declaringType , result )
402+ )
403+ or
404+ // Conversely, if this function is not
405+ // declared in a class, only consider other functions not declared in a
406+ // class.
407+ exists ( string name , Namespace namespace |
408+ candGetAnOverloadNonMember ( name , namespace , this ) and
409+ candGetAnOverloadNonMember ( name , namespace , result )
410+ )
407411 ) and
412+ result != this and
408413 // Instantiations and specializations don't participate in overload
409414 // resolution.
410415 not (
@@ -462,6 +467,22 @@ class Function extends Declaration, ControlFlowNode, AccessHolder, @function {
462467 override AccessHolder getEnclosingAccessHolder ( ) { result = this .getDeclaringType ( ) }
463468}
464469
470+ pragma [ noinline]
471+ private predicate candGetAnOverloadMember (
472+ string name , Namespace namespace , Class declaringType , Function f
473+ ) {
474+ f .getName ( ) = name and
475+ f .getNamespace ( ) = namespace and
476+ f .getDeclaringType ( ) = declaringType
477+ }
478+
479+ pragma [ noinline]
480+ private predicate candGetAnOverloadNonMember ( string name , Namespace namespace , Function f ) {
481+ f .getName ( ) = name and
482+ f .getNamespace ( ) = namespace and
483+ not exists ( f .getDeclaringType ( ) )
484+ }
485+
465486/**
466487 * A particular declaration or definition of a C/C++ function. For example the
467488 * declaration and definition of `MyFunction` in the following code are each a
0 commit comments