diff mbox series

[tree.c] Replace cast to (char *) by const_cast<char *>

Message ID CAAgBjMnCKFPthT-6zs+hm=WuWJEEA4ntYyiEyT3jq-Sp4Mtspg@mail.gmail.com
State New
Headers show
Series [tree.c] Replace cast to (char *) by const_cast<char *> | expand

Commit Message

Prathamesh Kulkarni June 18, 2018, 1:55 p.m. UTC
Hi,
I am getting the following build error with trunk:
../../gcc/gcc/tree.c: In member function ‘void
escaped_string::escape(const char*)’:
../../gcc/gcc/tree.c:12457:20: error: cast from type ‘const char*’ to
type ‘char*’ casts away qualifiers [-Werror=cast-qual]
   m_str = (char *) unescaped;
                    ^~~~~~~~~
I think this is caused by r261697 in tree.c:
  m_str = (char *) unescaped;

The patch changes it to const_cast<char *> (unescaped) which fixes the
build for me.
OK to commit ?

Thanks,
Prathamesh

Comments

Nick Clifton June 18, 2018, 1:58 p.m. UTC | #1
Hi Prathamesh,

> I am getting the following build error with trunk:

> ../../gcc/gcc/tree.c: In member function ‘void

> escaped_string::escape(const char*)’:

> ../../gcc/gcc/tree.c:12457:20: error: cast from type ‘const char*’ to

> type ‘char*’ casts away qualifiers [-Werror=cast-qual]

>    m_str = (char *) unescaped;

>                     ^~~~~~~~~

> I think this is caused by r261697 in tree.c:

>   m_str = (char *) unescaped;

> 

> The patch changes it to const_cast<char *> (unescaped) which fixes the

> build for me.


