http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57901

            Bug ID: 57901
           Summary: [C++11][constexpr] Cannot call-by-value such that
                    class has non-trivial (constexpr) move constructor
           Product: gcc
           Version: 4.8.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: bolero.murakami at gmail dot com

Code:
//--------
struct Z {
    Z()         = default;
    Z(Z const&) = default;
    constexpr Z(Z&&) {} /* non-trivial (constexpr) move ctor */
};

template<typename T>
constexpr int fn0(T v) { return 0; }
template<typename T>
constexpr int fn (T v) { return fn0(v); }

constexpr auto t0 = fn0(Z()); // OK!
constexpr auto t  = fn (Z()); // error! (GCC 4.8.1, -std=c++11)
//--------

Error message:
in constexpr expansion of ‘fn<Z>(Z())’
error: ‘v’ is not a constant expression
   constexpr auto t = fn(Z());
                            ^


Class Z is literal type.
However, compilation error when it is call-by-value(more than once).

I tested this code in gcc-4.7.3, is passed.
The problem is reproduced in gcc-4.8.0, gcc-4.8.1

Reply via email to