c++qtc++11qt5debian-stretch

Qt 5.7.1 / gcc 6.3.0: error: body of constexpr function 'static constexpr int QMetaTypeId2<T>


This piece of code

namespace Config {
  class Value {
  public:
    enum Type {
      Null,
      Integer,
      String,
      Map,
      List,
      Boolean
    };

    Value();
    Value(int v);
    Value(const QString &v);
    Value(const QMap<QString, Value> &v);
    Value(const QList<Value> &v);
    Value(bool v);

    template<class T> T get() const {
      return value.value<T>();
    }

    enum Type type() const;
    enum Type listType() const;
    bool isNull() const;

    void setListType(enum Type t);

    operator QString() const;
    QString toString() const;

  private:
    QVariant value;
    enum Type value_type;
    enum Type list_elements_type;
  };
}

Q_DECLARE_METATYPE(Config::Value)

(https://github.com/olegantonyan/mpz/blob/master/app/config/value.h) Compiles on recent versions of gcc/qt, but fails on Debian stretch (gcc 6.3.0, qt 5.7.1)

../../../../include/x86_64-linux-gnu/qt5/QtCore/qglobal.h:746:47: error: static assertion failed: Type is not registered, please use the Q_DECLARE_METATYPE macro to make it known to Qt's meta-object system

../../../../include/x86_64-linux-gnu/qt5/QtCore/qmetatype.h:1604:100: error: body of constexpr function 'static constexpr int QMetaTypeId2<T>::qt_metatype_id() [with T = std::nullptr_t]' not a return-statement

Full build log https://build.opensuse.org/package/live_build_log/home:oleg_antonyan/mpz/Debian_9.0/x86_64

Also works fine on CentOS7 (gcc 4.8.5, qt 5.6.1). Haven't tested on more ancient versions.

Any ideas what could be wrong here?


Solution

  • Found the problem: value.setValue(nullptr); in the constructor, where value is QVariant.

    Removed this line and now it compiles OK. Not sure why I put it there in the first place