Bug with pointer to const member function

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Bug with pointer to const member function

Benoit Belley
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
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Bug with pointer to const member function

Douglas Gregor
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
> [hidden email]
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev


_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Bug with pointer to const member function

Sean McBride
On Wed, 6 Oct 2010 07:54:51 -0700, Douglas Gregor said:

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

It might be good to clarify that here:

<http://clang.llvm.org/get_started.html>

where it currently says "If you run into problems, please file bugs in
LLVM Bugzilla or bring up the issue on the Clang development mailing list."

--
____________________________________________________________
Sean McBride, B. Eng                 [hidden email]
Rogue Research                        www.rogue-research.com
Mac Software Developer              Montréal, Québec, Canada



_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Bug with pointer to const member function

Benoit Belley
In reply to this post by Douglas Gregor
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
[hidden email]<mailto:[hidden email]>
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@01CAF376.C0A99470]



_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev

image002.gif (892 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Bug with pointer to const member function

Douglas Gregor

On Oct 6, 2010, at 10:51 AM, Benoit Belley wrote:

> Sure. Here’s the bug report then:
>
> http://llvm.org/bugs/show_bug.cgi?id=8315
>
> Benoit

Thanks!

> 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
> [hidden email]<mailto:[hidden email]>
> 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@01CAF376.C0A99470]
>
>


_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Bug with pointer to const member function

Douglas Gregor
In reply to this post by Sean McBride

On Oct 6, 2010, at 8:29 AM, Sean McBride wrote:

> On Wed, 6 Oct 2010 07:54:51 -0700, Douglas Gregor said:
>
>> In general, please reports bugs directly by filing them in Bugzilla.
>
> It might be good to clarify that here:
>
> <http://clang.llvm.org/get_started.html>
>
> where it currently says "If you run into problems, please file bugs in
> LLVM Bugzilla or bring up the issue on the Clang development mailing list."

Good point, thanks! It's fixed now.

        - Doug
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev