-
Notifications
You must be signed in to change notification settings - Fork 13.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Clang] template with NTTP param is static array element failed to compile #133047
Labels
Comments
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p2647r1.html use lambda workaround also ok |
Clang correctly accepts this with the following change (Godbolt link): - static constexpr bool kActiveDimensions[] = {ActiveDimensions...};
+ static constexpr bool kActiveDimensions[kNumDimensions] = {ActiveDimensions...}; |
@llvm/issue-subscribers-clang-frontend Author: Ted Mostly (wanghenshui)
it's code from CV-cuda, migrate to clang
#include <cstddef>
#include <stdint.h>
#include <utility>
#include <tuple>
template<bool Active = true, typename T>
constexpr inline bool IsOutside(T c, T s)
{
if constexpr (Active)
{
return (c < 0) || (c >= s);
}
return false;
}
template<bool... ActiveDimensions>
class BoolDimension
{
public:
static constexpr int kNumDimensions = sizeof...(ActiveDimensions);
struct ActiveMap
{
bool from[kNumDimensions];
constexpr ActiveMap()
: from()
{
int j = 0;
for (int i = 0; i < kNumDimensions; ++i)
{
if (kActiveDimensions[i])
{
from[i] = j++;
}
}
}
};
static constexpr ActiveMap kMap{};
static constexpr bool kActiveDimensions[] = {ActiveDimensions...};
static constexpr int kNumActiveDimensions = ((ActiveDimensions ? 1 : 0) + ...);
int64_t m_tensorShape[kNumActiveDimensions] = {0};
template<typename... Args, std::size_t... Is>
inline bool check(std::index_sequence<Is...>, Args... c) const
{
//static constexpr const auto kDimensions = std::make_tuple(ActiveDimensions...);
//if ((IsOutside<std::get<Is>(kDimensions)>(c,false) || ...))
if ((IsOutside<kActiveDimensions[Is]>(c,false) || ...))
{
return true;
}
return false;
}
};
int main() {
BoolDimension<true, true, false, false> d;
constexpr auto Is = std::make_index_sequence<1>{};
return d.check(Is, false);
} in check function, IsOutside not accept array element, change to tuple with get is ok |
zyn0217
added a commit
that referenced
this issue
Mar 27, 2025
…tantiated (#133212) The instantiation of a VarDecl's initializer might be deferred until the variable is actually used. However, we were still building the DeclRefExpr with a type that could later be changed by the initializer's instantiation, which is incorrect when incomplete arrays are involved. Fixes #79750 Fixes #113936 Fixes #133047
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
it's code from CV-cuda, migrate to clang
in check function, IsOutside not accept array element, change to tuple with get is ok
https://godbolt.org/z/n1K5vGcrE
The text was updated successfully, but these errors were encountered: