Mo

Modifying Clang for a Safer, More Explicit C++

Hacker News

Modifying Clang for a Safer, More Explicit C++

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't invent a new language or compiler, but took the world's best compiler, clang, and modified it to begin iterating towards a new furture of C++. Naming things is hard, so I call this 'Modified C++'. Some of the following could be implemented as tooling in a linter or checker, but the idea is to update the compiler directly. I also wanted to learn more about clang. This compiler needs a flag to enable/disable this functionality so that existing library code can be used with a 'diagnostic ignored' pragma. You can build clang using the normal non-bootstrap process and you'll be left with a clang that compiles C++ but with the following modifications: - All basic types (excluding pointers and references) are const by default and may be marked 'mutable' to allow them to be changed after declaration - Lambda capture lists must be explicit (no [&] or [=], by themselves) - Braces are required for conditional statements, case and default statements within switches, and loops - Implicit conversions to bool are prohibited (e.g., pointers must be compared against nullptr/NULL) - No goto support - Explicit 'rule of six' for classes must be programmer-implemented (default, copy, and move c'tors, copy and move assignment, d'tor) - No C style casts Here's an example program that's valid in Modified C++: mutable int main(int, char**) { mutable int x = 0; return x; } Here's another that will fail to compile: mutable int main(int, char**) { int x = 1; x = 0; // x is constant return x; } I'd like your feedback. Future changes I'm thinking about are: - feature flag for modified c++ to enable/disable with 'diagnostic ignored' pragma, to support existing headers and libraries - support enum classes only - constructor declarations are explicit by default - namespaces within classes - normalize lambda and free function syntax - your ideas here

Share card

Actual performance

76points
87comments
Made the leaderboard

Launch Intel predictions

Analyze your own launch →
Indie HackersFits the IH revenue-focused audience · Missing: supports, reddit linkedin, podcasting
71%71% predicted probability of success on Indie Hackers, based on ML models trained on real launch data.
Hacker NewsStrong engagement from HN community · Strong signals: exist, existing, ide · Missing: https docs, excited, just released
70%70% predicted probability of success on Hacker News, based on ML models trained on real launch data.
nativeThis product was originally launched on this platform.
Product HuntOn track for Day 1 leaderboard · Strong signals: new, using, code · Missing: mac, agents, macos
59%59% predicted probability of success on Product Hunt, based on ML models trained on real launch data.
AppSumoMay struggle as an AppSumo deal · Missing: plus, platform, intuitive
48%48% predicted probability of success on AppSumo, based on ML models trained on real launch data.
TrustMRRLess likely to generate early MRR · Missing: mobile apps, ios, personal
39%39% predicted probability of success on TrustMRR, based on ML models trained on real launch data.
Acquire.comPre-revenue stage for this audience · Missing: arr, mrr, revenue
12%12% predicted probability of success on Acquire.com, based on ML models trained on real launch data.
BetaListMay not resonate with beta-testers · Missing: web3, chat, crypto
0%0% predicted probability of success on BetaList, based on ML models trained on real launch data.

Correct prediction on native model

Similar products

TRUEPAUSE
TRUEPAUSE47%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

Safer Digital Transactions Concept

Indie Hackerscommitment-side-project
Ca
Cachekill – A safer alternative to rm -RF node_modules59%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

Cachekill – A safer alternative to rm -RF node_modules

Hacker News2
Ge
GelaTalk – A safer messaging app for drivers59%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

GelaTalk – A safer messaging app for drivers

Hacker News6
Di
Digital Streaking – The Safer Alternative to Streaking at the Superbowl48%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

Digital Streaking – The Safer Alternative to Streaking at the Superbowl

Hacker News2
FO
FOHO – Safer rentals for foreigners in Korea with escrow and AI36%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

FOHO – Safer rentals for foreigners in Korea with escrow and AI

Hacker News6
Tr
Trace of Radiance – Faster and Safer Raytracing in Nim52%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

Trace of Radiance – Faster and Safer Raytracing in Nim

Hacker News5
Ma
Making pets safer with Arduino42%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

Making pets safer with Arduino

Hacker News2
Ma
Making pets safer with Arduino42%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

Making pets safer with Arduino

Hacker News1
CareCompass-xi
CareCompass-xi29%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

Navigate Your Health. Smarter, Safer, Together.

Indie Hackers1$100/moadvertising
Fe
FeatureFlare – safer feature rollouts with targeting, release workflows47%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

FeatureFlare – safer feature rollouts with targeting, release workflows

Hacker News1