Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

gcc 7.2 header files breaks old code

60 views
Skip to first unread message

pedr...@lycos.com

unread,
Sep 16, 2017, 10:32:36 PM9/16/17
to
I have some package, that builds find with old gcc/g++ 4.4 and 4.8 (working with
enterprise linux). I had a go with a distro that has newer gcc 7.2
All went fine except a heap of errors related to stl_algobase.hh such as:

/usr/include/c++/7/bits/stl_algobase.h:243:56: error: macro "min" passed 3 arguments, but takes just 2
min(const _Tp& __a, const _Tp& __b, _Compare __comp)

the chain of includes leading up to this is:
In file included from /usr/include/c++/7/bits/char_traits.h:39:0,
from /usr/include/c++/7/ios:40,
from /usr/include/c++/7/ostream:38,
from /usr/include/c++/7/iostream:39,

so something has changed since the ancient versions I used before.

Trying various compiler flags -std=c++98 or gnu++98 helps not.

Alf P. Steinbach

unread,
Sep 17, 2017, 1:36:01 AM9/17/17
to
In C++14 §25.4.7 there are the following overloads of `min`:

template<class T> constexpr const T& min(const T& a, const T& b);

template<class T, class Compare>
constexpr const T& min(const T& a, const T& b, Compare comp);

template<class T>
constexpr T min(initializer_list<T> t);

template<class T, class Compare>
constexpr T min(initializer_list<T> t, Compare comp);

`min` is not a macro in standard C++.

Maybe that fact can guide you towards resolving this?


Cheers & hth.,

- Alf

Jorgen Grahn

unread,
Sep 17, 2017, 1:44:15 AM9/17/17
to
Probably a case of a new compiler revealing broken code.

Check if your package or some library it uses defines a macro called
'min'. As you can see when you think about it, the code in
stl_algobase.h would become very unhappy if that was the case.

/Jorgen

--
// Jorgen Grahn <grahn@ Oo o. . .
\X/ snipabacken.se> O o .

Öö Tiib

unread,
Sep 17, 2017, 2:30:41 PM9/17/17
to
Somehow the authors of your package have managed to do same stupid
thing that Microsoft did. Microsoft did so that the windows.h declared
macros named "min" and "max" and so standard library did not work.

Solution on case of windows was that who did not want non-working
standard library had to define NOMINMAX then windows.h did not
define macros min and max. However Microsoft's own headers like
gdiplus.h used those min and max macros and so more clever solution
was needed.

Perhaps just search for "#define min" in your code base and replace
it with "#define never_use_names_from_standard_library_for_macros_min".
Same do with "max" of yours.

Manfred

unread,
Sep 18, 2017, 6:56:23 AM9/18/17
to
On 9/17/2017 8:30 PM, Öö Tiib wrote:
> On Sunday, 17 September 2017 05:32:36 UTC+3, pedr...@lycos.com wrote:
>> I have some package, that builds find with old gcc/g++ 4.4 and 4.8 (working with
>> enterprise linux). I had a go with a distro that has newer gcc 7.2
>> All went fine except a heap of errors related to stl_algobase.hh such as:
>>
>> /usr/include/c++/7/bits/stl_algobase.h:243:56: error: macro "min" passed 3 arguments, but takes just 2
>> min(const _Tp& __a, const _Tp& __b, _Compare __comp)
>>
>> the chain of includes leading up to this is:
>> In file included from /usr/include/c++/7/bits/char_traits.h:39:0,
>> from /usr/include/c++/7/ios:40,
>> from /usr/include/c++/7/ostream:38,
>> from /usr/include/c++/7/iostream:39,
>>
>> so something has changed since the ancient versions I used before.
>>
>> Trying various compiler flags -std=c++98 or gnu++98 helps not.
>
> Somehow the authors of your package have managed to do same stupid
> thing that Microsoft did. Microsoft did so that the windows.h declared
> macros named "min" and "max" and so standard library did not work.

Agreed with the opinion about MS macros

>
> Solution on case of windows was that who did not want non-working
> standard library had to define NOMINMAX then windows.h did not
> define macros min and max. However Microsoft's own headers like
> gdiplus.h used those min and max macros and so more clever solution
> was needed.

There is a trick for this:
#include <algorithm>
(std::min)(17, 29)

https://social.msdn.microsoft.com/Forums/vstudio/en-US/9b83c008-7bfc-483d-9395-959d4ccefff6/vs-10-where-is-cppmax-and-cppmin-or-equivalent?forum=vcgeneral

(It works with MSVC, never used with gcc)

Kan

unread,
Sep 18, 2017, 8:37:23 AM9/18/17
to
Yes, but however you still have problems with other calls like
std::numeric_limits<T>::min(), so in this case I solved writing:

#include <Windows.h>
#undef min
#undef max
#include <algorithm>

Then use std::min and std::max instead on min and max.
Otherwise, if you really don't want to change the source code:
using std::min;
using std::max;
0 new messages