https://github.com/nehaGautam07 created 
https://github.com/llvm/llvm-project/pull/181404

Add checks in GetNameFromUnqualifiedId to handle invalid
TemplateId cases safely. This avoids a crash when parsing
malformed code like 'operator | <>' and allows normal
error reporting to continue.

Fixes #177549 

>From e5d7a4b2bd5d50f091a8aa90ddeb0fa7af1930c8 Mon Sep 17 00:00:00 2001
From: neharaj <[email protected]>
Date: Fri, 13 Feb 2026 19:25:11 +0000
Subject: [PATCH] [Sema] Fix crash on invalid operator template-id

---
 clang/lib/Sema/SemaDecl.cpp                            | 10 ++++++++++
 clang/test/SemaCXX/crash-invalid-operator-template.cpp |  3 +++
 2 files changed, 13 insertions(+)
 create mode 100644 clang/test/SemaCXX/crash-invalid-operator-template.cpp

diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 7af6ce62d08dd..369a5f11ef5aa 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -6101,7 +6101,17 @@ Sema::GetNameFromUnqualifiedId(const UnqualifiedId 
&Name) {
   }
 
   case UnqualifiedIdKind::IK_TemplateId: {
+    if (!Name.TemplateId)
+      return DeclarationNameInfo();
+
+    if (Name.TemplateId->isInvalid())
+      return DeclarationNameInfo();
+
     TemplateName TName = Name.TemplateId->Template.get();
+
+    if (TName.isNull())
+      return DeclarationNameInfo();
+
     SourceLocation TNameLoc = Name.TemplateId->TemplateNameLoc;
     return Context.getNameForTemplate(TName, TNameLoc);
   }
diff --git a/clang/test/SemaCXX/crash-invalid-operator-template.cpp 
b/clang/test/SemaCXX/crash-invalid-operator-template.cpp
new file mode 100644
index 0000000000000..d383b5f26d8e9
--- /dev/null
+++ b/clang/test/SemaCXX/crash-invalid-operator-template.cpp
@@ -0,0 +1,3 @@
+// RUN: not %clang_cc1 -fsyntax-only  %s
+
+typedef(( operator | <> ) ) ( class { private: });
\ No newline at end of file

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to