[clang] [Clang] Fix infinite loop on '::' inside parens in C mode (PR #195377)
via cfe-commits
cfe-commits at lists.llvm.org
Fri May 1 16:08:40 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Petr Beneš (wbenny)
<details>
<summary>Changes</summary>
`Parser::isTypeSpecifierQualifier` was recursing on the same `::` token forever when called from `isTypeIdInParens` while parsing a parenthesized expression in C mode.
Fixes: #<!-- -->195367
---
Full diff: https://github.com/llvm/llvm-project/pull/195377.diff
2 Files Affected:
- (modified) clang/lib/Parse/ParseDecl.cpp (+2)
- (added) clang/test/Parser/c-global-scope-coloncolon.c (+3)
``````````diff
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}}
``````````
</details>
https://github.com/llvm/llvm-project/pull/195377
More information about the cfe-commits
mailing list