Issue
Context: I'm doing some compile time programming which involves manipulating types using constexpr functions that are only evaluated in a decltype context.
For example a pop function that removes the first type from a list of types:
template <typename T0, typename... T1toN>
constexpr auto pop(List<T0, T1toN...>) -> List<T1toN...>;
These functions are used like this
decltype(pop(my_type_list))
In other words, they are never 'executed'. Yet, the compiler (g++) gives me warnings such as warning: inline function ‘constexpr List<T1toN ...> pop(List<T0, T1toN ...>) [with T0 = Type1; T1toN = {Type2, Type3}]’ used but never defined
EDIT: It turns out the the warning only appears when the functions are evaluated in a decltype indirectly. i.e. A top level function which is only evaluated in a decltype uses a subfunction. results in a warning for the subfunction. Jarod42 created a nice reproduction scenario here
Question: Is there any way I can suppress this used but never defined warning? And is it possible to only do it for functions evaluated (indirectly) in a decltype context?
I am using g++ version 8.3
Solution
In
template <typename ...> struct List{};
template <typename T0, typename... T1toN>
constexpr auto pop(List<T0, T1toN...>) -> List<T1toN...>;
template <typename T0, typename... T1toN>
constexpr auto pop2(List<T0, T1toN...> l) { return pop(l); } // You use pop
constexpr List<int, int> my_type_list;
using type = decltype(pop2(my_type_list));
pop2
should not have definition, and be:
template <typename T0, typename... T1toN>
constexpr auto pop2(List<T0, T1toN...> l) -> decltype(pop(l));
Answered By - Jarod42 Answer Checked By - Katrina (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.