This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
RFC: Use std::{min,max} instead of MIN/MAX?
- From: Marek Polacek <polacek at redhat dot com>
- To: GCC Patches <gcc-patches at gcc dot gnu dot org>
- Date: Fri, 10 Jul 2015 15:19:10 +0200
- Subject: RFC: Use std::{min,max} instead of MIN/MAX?
- Authentication-results: sourceware.org; auth=none
Uros had the idea of using std::min/max instead of our MIN/MAX
macros defined in system.h. I thought I would do this cleanup,
but very soon I ran into a problem of failed template argument
substitution: std::min/max function templates require that both
arguments be of the same type:
/home/marek/src/gcc/gcc/caller-save.c: In function âvoid replace_reg_with_saved_mem(rtx_def**, machine_mode, int, void*)â:
/home/marek/src/gcc/gcc/caller-save.c:1151:63: error: no matching function for call to âmin(int, short unsigned int)â
offset -= (std::min (UNITS_PER_WORD, GET_MODE_SIZE (mode))
^
In file included from /usr/include/c++/5.1.1/bits/char_traits.h:39:0,
from /usr/include/c++/5.1.1/string:40,
from /home/marek/src/gcc/gcc/system.h:201,
from /home/marek/src/gcc/gcc/caller-save.c:21:
/usr/include/c++/5.1.1/bits/stl_algobase.h:195:5: note: candidate: template<class _Tp> const _Tp& std::min(const _Tp&, const _Tp&)
min(const _Tp& __a, const _Tp& __b)
^
/usr/include/c++/5.1.1/bits/stl_algobase.h:195:5: note: template argument deduction/substitution failed:
/home/marek/src/gcc/gcc/caller-save.c:1151:63: note: deduced conflicting types for parameter âconst _Tpâ (âintâ and âshort unsigned intâ)
offset -= (std::min (UNITS_PER_WORD, GET_MODE_SIZE (mode))
We can work around this by using casts, but that seems too ugly a solution.
So it appears to me that we're stuck with our MIN/MAX macros.
Thoughts?
Marek