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

building with clang fails with error: "ISO C++17 does not allow 'register' storage class specifier" #27

Open
BenWibking opened this issue Nov 15, 2022 · 6 comments

Comments

@BenWibking
Copy link

Building Amrvis fails with Apple Clang 14.0.0 (CommandLineTools 14.1.0):

Amrvis git:(main) ✗ gcc -v
Apple clang version 14.0.0 (clang-1400.0.29.202)
Target: arm64-apple-darwin22.1.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
Amrvis git:(main) ✗ pkgutil --pkg-info=com.apple.pkg.CLTools_Executables
package-id: com.apple.pkg.CLTools_Executables
version: 14.1.0.0.1.1666437224
volume: /
location: /
install-time: 1667353916
groups: com.apple.FindSystemFiles.pkg-group
Amrvis git:(main) ✗ make
Loading ../amrex/Tools/GNUMake/comps/gnu.mak...
Loading ../amrex/Tools/GNUMake/sites/Make.unknown...
Compiling AmrPicture.cpp ...
g++ -MMD -MP  -Werror=return-type -gdwarf-4 -O3 -std=c++17  -rdynamic -fno-omit-frame-pointer -pthread   -DAMREX_EXPORT_DYNAMIC  -DBL_SPACEDIM=3 -DAMREX_SPACEDIM=3 -DBL_FORT_USE_UNDERSCORE -DAMREX_FORT_USE_UNDERSCORE -DBL_Darwin -DAMREX_Darwin -DNDEBUG -DBL_OPTIO -Itmp_build_dir/s/3d.gnu.EXE -I. -I. -I../amrex/Src/Base -I../amrex/Src/Extern/amrdata -I/opt/homebrew/include -I/opt/X11/include -I/usr/include/ -I/usr/local/include -I/opt/local/include -I/opt/X11/include -I../amrex/Src/Base -I../amrex/Src/Base/Parser -I../amrex/Src/Extern/amrdata  -c AmrPicture.cpp -o tmp_build_dir/o/3d.gnu.EXE/AmrPicture.o
clang: warning: argument unused during compilation: '-rdynamic' [-Wunused-command-line-argument]
In file included from AmrPicture.cpp:7:
In file included from ./PltApp.H:9:
/opt/homebrew/include/Xm/Xm.h:1514:25: error: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
                        register int from_type,
                        ^~~~~~~~~
@WeiqunZhang
Copy link
Member

Why does gcc -v show it's Apple clang?

The register keyword is deprecated, but

The keyword is unused and reserved. | (since C++17)

https://en.cppreference.com/w/cpp/keyword/register

@BenWibking
Copy link
Author

I don't think there's any official documentation on this, but Apple has replaced /usr/bin/gcc with a binary that just runs Apple's version of clang for several years now (see e.g., https://www.quora.com/Why-does-the-gcc-command-on-MacOS-execute-clang).

The actual gcc binaries installed via Homebrew are available as gcc-11 or gcc-12, depending on the major version.

@BenWibking
Copy link
Author

Maybe the makefile could parse the output of either:

➜  ~ brew list gcc
/opt/homebrew/Cellar/gcc/12.2.0/bin/aarch64-apple-darwin21-c++-12
/opt/homebrew/Cellar/gcc/12.2.0/bin/aarch64-apple-darwin21-g++-12
/opt/homebrew/Cellar/gcc/12.2.0/bin/aarch64-apple-darwin21-gcc-12
/opt/homebrew/Cellar/gcc/12.2.0/bin/aarch64-apple-darwin21-gcc-ar-12
/opt/homebrew/Cellar/gcc/12.2.0/bin/aarch64-apple-darwin21-gcc-nm-12
/opt/homebrew/Cellar/gcc/12.2.0/bin/aarch64-apple-darwin21-gcc-ranlib-12
/opt/homebrew/Cellar/gcc/12.2.0/bin/aarch64-apple-darwin21-gfortran-12
/opt/homebrew/Cellar/gcc/12.2.0/bin/c++-12
/opt/homebrew/Cellar/gcc/12.2.0/bin/cpp-12
/opt/homebrew/Cellar/gcc/12.2.0/bin/g++-12
/opt/homebrew/Cellar/gcc/12.2.0/bin/gcc-12
/opt/homebrew/Cellar/gcc/12.2.0/bin/gcc-ar-12
/opt/homebrew/Cellar/gcc/12.2.0/bin/gcc-nm-12
/opt/homebrew/Cellar/gcc/12.2.0/bin/gcc-ranlib-12
/opt/homebrew/Cellar/gcc/12.2.0/bin/gcov-12
/opt/homebrew/Cellar/gcc/12.2.0/bin/gcov-dump-12
/opt/homebrew/Cellar/gcc/12.2.0/bin/gcov-tool-12
/opt/homebrew/Cellar/gcc/12.2.0/bin/gfortran
/opt/homebrew/Cellar/gcc/12.2.0/bin/gfortran-12
/opt/homebrew/Cellar/gcc/12.2.0/bin/lto-dump-12
/opt/homebrew/Cellar/gcc/12.2.0/include/c++/ (806 files)
/opt/homebrew/Cellar/gcc/12.2.0/lib/gcc/ (607 files)
/opt/homebrew/Cellar/gcc/12.2.0/libexec/gcc/ (14 files)
/opt/homebrew/Cellar/gcc/12.2.0/share/gcc-12/ (4 files)
/opt/homebrew/Cellar/gcc/12.2.0/share/man/ (11 files)
➜  ~ brew list --versions gcc
gcc 12.2.0

or else abort if gcc is actually clang when running on macOS?

@BenWibking
Copy link
Author

The register error is due to the fact that upstream clang has not supported the register keyword in C++17 mode since at least 2018 (https://lists.llvm.org/pipermail/llvm-dev/2018-December/128737.html).

@BenWibking BenWibking changed the title build fails with error: "ISO C++17 does not allow 'register' storage class specifier" building with clang fails with error: "ISO C++17 does not allow 'register' storage class specifier" Nov 15, 2022
@BenWibking
Copy link
Author

The root of the issue is that clang treats the deprecated register keyword as an error, whereas gcc still allows it with a warning (as of version 12).

On macOS, /usr/bin/gcc is actually a wrapper for Apple's build of clang, so AMReX needs to find the real gcc and invoke it instead. Homebrew installs gcc binaries appended with their major version number so as not to interfere with Apple's fake gcc. The major version number and binary path can be extracted from the output of brew list gcc and replace the compiler names currently used in amrex/Tools/GNUMake/comps/gnu.mak.

When I do this, I can successfully build Amrvis.

@BenWibking
Copy link
Author

Since this is an issue for all AMReX builds, I've created an issue for this in the AMReX repo: AMReX-Codes/amrex#3033

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants