[PATCH] D137263: add boundary check for ASTUnresolvedSet::erase

Fangrui Song via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sun Nov 6 15:07:57 PST 2022


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGb84fd822fa7e: Add boundary check for ASTUnresolvedSet::erase (authored by zhouyizhou, committed by MaskRay).

Changed prior to commit:
  https://reviews.llvm.org/D137263?vs=473509&id=473512#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D137263/new/

https://reviews.llvm.org/D137263

Files:
  clang/include/clang/AST/ASTUnresolvedSet.h
  clang/test/SemaCXX/using-decl-templates.cpp


Index: clang/test/SemaCXX/using-decl-templates.cpp
===================================================================
--- clang/test/SemaCXX/using-decl-templates.cpp
+++ clang/test/SemaCXX/using-decl-templates.cpp
@@ -102,6 +102,28 @@
 };
 } // namespace DontDiagnoseInvalidTest
 
+namespace shadow_nested_operator {
+template <typename T>
+struct A {
+  struct Nested {};
+  operator Nested*() {return 0;};
+};
+
+template <typename T>
+struct B : A<T> {
+  using A<T>::operator typename A<T>::Nested*;
+  operator typename A<T>::Nested *() {
+    struct A<T> * thi = this;
+    return *thi;
+ };
+};
+
+int foo () {
+  struct B<int> b;
+  auto s = *b;
+}
+} // namespace shadow_nested_operator
+
 namespace func_templ {
 namespace sss {
 double foo(int, double);
Index: clang/include/clang/AST/ASTUnresolvedSet.h
===================================================================
--- clang/include/clang/AST/ASTUnresolvedSet.h
+++ clang/include/clang/AST/ASTUnresolvedSet.h
@@ -69,7 +69,12 @@
     return false;
   }
 
-  void erase(unsigned I) { Decls[I] = Decls.pop_back_val(); }
+  void erase(unsigned I) {
+    if (I == Decls.size() - 1)
+      Decls.pop_back();
+    else
+      Decls[I] = Decls.pop_back_val();
+  }
 
   void clear() { Decls.clear(); }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D137263.473512.patch
Type: text/x-patch
Size: 1265 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20221106/6a3d3691/attachment.bin>


More information about the cfe-commits mailing list