Re: RFC: Use std::{min,max} instead of MIN/MAX?
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 (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
Re: RFC: Use std::{min,max} instead of MIN/MAX?
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 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 (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
RFC: Use std::{min,max} instead of MIN/MAX?
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 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