9
// Compiled by Visual Studio 2012

struct A
{
    bool operator ==(const A& other) const
    {
        for (decltype(this->n) i = 0; i < n; ++i) // OK
        {}

        return true;
    }

protected:
    size_t n;
};

struct B : public A
{
    bool operator ==(const B& other) const
    {
        for (decltype(this->n) i = 0; i < n; ++i) // error C2105: '++' needs l-value
        {}

        return true;
    }
};

これは VC++ 2012 のバグですか?

4

1 に答える 1

6

これは、VS2012 コンパイラのバグのようです。この仕様は、セクション 7.1.6.2 のパラグラフ 4 で非常に明確です。実際、指定された例の 1 つは、 const-pointer を介して参照する式を示していますadecltype(a->x)利回りdouble、一方でdecltype((a->x))利回りdouble const &

これはバグです。コンパイラはそれが であると考えているiためconst、できません++

于 2012-10-16T06:07:41.537 に答える