Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Latest macOS system header causes compilation failures on GCC #2837

Closed
morinmorin opened this issue Mar 11, 2024 · 4 comments · Fixed by #2839
Closed

Latest macOS system header causes compilation failures on GCC #2837

morinmorin opened this issue Mar 11, 2024 · 4 comments · Fixed by #2839

Comments

@morinmorin
Copy link
Contributor

Description
After recent developer tools update on macOS Sonoma (i.e. "Command Line Tools for Xcode 15.3"), some Catch2 headers fail to compile on GCC.

Test case

// v2's `single_include/catch2/catch.hpp` includes `TargetConditionals.h`
#include <catch2/catch.hpp>

and

// v3's `catch2/internal/catch_platform.hpp`, which is included by `catch2/catch_all.hpp`, includes `TargetConditionals.h`
#include <catch2/catch_all.hpp>

fail to compile on GCC 13 or earlier, after updating to "Command Line Tools for Xcode 15.3".

Background
"Command Line Tools for Xcode 15.3" introduces a problematic code at Line 140 of usr/include/TargetConditionals.h (i.e. MacOSX14.4.sdk/usr/include/TargetConditionals.h):

#if !defined(__has_extension) || # !__has_extension(define_target_os_macros)

This is problematic, since compilers without __has_extension support cause compilation failure with it. Notably, GCC does not support __has_extension until the next release (GCC 14).

(I think this should be fixed upstream by Apple, but ...) it may make some sense to add guard for __has_extension:

#ifdef __APPLE__
#  ifndef __has_extension
#  define __has_extension(x) 0
#  endif
#  include <TargetConditionals.h>
@horenmar
Copy link
Member

Why does the compilation fail there? Is this a hard error?

@morinmorin
Copy link
Contributor Author

Yes, that's hard errors. For example, on mac with the latest developer tools, this

echo '#include <catch2/catch_all.hpp>' | g++-13 -xc++ -

produces the following error messages

In file included from catch2/internal/catch_platform.hpp:14,
                 from catch2/internal/catch_compiler_capabilities.hpp:27,
                 from catch2/benchmark/catch_benchmark.hpp:14,
                 from catch2/benchmark/catch_benchmark_all.hpp:24,
                 from catch2/catch_all.hpp:25,
                 from <stdin>:1:
/usr/include/TargetConditionals.h:140:50: error: missing binary operator before token "("
  140 | #if !defined(__has_extension) || !__has_extension(define_target_os_macros)

The code !__has_extension(define_target_os_macros) causes compilation failure, because __has_extension is not supported/defined on GCC (until the next release of GCC).

@horenmar
Copy link
Member

Hmmm, yeah there was a reason why we are checking headers like this

#if defined(__has_include)
  #if __has_include(<string_view>) && defined(CATCH_CPP17_OR_GREATER)

I'll accept a PR that adds the workaround.

@morinmorin
Copy link
Contributor Author

Thanks. I'll submit PR later.

Blyschak added a commit to Blyschak/co_ecs that referenced this issue Mar 30, 2024
Signed-off-by: Blyschak <stepanblischak@gmail.com>
hbeni added a commit to hbeni/fgcom-mumble that referenced this issue May 13, 2024
- Build scripts now to g++13 with classic linker
- Catch2 picked fix catchorg/Catch2#2837

With the new macOS linker the build fails with a weird error.
Turned out, we need gcc13 together with the classic linker to successfully build on the github runner.
hbeni added a commit to hbeni/fgcom-mumble that referenced this issue May 13, 2024
- Build scripts now to g++13 with classic linker
- Catch2 picked fix catchorg/Catch2#2837

With the new macOS linker the build fails with a weird error.
Turned out, we need gcc13 together with the classic linker to successfully build on the github runner.
hbeni added a commit to hbeni/fgcom-mumble that referenced this issue May 13, 2024
- Build scripts now to g++13 with classic linker
- Catch2 picked fix catchorg/Catch2#2837

With the new macOS linker the build fails with a weird error.
Turned out, we need gcc13 together with the classic linker to successfully build on the github runner.
SergNikitin added a commit to Tabonita/Algos that referenced this issue Jun 2, 2024
SergNikitin added a commit to Tabonita/Algos that referenced this issue Jun 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants