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 ^^^^^^^^^^^^^^^^^^^^^^^^^
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 ^^^^^^^^^^^^^^^^^^^^^^^^^
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits