[LLVMbugs] [Bug 9555] New: Suboptimal error message for providing T* to method requiring T or T&

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Fri Mar 25 13:21:40 PDT 2011


http://llvm.org/bugs/show_bug.cgi?id=9555

           Summary: Suboptimal error message for providing T* to method
                    requiring T or T&
           Product: clang
           Version: unspecified
          Platform: Macintosh
        OS/Version: MacOS X
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++
        AssignedTo: unassignedclangbugs at nondot.org
        ReportedBy: jonathan.sauer at gmx.de
                CC: llvmbugs at cs.uiuc.edu, dgregor at apple.com


Compiling the following (invalid) code:

struct V {
    void foo(V&)
    {
    }

    void bar(V)
    {
    }
};


int main(int, char**)
{
    V* v = new V;
    v->bar(v);
    v->foo(v);
    v->foo(static_cast<V*>(0));
}


results in the following compile errors:

$ /opt/bin/clang clang.cpp
clang.cpp:15:9: error: no viable conversion from 'V *' to 'V'
        v->bar(v);
               ^
clang.cpp:1:8: note: candidate constructor (the implicit copy constructor) not
viable: no known
      conversion from 'V *' to 'const V &' for 1st argument
struct V {
       ^
clang.cpp:6:12: note: passing argument to parameter here
        void bar(V)
                  ^
clang.cpp:16:9: error: non-const lvalue reference to type 'V' cannot bind to a
value of unrelated
      type 'V *'
        v->foo(v);
               ^
clang.cpp:2:13: note: passing argument to parameter here
        void foo(V&)
                   ^
clang.cpp:17:9: error: non-const lvalue reference to type 'V' cannot bind to a
temporary of type
      'V *'
        v->foo(static_cast<V*>(0));
               ^~~~~~~~~~~~~~~~~~
clang.cpp:2:13: note: passing argument to parameter here
        void foo(V&)
                   ^
3 errors generated.

While the first error is fine, the second and third are not really helpful.
Especially since I just forgot the "*" to dereference the pointer before
passing it to foo and bar.

I think in cases like these (required T or reference to T, but got pointer to
T), clang could even provide a fixit ("did you mean '*<expr>'?").


My clang version:

$ /opt/bin/clang --version
clang version 3.0 (trunk 127993)
Target: x86_64-apple-darwin10
Thread model: posix

-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.



More information about the llvm-bugs mailing list