Bug 280382 - '#include <algorithm>' fails when -std=c++98 and -pedantic-errors options are specified (found on the devel/benchmark port)
Summary: '#include <algorithm>' fails when -std=c++98 and -pedantic-errors options are...
Status: Closed DUPLICATE of bug 276738
Alias: None
Product: Base System
Classification: Unclassified
Component: misc (show other bugs)
Version: 14.1-STABLE
Hardware: Any Any
: --- Affects Only Me
Assignee: freebsd-toolchain (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-07-20 07:40 UTC by Yuri Victorovich
Modified: 2024-07-20 16:13 UTC (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Yuri Victorovich freebsd_committer freebsd_triage 2024-07-20 07:40:55 UTC
When '#include <algorithm>' is compiled with '-pedantic -pedantic-errors -std=c++98' it fails:
In file included from x.cpp:4:
In file included from /usr/include/c++/v1/algorithm:1787:
In file included from /usr/include/c++/v1/__algorithm/adjacent_find.h:14:
/usr/include/c++/v1/__algorithm/iterator_operations.h:105:9: error: too many arguments provided to function-like macro invocation
  105 |         "It looks like your iterator's `iterator_traits<It>::reference` does not match the return type of "
      |         ^
etc etc

Based on https://en.cppreference.com/w/cpp/header/algorithm <algorithm> existed in the c++98 standard, so such include should compile fine.
Comment 1 Mark Millard 2024-07-20 12:14:48 UTC
(In reply to Yuri Victorovich from comment #0)

https://libcxx.llvm.org reports:

QUOTE
libc++ is a new implementation of the C++ standard library, targeting C++11 and above.

Features and Goals
Correctness as defined by the C++11 standard.
END QUOTE

So: Not a bug. FreeBSD gave up on C++98 when it decided to be
based, in part, on libc++ .

Some notes on interpreting this:

Listing everything not supported is highly unusual and would be
a big effort. Normally if support is not mentioned, it is not
supported and what is explicitly supported is explicitly mentioned.

The lack of a page https://libcxx.llvm.org/DesignDocs/ExtendedCXX98Support.html
is also highly suggestive of lack of C++98 support.

Even https://libcxx.llvm.org/DesignDocs/ExtendedCXX03Support.html says
for C++03:

QUOTE
Clang provides a large subset of C++11 in C++03 as an extension.
END QUOTE

(Again, an explicit mention of the partial support.)

But C++03 is after C++ 98 as well and that note does not imply
anything for the C++98 status.
Comment 2 Dimitry Andric freebsd_committer freebsd_triage 2024-07-20 12:39:51 UTC
This is another instance of our static_assert implementation in cdefs.h going haywire in C++98 mode, as already reported in bug 276738. The problem is that you would have to rewrite all static_assert invocations in libc++'s headers with extra parentheses, which is not going to happen. (In fact, upstream has been removing these old compat crutches actively.)

The fix here is simply to remove -pedantic-errors, as this option serves no useful purpose, except being overly pedantic. :)

*** This bug has been marked as a duplicate of bug 276738 ***
Comment 3 Warner Losh freebsd_committer freebsd_triage 2024-07-20 13:35:38 UTC
Also... 6627df30d767a97692778adbc7f579172fc787ce doesn't redefine _Static_assert to something useless which helps, but that's current only.... Parts of this might be MFC-able.

I'll make a note in cdefs.9, though about this situation.
Comment 4 Warner Losh freebsd_committer freebsd_triage 2024-07-20 16:04:22 UTC
I've merged part of the compiler modernization work to stable/14 and stable/13.
They should appear in the bug soon (I'm compiling world just to make sure).
Also, the hash was wrong. It should have been:

commit d5c01e1124ffa4adb2513e7e8d708d7072dbfc75
Author: Warner Losh <imp@FreeBSD.org>
Date:   Thu Jun 20 17:03:15 2024 -0600

    cdefs.h: Remove pre gcc 5.0 support

that was tagged. This is what's being partially MFC'd.
Comment 5 commit-hook freebsd_committer freebsd_triage 2024-07-20 16:08:06 UTC
A commit in branch stable/14 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=22cdafe197ac960c5ce839ef6ec699b59f4b0080

commit 22cdafe197ac960c5ce839ef6ec699b59f4b0080
Author:     Warner Losh <imp@FreeBSD.org>
AuthorDate: 2024-07-20 15:57:53 +0000
Commit:     Warner Losh <imp@FreeBSD.org>
CommitDate: 2024-07-20 15:57:53 +0000

    cdefs.h: Don't define fallback for _Static_assert

    Remove pre 4.6 code to define _Static_assert in terms of _COUNTER.  We
    no longer need to support compilers this old (in fact support for all
    pre gcc 10 compilers has been removed in -current). This is a partial
    MFC of that work because removing this fixes a bug that's oft reported
    with -pedantic-errors and C++98 compilations.

    PR: 280382, 276738
    Sponsored by:           Netflix

    This is a direct commit to stable/14.

 sys/sys/cdefs.h | 9 ---------
 1 file changed, 9 deletions(-)
Comment 6 commit-hook freebsd_committer freebsd_triage 2024-07-20 16:13:12 UTC
A commit in branch stable/13 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=d3de5c5b45293d15f8b87f2e529318dd99988d4c

commit d3de5c5b45293d15f8b87f2e529318dd99988d4c
Author:     Warner Losh <imp@FreeBSD.org>
AuthorDate: 2024-07-20 15:57:53 +0000
Commit:     Warner Losh <imp@FreeBSD.org>
CommitDate: 2024-07-20 16:11:49 +0000

    cdefs.h: Don't define fallback for _Static_assert

    Remove pre 4.6 code to define _Static_assert in terms of _COUNTER.  We
    no longer need to support compilers this old (in fact support for all
    pre gcc 10 compilers has been removed in -current). This is a partial
    MFC of that work because removing this fixes a bug that's oft reported
    with -pedantic-errors and C++98 compilations.

    PR: 280382, 276738
    Sponsored by:           Netflix

    This is a direct commit to stable/14.

    (cherry picked from commit 22cdafe197ac960c5ce839ef6ec699b59f4b0080)

 sys/sys/cdefs.h | 9 ---------
 1 file changed, 9 deletions(-)