http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60511
Bug ID: 60511 Summary: [C++1y][N3652] Missing extended constexpr function support Product: gcc Version: 4.9.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: daniel.kruegler at googlemail dot com gcc 4.9.0 20140309 (experimental) compiled with the flags -std=c++1y -Wall -pedantic rejects: //---------------------- template<class T> struct L { T t; constexpr L(const T& t) : t(t) {} constexpr const T& value() const & { return t; } constexpr T& value() & { return t; } }; template<class T> constexpr T twice(const T& t) { L<T> l(t); l.value() *= 2; return l.value(); } int main() { constexpr int i = twice(12); static_assert(i == 24, ""); } //---------------------- <quote> prog.cc:7:16: error: 'constexpr T& L<T>::value() const &' cannot be overloaded constexpr T& value() & { return t; } ^ prog.cc:6:22: error: with 'constexpr const T& L<T>::value() const &' constexpr const T& value() const & { return t; } ^ prog.cc: In instantiation of 'constexpr T twice(const T&) [with T = int]': prog.cc:18:29: required from here prog.cc:13:13: error: assignment of read-only location 'l.L<T>::value<int>()' l.value() *= 2; ^ prog.cc:15:1: error: body of constexpr function 'constexpr T twice(const T&) [with T = int]' not a return-statement } ^ prog.cc: In function 'int main()': prog.cc:18:29: error: 'constexpr T twice(const T&) [with T = int]' called in a constant expression constexpr int i = twice(12); ^ prog.cc:11:13: note: 'constexpr T twice(const T&) [with T = int]' is not usable as a constexpr function because: constexpr T twice(const T& t) { ^ </quote> The compiler seems currently not apply the extended C++14 constexpr rules as of http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3652.html 1) constexpr makes non-static member functions automatically const member functions 2) constexpr functions require a single return statement 3) constexpr functions reject mutable operations