[clang] [Clang] Fix infinite loop on '::' inside parens in C mode (PR #195377)
Petr Beneš via cfe-commits
cfe-commits at lists.llvm.org
Fri May 1 16:07:56 PDT 2026
https://github.com/wbenny created https://github.com/llvm/llvm-project/pull/195377
`Parser::isTypeSpecifierQualifier` was recursing on the same `::` token forever when called from `isTypeIdInParens` while parsing a parenthesized expression in C mode.
Fixes: #195367
>From 9a4b3c7b98b028202c7f8e0a27b02d4504ce19b1 Mon Sep 17 00:00:00 2001
From: root <w.benny at outlook.com>
Date: Sat, 2 May 2026 01:06:25 +0200
Subject: [PATCH] [Clang] Fix infinite loop on '::' inside parens in C mode
`Parser::isTypeSpecifierQualifier` was recursing on the same `::` token
forever when called from `isTypeIdInParens` while parsing a parenthesized
expression in C mode.
Fixes: #195367
---
clang/lib/Parse/ParseDecl.cpp | 2 ++
clang/test/Parser/c-global-scope-coloncolon.c | 3 +++
2 files changed, 5 insertions(+)
create mode 100644 clang/test/Parser/c-global-scope-coloncolon.c
diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp
index 434a1a8fcb223..b5f06c9e01077 100644
--- a/clang/lib/Parse/ParseDecl.cpp
+++ b/clang/lib/Parse/ParseDecl.cpp
@@ -5632,6 +5632,8 @@ bool Parser::isTypeSpecifierQualifier(const Token &Tok) {
return isTypeSpecifierQualifier(getCurToken());
case tok::coloncolon: // ::foo::bar
+ if (!getLangOpts().CPlusPlus && !getLangOpts().ObjC)
+ return false;
if (NextToken().is(tok::kw_new) || // ::new
NextToken().is(tok::kw_delete)) // ::delete
return false;
diff --git a/clang/test/Parser/c-global-scope-coloncolon.c b/clang/test/Parser/c-global-scope-coloncolon.c
new file mode 100644
index 0000000000000..508b89ef6a180
--- /dev/null
+++ b/clang/test/Parser/c-global-scope-coloncolon.c
@@ -0,0 +1,3 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+int x = (::h); // expected-error {{expected expression}}
More information about the cfe-commits
mailing list