[clang] [Sema] Fix crash on invalid operator template-id (PR #181404)
via cfe-commits
cfe-commits at lists.llvm.org
Sun Feb 15 09:46:45 PST 2026
https://github.com/nehaGautam07 updated https://github.com/llvm/llvm-project/pull/181404
>From ab88ceb4cc10f56e5797fc750b177d695a8beb99 Mon Sep 17 00:00:00 2001
From: neharaj <neharajgautam07 at gmail.com>
Date: Fri, 13 Feb 2026 19:25:11 +0000
Subject: [PATCH] [Sema] Fix crash on invalid operator template-id
---
clang/lib/Sema/SemaDecl.cpp | 4 ++++
clang/test/SemaCXX/crash-invalid-operator-template.cpp | 7 +++++++
2 files changed, 11 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..daad0c611394a 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -6101,6 +6101,10 @@ Sema::GetNameFromUnqualifiedId(const UnqualifiedId &Name) {
}
case UnqualifiedIdKind::IK_TemplateId: {
+
+ if (Name.TemplateId->isInvalid())
+ return DeclarationNameInfo();
+
TemplateName TName = Name.TemplateId->Template.get();
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..7a7b95c612e4d
--- /dev/null
+++ b/clang/test/SemaCXX/crash-invalid-operator-template.cpp
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+typedef(( operator | <> ) ) ( class { private: });
+// expected-error at -1 {{cannot be defined in a parameter type}}
+// expected-error at -2 {{type specifier is required}}
+// expected-error at -3 {{typedef name must be an identifier}}
+
More information about the cfe-commits
mailing list