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

gcc13 requires include <cstdint> for uint64_t #983

Merged
merged 2 commits into from
May 5, 2023

Conversation

mizar
Copy link
Contributor

@mizar mizar commented May 4, 2023

g++ 13 では、 testlib の場合、 uint64_t の使用に 標準ライブラリヘッダ <cstdint> のインクルードが必須となったようです。( g++ 12以前でも何らかの他のインクルードファイルを経由して <cstdint> が読み込まれていたのだと推測していますが、それが無くなったのかもしれません。)
私の環境の一つ (Archlinux) では、最近 gcc が 13 に更新されたためこの影響を受けたようです。

テスト手順例 (Docker + Archlinux):

docker run -it --rm archlinux:base-devel-20230430.0.146624
# git のインストール
pacman -Sy --noconfirm git

# 変更前コードのcheckout
# https://github.com/yosupo06/library-checker-problems/tree/cb2911f7c42bf40caf8d7ca719537dccf7b18aaf
mkdir -p ~/library-checker-problems
cd ~/library-checker-problems
git init
git remote add origin https://github.com/yosupo06/library-checker-problems.git
git fetch --depth 1 origin cb2911f7c42bf40caf8d7ca719537dccf7b18aaf
git checkout FETCH_HEAD

# g++ のバージョン確認
## gcc version 12.2.1 20230201 (GCC)
g++ -v

# ビルドテスト (正常終了)
g++ -O2 -std=c++17 -Wall -Wextra -Werror -Wno-unused-result -I ~/library-checker-problems/common -o ~/library-checker-problems/sample/many_aplusb/checker ~/library-checker-problems/sample/many_aplusb/checker.cpp

# clang のインストール、 gcc の更新
pacman -Sy --noconfirm clang gcc

# g++ のバージョン確認
## gcc version 13.1.1 20230429 (GCC)
g++ -v

# clang++ のバージョン確認
## clang version 15.0.7
clang++ -v

# ビルドテスト (エラー)
g++ -O2 -std=c++17 -Wall -Wextra -Werror -Wno-unused-result -I ~/library-checker-problems/common -o ~/library-checker-problems/sample/many_aplusb/checker ~/library-checker-problems/sample/many_aplusb/checker.cpp

# ビルドテスト (エラー)
clang++ -O2 -std=c++17 -Wall -Wextra -Werror -Wno-unused-result -I ~/library-checker-problems/common -o ~/library-checker-problems/sample/many_aplusb/checker ~/library-checker-problems/sample/many_aplusb/checker.cpp

# 提案コードのcheckout
git fetch --depth 1 origin 4c8c3ad4d34085c42b6cc887c9a6b969e4f1af4f
git checkout FETCH_HEAD

# ビルドテスト (正常終了)
g++ -O2 -std=c++17 -Wall -Wextra -Werror -Wno-unused-result -I ~/library-checker-problems/common -o ~/library-checker-problems/sample/many_aplusb/checker ~/library-checker-problems/sample/many_aplusb/checker.cpp

# ビルドテスト (正常終了)
clang++ -O2 -std=c++17 -Wall -Wextra -Werror -Wno-unused-result -I ~/library-checker-problems/common -o ~/library-checker-problems/sample/many_aplusb/checker ~/library-checker-problems/sample/many_aplusb/checker.cpp

テスト手順例 (Docker + Ubuntu 23.04 + g++-13):

docker run -it --rm ubuntu:23.04
# ミラーサイトからパッケージを取得する場合、以下の `sed` を実行
# ca-certificates パッケージをインストールする前に https ミラーサイトに接続すると
# `No system certificates available. Try installing ca-certificates.` と警告が発生するので留意)
## sed -i.bak -r 's!(deb|deb-src) \S+!\1 mirror://mirrors.ubuntu.com/mirrors.txt!' /etc/apt/sources.list

apt update

apt install -y ca-certificates

apt install -y clang-13 clang-14 clang-15 clang-16 g++-12 g++-13 git

# g++-12 のバージョン確認
## gcc version 12.2.0 (Ubuntu 12.2.0-17ubuntu1)
g++-12 -v

# g++-13 のバージョン確認
## gcc version 13.0.1 20230320 (experimental) [master r13-6759-g5194ad1958c] (Ubuntu 13-20230320-1ubuntu1)
g++-13 -v

# clang++-13 のバージョン確認
## Ubuntu clang version 13.0.1-11ubuntu14
clang++-13 -v

