-
Notifications
You must be signed in to change notification settings - Fork 12.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Sema] Fix __array_rank queried type at template instantiation
The type being queried was left as a template type parameter, making the whole expression as dependent and thus not eligible to static_assert.
- Loading branch information
v01dxyz
committed
Jan 26, 2025
1 parent
8035d38
commit 8283e34
Showing
3 changed files
with
39 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// RUN: %clang_cc1 -fsyntax-only %s | ||
|
||
// When __array_rank is used with a template type parameter, this | ||
// test ensures clang considers the final expression as having an | ||
// integral type. | ||
// | ||
// Although array_extent was handled well, it is added here. | ||
template <typename T, int N> | ||
constexpr int array_rank(T (&lhs)[N]) { | ||
return __array_rank(T[N]); | ||
} | ||
|
||
template <int I, typename T, int N> | ||
constexpr int array_extent(T (&lhs)[N]) { | ||
return __array_extent(T[N], I); | ||
} | ||
|
||
int main() { | ||
constexpr int vec[] = {0, 1, 2, 1}; | ||
constexpr int mat[4][4] = { | ||
{1, 0, 0, 0}, | ||
{0, 1, 0, 0}, | ||
{0, 0, 1, 0}, | ||
{0, 0, 0, 1} | ||
}; | ||
|
||
(void) (array_rank(vec) == 1); | ||
(void) (array_rank(vec) == 2); | ||
|
||
static_assert(array_rank(vec) == 1); | ||
static_assert(array_rank(mat) == 2); | ||
|
||
static_assert(array_extent<0>(vec) == 4); | ||
static_assert(array_extent<0>(mat) == 4); | ||
static_assert(array_extent<1>(mat) == 4); | ||
static_assert(array_extent<1>(vec) == 0); | ||
} |