[clang] [clang] Fixes alias declaration fix-it location for token-split '>>' (PR #184621)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Mar 4 06:27:14 PST 2026
https://github.com/abhijeetsharma200 created https://github.com/llvm/llvm-project/pull/184621
Fixes #184425
>From 3ced31f27094baa45cdb664549f6d7ddc7b70279 Mon Sep 17 00:00:00 2001
From: Abhijeet Sharma <abhijeetsharma2002 at gmail.com>
Date: Wed, 4 Mar 2026 15:12:24 +0100
Subject: [PATCH 1/2] [clang] Fix alias declaration fix-it location for
token-split '>>', fixes #184425
---
clang/lib/Lex/Lexer.cpp | 13 ++++++++++++-
clang/test/Parser/cxx0x-decl.cpp | 2 --
2 files changed, 12 insertions(+), 3 deletions(-)
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;
>From dc9850eaf4a68ce3f6488172b40e8ab16cd1f6da Mon Sep 17 00:00:00 2001
From: Abhijeet Sharma <abhijeetsharma2002 at gmail.com>
Date: Wed, 4 Mar 2026 15:24:52 +0100
Subject: [PATCH 2/2] Added test file
---
clang/test/Parser/cxx11-alias-decl-split-token-fixit.cpp | 6 ++++++
1 file changed, 6 insertions(+)
create mode 100644 clang/test/Parser/cxx11-alias-decl-split-token-fixit.cpp
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}:";"
More information about the cfe-commits
mailing list