g++ doesn't compile constexpr function with assert in it

后端 未结 4 1765
梦如初夏
梦如初夏 2020-12-15 01:33
template constexpr inline 
T getClamped(const T& mValue, const T& mMin, const T& mMax) 
{ 
     assert(mMin < mMax); // remove this          


        
4条回答
  •  难免孤独
    2020-12-15 01:38

    g++ is right. Per the standard, a non-static assert is not permitted in a constexpr statement.

    ... its function-body shall be a compound-statement that contains only:
      null statements,
      static_assert-declarations,
      typedef declarations and alias-declarations that do not define classes or enumerations,
      using-declarations,
      using-directives,
      and exactly one return statement.
          -- 7.1.5/3

提交回复
热议问题