[LLVMbugs] [Bug 6678] New: incoherent warning when calling a non-const method with a const object

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Mon Mar 22 12:05:17 PDT 2010


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

           Summary: incoherent warning when calling a non-const method
                    with a const object
           Product: clang
           Version: trunk
          Platform: PC
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++
        AssignedTo: unassignedclangbugs at nondot.org
        ReportedBy: kremenek at apple.com
                CC: llvmbugs at cs.uiuc.edu, dgregor at apple.com


Consider the following example:

$ cat t.cpp
class Foo {
public:
  void bar();
};

void test(const Foo *x) {
  x->bar();
}

This is what clang says:

$ clang -fsyntax-only t.cpp
t.cpp:7:3: error: cannot initialize object parameter of type 'Foo' with an
expression of type 'Foo const'
  x->bar();
  ^
1 diagnostic generated.

This is what gcc says:

$ gcc -fsytnax-only t.cpp
t.cpp: In function ‘void test(const Foo*)’:
t.cpp:7: error: passing ‘const Foo’ as ‘this’ argument of ‘void Foo::bar()’
discards qualifiers


gcc's warning is much better.  It tells me exactly the nature of the problem. 
Clang's warning is incoherent and not really useful.

-- 
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