I need to remove the use of static_cast from the project and prevent normal compilation if static_cast is added, the gcc documentation doesn't say how warnings can be enabled when using static_cast.
I searched the gcc documentation for the static_cast keyword, but did not find anything suitable.
I highly doubt that there is any compiler setting for that in general.
static_castis a completely normal feature of the language to use and the preferred way over C-style explicit casts. It is not clear what purpose such a warning would serve. In factstatic_castis conventionally used to tell the compiler to not warn about otherwise implicit conversions that might be problematic like narrowing conversions.There is a clang-tidy check
cppcoreguidelines-pro-type-static-cast-downcastto warn of uses ofstatic_castthat are downcasts (which may lead to UB and are recommended by the core guidelines to be replaced withdynamic_cast).Maybe there is also some clang-tidy check or similar that warns if a
static_castconversion would also be possible implicitly, but that would probably interfere with the convention mentioned above.You'll likely need to use an external tool. Something as simple as
grep -R static_assert .or somesed/awkto replace uses ofstatic_assertin the way you want may be sufficient. If you need to actually modify the parsed AST, you'll probably need to write something e.g. based on Clang's libraries/tooling.