Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #7822

Re: removing constness of a true const

Path csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!weretis.net!feeder1.news.weretis.net!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From "Bo Persson" <bop@gmb.dk>
Newsgroups comp.lang.c++
Subject Re: removing constness of a true const
Date Thu, 14 Jul 2011 23:33:47 +0200
Lines 27
Message-ID <9895ljF70aU1@mid.individual.net> (permalink)
References <1e55c267-2789-498c-a5a1-f56e499336e5@z12g2000yqj.googlegroups.com> <ivn7kt$2t9r$1@news.ett.com.ua> <47b1098f-e550-424b-acd3-a26d2e419b4d@12g2000yqr.googlegroups.com>
X-Trace individual.net BIxCUfBfg4uDhx5/il51+QE09q4VYg4gzpIrWX3oEWtMgNlI7B
Cancel-Lock sha1:9qz7Mx0fFuJM0L/lfCYuwY4yt+Q=
X-Priority 3
X-MSMail-Priority Normal
X-Newsreader Microsoft Outlook Express 6.00.2900.5931
X-MIMEOLE Produced By Microsoft MimeOLE V6.00.2900.6109
X-RFC2646 Format=Flowed; Original
X-Antivirus avast! (VPS 110714-1, 2011-07-14), Outbound message
X-Antivirus-Status Clean
Xref x330-a1.tempe.blueboxinc.net comp.lang.c++:7822

Show key headers only | View raw


siddhu wrote:
> On Jul 14, 1:05 pm, "Balog Pal" <p...@lib.hu> wrote:
>> "siddhu" <siddharth....@gmail.com>
>>
>>> I guess removing constness of a true const( I guess it is also
>>> called bitwise const ) using const_cast is undefined behavior.
>>> Can you please give an example of a true const and may be a
>>> sample code which exhibits undefined behavior by removing
>>> constness of a true const.
>>
>> Removing constness is well defined. But actually modifying
>> non-mutable member of a const object is UB. By any means,
>> including the use of pointer/ref from const_cast.
>
> Thanks Balog!
> Does that mean removing constness of 'this' in const member function
> is an UB?

It is if the object is really const.

Suppose the data is stored in a ROM. What happens when you try to 
change it?


Bo Persson

Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

removing constness of a true const siddhu <siddharth.sng@gmail.com> - 2011-07-14 08:07 -0700
  Re: removing constness of a true const Victor Bazarov <v.bazarov@comcast.invalid> - 2011-07-14 11:55 -0400
    Re: removing constness of a true const siddhu <siddharth.sng@gmail.com> - 2011-07-14 09:25 -0700
      Re: removing constness of a true const Victor Bazarov <v.bazarov@comcast.invalid> - 2011-07-14 16:18 -0400
        Re: removing constness of a true const "Balog Pal" <pasa@lib.hu> - 2011-07-15 01:18 +0200
          Re: removing constness of a true const Victor Bazarov <v.bazarov@comcast.invalid> - 2011-07-15 08:17 -0400
            Re: removing constness of a true const "Balog Pal" <pasa@lib.hu> - 2011-07-15 18:04 +0200
              Re: removing constness of a true const Ian Collins <ian-news@hotmail.com> - 2011-07-16 08:36 +1200
                Re: removing constness of a true const "Balog Pal" <pasa@lib.hu> - 2011-07-16 02:00 +0200
            Re: removing constness of a true const Paavo Helde <myfirstname@osa.pri.ee> - 2011-07-15 16:08 -0500
              Re: removing constness of a true const Ian Collins <ian-news@hotmail.com> - 2011-07-16 09:30 +1200
  Re: removing constness of a true const "Balog Pal" <pasa@lib.hu> - 2011-07-14 19:05 +0200
    Re: removing constness of a true const siddhu <siddharth.sng@gmail.com> - 2011-07-14 12:05 -0700
      Re: removing constness of a true const "Bo Persson" <bop@gmb.dk> - 2011-07-14 23:33 +0200
        Re: removing constness of a true const Victor Bazarov <v.bazarov@comcast.invalid> - 2011-07-14 17:46 -0400
          Re: removing constness of a true const "Bo Persson" <bop@gmb.dk> - 2011-07-16 08:32 +0200
  Re: removing constness of a true const "Johannes Schaub (litb)" <schaub.johannes@googlemail.com> - 2011-07-15 15:02 +0200
    Re: removing constness of a true const Victor Bazarov <v.bazarov@comcast.invalid> - 2011-07-15 09:54 -0400

csiph-web