This revision was automatically updated to reflect the committed changes.
hokein marked an inline comment as done.
Closed by commit rG936ec89e91e2: [AST] Fix a clang crash on an invalid 
for-range statement. (authored by hokein).

Changed prior to commit:
  https://reviews.llvm.org/D81384?vs=269188&id=269259#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D81384

Files:
  clang/lib/Sema/SemaStmt.cpp
  clang/test/SemaCXX/for-range-crash.cpp


Index: clang/test/SemaCXX/for-range-crash.cpp
===================================================================
--- /dev/null
+++ clang/test/SemaCXX/for-range-crash.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++17 %s
+
+template <typename>
+class Bar {
+  Bar<int> *variables_to_modify;
+  foo() { // expected-error {{C++ requires a type specifier for all 
declarations}}
+    for (auto *c : *variables_to_modify)
+      delete c;
+  }
+};
Index: clang/lib/Sema/SemaStmt.cpp
===================================================================
--- clang/lib/Sema/SemaStmt.cpp
+++ clang/lib/Sema/SemaStmt.cpp
@@ -2434,8 +2434,11 @@
     QualType RangeType = Range->getType();
 
     if (RequireCompleteType(RangeLoc, RangeType,
-                            diag::err_for_range_incomplete_type))
+                            diag::err_for_range_incomplete_type)) {
+      if (LoopVar->getType()->isUndeducedType())
+        LoopVar->setInvalidDecl();
       return StmtError();
+    }
 
     // Build auto __begin = begin-expr, __end = end-expr.
     // Divide by 2, since the variables are in the inner scope (loop body).


Index: clang/test/SemaCXX/for-range-crash.cpp
===================================================================
--- /dev/null
+++ clang/test/SemaCXX/for-range-crash.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++17 %s
+
+template <typename>
+class Bar {
+  Bar<int> *variables_to_modify;
+  foo() { // expected-error {{C++ requires a type specifier for all declarations}}
+    for (auto *c : *variables_to_modify)
+      delete c;
+  }
+};
Index: clang/lib/Sema/SemaStmt.cpp
===================================================================
--- clang/lib/Sema/SemaStmt.cpp
+++ clang/lib/Sema/SemaStmt.cpp
@@ -2434,8 +2434,11 @@
     QualType RangeType = Range->getType();
 
     if (RequireCompleteType(RangeLoc, RangeType,
-                            diag::err_for_range_incomplete_type))
+                            diag::err_for_range_incomplete_type)) {
+      if (LoopVar->getType()->isUndeducedType())
+        LoopVar->setInvalidDecl();
       return StmtError();
+    }
 
     // Build auto __begin = begin-expr, __end = end-expr.
     // Divide by 2, since the variables are in the inner scope (loop body).
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to