I cannot approve this patch, but I can say thanks very much for catching
this problem and proposing a fix.  I guess that I must be using an old
version of g++ for my testing as this error did not show up. :-(

Cheers
  Nick
Prathamesh Kulkarni June 18, 2018, 2:08 p.m. UTC | #2
On 18 June 2018 at 19:28, Nick Clifton <nickc@redhat.com> wrote:
> Hi Prathamesh,

>

>> I am getting the following build error with trunk:

>> ../../gcc/gcc/tree.c: In member function ‘void

>> escaped_string::escape(const char*)’:

>> ../../gcc/gcc/tree.c:12457:20: error: cast from type ‘const char*’ to

>> type ‘char*’ casts away qualifiers [-Werror=cast-qual]

>>    m_str = (char *) unescaped;

>>                     ^~~~~~~~~

>> I think this is caused by r261697 in tree.c:

>>   m_str = (char *) unescaped;

>>

>> The patch changes it to const_cast<char *> (unescaped) which fixes the

>> build for me.

>

> I cannot approve this patch, but I can say thanks very much for catching

> this problem and proposing a fix.  I guess that I must be using an old

> version of g++ for my testing as this error did not show up. :-(

Hi Nick,
Thanks for confirming. I went ahead and committed the patch in r261700
since I guess it's trivial enough to fit under the "obvious" rule.

Thanks,
Prathamesh
>

> Cheers

>   Nick

>

>
Jeff Law June 18, 2018, 2:34 p.m. UTC | #3
On 06/18/2018 08:08 AM, Prathamesh Kulkarni wrote:
> On 18 June 2018 at 19:28, Nick Clifton <nickc@redhat.com> wrote:

>> Hi Prathamesh,

>>

>>> I am getting the following build error with trunk:

>>> ../../gcc/gcc/tree.c: In member function ‘void

>>> escaped_string::escape(const char*)’:

>>> ../../gcc/gcc/tree.c:12457:20: error: cast from type ‘const char*’ to

>>> type ‘char*’ casts away qualifiers [-Werror=cast-qual]

>>>    m_str = (char *) unescaped;

>>>                     ^~~~~~~~~

>>> I think this is caused by r261697 in tree.c:

>>>   m_str = (char *) unescaped;

>>>

>>> The patch changes it to const_cast<char *> (unescaped) which fixes the

>>> build for me.

>>

>> I cannot approve this patch, but I can say thanks very much for catching

>> this problem and proposing a fix.  I guess that I must be using an old

>> version of g++ for my testing as this error did not show up. :-(

> Hi Nick,

> Thanks for confirming. I went ahead and committed the patch in r261700

> since I guess it's trivial enough to fit under the "obvious" rule.

Yes.

Thanks for taking care of it.

jeff
Jakub Jelinek June 18, 2018, 4:41 p.m. UTC | #4
On Mon, Jun 18, 2018 at 08:34:28AM -0600, Jeff Law wrote:
> On 06/18/2018 08:08 AM, Prathamesh Kulkarni wrote:

> > On 18 June 2018 at 19:28, Nick Clifton <nickc@redhat.com> wrote:

> >> Hi Prathamesh,

> >>

> >>> I am getting the following build error with trunk:

> >>> ../../gcc/gcc/tree.c: In member function ‘void

> >>> escaped_string::escape(const char*)’:

> >>> ../../gcc/gcc/tree.c:12457:20: error: cast from type ‘const char*’ to

> >>> type ‘char*’ casts away qualifiers [-Werror=cast-qual]

> >>>    m_str = (char *) unescaped;

> >>>                     ^~~~~~~~~

> >>> I think this is caused by r261697 in tree.c:

> >>>   m_str = (char *) unescaped;

> >>>

> >>> The patch changes it to const_cast<char *> (unescaped) which fixes the

> >>> build for me.

> >>

> >> I cannot approve this patch, but I can say thanks very much for catching

> >> this problem and proposing a fix.  I guess that I must be using an old

> >> version of g++ for my testing as this error did not show up. :-(

> > Hi Nick,

> > Thanks for confirming. I went ahead and committed the patch in r261700

> > since I guess it's trivial enough to fit under the "obvious" rule.

> Yes.

> 

> Thanks for taking care of it.


Shouldn't we use
  m_str = CONST_CAST (char *, unescaped);
instead?  That is what most similar spots use.

	Jakub
Jason Merrill June 18, 2018, 5:48 p.m. UTC | #5
On Mon, Jun 18, 2018 at 12:41 PM, Jakub Jelinek <jakub@redhat.com> wrote:
> On Mon, Jun 18, 2018 at 08:34:28AM -0600, Jeff Law wrote:

>> On 06/18/2018 08:08 AM, Prathamesh Kulkarni wrote:

>> > On 18 June 2018 at 19:28, Nick Clifton <nickc@redhat.com> wrote:

>> >> Hi Prathamesh,

>> >>

>> >>> I am getting the following build error with trunk:

>> >>> ../../gcc/gcc/tree.c: In member function ‘void

>> >>> escaped_string::escape(const char*)’:

>> >>> ../../gcc/gcc/tree.c:12457:20: error: cast from type ‘const char*’ to

>> >>> type ‘char*’ casts away qualifiers [-Werror=cast-qual]

>> >>>    m_str = (char *) unescaped;

>> >>>                     ^~~~~~~~~

>> >>> I think this is caused by r261697 in tree.c:

>> >>>   m_str = (char *) unescaped;

>> >>>

>> >>> The patch changes it to const_cast<char *> (unescaped) which fixes the

>> >>> build for me.

>> >>

>> >> I cannot approve this patch, but I can say thanks very much for catching

>> >> this problem and proposing a fix.  I guess that I must be using an old

>> >> version of g++ for my testing as this error did not show up. :-(

>> > Hi Nick,

>> > Thanks for confirming. I went ahead and committed the patch in r261700

>> > since I guess it's trivial enough to fit under the "obvious" rule.

>> Yes.

>>

>> Thanks for taking care of it.

>

> Shouldn't we use

>   m_str = CONST_CAST (char *, unescaped);

> instead?  That is what most similar spots use.


That macro seems obsolete now that we compile as C++.

Jason
Jakub Jelinek June 18, 2018, 5:51 p.m. UTC | #6
On Mon, Jun 18, 2018 at 01:48:05PM -0400, Jason Merrill wrote:
> On Mon, Jun 18, 2018 at 12:41 PM, Jakub Jelinek <jakub@redhat.com> wrote:

> > On Mon, Jun 18, 2018 at 08:34:28AM -0600, Jeff Law wrote:

> >> On 06/18/2018 08:08 AM, Prathamesh Kulkarni wrote:

> >> > On 18 June 2018 at 19:28, Nick Clifton <nickc@redhat.com> wrote:

> >> >> Hi Prathamesh,

> >> >>

> >> >>> I am getting the following build error with trunk:

> >> >>> ../../gcc/gcc/tree.c: In member function ‘void

> >> >>> escaped_string::escape(const char*)’:

> >> >>> ../../gcc/gcc/tree.c:12457:20: error: cast from type ‘const char*’ to

> >> >>> type ‘char*’ casts away qualifiers [-Werror=cast-qual]

> >> >>>    m_str = (char *) unescaped;

> >> >>>                     ^~~~~~~~~

> >> >>> I think this is caused by r261697 in tree.c:

> >> >>>   m_str = (char *) unescaped;

> >> >>>

> >> >>> The patch changes it to const_cast<char *> (unescaped) which fixes the

> >> >>> build for me.

> >> >>

> >> >> I cannot approve this patch, but I can say thanks very much for catching

> >> >> this problem and proposing a fix.  I guess that I must be using an old

> >> >> version of g++ for my testing as this error did not show up. :-(

> >> > Hi Nick,

> >> > Thanks for confirming. I went ahead and committed the patch in r261700

> >> > since I guess it's trivial enough to fit under the "obvious" rule.

> >> Yes.

> >>

> >> Thanks for taking care of it.

> >

> > Shouldn't we use

> >   m_str = CONST_CAST (char *, unescaped);

> > instead?  That is what most similar spots use.

> 

> That macro seems obsolete now that we compile as C++.


But shouldn't we then remove/poison those macros and replace all uses?
I don't care much if we use CONST_CAST or const_cast, but care about
consistency.

	Jakub
Jason Merrill June 18, 2018, 5:58 p.m. UTC | #7
On Mon, Jun 18, 2018 at 1:51 PM, Jakub Jelinek <jakub@redhat.com> wrote:
> On Mon, Jun 18, 2018 at 01:48:05PM -0400, Jason Merrill wrote:

>> On Mon, Jun 18, 2018 at 12:41 PM, Jakub Jelinek <jakub@redhat.com> wrote:

>> > On Mon, Jun 18, 2018 at 08:34:28AM -0600, Jeff Law wrote:

>> >> On 06/18/2018 08:08 AM, Prathamesh Kulkarni wrote:

>> >> > On 18 June 2018 at 19:28, Nick Clifton <nickc@redhat.com> wrote:

>> >> >> Hi Prathamesh,

>> >> >>

>> >> >>> I am getting the following build error with trunk:

>> >> >>> ../../gcc/gcc/tree.c: In member function ‘void

>> >> >>> escaped_string::escape(const char*)’:

>> >> >>> ../../gcc/gcc/tree.c:12457:20: error: cast from type ‘const char*’ to

>> >> >>> type ‘char*’ casts away qualifiers [-Werror=cast-qual]

>> >> >>>    m_str = (char *) unescaped;

>> >> >>>                     ^~~~~~~~~

>> >> >>> I think this is caused by r261697 in tree.c:

>> >> >>>   m_str = (char *) unescaped;

>> >> >>>

>> >> >>> The patch changes it to const_cast<char *> (unescaped) which fixes the

>> >> >>> build for me.

>> >> >>

>> >> >> I cannot approve this patch, but I can say thanks very much for catching

>> >> >> this problem and proposing a fix.  I guess that I must be using an old

>> >> >> version of g++ for my testing as this error did not show up. :-(

>> >> > Hi Nick,

>> >> > Thanks for confirming. I went ahead and committed the patch in r261700

>> >> > since I guess it's trivial enough to fit under the "obvious" rule.

>> >> Yes.

>> >>

>> >> Thanks for taking care of it.

>> >

>> > Shouldn't we use

>> >   m_str = CONST_CAST (char *, unescaped);

>> > instead?  That is what most similar spots use.

>>

>> That macro seems obsolete now that we compile as C++.

>

> But shouldn't we then remove/poison those macros and replace all uses?

> I don't care much if we use CONST_CAST or const_cast, but care about

> consistency.


That would make sense.

Jason
diff mbox series

Patch

diff --git a/gcc/tree.c b/gcc/tree.c
index 6728f1c..889d88c 100644
--- a/gcc/tree.c
+++ b/gcc/tree.c
@@ -12454,7 +12454,7 @@  escaped_string::escape (const char *unescaped)
   if (m_owned)
     free (m_str);
 
-  m_str = (char *) unescaped;
+  m_str = const_cast<char *> (unescaped);
   m_owned = false;
 
   if (unescaped == NULL || *unescaped == 0)