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


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

Re: A question about if constexpr

Newsgroups comp.lang.c++
Date 2019-11-29 17:15 -0800
References (1 earlier) <cone.1574898034.956666.129095.1004@monster.email-scan.com> <qro3p4$gd7$1@dont-email.me> <2f0c5b1c-897c-4de9-bd28-1e06b6128045@googlegroups.com> <afb846b3-3b3d-4660-912b-76c4e52a8134@googlegroups.com> <qrqldf$dbu$1@dont-email.me>
Message-ID <4ba97dfb-e642-4f0d-a129-60fdcb4999ee@googlegroups.com> (permalink)
Subject Re: A question about if constexpr
From Öö Tiib <ootiib@hot.ee>

Show all headers | View raw


On Friday, 29 November 2019 10:38:18 UTC+2, David Brown  wrote:
> On 29/11/2019 08:50, Öö Tiib wrote:
> > On Friday, 29 November 2019 07:09:19 UTC+2, Daniel  wrote:
> >> On Thursday, November 28, 2019 at 4:25:03 AM UTC-5, David Brown wrote:
> >>>
> >>> If the compiler is not
> >>> generating identical code for an "if constexpr" and an "if" where the
> >>> expression happens to be known at compile time (whether it is
> >>> technically a C++ constant or not), then the compiler is doing a poor
> >>> job at optimising.
> >>>
> >> Which raises the question, what is the point of the constexpr if statement anyway? 
> > 
> > In template code it is like super #if but outside of templates it is
> > basically only for to tell to readers, maintainers and compiler that
> > the condition is supposed to be constant expression by original logic
> > and something is perhaps gone bad when it is not anymore.
> > 
> 
> <https://en.cppreference.com/w/cpp/language/if>
> 
> One other point is that since the discarded part is discarded, any
> identifiers it uses do not need to be defined or linked in with the code.

I'm in doubt about that other point. I noticed it long time ago that
the implementations do not link useless functions. It was like 2004
or maybe 2007.

I did delete unused functions after refactoring and since there
was tens of such I used impossibility to set breakpoints in those
as heuristic that these are now unused.

However my program became ill-formed since I had erased one that
was optimized out but not because it wasn't called but because it
was called only in branch that was impossible to take. 

So compilers did not need if constexpr back then for it ... why
these suddenly started to need it now?

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


Thread

