llvmbot wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Qiongsi Wu (qiongsiwu)

<details>
<summary>Changes</summary>

The parser hangs when processing method parameters with types prefixed by `::`. 
For example, 
```
- (instancetype)init:(::A *) foo;
```

The parser should not hang, and it should emit an error. This PR implements the 
error check. 

---
Full diff: https://github.com/llvm/llvm-project/pull/119908.diff


2 Files Affected:

- (modified) clang/lib/Parse/Parser.cpp (+7-1) 
- (added) clang/test/Parser/objc-coloncolon.m (+5) 


``````````diff
diff --git a/clang/lib/Parse/Parser.cpp b/clang/lib/Parse/Parser.cpp
index 36e56a92c3092e..aa78d702553172 100644
--- a/clang/lib/Parse/Parser.cpp
+++ b/clang/lib/Parse/Parser.cpp
@@ -2222,8 +2222,14 @@ bool Parser::TryAnnotateTypeOrScopeTokenAfterScopeSpec(
     }
   }
 
-  if (SS.isEmpty())
+  if (SS.isEmpty()) {
+    if (getLangOpts().ObjC && Tok.is(tok::coloncolon)) {
+      // ObjectiveC does not allow :: as as a scope token.
+      Diag(ConsumeToken(), diag::err_expected_type);
+      return true;
+    }
     return false;
+  }
 
   // A C++ scope specifier that isn't followed by a typename.
   AnnotateScopeToken(SS, IsNewScope);
diff --git a/clang/test/Parser/objc-coloncolon.m 
b/clang/test/Parser/objc-coloncolon.m
new file mode 100644
index 00000000000000..e8a09898263bb3
--- /dev/null
+++ b/clang/test/Parser/objc-coloncolon.m
@@ -0,0 +1,5 @@
+// RUN: %clang_cc1 -x objective-c -fsyntax-only -verify %s
+
+@interface A
+- (instancetype)init:(::A *) foo; // expected-error {{expected a type}} 
+@end

``````````

</details>


https://github.com/llvm/llvm-project/pull/119908
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to