cishida updated this revision to Diff 431543. cishida added a comment. Restrict using the canonical decl's source location to only when the prototype was inferred from previously seen decl.
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D126258/new/ https://reviews.llvm.org/D126258 Files: clang/lib/Sema/SemaDecl.cpp clang/test/Sema/prototype-redecls.c Index: clang/test/Sema/prototype-redecls.c =================================================================== --- clang/test/Sema/prototype-redecls.c +++ clang/test/Sema/prototype-redecls.c @@ -12,6 +12,10 @@ void blerp(short); // expected-note {{previous}} void blerp(x) int x; {} // expected-error {{conflicting types for 'blerp'}} +void foo(int); // expected-note {{previous}} +void foo(); +void foo() {} // expected-error {{conflicting types for 'foo'}} + void glerp(int); void glerp(x) short x; {} // Okay, promoted type is fine Index: clang/lib/Sema/SemaDecl.cpp =================================================================== --- clang/lib/Sema/SemaDecl.cpp +++ clang/lib/Sema/SemaDecl.cpp @@ -3911,6 +3911,8 @@ // ASTContext::typesAreCompatible(). if (Old->hasPrototype() && !New->hasWrittenPrototype() && NewDeclIsDefn && Old->getNumParams() != New->getNumParams()) { + if (Old->hasInheritedPrototype()) + Old = Old->getCanonicalDecl(); Diag(New->getLocation(), diag::err_conflicting_types) << New; Diag(Old->getLocation(), PrevDiag) << Old << Old->getType(); return true;
Index: clang/test/Sema/prototype-redecls.c =================================================================== --- clang/test/Sema/prototype-redecls.c +++ clang/test/Sema/prototype-redecls.c @@ -12,6 +12,10 @@ void blerp(short); // expected-note {{previous}} void blerp(x) int x; {} // expected-error {{conflicting types for 'blerp'}} +void foo(int); // expected-note {{previous}} +void foo(); +void foo() {} // expected-error {{conflicting types for 'foo'}} + void glerp(int); void glerp(x) short x; {} // Okay, promoted type is fine Index: clang/lib/Sema/SemaDecl.cpp =================================================================== --- clang/lib/Sema/SemaDecl.cpp +++ clang/lib/Sema/SemaDecl.cpp @@ -3911,6 +3911,8 @@ // ASTContext::typesAreCompatible(). if (Old->hasPrototype() && !New->hasWrittenPrototype() && NewDeclIsDefn && Old->getNumParams() != New->getNumParams()) { + if (Old->hasInheritedPrototype()) + Old = Old->getCanonicalDecl(); Diag(New->getLocation(), diag::err_conflicting_types) << New; Diag(Old->getLocation(), PrevDiag) << Old << Old->getType(); return true;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits