/// \brief Determine whether the conversion from FromType to ToType is a valid
/// conversion that strips "noreturn" off the nested function type.
-static bool IsNoReturnConversion(ASTContext &Context, QualType FromType,
- QualType ToType, QualType &ResultTy) {
+bool Sema::IsNoReturnConversion(QualType FromType, QualType ToType,
+ QualType &ResultTy) {
if (Context.hasSameUnqualifiedType(FromType, ToType))
return false;
S.ExtractUnqualifiedFunctionType(ToType), FromType)) {
QualType resultTy;
// if the function type matches except for [[noreturn]], it's ok
- if (!IsNoReturnConversion(S.Context, FromType,
+ if (!S.IsNoReturnConversion(FromType,
S.ExtractUnqualifiedFunctionType(ToType), resultTy))
// otherwise, only a boolean conversion is standard
if (!ToType->isBooleanType())
// Compatible conversions (Clang extension for C function overloading)
SCS.Second = ICK_Compatible_Conversion;
FromType = ToType.getUnqualifiedType();
- } else if (IsNoReturnConversion(S.Context, FromType, ToType, FromType)) {
+ } else if (S.IsNoReturnConversion(FromType, ToType, FromType)) {
// Treat a conversion that strips "noreturn" as an identity conversion.
SCS.Second = ICK_NoReturn_Adjustment;
} else if (IsTransparentUnionStandardConversion(S, From, ToType,
QualType ResultTy;
if (Context.hasSameUnqualifiedType(TargetFunctionType,
FunDecl->getType()) ||
- IsNoReturnConversion(Context, FunDecl->getType(), TargetFunctionType,
- ResultTy)) {
+ S.IsNoReturnConversion(FunDecl->getType(), TargetFunctionType,
+ ResultTy)) {
Matches.push_back(std::make_pair(CurAccessFunPair,
cast<FunctionDecl>(FunDecl->getCanonicalDecl())));
FoundNonTemplateFunction = true;
// - The transformed A can be another pointer or pointer to member
// type that can be converted to the deduced A via a qualification
// conversion.
+ //
+ // Also allow conversions which merely strip [[noreturn]] from function types
+ // (recursively) as an extension.
+ // FIXME: Currently, this doesn't place nicely with qualfication conversions.
bool ObjCLifetimeConversion = false;
+ QualType ResultTy;
if ((A->isAnyPointerType() || A->isMemberPointerType()) &&
- S.IsQualificationConversion(A, DeducedA, false, ObjCLifetimeConversion))
+ (S.IsQualificationConversion(A, DeducedA, false,
+ ObjCLifetimeConversion) ||
+ S.IsNoReturnConversion(A, DeducedA, ResultTy)))
return false;
A<int> a0 = f3(ip);
A<volatile int> a1 = f3(vip);
}
-
+
+// Also accept conversions for pointer types which require removing
+// [[noreturn]].
+namespace noreturn_stripping {
+ template <class R>
+ void f(R (*function)());
+
+ void g() __attribute__ ((__noreturn__));
+ void h();
+ void test() {
+ f(g);
+ f(h);
+ }
+}
+
// - If P is a class, and P has the form template-id, then A can be a
// derived class of the deduced A. Likewise, if P is a pointer to a class
// of the form template-id, A can be a pointer to a derived class pointed