Snippets

aokomoriuta clangとOpenMPを組み合わせると何故かconstが外れるやつ

Created by aokomoriuta
// g++ test.cpp -std=c++14 -fopenmp     -> OK (Compile Error)
// clang++ test.cpp -std=c++11 -fopenmp -> NG (Passed, why?)
#include <array>

template<std::size_t NN>
class Foo
{
public:
    static constexpr auto N = NN;

private:
    std::array<int, N> val;
    
public:   
    int& Val(const std::size_t i)
    {
        return val[i];
    }
    
    const int& Val(const std::size_t i) const
    {
        return val[i];
    }
};

#include <iostream>

using F = Foo<10>;

static void Bar(const F& f)
{
    #pragma omp parallel for
    for(auto i = decltype(f.N)(0); i < f.N; i++)
    {
        f.Val(i) = -i; // ****************** This should not be assignable ****************
    }
    
    for(auto i = decltype(f.N)(0); i < f.N; i++)
    {
        std::cout << f.Val(i) << std::endl;
    }
}
int main()
{
    F f;
    
    for(auto i = decltype(f.N)(0); i < f.N; i++)
    {
        f.Val(i) = i;
    }
    
    Bar(f);
    
    return 0;
}

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.