Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
cvalue and constant integral expression in generic context
#1
We would like to have some clarification regarding cvalues and integral constant expressions when considering C++14.

Main Question: Is N, which is an integral constant expression, a cvalue as defined in MISRA C++:2008?


Code:
template <typename T, int N>
constexpr auto fun()
{
    constexpr auto v = T{N};
   
    return /* something */;
}


Question 2: Does the use of {} or () have any affect on whether N is a cvalue?

Question 3: Does it matter whether T is fundamental type or a class type? For example:

Code:
template <typename T>
struct CustomScalar final
{
    T val{};

    constexpr CustomScalar() = default;
    explicit constexpr CustomScalar(T x) : val{x} {}
};

int main()
{
    fun<CustomScalar<float>, 2>();
}
Reply
#2
From the definitions in MISRA 2008, integral constant expressions are never cvalues. 

As far as we can determine, your example code should be compliant, at least with respect to the use of cvalues.
Posted by and on behalf of
the MISRA C++ Working Group
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)