The C++ Standard Library: clang++とg++でコンパイルしてみた(9)num

More than 1 year has passed since last update.

The C++ Standard Library - A Tutorial and Reference, 2nd Edition by Nicolai M. Josuttis

http://cppstdlib.com

The C++ Standard Library: clang++とg++でコンパイルしてみた(まとめ)

https://qiita.com/kaizen_nagoya/items/9bdfaa392443d13e5759


目的(purpose)

The C++ Standard Libraryコンパイル記録は、コンパイラおよび対応標準、コンパイラの版により、コンパイルエラーMessageの違いを記録し、どのエラーが出たら、どの版またはどの対応標準にすればエラーが少なくなるかを考察するための資料の第一歩です。


成果(outcome)

(1)コンパイラの種類、対応標準の違いによってエラーの数が違う。

(2)同じエラーであってもMessageの表現が違う。

(3) Error Messageのネットで検索する際に役立つ。


編纂器(compiler)


clang++

clang version 6.0.0 (tags/RELEASE_600/final)

Target: x86_64-apple-darwin17.5.0

Thread model: posix

InstalledDir: /usr/local/opt/llvm/bin


g++

g++ (Homebrew GCC 8.1.0) 8.1.0

Copyright (C) 2018 Free Software Foundation, Inc.

This is free software; see the source for copying conditions. There is NO

warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.


編纂実行(compile and go)


num


num

clang++ ./num/complex1.cpp -std=c++2a -Wall

c1: (4,3)
c2: (3.65844,3.40819)
c1: magnitude: 5 (squared magnitude: 25) phase angle: 0.643501
c2: magnitude: 5 (squared magnitude: 25) phase angle: 0.75
c1 conjugated: (4,-3)
c2 conjugated: (3.65844,-3.40819)
4.4 + c1 * 1.8: (11.6,5.4)
c1 + c2: (7.65844,6.40819)
c1 += sqrt(c1): (6.12132,3.70711)
g++ ./num/complex1.cpp -std=c++2a -Wall
c1: (4,3)
c2: (3.65844,3.40819)
c1: magnitude: 5 (squared magnitude: 25) phase angle: 0.643501
c2: magnitude: 5 (squared magnitude: 25) phase angle: 0.75
c1 conjugated: (4,-3)
c2 conjugated: (3.65844,-3.40819)
4.4 + c1 * 1.8: (11.6,5.4)
c1 + c2: (7.65844,6.40819)
c1 += sqrt(c1): (6.12132,3.70711)
clang++ ./num/complex2.cpp -std=c++2a -Wall
complex number c1: input error
g++ ./num/complex2.cpp -std=c++2a -Wall

complex2でclang++は入力待ちになる。どちらも

12, 34, 56, 77と入力すると次のようになる。

$./a.out

12
complex number c1: complex number c2: 34
c1 raised to the c2: (4.92224e+36,0)

45
complex number c1: complex number c2: 67
c1 raised to the c2: (5.82423e+110,0)

$ ../cga.sh num2

clang++ dist1.cpp -std=c++2a -Wall
uniform_real_distribution:
- min(): 0
- max(): 10
- values: 3.83416 9.47764 1.30427 8.30965
====
0: 20087
1: 20057
2: 19878
3: 19877
4: 20005
5: 20118
6: 20063
7: 19886
8: 20003
9: 20026
====

normal_distribution:
- min(): -inf
- max(): inf
- values: -0.140331 0.538967 -0.131724 0.117963
====
-4: 9
-3: 245
-2: 4325
-1: 26843
0: 136947
1: 26987
2: 4377
3: 258
4: 9
====

exponential_distribution:
- min(): 0
- max(): inf
- values: 0.48356 2.95199 0.139753 1.77765
====
0: 126327
1: 46637
2: 17118
3: 6226
4: 2337
5: 865
6: 313
7: 108
8: 38
9: 22
10: 6
11: 2
12: 1
====

gamma_distribution:
- min(): 0
- max(): inf
- values: 0.48356 2.95199 0.139753 1.77765
====
0: 126327
1: 46637
2: 17118
3: 6226
4: 2337
5: 865
6: 313
7: 108
8: 38
9: 22
10: 6
11: 2
12: 1
====

g++ dist1.cpp -std=c++2a -Wall
uniform_real_distribution:
- min(): 0
- max(): 10
- values: 3.83416 9.47764 1.30427 8.30965
====
0: 20087
1: 20057
2: 19878
3: 19877
4: 20005
5: 20118
6: 20063
7: 19886
8: 20003
9: 20026
====

