TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Catching use-after-move C++ bugs with Clang's consumed annotations

175 pointsby awesomeklingalmost 6 years ago

8 comments

matthewbaueralmost 6 years ago
Perhaps the future of software isn't "rewrite everything in Rust", but instead we end up annotating existing C/C++ with borrow checking information. This would be similar to how there is a push in JavaScript to add TypeScript annotations everywhere. It gives you the flexibility of the existing language and ecosystem while still allowing you to use new techniques in programming languages.
评论 #20403537 未加载
评论 #20405702 未加载
评论 #20403924 未加载
评论 #20403309 未加载
评论 #20404029 未加载
评论 #20409106 未加载
评论 #20407139 未加载
评论 #20409226 未加载
评论 #20406819 未加载
评论 #20409331 未加载
sudeepjalmost 6 years ago
With C++ even if your project follows this, there is no way to <i>enforce</i> this across your project&#x27;s dependencies &amp; wider eco-system.<p>With Rust, its entire ecosystem (however nascent) is subjected to the same strict rules. This is <i>big</i> plus when Rust eco-system matures functionality wise.
评论 #20404422 未加载
评论 #20404575 未加载
评论 #20404399 未加载
评论 #20404557 未加载
habermanalmost 6 years ago
Why isn&#x27;t a moved-from object <i>always</i> considered &quot;consumed&quot;?
评论 #20403264 未加载
评论 #20403138 未加载
评论 #20403617 未加载
评论 #20405048 未加载
评论 #20407055 未加载
innotalmost 6 years ago
&gt; Once you std::move an object and pass it to someone who takes an rvalue-reference, your local object may very well end up in an invalid state.<p>As far as I remember, move constructors&#x2F;assignments must leave the moved-from object in a valid state - just that the standard doesn&#x27;t say anything about what that state is for standard classes.<p>Also, I have seen code where some kind of &quot;result&quot; can be moved from an object and then re-generated from scratch with different inputs. In that case it was perfectly valid to use it after move. But that&#x27;s nitpicking, anyways.
评论 #20404041 未加载
评论 #20403412 未加载
评论 #20405557 未加载
saagarjhaalmost 6 years ago
Looks like a lightweight borrow checker, although I wonder how well it fares in places where lifetimes are difficult to track. Or is there a way to annotate methods with this information as well?
评论 #20402968 未加载
评论 #20403238 未加载
gumbyalmost 6 years ago
Very nice!
pjmlpalmost 6 years ago
Cool idea.
rsp1984almost 6 years ago
I&#x27;ve been writing C++ for 21 years now (started when I was 14). To be honest, I have never seen a solid case where move semantics provided added value (in terms of code readability and maintainability) over just passing object references as function parameters.<p>That big ugly object that would get copied on function return -- just create it before the function call and pass it in as a reference! No copy required.
评论 #20404855 未加载
评论 #20404590 未加载
评论 #20406033 未加载
评论 #20407730 未加载
评论 #20403864 未加载
评论 #20403738 未加载
评论 #20403874 未加载
评论 #20403969 未加载
评论 #20404159 未加载
评论 #20403808 未加载