* RFC: Use std::{min,max} instead of MIN/MAX?
@ 2015-07-10 13:19 Marek Polacek
2015-07-10 19:36 ` Trevor Saunders
0 siblings, 1 reply; 3+ messages in thread
From: Marek Polacek @ 2015-07-10 13:19 UTC (permalink / raw)
To: GCC Patches
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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: RFC: Use std::{min,max} instead of MIN/MAX?
2015-07-10 13:19 RFC: Use std::{min,max} instead of MIN/MAX? Marek Polacek
@ 2015-07-10 19:36 ` Trevor Saunders
2015-07-11 9:58 ` Marek Polacek
0 siblings, 1 reply; 3+ messages in thread
From: Trevor Saunders @ 2015-07-10 19:36 UTC (permalink / raw)
To: Marek Polacek; +Cc: GCC Patches
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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: RFC: Use std::{min,max} instead of MIN/MAX?
2015-07-10 19:36 ` Trevor Saunders
@ 2015-07-11 9:58 ` Marek Polacek
0 siblings, 0 replies; 3+ messages in thread
From: Marek Polacek @ 2015-07-11 9:58 UTC (permalink / raw)
To: Trevor Saunders; +Cc: GCC Patches
On Fri, Jul 10, 2015 at 03:35:57PM -0400, Trevor Saunders wrote:
> 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.
Thanks for pointing this out. Yea, that'd be an option, though I don't
think people would be too happy about that.
Marek
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2015-07-11 9:58 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-07-10 13:19 RFC: Use std::{min,max} instead of MIN/MAX? Marek Polacek
2015-07-10 19:36 ` Trevor Saunders
2015-07-11 9:58 ` Marek Polacek
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).