A bug of CLion on parsing structs inside a function

Answered

 Here I write a function buildSA() with a struct inside:

void buildSA()
{
    struct Node {
        int k1, k2, id;
        bool operator < (const Node& rhs) const {
            return k1 < rhs.k1 || (k1 == rhs.k1 && k2 < rhs.k2);
        }
        bool operator == (const Node& rhs) const {
            return k1 == rhs.k1 && k2 == rhs.k2;
        }
    };
    //Some other code

    std::vector<Node> nodes((size_t)len), temp((size_t)len);
    //...
    int last = 0;
    for (int i = 0; i < len; i++)
    {
        if (!(i > 0 && nodes[i] == nodes[i - 1]))
            last += 1;
        rank[nodes[i].id] = last;
    }
    //...
}

Then I notice that the IDE shows an incorrect error message with the comparison nodes[i] == nodes[i - 1] saying "Can't compare structures", even though I've implemented operator == for struct Node. Nothing goes wrong when I put struct Node outside the function buildSA().

Is this a bug of CLion or is there something improper with my code?

0
1 comment

Hi! Thanks for reporting. I've created the issue in our tracker: https://youtrack.jetbrains.com/issue/CPP-12577. Feel free to comment or upvote, follow it to get updates.

0

Please sign in to leave a comment.