[PATCH] avoid -Wnonull for dynamic_cast (PR 99251)
Martin Sebor
msebor@gmail.com
Wed Feb 24 22:25:40 GMT 2021
In r11-6900 (PR 98646 - static_cast confuses -Wnonnull) we decided
that issuing -Wnonnull for dereferencing the result of dynamic_cast
was helpful despite the false positives it causes when the pointer
is guaranteed not to be null because of a prior test.
The test case in PR 99251 along with the feedback I got from Martin
Liska have convinced me it was not the right decision.
The attached patch arranges for dynamic_cast to also suppress -Wnonnull
analogously to static_cast. Since there already is a helper function
that builds the if-not-null test (ifnonnull) and sets TREE_NO_WARNING,
I factored out the corresponding code from build_base_path that sets
the additional TREE_NO_WARNING bit for static_cast into the function
and called it from both places. I also renamed the function to make
its purpose clearer and for consistency with other build_xxx APIs.
Tested on x86_64-linux.
Martin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: gcc-99251.diff
Type: text/x-patch
Size: 7125 bytes
Desc: not available
URL: <https://gcc.gnu.org/pipermail/gcc-patches/attachments/20210224/5678e62c/attachment.bin>
More information about the Gcc-patches
mailing list