LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 5941 - improve diagnostic for * vs & confusion
Summary: improve diagnostic for * vs & confusion
Status: NEW
Alias: None
Product: clang
Classification: Unclassified
Component: C++ (show other bugs)
Version: unspecified
Hardware: PC All
: P normal
Assignee: Ryan Yee
URL:
Keywords: quality-of-implementation
Depends on:
Blocks:
 
Reported: 2010-01-04 18:25 PST by Chris Lattner
Modified: 2019-05-20 10:05 PDT (History)
8 users (show)

See Also:
Fixed By Commit(s):


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Chris Lattner 2010-01-04 18:25:43 PST
Consider:

class A;
void f0(A *a);
void f1(A &a);
void f2(A *a) {
  f1(a);
}
void f3(A &a) {
  f0(a);
}

We produce:
t.cc:7:3: error: no matching function for call to 'f1'
  f1(a);
  ^~
t.cc:4:6: note: candidate function
void f1(A &a);
     ^
t.cc:11:3: error: no matching function for call to 'f0'
  f0(a);
  ^~
t.cc:3:6: note: candidate function
void f0(A *a);
     ^

In addition to producing a better error message for this common issue, it would be really nice to produce a fixit that ass a & or *.

This is AKA rdar://7113438
Comment 1 Douglas Gregor 2011-03-25 17:07:58 PDT
*** Bug 9555 has been marked as a duplicate of this bug. ***
Comment 2 Kaelyn Takata 2012-06-21 19:12:16 PDT
As of r158931, clang's error messages are better:

$ cat tmp.cc 
class A;
void f0(A *a);
void f1(A &a);
void f2(A *a) {
  f1(a);
}
void f3(A &a) {
  f0(a);
}


$ ./bin/clang -fsyntax-only tmp.cc 
tmp.cc:5:3: error: no matching function for call to 'f1'
  f1(a);
  ^~
tmp.cc:3:6: note: candidate function not viable: cannot convert argument of incomplete type 'A *' to
      'A &'
void f1(A &a);
     ^
tmp.cc:8:3: error: no matching function for call to 'f0'
  f0(a);
  ^~
tmp.cc:2:6: note: candidate function not viable: cannot convert argument of incomplete type 'A' to
      'A *'
void f0(A *a);
     ^
2 errors generated.


And if you change "class A;" to "class A {};":

$ ./bin/clang -fsyntax-only tmp.cc 
tmp.cc:5:3: error: no matching function for call to 'f1'
  f1(a);
  ^~
tmp.cc:3:6: note: candidate function not viable: no known conversion from 'A *' to 'A &' for 1st
      argument; dereference the argument with *
void f1(A &a);
     ^
tmp.cc:8:3: error: no matching function for call to 'f0'
  f0(a);
  ^~
tmp.cc:2:6: note: candidate function not viable: no known conversion from 'A' to 'A *' for 1st
      argument; take the address of the argument with &
void f0(A *a);
     ^
2 errors generated.


The error message when A is an incomplete type could use a bit more love to make it more helpful like when A is a complete type, and there aren't any fix-it hints for any of the cases.
Comment 3 Ryan Yee 2016-02-06 15:22:33 PST
Created a patch submission here: http://reviews.llvm.org/D16949