[clang] [Clang] Resolved type of expression indexing into pack of values of a non-dependent type (PR #121405)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Dec 31 08:23:52 PST 2024
https://github.com/TilakChad created https://github.com/llvm/llvm-project/pull/121405
For use of non-dependent type inside template, clang verifies eagerly that the type of variable being declared matches to that type.
With this PR, we assign the type of the PackIndexingExpr to the type of the pack it refers to.
This fixes https://github.com/llvm/llvm-project/issues/121242.
>From 2719a5d7ef30908de9e140ab4fd1b01c9e11d51c Mon Sep 17 00:00:00 2001
From: Tilak Chad <tilakchad111 at gmail.com>
Date: Tue, 31 Dec 2024 21:57:50 +0545
Subject: [PATCH] [Clang] Resolved type of expression indexing into pack of
values of a non-dependent type
---
clang/docs/ReleaseNotes.rst | 1 +
clang/lib/AST/ExprCXX.cpp | 2 +-
clang/test/SemaCXX/cxx2c-pack-indexing.cpp | 16 ++++++++++++++++
3 files changed, 18 insertions(+), 1 deletion(-)
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 983c1da20ed4c8..612541b0ddf84c 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -886,6 +886,7 @@ Bug Fixes to C++ Support
out of a module (which is the case e.g. in MSVC's implementation of ``std`` module). (#GH118218)
- Fixed a pack expansion issue in checking unexpanded parameter sizes. (#GH17042)
- Fixed a bug where captured structured bindings were modifiable inside non-mutable lambda (#GH95081)
+- Fixed an issue while resolving type of expression indexing into a pack of values of non-dependent type (#GH121242)
Bug Fixes to AST Handling
^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/clang/lib/AST/ExprCXX.cpp b/clang/lib/AST/ExprCXX.cpp
index fc09d24fc30cb4..5bf5d6adf525a8 100644
--- a/clang/lib/AST/ExprCXX.cpp
+++ b/clang/lib/AST/ExprCXX.cpp
@@ -1722,7 +1722,7 @@ PackIndexingExpr *PackIndexingExpr::Create(
if (Index && FullySubstituted && !SubstitutedExprs.empty())
Type = SubstitutedExprs[*Index]->getType();
else
- Type = Context.DependentTy;
+ Type = PackIdExpr->getType();
void *Storage =
Context.Allocate(totalSizeToAlloc<Expr *>(SubstitutedExprs.size()));
diff --git a/clang/test/SemaCXX/cxx2c-pack-indexing.cpp b/clang/test/SemaCXX/cxx2c-pack-indexing.cpp
index cb679a6c3ad879..58b642d2735b6e 100644
--- a/clang/test/SemaCXX/cxx2c-pack-indexing.cpp
+++ b/clang/test/SemaCXX/cxx2c-pack-indexing.cpp
@@ -305,3 +305,19 @@ template <class... Args> struct mdispatch_ {
mdispatch_<int, int> d;
} // namespace GH116105
+
+namespace GH121242 {
+ // Non-dependent type pack access
+ template <int...x>
+ int y = x...[0];
+
+ struct X {};
+
+ template <X...x>
+ X z = x...[0];
+
+ void foo() {
+ (void)y<0>;
+ (void)z<X{}>;
+ }
+} // namespace GH121242
More information about the cfe-commits
mailing list