[PATCH] D154492: [Clang] Fix handling of using declarations in for loop init statements.

Corentin Jabot via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Jul 5 07:21:07 PDT 2023


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG1077a3439111: [Clang] Fix handling of using declarations in for loop init statements. (authored by cor3ntin).

Changed prior to commit:
  https://reviews.llvm.org/D154492?vs=537290&id=537351#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154492

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Parse/ParseStmt.cpp
  clang/test/SemaCXX/cxx23-init-statement.cpp


Index: clang/test/SemaCXX/cxx23-init-statement.cpp
===================================================================
--- /dev/null
+++ clang/test/SemaCXX/cxx23-init-statement.cpp
@@ -0,0 +1,33 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++23 %s
+
+namespace GH63627 {
+template<class T>
+void ok() {
+  if  (using U = decltype([]{ return 42;}); true) {
+      static_assert(U{}() == 42);
+  }
+  for (using U = decltype([]{ return 42;}); [[maybe_unused]] auto x : "abc") {
+      static_assert(U{}() == 42);
+  }
+  for (using U = decltype([]{ return 42;}); false; ) {
+      static_assert(U{}() == 42);
+  }
+}
+
+template<class T>
+void err() {
+  if  (using U = decltype([]{}.foo); true) {}  // expected-error {{no member named 'foo'}}
+
+  for (using U = decltype([]{}.foo);          // expected-error {{no member named 'foo'}}
+       [[maybe_unused]] auto x : "abc") { }
+
+  for (using U = decltype([]{}.foo);          // expected-error {{no member named 'foo'}}
+       false ; ) { }
+};
+
+void test() {
+  ok<int>();
+  err<int>(); // expected-note {{in instantiation of function template specialization 'GH63627::err<int>'}}
+}
+
+}
Index: clang/lib/Parse/ParseStmt.cpp
===================================================================
--- clang/lib/Parse/ParseStmt.cpp
+++ clang/lib/Parse/ParseStmt.cpp
@@ -2054,15 +2054,15 @@
       Diag(Tok, diag::warn_gcc_variable_decl_in_for_loop);
     }
     DeclGroupPtrTy DG;
+    SourceLocation DeclStart = Tok.getLocation(), DeclEnd;
     if (Tok.is(tok::kw_using)) {
       DG = ParseAliasDeclarationInInitStatement(DeclaratorContext::ForInit,
                                                 attrs);
+      FirstPart = Actions.ActOnDeclStmt(DG, DeclStart, Tok.getLocation());
     } else {
       // In C++0x, "for (T NS:a" might not be a typo for ::
       bool MightBeForRangeStmt = getLangOpts().CPlusPlus;
       ColonProtectionRAIIObject ColonProtection(*this, MightBeForRangeStmt);
-
-      SourceLocation DeclStart = Tok.getLocation(), DeclEnd;
       ParsedAttributes DeclSpecAttrs(AttrFactory);
       DG = ParseSimpleDeclaration(
           DeclaratorContext::ForInit, DeclEnd, attrs, DeclSpecAttrs, false,
Index: clang/docs/ReleaseNotes.rst
===================================================================
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -635,6 +635,9 @@
 - Allow abstract parameter and return types in functions that are
   either deleted or not defined.
   (`#63012 <https://github.com/llvm/llvm-project/issues/63012>`_)
+- Fix handling of using-declarations in the init statements of for
+  loop declarations.
+  (`#63627 <https://github.com/llvm/llvm-project/issues/63627>`_)
 
 Bug Fixes to AST Handling
 ^^^^^^^^^^^^^^^^^^^^^^^^^


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D154492.537351.patch
Type: text/x-patch
Size: 2754 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230705/23f15a00/attachment.bin>


More information about the cfe-commits mailing list