A question about if constexpr Daniel <danielaparker@gmail.com> - 2019-11-27 05:45 -0800
  Re: A question about if constexpr "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> - 2019-11-27 15:03 +0100
    Re: A question about if constexpr Mr Flibble <flibbleREMOVETHISBIT@i42.co.uk> - 2019-11-29 16:33 +0000
      Re: A question about if constexpr Öö Tiib <ootiib@hot.ee> - 2019-11-29 16:52 -0800
        Re: A question about if constexpr David Brown <david.brown@hesbynett.no> - 2019-11-30 12:03 +0100
          Re: A question about if constexpr Öö Tiib <ootiib@hot.ee> - 2019-11-30 03:47 -0800
            Re: A question about if constexpr David Brown <david.brown@hesbynett.no> - 2019-11-30 15:08 +0100
  Re: A question about if constexpr Sam <sam@email-scan.com> - 2019-11-27 18:40 -0500
    Re: A question about if constexpr Öö Tiib <ootiib@hot.ee> - 2019-11-27 23:16 -0800
      Re: A question about if constexpr Mr Flibble <flibbleREMOVETHISBIT@i42.co.uk> - 2019-11-29 16:35 +0000
        Re: A question about if constexpr Öö Tiib <ootiib@hot.ee> - 2019-11-29 16:41 -0800
    Re: A question about if constexpr David Brown <david.brown@hesbynett.no> - 2019-11-28 10:24 +0100
      Re: A question about if constexpr Bo Persson <bo@bo-persson.se> - 2019-11-28 11:58 +0100
        Re: A question about if constexpr David Brown <david.brown@hesbynett.no> - 2019-11-28 12:37 +0100
        Re: A question about if constexpr Robert Wessel <robertwessel2@yahoo.com> - 2019-11-28 14:04 -0600
          Re: A question about if constexpr David Brown <david.brown@hesbynett.no> - 2019-11-29 09:23 +0100
            Re: A question about if constexpr Robert Wessel <robertwessel2@yahoo.com> - 2019-11-29 14:42 -0600
      Re: A question about if constexpr Daniel <danielaparker@gmail.com> - 2019-11-28 21:09 -0800
        Re: A question about if constexpr "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> - 2019-11-29 07:41 +0100
        Re: A question about if constexpr Öö Tiib <ootiib@hot.ee> - 2019-11-28 23:50 -0800
          Re: A question about if constexpr David Brown <david.brown@hesbynett.no> - 2019-11-29 09:38 +0100
            Re: A question about if constexpr Öö Tiib <ootiib@hot.ee> - 2019-11-29 17:15 -0800
              Re: A question about if constexpr Paavo Helde <myfirstname@osa.pri.ee> - 2019-11-30 08:19 +0200
                Re: A question about if constexpr Ned Latham <nedlatham@woden.valhalla.oz> - 2019-11-30 00:24 -0600
                Re: A question about if constexpr Öö Tiib <ootiib@hot.ee> - 2019-11-30 02:13 -0800
                Re: A question about if constexpr Ned Latham <nedlatham@woden.valhalla.oz> - 2019-11-30 04:56 -0600
                Re: A question about if constexpr Öö Tiib <ootiib@hot.ee> - 2019-11-30 03:20 -0800
                Re: A question about if constexpr Ned Latham <nedlatham@woden.valhalla.oz> - 2019-11-30 05:38 -0600
                Re: A question about if constexpr Öö Tiib <ootiib@hot.ee> - 2019-11-30 04:57 -0800
                Re: A question about if constexpr Ned Latham <nedlatham@woden.valhalla.oz> - 2019-11-30 09:46 -0600
                Re: A question about if constexpr Öö Tiib <ootiib@hot.ee> - 2019-11-30 11:09 -0800
                Re: A question about if constexpr Ned Latham <nedlatham@woden.valhalla.oz> - 2019-11-30 20:03 -0600
                Re: A question about if constexpr Öö Tiib <ootiib@hot.ee> - 2019-11-30 23:43 -0800
                Re: A question about if constexpr Ned Latham <nedlatham@woden.valhalla.oz> - 2019-12-01 04:56 -0600
                Re: A question about if constexpr Christian Gollwitzer <auriocus@gmx.de> - 2019-12-01 18:33 +0100
                Re: A question about if constexpr Ned Latham <nedlatham@woden.valhalla.oz> - 2019-12-01 19:27 -0600
                Re: A question about if constexpr boltar@nowhere.co.uk - 2019-12-02 08:34 +0000
                Re: A question about if constexpr Ned Latham <nedlatham@woden.valhalla.oz> - 2019-12-02 04:21 -0600
                Re: A question about if constexpr boltar@nowhere.co.uk - 2019-12-02 08:33 +0000
                Re: A question about if constexpr Mr Flibble <flibbleREMOVETHISBIT@i42.co.uk> - 2019-12-03 17:05 +0000
                Re: A question about if constexpr boltar@nowhere.co.uk - 2019-12-03 17:09 +0000
                Re: A question about if constexpr Mr Flibble <flibbleREMOVETHISBIT@i42.co.uk> - 2019-12-03 18:03 +0000
                Re: A question about if constexpr boltar@nowhere.co.uk - 2019-12-04 16:49 +0000
                Re: A question about if constexpr Mr Flibble <flibbleREMOVETHISBIT@i42.co.uk> - 2019-12-04 18:36 +0000
                Re: A question about if constexpr boltar@nowhere.co.uk - 2019-12-05 12:51 +0000
        Re: A question about if constexpr David Brown <david.brown@hesbynett.no> - 2019-11-29 09:30 +0100
      Re: A question about if constexpr Paavo Helde <myfirstname@osa.pri.ee> - 2019-11-29 10:51 +0200
  Re: A question about if constexpr Tim Rentsch <tr.17687@z991.linuxsc.com> - 2019-11-28 13:52 -0800
  Re: A question about if constexpr Bonita Montero <Bonita.Montero@gmail.com> - 2019-12-01 14:42 +0100

csiph-web