Author: rsmith Date: Tue Nov 29 16:32:05 2016 New Revision: 288208 URL: http://llvm.org/viewvc/llvm-project?rev=288208&view=rev Log: [c++1z] PR31210: ignore exception specification when matching the type of a builtin with the type of an explicit declaration of the same function.
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp cfe/trunk/test/SemaCXX/cxx1z-noexcept-function-type.cpp Modified: cfe/trunk/lib/Sema/SemaDecl.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=288208&r1=288207&r2=288208&view=diff ============================================================================== --- cfe/trunk/lib/Sema/SemaDecl.cpp (original) +++ cfe/trunk/lib/Sema/SemaDecl.cpp Tue Nov 29 16:32:05 2016 @@ -9028,9 +9028,25 @@ bool Sema::CheckFunctionDeclaration(Scop 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<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); } } Modified: cfe/trunk/test/SemaCXX/cxx1z-noexcept-function-type.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/cxx1z-noexcept-function-type.cpp?rev=288208&r1=288207&r2=288208&view=diff ============================================================================== --- cfe/trunk/test/SemaCXX/cxx1z-noexcept-function-type.cpp (original) +++ cfe/trunk/test/SemaCXX/cxx1z-noexcept-function-type.cpp Tue Nov 29 16:32:05 2016 @@ -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]; +} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits