diff mbox

[libstdc++] : Avoid -Wcast-qual warnings in src/c++98/compatibility.cc

Message ID CAFULd4b1wMYmGosnnoCR_f3-hTjc2g0V1PAVKKCwzpEjLcQ1=Q@mail.gmail.com
State New
Headers show

Commit Message

Uros Bizjak Aug. 7, 2013, 8:48 p.m. UTC
Hello!

Attached patch avoids a bunch of -Wcast-qual warnings when building
libstdc++ on alpha-linux-gnu, a _GLIBCXX_LONG_DOUBLE_COMPAT target:

../../../../gcc-svn/trunk/libstdc++-v3/src/c++98/compatibility.cc:521:16:
warning: cast from type ‘const char*’ to type ‘void*’ casts away
qualifiers [-Wcast-qual]
       (void *) _ZTSe };
                ^
../../../../gcc-svn/trunk/libstdc++-v3/src/c++98/compatibility.cc:524:16:
warning: cast from type ‘const char*’ to type ‘void*’ casts away
qualifiers [-Wcast-qual]
       (void *) _ZTSPe, (void *) 0L, (void *) _ZTIe };
                ^
../../../../gcc-svn/trunk/libstdc++-v3/src/c++98/compatibility.cc:524:46:
warning: cast from type ‘const void* const*’ to type ‘void*’ casts
away qualifiers [-Wcast-qual]
       (void *) _ZTSPe, (void *) 0L, (void *) _ZTIe };
                                              ^
../../../../gcc-svn/trunk/libstdc++-v3/src/c++98/compatibility.cc:527:16:
warning: cast from type ‘const char*’ to type ‘void*’ casts away
qualifiers [-Wcast-qual]
       (void *) _ZTSPKe, (void *) 1L, (void *) _ZTIe };
                ^
../../../../gcc-svn/trunk/libstdc++-v3/src/c++98/compatibility.cc:527:47:
warning: cast from type ‘const void* const*’ to type ‘void*’ casts
away qualifiers [-Wcast-qual]
       (void *) _ZTSPKe, (void *) 1L, (void *) _ZTIe };

2013-08-07  Uros Bizjak  <ubizjak@gmail.com>

    * src/c++98/compatibility.cc (_ZTIe): Use const_cast to avoid warning.
    (_ZTIPe): Ditto.
    (ZTIPKe): Ditto.

The patch was bootstrapped on alpha-linux-gnu, regression test is still running.

OK for mainline if regtest shows no problems? Also for 4.8?

Uros.

Comments

Paolo Carlini Aug. 7, 2013, 9:47 p.m. UTC | #1
Hi,

On 08/07/2013 10:48 PM, Uros Bizjak wrote:
> 2013-08-07  Uros Bizjak  <ubizjak@gmail.com>
>
>      * src/c++98/compatibility.cc (_ZTIe): Use const_cast to avoid warning.
>      (_ZTIPe): Ditto.
>      (ZTIPKe): Ditto.
>
> The patch was bootstrapped on alpha-linux-gnu, regression test is still running.
>
> OK for mainline if regtest shows no problems? Also for 4.8?
I think you want in any case Jakub to have a look.

Paolo.
Jakub Jelinek Aug. 14, 2013, 8:29 a.m. UTC | #2
On Wed, Aug 07, 2013 at 11:47:55PM +0200, Paolo Carlini wrote:
> Hi,
> 
> On 08/07/2013 10:48 PM, Uros Bizjak wrote:
> >2013-08-07  Uros Bizjak  <ubizjak@gmail.com>
> >
> >     * src/c++98/compatibility.cc (_ZTIe): Use const_cast to avoid warning.
> >     (_ZTIPe): Ditto.
> >     (ZTIPKe): Ditto.
> >
> >The patch was bootstrapped on alpha-linux-gnu, regression test is still running.
> >
> >OK for mainline if regtest shows no problems? Also for 4.8?
> I think you want in any case Jakub to have a look.

Changing all those (void *) casts into (const void *) in the _ZTIe,
_ZTIPe and _ZTIPKe initializers seems to also work.  I'm not really a C++
guy, so I'll leave whether (const void *) or const_cast should be used
to libstdc++ maintainers.  I'm just surprised you haven't changed
all the spots, just some of them, and
(void *) &_ZTVN10__cxxabiv123__fundamental_type_infoE[2] and similar
and (void *) 1L etc. were left untouched.

	Jakub
Uros Bizjak Aug. 14, 2013, 8:41 a.m. UTC | #3
On Wed, Aug 14, 2013 at 10:29 AM, Jakub Jelinek <jakub@redhat.com> wrote:

>> >2013-08-07  Uros Bizjak  <ubizjak@gmail.com>
>> >
>> >     * src/c++98/compatibility.cc (_ZTIe): Use const_cast to avoid warning.
>> >     (_ZTIPe): Ditto.
>> >     (ZTIPKe): Ditto.
>> >
>> >The patch was bootstrapped on alpha-linux-gnu, regression test is still running.
>> >
>> >OK for mainline if regtest shows no problems? Also for 4.8?
>> I think you want in any case Jakub to have a look.
>
> Changing all those (void *) casts into (const void *) in the _ZTIe,
> _ZTIPe and _ZTIPKe initializers seems to also work.  I'm not really a C++
> guy, so I'll leave whether (const void *) or const_cast should be used
> to libstdc++ maintainers.  I'm just surprised you haven't changed
> all the spots, just some of them, and
> (void *) &_ZTVN10__cxxabiv123__fundamental_type_infoE[2] and similar
> and (void *) 1L etc. were left untouched.

These didn't emit warnings for my target (alpha), so also not being a
C++ person, I left them as they were.

Uros.
Paolo Carlini Aug. 14, 2013, 8:51 a.m. UTC | #4
On 08/14/2013 10:41 AM, Uros Bizjak wrote:
> These didn't emit warnings for my target (alpha), so also not being a 
> C++ person, I left them as they were. 
Ok then, for now let's simply go ahead with your original patch. Please 
also add a one line comment before the first cast.

Thanks!
Paolo.
diff mbox

Patch

Index: src/c++98/compatibility.cc
===================================================================
--- src/c++98/compatibility.cc	(revision 201568)
+++ src/c++98/compatibility.cc	(working copy)
@@ -518,13 +518,15 @@ 
 extern __attribute__((used, weak)) const char _ZTSPKe[4] = "PKe";
 extern __attribute__((used, weak)) const void * const _ZTIe[2]
   = { (void *) &_ZTVN10__cxxabiv123__fundamental_type_infoE[2],
-      (void *) _ZTSe };
+      const_cast<char*>(_ZTSe) };
 extern __attribute__((used, weak)) const void * const _ZTIPe[4]
   = { (void *) &_ZTVN10__cxxabiv119__pointer_type_infoE[2],
-      (void *) _ZTSPe, (void *) 0L, (void *) _ZTIe };
+      const_cast<char*>(_ZTSPe), (void *) 0L,
+      const_cast<void* const*>(_ZTIe) };
 extern __attribute__((used, weak)) const void * const _ZTIPKe[4]
   = { (void *) &_ZTVN10__cxxabiv119__pointer_type_infoE[2],
-      (void *) _ZTSPKe, (void *) 1L, (void *) _ZTIe };
+      const_cast<char*>(_ZTSPKe), (void *) 1L,
+      const_cast<void* const*>(_ZTIe) };
 #endif // _GLIBCXX_LONG_DOUBLE_COMPAT
 
 #ifdef _GLIBCXX_SYMVER_DARWIN