TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

New C++ features in GCC 15

38 点作者 jrepinc16 天前

4 条评论

tlb16 天前
&gt; Fix for range-based for loops<p>Oh man, having different compilers in c++20 mode handle things differently is going to cause more grief, not less.<p>Reminder: Prior to c++23 the following is broken:<p><pre><code> vector&lt;int&gt; const &amp;identity(vector&lt;int&gt; const &amp;a) { return a; } for (auto a : identity(vector&lt;int&gt;{1,2})) { ... } </code></pre> That&#x27;s because the lifetime of the vector isn&#x27;t extended through the life of the for loop. That is, the vector is destructed right after identity returns, and the for loop ends up trying to iterate through a vector that&#x27;s been destructed.<p>But now gcc in c++20 with -frange-for-ext-temps mode will extend the lifetime of the vector and the above code will work, and people will write code like that, and it&#x27;ll break mysteriously on other c++20 compilers. The usual way it breaks is that the for loop does nothing because in destructing the vector it sets the begin and end pointers to null, so it&#x27;s a subtle kind of breakage.<p>BTW clang with -Wall doesn&#x27;t complain about the above broken code.
评论 #43792880 未加载
pjmlp16 天前
For me one of the big improvements is the modules support, GCC is now joining clang and MSVC, kudos to the team.
LorenDB16 天前
#embed should make it fairly easy to write an installer from scratch. You&#x27;ll still have to handle things like registry keys on Windows manually, but the barrier to entry for developing installers will be much lower.
评论 #43792865 未加载
ashvardanian16 天前
`#embed`, finally! Fixing UB in range-based `for` loops is also a good one!