4 ms·
Sounds amazing. Anyone have code examples that integrate a lot of the newer stuff? Dumb question. Why isn't omitting 'return' always an error in gcc rather th
by ilaksh 7y ago
Sounds amazing. Anyone have code examples that integrate a lot of the newer stuff?
Dumb question. Why isn't omitting 'return' always an error in gcc rather than just a warning?
- plorkyeran 7y agoint foo() { bar(); } is a perfectly well-formed function as long as bar() never returns. Allowing this without requiring bar() to be annotated as noreturn is generally considered a mistake, but correcting it would break existing valid programs.
- ComputerGuru 7y agoC++17 already made backward compatibility a non-goal (within reason, obviously) and broke previously valid programs.
- ComputerGuru 7y agoI don’t care that my previous comment post has been downvoted, but I do want to clarify that I wasn’t being facetious; C++17 removes a number of old features and constructs that had been previously deprecated and there exist programs that compiled under C++14 that need non-trivial changes to compile under C++17.
- temac 7y ago> but correcting it would break existing valid programs That's very often the case when enhancing static safety guarantees. And that's often worth it.
- ahartmetz 7y agoIn any case, just add -Werror=return-type to your compiler flags... After I had forgotten a return once, that option saved me several times.
- Gibbon1 7y agoLikely answer is, doesn't really cause problems for anyone in practice. Experienced C++ programmers fix warnings. Also the ABI specifies how to call and get the return value of a function. The long and the short if it is the execution thread doesn't go off the rails if there is a mismatch in expected behavior. Your data may be garbage tho.
- DerekL 7y agoIt would be nice if the program would abort if a non-void function returns without a value. The only cost would be a slightly larger executable.