# clang++-14 のバージョン確認
## Ubuntu clang version 14.0.6
clang++-14 -v

# clang++-15 のバージョン確認
## Ubuntu clang version 15.0.7
clang++-15 -v

# clang++-16 のバージョン確認
## Ubuntu clang version 16.0.0 (1~exp5ubuntu3)
clang++-16 -v

# 変更前コードのcheckout
# https://github.com/yosupo06/library-checker-problems/tree/cb2911f7c42bf40caf8d7ca719537dccf7b18aaf
mkdir -p ~/library-checker-problems
cd ~/library-checker-problems
git init
git remote add origin https://github.com/yosupo06/library-checker-problems.git
git fetch --depth 1 origin cb2911f7c42bf40caf8d7ca719537dccf7b18aaf
git checkout FETCH_HEAD

# ビルドテスト (正常終了)
g++-12 -O2 -std=c++17 -Wall -Wextra -Werror -Wno-unused-result -I ~/library-checker-problems/common -o ~/library-checker-problems/sample/many_aplusb/checker ~/library-checker-problems/sample/many_aplusb/checker.cpp

# ビルドテスト (エラー)
g++-13 -O2 -std=c++17 -Wall -Wextra -Werror -Wno-unused-result -I ~/library-checker-problems/common -o ~/library-checker-problems/sample/many_aplusb/checker ~/library-checker-problems/sample/many_aplusb/checker.cpp

# ビルドテスト (エラー) Ubuntu 23.04 の場合は clang++-13, clang++-14, clang++-15 でも同様にエラー
## Ubuntu 22.04 の clang++-13, clang++-14, clang++-15 ではエラーは出ない
clang++-16 -O2 -std=c++17 -Wall -Wextra -Werror -Wno-unused-result -I ~/library-checker-problems/common -o ~/library-checker-problems/sample/many_aplusb/checker ~/library-checker-problems/sample/many_aplusb/checker.cpp

# 提案コードのcheckout
# https://github.com/yosupo06/library-checker-problems/tree/4c8c3ad4d34085c42b6cc887c9a6b969e4f1af4f
git fetch --depth 1 origin 4c8c3ad4d34085c42b6cc887c9a6b969e4f1af4f
git checkout FETCH_HEAD

# ビルドテスト (正常終了)
g++-12 -O2 -std=c++17 -Wall -Wextra -Werror -Wno-unused-result -I ~/library-checker-problems/common -o ~/library-checker-problems/sample/many_aplusb/checker ~/library-checker-problems/sample/many_aplusb/checker.cpp

# ビルドテスト (正常終了)
g++-13 -O2 -std=c++17 -Wall -Wextra -Werror -Wno-unused-result -I ~/library-checker-problems/common -o ~/library-checker-problems/sample/many_aplusb/checker ~/library-checker-problems/sample/many_aplusb/checker.cpp

# ビルドテスト (正常終了)
clang++-16 -O2 -std=c++17 -Wall -Wextra -Werror -Wno-unused-result -I ~/library-checker-problems/common -o ~/library-checker-problems/sample/many_aplusb/checker ~/library-checker-problems/sample/many_aplusb/checker.cpp

エラー出力例 (g++ 13):

In file included from /root/library-checker-problems/sample/many_aplusb/checker.cpp:25:
/root/library-checker-problems/common/testlib.h: In member function 'std::vector<T> random_t::distinct(int, T, T)':
/root/library-checker-problems/common/testlib.h:1136:9: error: 'uint64_t' was not declared in this scope
 1136 |         uint64_t n = to - from + 1;
      |         ^~~~~~~~
/root/library-checker-problems/common/testlib.h:207:1: note: 'uint64_t' is defined in header '<cstdint>'; did you forget to '#include <cstdint>'?
  206 | #   include <unistd.h>
  +++ |+#include <cstdint>
  207 | #endif
/root/library-checker-problems/common/testlib.h:1137:30: error: 'n' was not declared in this scope
 1137 |         if (uint64_t(size) > n)
      |                              ^
/root/library-checker-problems/common/testlib.h:1142:32: error: 'n' was not declared in this scope
 1142 |             expected += double(n) / double(n - i + 1);
      |                                ^
