3

My program changed its behavior after updating Visual Studio to the latest version (2026).

Simplifying it, I got the following minimal example, which contains a ternary operator with a throw in inactive branch:

constexpr int x = [] { struct { int vs[3]; } a{}; auto && v = (true ? a : throw 0).vs[0]; v = 1; return a.vs[0]; }(); // x = 1 in VS2022 v17.13 // x = 0 in VS2022 v17.14.14 and VS2026 v18.0.0 

In Visual Studio 2022 v17.13, x evaluated to 1. But in the latest Visual Studios: both 2022 v17.14.14 and the recently released Visual Studio 2026 v18.0.0, x already evaluates to 0. Online demo.

Which result is correct here if the program is well formed?

2
  • Looks like a bug in Visual Studio. You should file a bug with Microsoft. Commented Nov 15 at 22:27
  • Relevant: stackoverflow.com/a/1213076/4706785 Commented Nov 15 at 23:54

1 Answer 1

4

Before resolution of CWG 1560 lvalue-to-rvalue conversion would have been applied to a, i.e. you would have ended up binding the reference to a new temporary object. Meaning you get 0 as result.

After resolution via CWG 1550 this is not done anymore and you should get 1 as result.

So this looks like a regression in MSVC.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.