Y
HN Search
Hacker News Search
new
|
comments
|
top
|
jobs
compiler-devel
searching PlanetScale…
1.
▲
2.
▲
3.
▲
4.
▲
5.
▲
6.
▲
9 ms
·
91.
▲
by
compiler-devel
4y ago
const can serve to mark invariants in your code as well as provide the compiler with information that it can use for optimizations. I highly recommend Scott Meyers' "Effective C++" wherein Item #3 is to 'Use const whenev
92.
▲
by
compiler-devel
4y ago
Wow, thank you for this rich and thorough follow up. Interestingly, in the present C++ standard, 'mutable' indeed is a storage class like 'register' while 'const' is a CV-qualifier. I thought it quite odd that
93.
▲
by
compiler-devel
4y ago
Generally speaking a const member function can't call a member function that is non-const or a member function that modifies a member variable that's not declared mutable. If the present const member function has a const reference
94.
▲
by
compiler-devel
4y ago
Yes, good point, I retract what I said before. Thanks!
95.
▲
by
compiler-devel
4y ago
Great point, I was thinking of ints as 32 bits. You're absolutely correct for 64 bit ints!
96.
▲
by
compiler-devel
4y ago
Thank you for your thoughtful response. vector<int> wouldn't work because copy semantics wouldn't apply for a constant type, so mutable would be needed (as you rightly pointed out). I'm not sure that vector<int> s
97.
▲
by
compiler-devel
4y ago
Some implicit conversions are okay, like type promotion from int to double. Some type coercions are fraught, like char to int or back again. I agree that array decay to pointer could be explicit, and pointers shouldn't cast to arrays.
98.
▲
by
compiler-devel
4y ago
https://www.synopsys.com/blogs/software-security/understandi...
99.
▲
by
compiler-devel
4y ago
No C style casts allowed, so maybe static_cast<bool>(...) ;-)
100.
▲
by
compiler-devel
4y ago
Agreed, that's why I started by modifying clang. I think we can start dropping some of the crufty legacy in the C++ language without throwing it all out and starting again. While clang tidy could be used to check for a lot of these, I
101.
▲
by
compiler-devel
4y ago
Thanks! Aside from the default const/mutable change, this was my approach. To improve adoption, it would be easy to add a feature flag for this set of changes which could be applied on a per file basis.
102.
▲
by
compiler-devel
4y ago
Yes, some (maybe most) could be implemented in a plugin. I wanted to make these changes in part to better understand the clang internals and also show that rather than use external tooling, the language itself can (should?) be changed.
103.
▲
by
compiler-devel
4y ago
Thank you for this great feedback. I'll do my best to respond to each of your points: WRT const, you're correct and I'd need to go further in updating const behaviors in the language. I stole this idea from Rust (sort of) in
104.
▲
Show HN: Modifying Clang for a Safer, More Explicit C++
(github.com)
76 points
by
compiler-devel
4y ago
|
87 comments
105.
▲
by
compiler-devel
4y ago
Modified C++ Inspired by the paper "Some Were Meant for C" by Stephen Kell, I decided to show that it's possible to iterate C++ to be safer, more explicit, and less error-prone. Here's a possible starting point: I didn&#