Skip to content

Commit a1a14e8

Browse files
committed
[Clang] Avoid misleading 'conflicting types' diagnostic with no-prototype decls.
Clang has recently started diagnosing prototype redeclaration errors like [rG385e7df33046](https://reviews.llvm.org/rG385e7df33046d7292612ee1e3ac00a59d8bc0441) This flagged legitimate issues in a codebase but was confusing to resolve because it actually conflicted with a function declaration from a system header and not from the one emitted with "note: ". This patch updates the error handling to use the canonical declaration's source location instead to avoid misleading errors like the one described. Reviewed By: aaron.ballman Differential Revision: https://reviews.llvm.org/D126258
1 parent 154f93c commit a1a14e8

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

clang/lib/Sema/SemaDecl.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3911,6 +3911,8 @@ bool Sema::MergeFunctionDecl(FunctionDecl *New, NamedDecl *&OldD, Scope *S,
39113911
// ASTContext::typesAreCompatible().
39123912
if (Old->hasPrototype() && !New->hasWrittenPrototype() && NewDeclIsDefn &&
39133913
Old->getNumParams() != New->getNumParams()) {
3914+
if (Old->hasInheritedPrototype())
3915+
Old = Old->getCanonicalDecl();
39143916
Diag(New->getLocation(), diag::err_conflicting_types) << New;
39153917
Diag(Old->getLocation(), PrevDiag) << Old << Old->getType();
39163918
return true;

clang/test/Sema/prototype-redecls.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ void blarg() {} // expected-error {{conflicting types for 'blarg'}}
1212
void blerp(short); // expected-note {{previous}}
1313
void blerp(x) int x; {} // expected-error {{conflicting types for 'blerp'}}
1414

15+
void foo(int); // expected-note {{previous}}
16+
void foo();
17+
void foo() {} // expected-error {{conflicting types for 'foo'}}
18+
1519
void glerp(int);
1620
void glerp(x) short x; {} // Okay, promoted type is fine
1721

0 commit comments

Comments
 (0)