Clang error: reference to ... function could not be resolved; did you mean to call it...? (err_ovl_unresolvable)

From emmtrix Wiki
Jump to navigation Jump to search
Text
error: reference to
overloaded
multiversioned
function could not be resolved; did you mean to call it
 
with no arguments
?

(since 7.0)

error: reference to overloaded function could not be resolved; did you mean to call it
 
with no arguments
?

(until 6.0)

Type Error
Category Semantic Issue
Internal Id err_ovl_unresolvable
Internal Message reference to %select{overloaded|multiversioned}1 function could not be resolved; did you mean to call it%select{| with no arguments}0? (since 7.0)
reference to overloaded function could not be resolved; did you mean to call it%select{| with no arguments}0? (until 6.0)
Regular Expression (?:error|fatal error)\: reference to (?:overloaded|multiversioned) function could not be resolved; did you mean to call it(?:| with no arguments)\?
First Commit 2010-10-12 36226621f600 Progress.

Description

The error is issued by the Clang compiler when it encounters a reference to a function that could not be uniquely resolved due to its being overloaded or multiversed. Overloaded functions have multiple definitions that differ by the number or types of their parameters. Multiversed functions, although less common in general programming practice, refer to those that might have different implementations based on differing execution or compilation contexts. This issue arises when the code attempts to use one of these functions without providing enough context, such as the necessary arguments, for the compiler to determine which specific version or overload of the function is intended to be called.

The compiler's inability to resolve to a specific function could stem from multiple potential causes:

  • Ambiguity due to the presence of multiple function overloads or versions that match the call context to some degree, but none exclusively.
  • Incorrect usage of function call syntax, leading to ambiguity or incorrect interpretation of the intended call.
  • Special cases where function template specialization or overloading interacts in complex ways with type deduction, possibly leading to unforeseen ambiguities.

When this error is triggered, the compiler essentially indicates that the written code does not provide enough clear detail to disambiguate which function should be invoked, suggesting that an explicit call (potentially specifying the desired overload with arguments or through the casting of arguments) might resolve the issue. Correct resolution often involves examining the function calls that lead to the error and providing additional context or simplifying complex or ambiguous calls.

 
AI Generated

Example

In the following example, an illustration is provided on how the Clang compiler identifies and reports an error when it encounters an ambiguous reference to an overloaded function that cannot be resolved without additional context. The code snippet attempts to use a ternary conditional operator to decide between two function calls based on a boolean condition. However, due to the ambiguous nature of the ternary conditional expression and the lack of explicit arguments or context, the compiler is unable to determine which overloaded version of the function is intended to be called. As a result, multiple errors and a warning are produced, highlighting various aspects of the ambiguity and syntax issues encountered. These include an unexpected ':' instead of '::', which may suggest an incorrect attempt at specifying scope or class member access, the primary error message indicating the unresolved reference to the overloaded function, and additional syntax errors such as the missing semicolon and incorrect context for function identification. Through these diagnostic messages, the compiler signals the need for clearer disambiguation in the code to enable successful compilation.  
AI Generated


Flags -xc++

[Try out in Compiler Explorer]

Source
struct A{}; struct B{}; // Types
template<typename T> T f(T); // Overload
int main(){true?f:A:f:B; return 0;}
Compiler Output
<source>:3:20: error: unexpected ':' in nested name specifier; did you mean '::'?
<source>:3:17: error: reference to overloaded function could not be resolved; did you mean to call it?
<source>:2:24: note: possible target for call
<source>:3:22: error: expected ';' after expression
<source>:3:21: error: no member named 'f' in 'A'
<source>:3:23: warning: declaration does not declare anything [-Wmissing-declarations]


Clang Internals (17.0.6)

Git Commit Message

Progress.

llvm-svn: 116287

Used in Clang Sources

This section lists all occurrences of the diagnostic within the Clang's codebase. For each occurrence, an auto-extracted snipped from the source code is listed including key elements like control structures, functions, or classes. It should illustrate the conditions under which the diagnostic is activated.

clang/lib/Sema/SemaExpr.cpp (line 21545)

/// Check for operands with placeholder types and complain if found.
/// Returns ExprError() if there was an error and no recovery was possible.
ExprResult Sema::CheckPlaceholderExpr(Expr *E) {
  // ...
  // Overloaded expressions.
  case BuiltinType::Overload: {
    // ...
    tryToRecoverWithCall(Result, PDiag(diag::err_ovl_unresolvable),

Triggered in Clang Tests

This section lists all internal Clang test cases that trigger the diagnostic.

clang/test/Sema/PR28181.c

  • clang/test/Sema/PR28181.c:12:21: error: reference to overloaded function could not be resolved; did you mean to call it?