Author: Aaron Ballman Date: 2022-08-09T11:36:48-04:00 New Revision: 4c02ab8c9742f6c32b17f49a306b3b072486f5c5
URL: https://github.com/llvm/llvm-project/commit/4c02ab8c9742f6c32b17f49a306b3b072486f5c5 DIFF: https://github.com/llvm/llvm-project/commit/4c02ab8c9742f6c32b17f49a306b3b072486f5c5.diff LOG: Change prototype merging error into a warning for builtins As was observed in https://reviews.llvm.org/D123627#3707635, it's confusing that a user can write: ``` float rintf(void) {} ``` and get a warning, but writing: ``` float rintf() {} ``` gives an error. This patch changes the behavior so that both are warnings, so that users who have functions which conflict with a builtin identifier can still use that identifier as they wish. Differential Revision: https://reviews.llvm.org/D131499 Added: Modified: clang/lib/Sema/SemaDecl.cpp clang/test/Sema/prototype-redecls.c Removed: ################################################################################ diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 605e4bf0abae..c3011c09a6dc 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -4042,7 +4042,7 @@ bool Sema::MergeFunctionDecl(FunctionDecl *New, NamedDecl *&OldD, Scope *S, // default argument promotion rules were already checked by // ASTContext::typesAreCompatible(). if (Old->hasPrototype() && !New->hasWrittenPrototype() && NewDeclIsDefn && - Old->getNumParams() != New->getNumParams()) { + Old->getNumParams() != New->getNumParams() && !Old->isImplicit()) { if (Old->hasInheritedPrototype()) Old = Old->getCanonicalDecl(); Diag(New->getLocation(), diag::err_conflicting_types) << New; diff --git a/clang/test/Sema/prototype-redecls.c b/clang/test/Sema/prototype-redecls.c index ed569b5223ce..49305db10d24 100644 --- a/clang/test/Sema/prototype-redecls.c +++ b/clang/test/Sema/prototype-redecls.c @@ -29,7 +29,7 @@ void garp(x) int x; {} // Ensure redeclarations that conflict with a builtin use a note which makes it // clear that the previous declaration was a builtin. -float rintf() { // expected-error {{conflicting types for 'rintf'}} \ +float rintf() { // expected-warning {{incompatible redeclaration of library function 'rintf'}} \ expected-note {{'rintf' is a builtin with type 'float (float)'}} return 1.0f; } _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits