https://github.com/zyn0217 created https://github.com/llvm/llvm-project/pull/219101
I'm not quite sure what that 'self-referential' meant and that logic doesn't seem to make much sense and it doesn't work for trailing return types. Fixes #162649 >From 572d94bae50349793cf39d0b1fa373d426da5d32 Mon Sep 17 00:00:00 2001 From: Younan Zhang <[email protected]> Date: Thu, 27 Aug 2026 12:10:41 +0800 Subject: [PATCH] [Clang] Fix getReturnTypeSourceRange() for trailing return types I'm not quite sure what that 'self-referential' meant and that logic doesn't seem to make much sense and it doesn't work for trailing return types. --- clang/docs/ReleaseNotes.md | 7 +++++-- clang/lib/AST/Decl.cpp | 5 +---- clang/test/Sema/warn-main-return-type.c | 5 +++-- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/clang/docs/ReleaseNotes.md b/clang/docs/ReleaseNotes.md index 8cc8eb5f80066..815e858b85360 100644 --- a/clang/docs/ReleaseNotes.md +++ b/clang/docs/ReleaseNotes.md @@ -486,9 +486,9 @@ features cannot lower the translation-unit ABI level; producing a spurious "no matching function" error with no candidate notes. (#GH210822) -- Fixed a crash when module directive export module foo not following a +- Fixed a crash when module directive export module foo not following a semicolon and there are no rest pp-tokens in current module file. (#GH187771) - + - Fixed a crash when a lambda parameter pack was given a default argument that is a pack expansion referencing an enclosing function's parameter pack (e.g. `[](Types... = args...) {}`). Clang now diagnoses the illegal default @@ -544,6 +544,9 @@ features cannot lower the translation-unit ABI level; serialized PCH/AST files and `-Wunused-local-typedef` diagnostics non-reproducible across runs. (#GH209639) +- `FunctionDecl::getReturnTypeSourceRange()` now returns correct source + location of a trailing return type. (#GH162649) + #### Miscellaneous Bug Fixes #### Miscellaneous Clang Crashes Fixed diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp index 0894097333d73..c9524dc82588a 100644 --- a/clang/lib/AST/Decl.cpp +++ b/clang/lib/AST/Decl.cpp @@ -4070,12 +4070,9 @@ SourceRange FunctionDecl::getReturnTypeSourceRange() const { if (!FTL) return SourceRange(); - // Skip self-referential return types. - const SourceManager &SM = getASTContext().getSourceManager(); SourceRange RTRange = FTL.getReturnLoc().getSourceRange(); SourceLocation Boundary = getNameInfo().getBeginLoc(); - if (RTRange.isInvalid() || Boundary.isInvalid() || - !SM.isBeforeInTranslationUnit(RTRange.getEnd(), Boundary)) + if (RTRange.isInvalid() || Boundary.isInvalid()) return SourceRange(); return RTRange; diff --git a/clang/test/Sema/warn-main-return-type.c b/clang/test/Sema/warn-main-return-type.c index 468a5de478e39..307395f70b4c0 100644 --- a/clang/test/Sema/warn-main-return-type.c +++ b/clang/test/Sema/warn-main-return-type.c @@ -43,8 +43,9 @@ fptr main(void) { return (fptr) 0; } -// expected-error@+2 {{conflicting types for 'main}} -// expected-warning@+1 {{return type of 'main' is not 'int'}} +// expected-error@+3 {{conflicting types for 'main}} +// expected-warning@+2 {{return type of 'main' is not 'int'}} +// expected-note@+1 {{change return type to 'int'}} void *(*main(void))(int a) { return (fptr) 0; } _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
