Possible C++11 regression: member of literal type breaks constexpr

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello,
I think hit a regression in gcc 4.9.0 when using a static constexpr
member as a template parameter when used in a certain way. However, as
the problem is a bit more complex wanted to ask whether this truly is
a bug in gcc and not on my side before reporting it to bugtracker.

The problematic code is at the end of this mail (everything after CODE section).

When compiled with gcc 4.9.0, the
ValueTypeInfo<ValueTypeEnum::doubleval> v; in the FillFunctor
constructor gives an error:

    bug2.cpp: In constructor ‘FillFunctor<Format>::FillFunctor()’:
    bug2.cpp:24:41:   in constexpr expansion of ‘const
ValueType{1}->ValueType::operator int()’
    bug2.cpp:24:41: error: ‘*(const ValueType*)this’ is not a constant
expression
       ValueTypeInfo<ValueTypeEnum::doubleval> v;
            ^
    bug2.cpp:24:41: note: in template argument for type ‘int’
    bug2.cpp:24:44: error: invalid type in declaration before ‘;’ token
       ValueTypeInfo<ValueTypeEnum::doubleval> v;


However, the same expression compiles just fine if its used in a
function, such as main(). Removing m_ID makes the code compile, too.
Also, the compilation works after replacing:

  ValueTypeInfo<ValueTypeEnum::doubleval> v;

with a:

  constexpr ValueType doubleval = ValueType(1);
  ValueTypeInfo<doubleval> v;


Best wishes,
Lukas

CODE
#####

class ValueType {
public:
    constexpr operator int() const {return m_ID;};
    constexpr ValueType(const int v)
        : m_ID(v) {}
private:
    int m_ID;
};

class ValueTypeEnum {
public:
    static constexpr ValueType doubleval = ValueType(1);
};

template <int format>
class ValueTypeInfo {
};

template <typename Format>
class FillFunctor {
public:
    FillFunctor() {
        ValueTypeInfo<ValueTypeEnum::doubleval> v;
    }
};

int main() {
    ValueTypeInfo<ValueTypeEnum::doubleval> v;
}





[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux