https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105400
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> --- This is just inlining and there is no way for GCC to know that the method type will return Type1 rather than Type2 here for the variable b. The warning is correct but only because of optimizations and such. Do you have the original preprocessed source? It might be the case you over simplified the testcase really.