normal_distribution:
- min(): -1.79769e+308
- max(): 1.79769e+308
- values: 0.538967 -0.140331 0.117963 -0.131724
====
-4: 9
-3: 245
-2: 4325
-1: 26843
0: 136947
1: 26987
2: 4377
3: 258
4: 9
====

exponential_distribution:
- min(): 0
- max(): 1.79769e+308
- values: 0.48356 2.95199 0.139753 1.77765
====
0: 126327
1: 46637
2: 17118
3: 6226
4: 2337
5: 865
6: 313
7: 108
8: 38
9: 22
10: 6
11: 2
12: 1
====

gamma_distribution:
- min(): 0
- max(): 1.79769e+308
- values: 1.21066 0.558526 1.60557 0.117964
====
0: 126315
1: 46477
2: 17160
3: 6271
4: 2413
5: 866
6: 327
7: 109
8: 41
9: 12
10: 7
11: 1
12: 1
====

clang++ gslice1.cpp -std=c++2a -Wall
0 1 2
3 4 5
6 7 8
9 10 11

12 13 14
15 16 17
18 19 20
21 22 23

3 1 2
9 4 5
15 7 8
9 10 11

27 13 14
33 16 17
39 19 20
21 22 23

g++ gslice1.cpp -std=c++2a -Wall
gslice1.cpp: In instantiation of 'void printValarray3D(const std::valarray<_Tp>&, int, int) [with T = double]':
gslice1.cpp:45:30: required from here
gslice1.cpp:19:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::size_t' {aka 'long unsigned int'} [-Wsign-compare]
for (int i=0; i<va.size()/(dim1*dim2); ++i) {
~^~~~~~~~~~~~~~~~~~~~~~
0 1 2
3 4 5
6 7 8
9 10 11

12 13 14
15 16 17
18 19 20
21 22 23

3 1 2
9 4 5
15 7 8
9 10 11

27 13 14
33 16 17
39 19 20
21 22 23

clang++ indirectarray1.cpp -std=c++2a -Wall
1.01 2.02 3.03 4.04
5.05 6.06 7.07 8.08
9.09 10.1 11.11 12.12

9.09 1.01 4.04 8.08

9.09 11.11 44.44 8.08

11.11 99 99 44.44
5.05 99 7.07 8.08
99 10.1 11.11 12.12

g++ indirectarray1.cpp -std=c++2a -Wall
indirectarray1.cpp: In instantiation of 'void printValarray(const std::valarray<_Tp>&, int) [with T = double]':
indirectarray1.cpp:37:23: required from here
indirectarray1.cpp:19:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::size_t' {aka 'long unsigned int'} [-Wsign-compare]
for (int i=0; i<va.size()/num; i++) {
~^~~~~~~~~~~~~~
1.01 2.02 3.03 4.04
5.05 6.06 7.07 8.08
9.09 10.1 11.11 12.12

9.09 1.01 4.04 8.08

9.09 11.11 44.44 8.08

11.11 99 99 44.44
5.05 99 7.07 8.08
99 10.1 11.11 12.12

clang++ maskarray1.cpp -std=c++2a -Wall
0 1 2
3 4 5
6 7 8
9 10 11

77 77 77
77 77 5
106 107 108
9 10 11

g++ maskarray1.cpp -std=c++2a -Wall
maskarray1.cpp: In instantiation of 'void printValarray(const std::valarray<_Tp>&, int) [with T = double]':
maskarray1.cpp:40:25: required from here
maskarray1.cpp:19:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::size_t' {aka 'long unsigned int'} [-Wsign-compare]
for (int i=0; i<va.size()/num; ++i) {
~^~~~~~~~~~~~~~
0 1 2
3 4 5
6 7 8
9 10 11

77 77 77
77 77 5
106 107 108
9 10 11

clang++ random1.cpp -std=c++2a -Wall
11 15 10 12 10 18 12 12 20 18 12 18 11 13 10 13 16 18 13 19
19.0684 19.3624 13.0846 13.9543 16.8914 15.9241 16.0948 15.9955
1 9 2 6 3 5 7 4 8
g++ random1.cpp -std=c++2a -Wall
random1.cpp: In function 'int main()':
random1.cpp:41:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
for (int i=0; i<v.size(); ++i) {
~^~~~~~~~~
10 11 18 15 15 12 10 17 17 20 14 15 19 10 10 15 17 10 14 10
16.8677 19.3044 15.2693 16.5392 17.0119 17.622 10.4746 13.2823
5 2 8 4 3 6 7 1 9
clang++ random2.cpp -std=c++2a -Wall
48271 182605794 1291394886 1914720637 2078669041 407355683
48271 182605794 1291394886 1914720637 2078669041 407355683
2027382 1226992407 551494037 961371815 1404753842 2076553157
1105902161 854716505 564586691 1596680831 192302371 1203428207
1105902161 854716505 564586691 1596680831 192302371 1203428207
564586691 1596680831 192302371 1203428207 1250328747 1738531149
g++ random2.cpp -std=c++2a -Wall
16807 282475249 1622650073 984943658 1144108930 470211272
16807 282475249 1622650073 984943658 1144108930 470211272
705894 1126542223 1579310009 565444343 807934826 421520601
101027544 1457850878 1458777923 2007237709 823564440 1115438165
101027544 1457850878 1458777923 2007237709 823564440 1115438165
1458777923 2007237709 823564440 1115438165 1784484492 74243042
clang++ slice1.cpp -std=c++2a -Wall
0 1 2
3 4 5
6 7 8
9 10 11

1 1 2
1024 4 5
5.7648e+06 7 8
1e+11 10 11

1 1 4
1024 4 10
5.7648e+06 7 16
1e+11 10 22

32 2 3.16228

1 1 8
1024 4 20
5.7648e+06 7 32
1e+11 10 44

g++ slice1.cpp -std=c++2a -Wall
slice1.cpp: In instantiation of 'void printValarray(const T&, int) [with T = std::valarray<double>]':
slice1.cpp:40:25: required from here
slice1.cpp:19:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::size_t' {aka 'long unsigned int'} [-Wsign-compare]
for (int i=0; i<va.size()/num; ++i) {
~^~~~~~~~~~~~~~
slice1.cpp: In instantiation of 'void printValarray(const T&, int) [with T = std::_Expr<std::_UnClos<std::_Sqrt, std::_ValArray, double>, double>]':
slice1.cpp:57:63: required from here
slice1.cpp:19:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::size_t' {aka 'long unsigned int'} [-Wsign-compare]
0 1 2
3 4 5
6 7 8
9 10 11

1 1 2
1024 4 5
5.7648e+06 7 8
1e+11 10 11

1 1 4
1024 4 10
5.7648e+06 7 16
1e+11 10 22

32 2 3.16228

1 1 8
1024 4 20
5.7648e+06 7 32
1e+11 10 44

clang++ valarray1.cpp -std=c++2a -Wall
0 1.1 2.2 3.3 4.4 5.5 6.6 7.7 8.8 9.9
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1
min(): 0
max(): 9.9
sum(): 49.5

0 1.1 2.2 3.3 4.4 5.5 6.6 7.7 8.8 9.9
g++ valarray1.cpp -std=c++2a -Wall
valarray1.cpp: In instantiation of 'void printValarray(const std::valarray<_Tp>&) [with T = double]':
valarray1.cpp:39:22: required from here
valarray1.cpp:19:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::size_t' {aka 'long unsigned int'} [-Wsign-compare]
for (int i=0; i<va.size(); i++) {
0 1.1 2.2 3.3 4.4 5.5 6.6 7.7 8.8 9.9
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1
min(): 0
max(): 9.9
sum(): 49.5

0 1.1 2.2 3.3 4.4 5.5 6.6 7.7 8.8 9.9
clang++ valarray2.cpp -std=c++2a -Wall
0 1.1 2.2 3.3 4.4 5.5 6.6 7.7 8.8
0 2.2 4.4 6.6 8.8 11 13.2 15.4 17.6
10 12.2 14.4 16.6 18.8 21 23.2 25.4 27.6
4 6.58324 8.29762 9.86905 11.3665 12.8166 14.2332 15.6243 16.9952
g++ valarray2.cpp -std=c++2a -Wall
valarray2.cpp: In function 'int main()':
valarray2.cpp:29:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::size_t' {aka 'long unsigned int'} [-Wsign-compare]
for (int i=0; i<va.size(); i++) {
~^~~~~~~~~~
valarray2.cpp: In instantiation of 'void printValarray(const std::valarray<_Tp>&) [with T = double]':
valarray2.cpp:34:21: required from here
valarray2.cpp:19:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::size_t' {aka 'long unsigned int'} [-Wsign-compare]
for (int i=0; i<va.size(); i++) {
0 1.1 2.2 3.3 4.4 5.5 6.6 7.7 8.8
0 2.2 4.4 6.6 8.8 11 13.2 15.4 17.6
10 12.2 14.4 16.6 18.8 21 23.2 25.4 27.6
4 6.58324 8.29762 9.86905 11.3665 12.8166 14.2332 15.6243 16.9952


検討事項(agenda)

1) コンパイルエラーをなくす修正方法

2) 役に立つまたは意味のあるその他の出力


参考資料(reference)


プログラミング言語教育のXYZ

https://qiita.com/kaizen_nagoya/items/1950c5810fb5c0b07be4

プログラミング言語教育のXYZ(youtube)

https://www.youtube.com/watch?v=He1_tg4px-w&t=486s


Autosar Guidelines C++14

Autosar Guidelines C++14 example code compile list(1-169)

https://qiita.com/kaizen_nagoya/items/8ccbf6675c3494d57a76


C++N4741 2018

Working Draft, Standard for Programming Language C++

http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/n4741.pdf

C++N4741, 2018 Standard Working Draft on ISO/IEC 14882 sample code compile list

https://qiita.com/kaizen_nagoya/items/3294c014044550896010


C++N4606 2016

Working Draft, Standard for Programming Language C++

http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/n4606.pdf

C++N4606, 2016符号断片編纂一覧(example code compile list)

Working Draft 2016, ISO/IEC 14882(1)

https://qiita.com/kaizen_nagoya/items/df5d62c35bd6ed1c3d43/


 CEDD(Compile Error Driven Design)

初めての CEDD(Compile Error Driven Design) 8回直してコンパイル。

https://qiita.com/kaizen_nagoya/items/9494236aa1753f3fd1e1

コンパイルエラーを記録するとよい理由7つ

https://qiita.com/kaizen_nagoya/items/85c0e92b206883140e89

docker gnu(gcc/g++) and llvm(clang/clang++)

https://qiita.com/drafts/059874ea39c4de64c0f7

[C][C++]の国際規格案の例題をコンパイルするときの課題7つ。

https://qiita.com/kaizen_nagoya/items/5f4b155030259497c4de

C++N4606 Working Draft 2016, ISO/IEC 14882, C++ standardのコード断片をコンパイルするためにしていること

https://qiita.com/kaizen_nagoya/items/a8d7ee2f2e29e76c19c1

コンパイル用shell script C版(clangとgcc)とC++版(clang++とg++)

https://qiita.com/kaizen_nagoya/items/74220c0577a512c2d7da

Clang/Clang++(LLVM) gcc/g++(GNU) コンパイラ警告等比較

https://qiita.com/kaizen_nagoya/items/9a82b958cc3aeef0403f

C++2003とC++2017でコンパイルエラーになるならない事例集

https://qiita.com/kaizen_nagoya/items/a13ea3823441c430edff

Qiitaに投稿するCのStyle例(暫定)

https://qiita.com/kaizen_nagoya/items/946df1528a6a1ef2bc0d

cpprefjpのdecltypeをコンパイル試験

https://qiita.com/kaizen_nagoya/items/090909af702f0d5d8a67

MISRA C++ 5-0-16

https://qiita.com/kaizen_nagoya/items/7df2d4e05db724752a74

C++ Templates Part1 BASICS Chapter 3. Class Templates 3.2 Use of Class Template Stack stack1test.cpp

https://qiita.com/kaizen_nagoya/items/cd5fc49106fad5a4e9ed

ISO/IEC TS 17961:2013 C Secure Coding Rules(1) All list(to be confirmed)

https://qiita.com/kaizen_nagoya/items/54e056195c4f11b850a1

C言語(C++)に対する誤解、曲解、無理解、爽快。

https://qiita.com/kaizen_nagoya/items/3f3992c9722c1cee2e3a

C Puzzle Bookの有り難み5つ、C言語規格及びCコンパイラの特性を認識

https://qiita.com/kaizen_nagoya/items/d89a48c1536a02ecdec9

'wchar.h' file not found で困った clang++ macOS

https://qiita.com/kaizen_nagoya/items/de15cd46d657517fac11

Open POSIX Test Suiteの使い方を調べはじめました

https://qiita.com/kaizen_nagoya/items/644d5e407f5faf96e6dc

MISRA-C 2012 Referenceに掲載している文献の入手可能性を確認

https://qiita.com/kaizen_nagoya/items/96dc8b125e462d5575bb

どうやって MISRA Example Suiteをコンパイルするか

https://qiita.com/kaizen_nagoya/items/fbdbff5ff696e2ca7f00

MISRA C まとめ #include

https://qiita.com/kaizen_nagoya/items/f1a79a7cbd281607c7c9

「C++完全理解ガイド」の同意できること上位10

https://qiita.com/kaizen_nagoya/items/aa5744e0c4a8618c7671


文献履歴(document history)

ver. 0.10 初稿 20180616

ver. 0.11 まとめURL追記 20180625