Skip to content

[Clang] template with NTTP param is static array element failed to compile #133047

@wanghenshui

Description

@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

https://godbolt.org/z/n1K5vGcrE

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:frontendLanguage frontend issues, e.g. anything involving "Sema"rejects-valid

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions