[LLVMbugs] [Bug 8315] New: Report error when applying a pointer-to-const-member-function to non-const object
bugzilla-daemon at llvm.org
bugzilla-daemon at llvm.org
Wed Oct 6 10:48:41 PDT 2010
http://llvm.org/bugs/show_bug.cgi?id=8315
Summary: Report error when applying a
pointer-to-const-member-function to non-const object
Product: clang
Version: trunk
Platform: All
OS/Version: All
Status: NEW
Severity: normal
Priority: P
Component: C++
AssignedTo: unassignedclangbugs at nondot.org
ReportedBy: benoit.belley at autodesk.com
CC: llvmbugs at cs.uiuc.edu, dgregor at apple.com
Created an attachment (id=5573)
--> (http://llvm.org/bugs/attachment.cgi?id=5573)
Test case
IClang fails to report an error when applying a pointer to a const member
function to non-const reference or pointer as demonstrated by the following
code example:
-----------------------------------------------------------------------------------------------------
class ClassA {};
typedef void (ClassA::*PtrToMem)();
typedef void (ClassA::*PtrToConstMem)() const;
void foo(
ClassA a,
const ClassA& a_const,
ClassA* ap,
const ClassA* ap_const,
PtrToMem ptr_to_mem,
PtrToConstMem ptr_to_const_mem
) {
(a.*ptr_to_mem)();
(a.*ptr_to_const_mem)();
(a_const.*ptr_to_mem)(); // expected-error{{invalid conversion from
'const ClassA*' to 'ClassA*'}}
(a_const.*ptr_to_const_mem)();
(ap->*ptr_to_mem)();
(ap->*ptr_to_const_mem)();
(ap_const->*ptr_to_mem)(); // expected-error{{invalid conversion from
'const ClassA*' to 'ClassA*'}}
(ap_const->*ptr_to_const_mem)();
}
-----------------------------------------------------------------------------------------------------
$ llvm/Debug+Asserts/bin/clang++ -c ptr_to_const_mem_bug.cpp
$
-----------------------------------------------------------------------------------------------------
I am currently using the SVN revision 114947 of clang.
Note that both the GNU g++ compiler and the Intel C++ compiler are properly
reporting the errors:
-----------------------------------------------------------------------------------------------------
$ g++ -c ptr_to_const_mem_bug.cpp
ptr_to_const_mem_bug.cpp: In function 'void foo(ClassA, const ClassA&, ClassA*,
const ClassA*, void (ClassA::*)(), void (ClassA::*)()const)':
ptr_to_const_mem_bug.cpp:18: error: invalid conversion from 'const ClassA*' to
'ClassA*'
ptr_to_const_mem_bug.cpp:24: error: invalid conversion from 'const ClassA*' to
'ClassA*’
$ icpc -c ptr_to_const_mem_bug.cpp
ptr_to_const_mem_bug.cpp(18): error: the object has cv-qualifiers that are not
compatible with the member function
object type is: const ClassA
(a_const.*ptr_to_mem)(); // expected-error{{invalid conversion from
'const ClassA*' to 'ClassA*'}}
^
ptr_to_const_mem_bug.cpp(24): error: the object has cv-qualifiers that are not
compatible with the member function
object type is: const ClassA
(ap_const->*ptr_to_mem)(); // expected-error{{invalid conversion from
'const ClassA*' to 'ClassA*'}}
^
compilation aborted for ptr_to_const_mem_bug.cpp (code 2)
$
-----------------------------------------------------------------------------------------------------
Cheers,
Benoit
--
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