/root/library-checker-problems/common/testlib.h:1144:31: error: 'n' was not declared in this scope
 1144 |         if (expected < double(n)) {
      |                               ^

エラー出力例 (clang++ 15):

In file included from /root/library-checker-problems/sample/many_aplusb/checker.cpp:25:
/root/library-checker-problems/common/testlib.h:1136:9: error: unknown type name 'uint64_t'
        uint64_t n = to - from + 1;
        ^
/root/library-checker-problems/common/testlib.h:1137:13: error: use of undeclared identifier 'uint64_t'
        if (uint64_t(size) > n)
            ^
2 errors generated.

common/testlib.h Outdated Show resolved Hide resolved
Co-authored-by: Kohei Morita <yosupo06@gmail.com>
@yosupo06 yosupo06 merged commit 19ba462 into yosupo06:master May 5, 2023
@mizar mizar deleted the gcc13-cstdint branch May 5, 2023 22:21
@mizar
Copy link
Contributor Author

mizar commented May 6, 2023

Ubuntu 23.04 では、 g++-13 がインストールされているか否かによって、 clang++ でのビルドにて uint64_t について怒られるか否かが変わるようです。

Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/12
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/13
Selected GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/13

手順例: (docker + ubuntu 23.04)

docker run -it --rm ubuntu:23.04
apt update

apt install -y ca-certificates

apt install -y clang-13 clang-14 clang-15 clang-16 g++-12 g++-13 git

mkdir -p ~/library-checker-problems
cd ~/library-checker-problems
git init
git remote add origin https://github.com/yosupo06/library-checker-problems.git
git fetch --depth 1 origin cb2911f7c42bf40caf8d7ca719537dccf7b18aaf
git checkout FETCH_HEAD

clang++-16 -O2 -std=c++17 -Wall -Wextra -Werror -Wno-unused-result -v -I ~/library-checker-problems/common -o ~/library-checker-problems/sample/many_aplusb/checker ~/library-checker-problems/sample/many_aplusb/checker.cpp

出力例:

Ubuntu clang version 16.0.0 (1~exp5ubuntu3)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/12
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/13
Selected GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/13
Candidate multilib: .;@m64
Selected multilib: .;@m64
 "/usr/lib/llvm-16/bin/clang" -cc1 -triple x86_64-pc-linux-gnu -emit-obj -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name checker.cpp -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=none -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -mllvm -treat-scalable-fixed-error-as-warning -debugger-tuning=gdb -v -fcoverage-compilation-dir=/root/library-checker-problems -resource-dir /usr/lib/llvm-16/lib/clang/16 -I /root/library-checker-problems/common -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13 -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/13/../../../../include/x86_64-linux-gnu/c++/13 -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13/backward -internal-isystem /usr/lib/llvm-16/lib/clang/16/include -internal-isystem /usr/local/include -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/13/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O2 -Wall -Wextra -Werror -Wno-unused-result -std=c++17 -fdeprecated-macro -fdebug-compilation-dir=/root/library-checker-problems -ferror-limit 19 -fgnuc-version=4.2.1 -fcxx-exceptions -fexceptions -fcolor-diagnostics -vectorize-loops -vectorize-slp -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/checker-d49298.o -x c++ /root/library-checker-problems/sample/many_aplusb/checker.cpp
clang -cc1 version 16.0.0 based upon LLVM 16.0.0 default target x86_64-pc-linux-gnu
ignoring nonexistent directory "/usr/bin/../lib/gcc/x86_64-linux-gnu/13/../../../../x86_64-linux-gnu/include"
ignoring nonexistent directory "/include"
#include "..." search starts here:
#include <...> search starts here:
 /root/library-checker-problems/common
 /usr/bin/../lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13
 /usr/bin/../lib/gcc/x86_64-linux-gnu/13/../../../../include/x86_64-linux-gnu/c++/13
 /usr/bin/../lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13/backward
 /usr/lib/llvm-16/lib/clang/16/include
 /usr/local/include
 /usr/include/x86_64-linux-gnu
 /usr/include
End of search list.
In file included from /root/library-checker-problems/sample/many_aplusb/checker.cpp:25:
/root/library-checker-problems/common/testlib.h:1136:9: error: unknown type name 'uint64_t'
        uint64_t n = to - from + 1;
        ^
/root/library-checker-problems/common/testlib.h:1137:13: error: use of undeclared identifier 'uint64_t'
        if (uint64_t(size) > n)
            ^
2 errors generated.

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

Successfully merging this pull request may close these issues.

2 participants