Building certain ports fails with errors in system C++ libraries

From: J David <j.david.lists_at_gmail.com>
Date: Fri, 30 Aug 2024 15:48:35 UTC
On a freshly-installed FreeBSD 14.1 amd64 system, I'm hitting errors
in the system C++ standard include files.

For example, trying to build editors/le produces:

c++ -DHAVE_CONFIG_H -I. -I../lib   -I../lib -I../lib  -isystem
/usr/local/include -D_THREAD_SAFE  -O2 -pipe -fstack-protector-strong
-isystem /usr/local/include -fno-strict-aliasing  -isystem
/usr/local/include  -Wall -Wwrite-strings -Woverloaded-virtual
-fno-exceptions -fno-rtti -fno-implement-inlines -MT highli.o -MD -MP
-MF .deps/highli.Tpo -c -o highli.o highli.cc
In file included from highli.cc:36:
In file included from /usr/include/c++/v1/set:1499:
In file included from /usr/include/c++/v1/functional:526:
In file included from
/usr/include/c++/v1/__functional/boyer_moore_searcher.h:27:
In file included from /usr/include/c++/v1/vector:325:
In file included from /usr/include/c++/v1/__format/formatter_bool.h:20:
In file included from /usr/include/c++/v1/__format/formatter_integral.h:35:
In file included from /usr/include/c++/v1/locale:209:
/usr/include/c++/v1/ios:260:25: error: expected ')'
  260 |   static const fmtflags hex         = 0x0008;
      |                         ^
./edit.h:158:26: note: expanded from macro 'hex'
  158 | #define hex     (editmode==HEXM)
      |                          ^
/usr/include/c++/v1/ios:260:25: note: to match this '('
./edit.h:158:17: note: expanded from macro 'hex'
  158 | #define hex     (editmode==HEXM)
      |                 ^
In file included from highli.cc:36:
In file included from /usr/include/c++/v1/set:1499:
In file included from /usr/include/c++/v1/functional:526:
In file included from
/usr/include/c++/v1/__functional/boyer_moore_searcher.h:27:
In file included from /usr/include/c++/v1/vector:325:
In file included from /usr/include/c++/v1/__format/formatter_bool.h:20:
In file included from /usr/include/c++/v1/__format/formatter_integral.h:35:
In file included from /usr/include/c++/v1/locale:209:
/usr/include/c++/v1/ios:794:40: error: expected ')'
  794 | _LIBCPP_HIDE_FROM_ABI inline ios_base& hex(ios_base& __str) {
      |                                        ^
./edit.h:158:26: note: expanded from macro 'hex'
  158 | #define hex     (editmode==HEXM)
      |                          ^
/usr/include/c++/v1/ios:794:40: note: to match this '('
./edit.h:158:17: note: expanded from macro 'hex'
  158 | #define hex     (editmode==HEXM)
      |                 ^
In file included from highli.cc:36:
In file included from /usr/include/c++/v1/set:1499:
In file included from /usr/include/c++/v1/functional:526:
In file included from
/usr/include/c++/v1/__functional/boyer_moore_searcher.h:27:
In file included from /usr/include/c++/v1/vector:325:
In file included from /usr/include/c++/v1/__format/formatter_bool.h:20:
In file included from /usr/include/c++/v1/__format/formatter_integral.h:35:
In file included from /usr/include/c++/v1/locale:209:
/usr/include/c++/v1/ios:795:24: error: expected unqualified-id
  795 |   __str.setf(ios_base::hex, ios_base::basefield);
      |                        ^
./edit.h:158:17: note: expanded from macro 'hex'
  158 | #define hex     (editmode==HEXM)
      |                 ^
In file included from highli.cc:36:
In file included from /usr/include/c++/v1/set:1499:
In file included from /usr/include/c++/v1/functional:526:
In file included from
/usr/include/c++/v1/__functional/boyer_moore_searcher.h:27:
In file included from /usr/include/c++/v1/vector:325:
In file included from /usr/include/c++/v1/__format/formatter_bool.h:20:
In file included from /usr/include/c++/v1/__format/formatter_integral.h:35:
In file included from /usr/include/c++/v1/locale:209:
/usr/include/c++/v1/ios:795:24: error: comparison between pointer and
integer ('ios_base &(*)(ios_base &)' and 'int')
  795 |   __str.setf(ios_base::hex, ios_base::basefield);
      |                        ^~~
./edit.h:158:26: note: expanded from macro 'hex'
  158 | #define hex     (editmode==HEXM)
      |                  ~~~~~~~~^ ~~~~
4 errors generated.

Errors in the system include files using the system compiler would
tend to indicate (to me) that I've damaged the install somehow. But
this is fresh off the ISO using the default system compiler with the
default system include files and default port options. Building using
Poudriere in a 13.3 or 14.1 jail produces the same result.

According to Freshports, there are no reported issues with this
package, and the automated infrastructure that builds the official
packages builds it with no problem for both 13.3 and 14.1. If there
were a real problem with the default environment, I would expect the
problem to show up there as well.

So there must be more to the story.

Does anyone know what might be going on here?  And/or how to find out
what settings are used to build the official FreeBSD packages so I can
try to reproduce it?

Thanks for any advice!