"const" und "constexpr" funktionieren nicht gleichzeitig



  • Hallo zusammen. Ich schlage mich gerade mit der konfiguration der libcxx auf einem embedded System herum. Folgendes Stück Code steht in der <limits>:

    template <class _Tp, bool = is_arithmetic<_Tp>::value>
    class __libcpp_numeric_limits
    {
    protected:
        typedef _Tp type;
    
        static _LIBCPP_CONSTEXPR const  bool is_specialized = false;
    
    // ....
    
    }
    

    Für den Fall das constexpr verwendet wird sollte gelten:

    #define _LIBCPP_CONSTEXPR constexpr
    

    Damit bekomme ich aber für Zeile 7 die Fehlermeldung (GCC 4.6): error: both 'const' and 'constexpr' can not be used here.
    Bleibt nur die Möglichkeit constexpr in der lib zu deaktivieren was ja auch nicht Sinn der Sache sein sollte. Unterstützt da der Compiler etwas nicht oder ist das ein Fehler in der Libcxx?


  • Mod

    bug in gcc 4.6, behoben ab Version 4.7



  • bei constexpr Funktionen wird const ignoriert

    7.1.5 The constexpr specifier
    8 A constexpr specifier for a non-static member function that is not a constructor declares that member function to be const (9.3.1). The keyword const is ignored if it appears in the cv-qualifier-seq of the function declarator of the declaration of such a member function.

    bei constexpr Variablen ist es nicht spezifiziert

    9 A constexpr specifier used in an object declaration declares the object as const. Such an object shall have literal type and shall be initialized. If it is initialized by a constructor call, that call shall be a constant expression (5.19). Otherwise, or if a constexpr specifier is used in a reference declaration, every fullexpression that appears in its initializer shall be a constant expression. Each implicit conversion used in converting the initializer expressions and each constructor call used for the initialization shall be one of those allowed in a constant expression (5.19).



  • Ok, Danke euch beiden.


Anmelden zum Antworten