This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: RFC: Use std::{min,max} instead of MIN/MAX?
- From: Trevor Saunders <tbsaunde at tbsaunde dot org>
- To: Marek Polacek <polacek at redhat dot com>
- Cc: GCC Patches <gcc-patches at gcc dot gnu dot org>
- Date: Fri, 10 Jul 2015 15:35:57 -0400
- Subject: Re: RFC: Use std::{min,max} instead of MIN/MAX?
- Authentication-results: sourceware.org; auth=none
- References: <20150710131910 dot GB2876 at redhat dot com>
On Fri, Jul 10, 2015 at 03:19:10PM +0200, Marek Polacek wrote:
> 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.
You can also explicitly pick the specialization you want with e.g.
std::max<long long> (x, y); its kind of long, but I can see an argument
for the explicitness so I'm not sure how ugly I think it is.
Trev
> So it appears to me that we're stuck with our MIN/MAX macros.
>
> Thoughts?
>
> Marek