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


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

Re: `bool` in pointer arithmetic: when does the promotion occur, if ever?

Path csiph.com!weretis.net!feeder8.news.weretis.net!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From Andrey Tarasevich <andreytarasevich@hotmail.com>
Newsgroups comp.lang.c++
Subject Re: `bool` in pointer arithmetic: when does the promotion occur, if ever?
Date Mon, 15 Aug 2022 11:29:29 -0700
Organization A noiseless patient Spider
Lines 35
Message-ID <tde3ab$3o7iu$1@dont-email.me> (permalink)
References <tde0o3$3nqef$1@dont-email.me> <tde24g$3o0ua$1@dont-email.me>
MIME-Version 1.0
Content-Type text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding 7bit
Injection-Date Mon, 15 Aug 2022 18:29:31 -0000 (UTC)
Injection-Info reader01.eternal-september.org; posting-host="d2ed0b7c2ac5ac8b29065a5ceb0c96fa"; logging-data="3939934"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+npDR4fo9M6WsVVG1bX5Uv"
User-Agent Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.12.0
Cancel-Lock sha1:XqECx7WpLkl/9w+fY3E5X6zSuRc=
In-Reply-To <tde24g$3o0ua$1@dont-email.me>
Content-Language en-US
Xref csiph.com comp.lang.c++:85940

Show key headers only | View raw


On 8/15/2022 11:09 AM, David Brown wrote:
>>
>> So, how does pointer+bool addition work then? When does `true` turn 
>> into 1 here?
>>
> 
> Under "7.6.6 Additive operators", it says that the usual arithmetic 
> conversions are performed on operands of arithmetic or enumeration type 
> - that includes bool.

No, no, no... You can't just arbitrarily pluck this part out of the 
whole rule. After/if you apply usual arithmetic conversions here, you 
are required to continue to follow the spec and complete all steps. You 
are required to follow the "Then the following rules are applied to the 
promoted operands:" part in 7.4/1.3 
(http://eel.is/c++draft/expr.arith.conv#1.3) The specification of usual 
arithmetic conversions does not have an "early exit" clause if one 
operand is a pointer.

Now, once you start following these "following rules", it becomes clear 
that they are not applicable (or defective) if one operand is a pointer. 
Firstly, the concept of "[integer conversion] rank" is not applicable to 
pointer types. Secondly, (if we ignore the "firstly") these rules 
ultimately require us to convert both operands to a common integer type.

Obviously, in pointer+bool contexts operands are NOT converted to a 
common integer type. So, no, usual arithmetic conversions do not apply 
here. As I already stated, the intent of the standard wording is to say 
that usual arithmetic conversions apply only when _both_ operands have 
integral or enum type.

-- 
Best regards,
Andrey

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


Thread

`bool` in pointer arithmetic: when does the promotion occur, if ever? Andrey Tarasevich <andreytarasevich@hotmail.com> - 2022-08-15 10:45 -0700
  Re: `bool` in pointer arithmetic: when does the promotion occur, if ever? David Brown <david.brown@hesbynett.no> - 2022-08-15 20:09 +0200
    Re: `bool` in pointer arithmetic: when does the promotion occur, if ever? Andrey Tarasevich <andreytarasevich@hotmail.com> - 2022-08-15 11:29 -0700
      Re: `bool` in pointer arithmetic: when does the promotion occur, if ever? Andrey Tarasevich <andreytarasevich@hotmail.com> - 2022-08-15 11:35 -0700
      Re: `bool` in pointer arithmetic: when does the promotion occur, if ever? David Brown <david.brown@hesbynett.no> - 2022-08-15 21:20 +0200
        Re: `bool` in pointer arithmetic: when does the promotion occur, if ever? red floyd <no.spam.here@its.invalid> - 2022-08-15 13:49 -0700
        Re: `bool` in pointer arithmetic: when does the promotion occur, if ever? Andrey Tarasevich <andreytarasevich@hotmail.com> - 2022-08-15 13:59 -0700
          Re: `bool` in pointer arithmetic: when does the promotion occur, if ever? David Brown <david.brown@hesbynett.no> - 2022-08-16 09:12 +0200
            Re: `bool` in pointer arithmetic: when does the promotion occur, if ever? Andrey Tarasevich <andreytarasevich@hotmail.com> - 2022-08-16 09:56 -0700
              Re: `bool` in pointer arithmetic: when does the promotion occur, if ever? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2022-09-15 07:18 -0700
                Re: `bool` in pointer arithmetic: when does the promotion occur, if ever? Language Lawyer <language.lawyer@gmail.com> - 2022-09-19 03:28 -0700
                Re: `bool` in pointer arithmetic: when does the promotion occur, if ever? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2022-10-02 12:37 -0700
  Re: `bool` in pointer arithmetic: when does the promotion occur, if ever? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2022-08-15 14:36 -0700
    Re: `bool` in pointer arithmetic: when does the promotion occur, if ever? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2022-08-15 14:57 -0700
  Re: `bool` in pointer arithmetic: when does the promotion occur, if ever? "Alf P. Steinbach" <alf.p.steinbach@gmail.com> - 2022-08-16 21:13 +0200
  Re: `bool` in pointer arithmetic: when does the promotion occur, if ever? Language Lawyer <language.lawyer@gmail.com> - 2022-08-17 09:08 -0700

csiph-web