[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 03:56:56 PDT 2023
cor3ntin created this revision.
Herald added a project: All.
cor3ntin requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
The type was never saved, and therefore never transformed
in dependent contexts.
Repository:
rG LLVM Github Monorepo
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=expected -std=c++23 -Wall %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
@@ -630,6 +630,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.537290.patch
Type: text/x-patch
Size: 2769 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230705/06b58f0b/attachment.bin>
More information about the cfe-commits
mailing list