================ @@ -1870,6 +1870,28 @@ bool Sema::IsFunctionConversion(QualType FromType, QualType ToType, FromFn = QT->getAs<FunctionType>(); Changed = true; } + + // For C, when called from checkPointerTypesForAssignment, + // we need not to alter FromFn, or else even an innocuous cast + // like dropping effects will fail. In C++ however we do want to + // alter FromFn. TODO: Is this correct? + if (getLangOpts().CPlusPlus) { + FromFPT = + dyn_cast<FunctionProtoType>(FromFn); // in case FromFn changed above ---------------- Sirraide wrote:
No, that one’s different. The point here is that `cast` asserts if the value you’re casting is-not-a the type you’re casting to, whereas `dyn_cast` returns `nullptr`. As a result, the intended way to use `dyn_cast` is to follow it with a check to see if it returned `nullptr`; in this case, however, the next line immediately uses the result of the cast without doing any checks whatsoever, so this would just crash if `dyn_cast` returned null, whereas `cast` would instead assert, which is what we want. In other words, if you’re not doing null checks, you want to use `cast` instead of `dyn_cast`. In this case, we’re in C++ mode (because of the surrounding `if`), so we should never have prototypeless functions; that means a `cast` here should be fine. https://github.com/llvm/llvm-project/pull/84983 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits