Making implicit conversions explicit.
Using bronto::rewrite_expr
to find implicit casts and make them explicit.
Given a type FromType
that is implicitly convertible to ToType
,
Write the following rule.
struct MakeExplicit : bronto::rewrite_expr {
BRONTO_BEFORE()
ToType before(FromType x) { return x; }
BRONTO_AFTER()
ToType before(FromType x) { return static_cast<ToType>(x); }
};
Sit back while Bronto inserts static_cast
in exactly the places where a cast was
previously implicit.
After Bronto has removed all of the implicit casts, mark the cast definition as explicit so users don't continue to use the implicit cast.
See it in action on Compiler Explorer.