/// \brief Change the result type of a function type once it is deduced.
void adjustDeducedFunctionResultType(FunctionDecl *FD, QualType ResultType);
+ /// \brief Determine whether two function types are the same, ignoring
+ /// exception specifications in cases where they're part of the type.
+ bool hasSameFunctionTypeIgnoringExceptionSpec(QualType T, QualType U);
+
/// \brief Change the exception specification on a function once it is
/// delay-parsed, instantiated, or computed.
void adjustExceptionSpec(FunctionDecl *FD,
Proto->getExtProtoInfo().withExceptionSpec(ESI));
}
+bool ASTContext::hasSameFunctionTypeIgnoringExceptionSpec(QualType T,
+ QualType U) {
+ return hasSameType(T, U) ||
+ (getLangOpts().CPlusPlus1z &&
+ hasSameType(getFunctionTypeWithExceptionSpec(*this, T, EST_None),
+ getFunctionTypeWithExceptionSpec(*this, U, EST_None)));
+}
+
void ASTContext::adjustExceptionSpec(
FunctionDecl *FD, const FunctionProtoType::ExceptionSpecInfo &ESI,
bool AsWritten) {
}
// Don't call function pointers which have been cast to some other type.
- if (!Info.Ctx.hasSameType(CalleeType->getPointeeType(), FD->getType()))
+ // Per DR (no number yet), the caller and callee can differ in noexcept.
+ if (!Info.Ctx.hasSameFunctionTypeIgnoringExceptionSpec(
+ CalleeType->getPointeeType(), FD->getType())) {
return Error(E);
+ }
} else
return Error(E);
ASTContext::GetBuiltinTypeError Error;
LookupPredefedObjCSuperType(*this, S, NewFD->getIdentifier());
QualType T = Context.GetBuiltinType(BuiltinID, Error);
- if (!T.isNull() && !Context.hasSameType(T, NewFD->getType())) {
- auto WithoutExceptionSpec = [&](QualType T) -> QualType {
- auto *Proto = T->getAs<FunctionProtoType>();
- if (!Proto)
- return T;
- return Context.getFunctionType(
- Proto->getReturnType(), Proto->getParamTypes(),
- Proto->getExtProtoInfo().withExceptionSpec(EST_None));
- };
-
- // If the type of the builtin differs only in its exception
- // specification, that's OK.
- // FIXME: If the types do differ in this way, it would be better to
- // retain the 'noexcept' form of the type.
- if (!getLangOpts().CPlusPlus1z ||
- !Context.hasSameType(WithoutExceptionSpec(T),
- WithoutExceptionSpec(NewFD->getType())))
- // The type of this function differs from the type of the builtin,
- // so forget about the builtin entirely.
- Context.BuiltinInfo.forgetBuiltin(BuiltinID, Context.Idents);
- }
+ // If the type of the builtin differs only in its exception
+ // specification, that's OK.
+ // FIXME: If the types do differ in this way, it would be better to
+ // retain the 'noexcept' form of the type.
+ if (!T.isNull() &&
+ !Context.hasSameFunctionTypeIgnoringExceptionSpec(T,
+ NewFD->getType()))
+ // The type of this function differs from the type of the builtin,
+ // so forget about the builtin entirely.
+ Context.BuiltinInfo.forgetBuiltin(BuiltinID, Context.Idents);
}
// If this function is declared as being extern "C", then check to see if