[cfe-dev] Bug with pointer to const member function

Benoit Belley Benoit.Belley at autodesk.com
Wed Oct 6 10:51:45 PDT 2010


Sure. Here’s the bug report then:

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

Benoit

Le 2010-10-06 à 10:54, Douglas Gregor a écrit :

In general, please reports bugs directly by filing them in Bugzilla.

- Doug

On Oct 6, 2010, at 7:49 AM, Benoit Belley wrote:

Hi Everyone,

It seems that Clang 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
$
-----------------------------------------------------------------------------------------------------


Is this a known bug ?

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


Benoit Belley
Sr Principal Developer
M&E-Product Development Group

Autodesk Canada Inc.
10 Rue Duke
Montreal, Quebec  H3C 2L7
Canada

_______________________________________________
cfe-dev mailing list
cfe-dev at cs.uiuc.edu<mailto:cfe-dev at cs.uiuc.edu>
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev




Benoit Belley
Sr Principal Developer
M&E-Product Development Group

Autodesk Canada Inc.
10 Rue Duke
Montreal, Quebec  H3C 2L7
Canada

Direct 514 954-7154



[cid:image002.gif at 01CAF376.C0A99470]


-------------- next part --------------
A non-text attachment was scrubbed...
Name: image002.gif
Type: image/gif
Size: 651 bytes
Desc: image002.gif
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20101006/c536ee64/attachment.gif>


More information about the cfe-dev mailing list