Date: Fri, 19 Sep 2025 08:29:18 -0700
On Thursday, 18 September 2025 21:09:47 Pacific Daylight Time Yongwei Wu wrote:
> > Yes, they do. ALL the time, especially in template code but anything that
> > is not nailed down and may have some generality too. For example,
> > anything that may depend on a configuration-time feature check. Given we
> > have the __cpp macros describing the availability of features, this
> > applies to the C++ Standard too.
>
> Arguable, especially if -O0 demonstrates completely different
> behaviour. I would normally use #if or if constexpr to ensure
> something is really eliminated, even if optimization is completely
> turned off.
Who said anything about different behaviour?
The compiler is allowed to remove dead code *because* it's dead and therefore
not observable. The Standard defines what is observable precisely for this
reason.
Timing is not observable. Obviously, timing in debug mode builds is VERY
different from timing in release builds. If timing were observable, then no
optimisations would be allowed.
> > Yes, they do. ALL the time, especially in template code but anything that
> > is not nailed down and may have some generality too. For example,
> > anything that may depend on a configuration-time feature check. Given we
> > have the __cpp macros describing the availability of features, this
> > applies to the C++ Standard too.
>
> Arguable, especially if -O0 demonstrates completely different
> behaviour. I would normally use #if or if constexpr to ensure
> something is really eliminated, even if optimization is completely
> turned off.
Who said anything about different behaviour?
The compiler is allowed to remove dead code *because* it's dead and therefore
not observable. The Standard defines what is observable precisely for this
reason.
Timing is not observable. Obviously, timing in debug mode builds is VERY
different from timing in release builds. If timing were observable, then no
optimisations would be allowed.
-- Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org Principal Engineer - Intel Platform & System Engineering
Received on 2025-09-19 15:29:35