From: Richard Smith Date: Tue, 29 Nov 2016 22:32:05 +0000 (+0000) Subject: [c++1z] PR31210: ignore exception specification when matching the type of a X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=afbf41f88323feb60fe813d5bd9e3fb1ef0e2353;p=clang [c++1z] PR31210: ignore exception specification when matching the type of a builtin with the type of an explicit declaration of the same function. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@288208 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index e8764a0edf..e2951cf174 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -9028,9 +9028,25 @@ bool Sema::CheckFunctionDeclaration(Scope *S, FunctionDecl *NewFD, LookupPredefedObjCSuperType(*this, S, NewFD->getIdentifier()); QualType T = Context.GetBuiltinType(BuiltinID, Error); if (!T.isNull() && !Context.hasSameType(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); + auto WithoutExceptionSpec = [&](QualType T) -> QualType { + auto *Proto = T->getAs(); + 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); } } diff --git a/test/SemaCXX/cxx1z-noexcept-function-type.cpp b/test/SemaCXX/cxx1z-noexcept-function-type.cpp index ae686d396b..d9233e681f 100644 --- a/test/SemaCXX/cxx1z-noexcept-function-type.cpp +++ b/test/SemaCXX/cxx1z-noexcept-function-type.cpp @@ -97,3 +97,13 @@ namespace ImplicitExceptionSpec { }; S::~S() {} } + +namespace Builtins { + // Pick two functions that ought to have the same noexceptness. + extern "C" int strcmp(const char *, const char *); + extern "C" int strncmp(const char *, const char *, decltype(sizeof(0))) noexcept; + + // Check we recognized both as builtins. + typedef int arr[strcmp("bar", "foo") + 4 * strncmp("foo", "bar", 4)]; + typedef int arr[3]; +}