llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang Author: Abhijeet (abhijeetsharma200) <details> <summary>Changes</summary> Fixes #<!-- -->184425 --- Full diff: https://github.com/llvm/llvm-project/pull/184621.diff 3 Files Affected: - (modified) clang/lib/Lex/Lexer.cpp (+12-1) - (modified) clang/test/Parser/cxx0x-decl.cpp (-2) - (added) clang/test/Parser/cxx11-alias-decl-split-token-fixit.cpp (+6) ``````````diff diff --git a/clang/lib/Lex/Lexer.cpp b/clang/lib/Lex/Lexer.cpp index cbf0c77232db7..6bec96601c9cf 100644 --- a/clang/lib/Lex/Lexer.cpp +++ b/clang/lib/Lex/Lexer.cpp @@ -862,7 +862,18 @@ SourceLocation Lexer::getLocForEndOfToken(SourceLocation Loc, unsigned Offset, return {}; if (Loc.isMacroID()) { - if (Offset > 0 || !isAtEndOfMacroExpansion(Loc, SM, LangOpts, &Loc)) + if (Offset > 0) + return {}; + + // Token-split expansions (e.g., '>>' split into '>') use a char range + // whose end is already the correct insertion point; skip MeasureTokenLength. + CharSourceRange ExpRange = SM.getImmediateExpansionRange(Loc); + if (!ExpRange.isTokenRange()) { + SourceLocation End = ExpRange.getEnd(); + return End.isFileID() ? End : SourceLocation{}; + } + + if (!isAtEndOfMacroExpansion(Loc, SM, LangOpts, &Loc)) return {}; // Points inside the macro expansion. } diff --git a/clang/test/Parser/cxx0x-decl.cpp b/clang/test/Parser/cxx0x-decl.cpp index 69a8d8a46557d..14643d7812641 100644 --- a/clang/test/Parser/cxx0x-decl.cpp +++ b/clang/test/Parser/cxx0x-decl.cpp @@ -190,8 +190,6 @@ namespace AliasDeclEndLocation { ; using D = AliasDeclEndLocation::A<int > // expected-error {{expected ';' after alias declaration}} - // FIXME: After splitting this >> into two > tokens, we incorrectly determine - // the end of the template-id to be after the *second* '>'. using E = AliasDeclEndLocation::A<int>>; #define GGG >>> using F = AliasDeclEndLocation::A<int GGG; diff --git a/clang/test/Parser/cxx11-alias-decl-split-token-fixit.cpp b/clang/test/Parser/cxx11-alias-decl-split-token-fixit.cpp new file mode 100644 index 0000000000000..f57025e1337eb --- /dev/null +++ b/clang/test/Parser/cxx11-alias-decl-split-token-fixit.cpp @@ -0,0 +1,6 @@ +// RUN: not %clang_cc1 -fsyntax-only -std=c++11 -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s +// RUN: %clang_cc1 -fsyntax-only -std=c++11 -verify %s + +template <typename> struct X {}; +using A = X<int>>; // expected-error {{expected ';' after alias declaration}} +// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:17-[[@LINE-1]]:17}:";" `````````` </details> https://github.com/llvm/llvm-project/pull/184621 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
