size() can not be used in constexpr context
While trying to compile dune with intel icc I came across of problem wiht constexpr function used as template-parameters, e.g. in treepath.hh:440
template<typename... T, typename std::enable_if<(sizeof...(T) > 0),bool>::type = true>
auto back(const HybridTreePath<T...>& tp)
-> decltype(treePathEntry<treePathSize(tp)-1>(tp))
{
return treePathEntry<treePathSize(tp)-1>(tp);
}
The function treePathSize
is a constexpr function, accepting a const ref to HybridTreePath
. This is not be allowed as template-parameter! See e.g. Stackoverflow: constexpr with untouched non-constexpr arguments: Who is correct, clang or gcc? and also [Stackoverflow: using result of constexpr function as a template parameter (clang vs gcc)] (https://stackoverflow.com/questions/43072361/using-result-of-constexpr-function-as-a-template-parameter-clang-vs-gcc)
So it seems to be accepted by gcc (what is wrong behavior) but not by any other compiler. Intel icc gives the best hint:
note: the value of parameter "tp" cannot be used as a constant
Possible solution:
- use class specialization instead of constexpr function overloading (pre-constexpr way)
- directly use
sizeof...(T)
Edited by Simon Praetorius