LoginSignup
0
0

More than 5 years have passed since last update.

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

Last updated at Posted at 2018-06-17

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)
##cont

```shell-session:cont
$ ./cga.sh  cont/cont
clang++ ./cont/array1.cpp -std=c++2a -Wall
11 22 33 44 0 0 0 0 0 0 
11 22 33 44 0 0 0 0 42 9999999 
sum: 10000151
-11 -22 -33 -44 0 0 0 0 -42 -9999999 
g++ ./cont/array1.cpp -std=c++2a -Wall
11 22 33 44 0 0 0 0 0 0 
11 22 33 44 0 0 0 0 42 9999999 
sum: 10000151
-11 -22 -33 -44 0 0 0 0 -42 -9999999 
clang++ ./cont/cstylearray1.cpp -std=c++2a -Wall
33 67 -4 13 5 2 
g++ ./cont/cstylearray1.cpp -std=c++2a -Wall
33 67 -4 13 5 2 
clang++ ./cont/cstylearray1old.cpp -std=c++2a -Wall
25 1 4 9 16 36 
g++ ./cont/cstylearray1old.cpp -std=c++2a -Wall
25 1 4 9 16 36 
clang++ ./cont/deque1.cpp -std=c++2a -Wall
first string
string
string
string
last string

string
another string
another string
resized string
g++ ./cont/deque1.cpp -std=c++2a -Wall
first string
string
string
string
last string

string
another string
another string
resized string
clang++ ./cont/forwardlist1.cpp -std=c++2a -Wall
initial:
 list1: 1 2 3 4 
 list2: 77 88 99 
6 new elems:
 list1: 1 2 3 4 
 list2: 10 11 12 13 10 99 77 88 99 
list2 into list1:
 list1: 10 11 12 13 10 99 77 88 99 1 2 3 4 
 list2: 10 11 12 13 10 99 77 88 99 
delete 2nd and after 99:
 list1: 10 11 12 13 10 99 77 88 99 1 2 3 4 
 list2: 10 12 13 10 99 
sorted and unique:
 list1: 1 2 3 4 10 10 11 12 13 77 88 99 99 
 list2: 1 2 3 4 10 11 12 13 77 88 99 
merged:
 list1: 1 1 2 2 3 3 4 4 10 10 10 11 11 12 12 13 13 77 77 88 88 99 99 99 
 list2: 
g++ ./cont/forwardlist1.cpp -std=c++2a -Wall
initial:
 list1: 1 2 3 4 
 list2: 77 88 99 
6 new elems:
 list1: 1 2 3 4 
 list2: 10 11 12 13 10 99 77 88 99 
list2 into list1:
 list1: 10 11 12 13 10 99 77 88 99 1 2 3 4 
 list2: 10 11 12 13 10 99 77 88 99 
delete 2nd and after 99:
 list1: 10 11 12 13 10 99 77 88 99 1 2 3 4 
 list2: 10 12 13 10 99 
sorted and unique:
 list1: 1 2 3 4 10 10 11 12 13 77 88 99 99 
 list2: 1 2 3 4 10 11 12 13 77 88 99 
merged:
 list1: 1 1 2 2 3 3 4 4 10 10 10 11 11 12 12 13 13 77 77 88 88 99 99 99 
 list2: 
clang++ ./cont/forwardlistfind1.cpp -std=c++2a -Wall
1 42 2 3 4 5 97 98 99 
g++ ./cont/forwardlistfind1.cpp -std=c++2a -Wall
1 42 2 3 4 5 97 98 99 
clang++ ./cont/forwardlistsplice1.cpp -std=c++2a -Wall
l1: 1 2 4 5 
l2: 97 98 3 99 
g++ ./cont/forwardlistsplice1.cpp -std=c++2a -Wall
l1: 1 2 4 5 
l2: 97 98 3 99 
clang++ ./cont/hashfunc1.cpp -std=c++2a -Wall
[nico,josuttis,42] 
g++ ./cont/hashfunc1.cpp -std=c++2a -Wall
[nico,josuttis,42] 
clang++ ./cont/hashfunc2.cpp -std=c++2a -Wall
[nico,josuttis,42] 
g++ ./cont/hashfunc2.cpp -std=c++2a -Wall
[nico,josuttis,42] 
clang++ ./cont/list1.cpp -std=c++2a -Wall
list1: 0 1 2 3 4 5 
list2: 5 4 3 2 1 0 

list1: 
list2: 5 4 0 1 2 3 4 5 3 2 1 0 

list1: 
list2: 4 0 1 2 3 4 5 3 2 1 0 5 

list1: 0 0 1 1 2 2 3 3 4 4 5 5 
list2: 0 1 2 3 4 5 

list1: 0 0 0 1 1 1 2 2 2 3 3 3 4 4 4 5 5 5 
list2: 

g++ ./cont/list1.cpp -std=c++2a -Wall
list1: 0 1 2 3 4 5 
list2: 5 4 3 2 1 0 

list1: 
list2: 5 4 0 1 2 3 4 5 3 2 1 0 

list1: 
list2: 4 0 1 2 3 4 5 3 2 1 0 5 

list1: 0 0 1 1 2 2 3 3 4 4 5 5 
list2: 0 1 2 3 4 5 

list1: 0 0 0 1 1 1 2 2 2 3 3 3 4 4 4 5 5 5 
list2: 

clang++ ./cont/map1.cpp -std=c++2a -Wall
struppi: 138.533
tim: 98.01
g++ ./cont/map1.cpp -std=c++2a -Wall
struppi: 138.533
tim: 98.01
clang++ ./cont/map2.cpp -std=c++2a -Wall
stock: BASF        price: 369.5
stock: BMW         price: 834
stock: Daimler     price: 819
stock: Siemens     price: 842.2
stock: VW          price: 413.5

stock: BASF        price: 739
stock: BMW         price: 1668
stock: Daimler     price: 1638
stock: Siemens     price: 1684.4
stock: VW          price: 827

stock: BASF        price: 739
stock: BMW         price: 1668
stock: Daimler     price: 1638
stock: Siemens     price: 1684.4
stock: Volkswagen  price: 827
g++ ./cont/map2.cpp -std=c++2a -Wall
stock: BASF        price: 369.5
stock: BMW         price: 834
stock: Daimler     price: 819
stock: Siemens     price: 842.2
stock: VW          price: 413.5

stock: BASF        price: 739
stock: BMW         price: 1668
stock: Daimler     price: 1638
stock: Siemens     price: 1684.4
stock: VW          price: 827

stock: BASF        price: 739
stock: BMW         price: 1668
stock: Daimler     price: 1638
stock: Siemens     price: 1684.4
stock: Volkswagen  price: 827
clang++ ./cont/mapcmp1.cpp -std=c++2a -Wall
Bestatter       undertaker
Deutschland     Germany
Haken           snag
Hund            dog
Unternehmen     enterprise
arbeiten        work
deutsch         German
gehen           walk
unternehmen     undertake

arbeiten        work
Bestatter       undertaker
deutsch         German
Deutschland     Germany
gehen           walk
Haken           snag
Hund            dog
Unternehmen     undertake

g++ ./cont/mapcmp1.cpp -std=c++2a -Wall
Bestatter       undertaker
Deutschland     Germany
Haken           snag
Hund            dog
Unternehmen     enterprise
arbeiten        work
deutsch         German
gehen           walk
unternehmen     undertake

arbeiten        work
Bestatter       undertaker
deutsch         German
Deutschland     Germany
gehen           walk
Haken           snag
Hund            dog
Unternehmen     undertake

clang++ ./cont/mapfind1.cpp -std=c++2a -Wall
key 3.0 found (3:2)
value 3.0 found (4:3)
g++ ./cont/mapfind1.cpp -std=c++2a -Wall
key 3.0 found (3:2)
value 3.0 found (4:3)
clang++ ./cont/multimap1.cpp -std=c++2a -Wall
 english   german 
--------------------
 car       Auto
 clever    raffiniert
 day       Tag
 smart     elegant
 smart     raffiniert
 smart     klug
 strange   fremd
 strange   seltsam
 trait     Merkmal

smart: 
    elegant
    raffiniert
    klug
raffiniert: 
    clever
    smart
g++ ./cont/multimap1.cpp -std=c++2a -Wall
 english   german 
--------------------
 car       Auto
 clever    raffiniert
 day       Tag
 smart     elegant
 smart     raffiniert
 smart     klug
 strange   fremd
 strange   seltsam
 trait     Merkmal

smart: 
    elegant
    raffiniert
    klug
raffiniert: 
    clever
    smart
clang++ ./cont/multiset1.cpp -std=c++2a -Wall
6 5 5 4 3 2 1 
4 inserted as element 5
1 2 3 4 4 5 5 6 
2 element(s) removed
3 4 4 6 
g++ ./cont/multiset1.cpp -std=c++2a -Wall
6 5 5 4 3 2 1 
4 inserted as element 5
1 2 3 4 4 5 5 6 
2 element(s) removed
3 4 4 6 
clang++ ./cont/refsem1.cpp -std=c++2a -Wall
./cont/refsem1.cpp:36:5: warning: control reaches end of non-void function [-Wreturn-type]
    }
    ^
1 warning generated.
bestsellers:
 Kong Yize: 20.1
 A Midsummer Night's Dream: 14.99
 The Maltese Falcon: 9.88
all:
 Kong Yize: 20.1
 A Midsummer Night's Dream: 14.99
 Water: 0.44
 The Maltese Falcon: 9.88
 Pizza: 2.22

./cga.sh: line 16:  7369 Illegal instruction: 4  ./$line.exe
g++ ./cont/refsem1.cpp -std=c++2a -Wall
./cont/refsem1.cpp: In member function 'float Item::setPrice(float)':
./cont/refsem1.cpp:36:5: warning: no return statement in function returning non-void [-Wreturn-type]
     }
     ^
bestsellers:
 Kong Yize: 20.1
 A Midsummer Night's Dream: 14.99
 The Maltese Falcon: 9.88
all:
 Kong Yize: 20.1
 A Midsummer Night's Dream: 14.99
 The Maltese Falcon: 9.88
 Water: 0.44
 Pizza: 2.22

bestsellers:
 Kong Yize: 44.77
 Pizza: 2.22
 The Maltese Falcon: 19.76
all:
 Kong Yize: 44.77
 A Midsummer Night's Dream: 29.98
 The Maltese Falcon: 19.76
 Water: 0.44
 Pizza: 2.22
clang++ ./cont/refwrap1.cpp -std=c++2a -Wall
./cont/refwrap1.cpp:36:5: warning: control reaches end of non-void function [-Wreturn-type]
    }
    ^
./cont/refwrap1.cpp:41:47: error: implicit instantiation of undefined template 'std::__1::vector<std::__1::reference_wrapper<Item>,
      std::__1::allocator<std::__1::reference_wrapper<Item> > >'
    std::vector<std::reference_wrapper<Item>> books;  // elements are references
                                              ^
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/iosfwd:200:28: note: template is declared here
class _LIBCPP_TEMPLATE_VIS vector;
                           ^
1 warning and 1 error generated.
g++ ./cont/refwrap1.cpp -std=c++2a -Wall
./cont/refwrap1.cpp: In member function 'float Item::setPrice(float)':
./cont/refwrap1.cpp:36:5: warning: no return statement in function returning non-void [-Wreturn-type]
     }
     ^
./cont/refwrap1.cpp: In function 'int main()':
./cont/refwrap1.cpp:41:10: error: 'vector' is not a member of 'std'
     std::vector<std::reference_wrapper<Item>> books;  // elements are references
          ^~~~~~
./cont/refwrap1.cpp:41:10: note: 'std::vector' is defined in header '<vector>'; did you forget to '#include <vector>'?
./cont/refwrap1.cpp:17:1:
+#include <vector>

./cont/refwrap1.cpp:41:10:
     std::vector<std::reference_wrapper<Item>> books;  // elements are references
          ^~~~~~
./cont/refwrap1.cpp:41:44: error: expected primary-expression before '>' token
     std::vector<std::reference_wrapper<Item>> books;  // elements are references
                                            ^~
./cont/refwrap1.cpp:41:47: error: 'books' was not declared in this scope
     std::vector<std::reference_wrapper<Item>> books;  // elements are references
                                               ^~~~~
./cont/refwrap1.cpp:41:47: note: suggested alternative: 'bool'
     std::vector<std::reference_wrapper<Item>> books;  // elements are references
                                               ^~~~~
                                               bool
./cont/refwrap1.cpp:47:29: error: unable to deduce 'auto&&' from 'books'
     for (const auto& book : books) {
                             ^~~~~
./cont/refwrap1.cpp:56:29: error: unable to deduce 'auto&&' from 'books'
     for (const Item& book : books) {
                             ^~~~~
clang++ ./cont/set1.cpp -std=c++2a -Wall
6 5 4 3 2 1 
4 already exists
1 2 3 4 5 6 
1 element(s) removed
3 4 6 
g++ ./cont/set1.cpp -std=c++2a -Wall
6 5 4 3 2 1 
4 already exists
1 2 3 4 5 6 
1 element(s) removed
3 4 6 
clang++ ./cont/setcmp1.cpp -std=c++2a -Wall
coll1: 1 2 4 5 6 7 
coll2: 7 6 5 4 2 1 
coll1: 7 6 5 4 3 2 1 
coll1 and coll2 have the same sorting criterion
g++ ./cont/setcmp1.cpp -std=c++2a -Wall
coll1: 1 2 4 5 6 7 
coll2: 7 6 5 4 2 1 
coll1: 7 6 5 4 3 2 1 
coll1 and coll2 have the same sorting criterion
clang++ ./cont/setrange1.cpp -std=c++2a -Wall
lower_bound(3): 4
upper_bound(3): 4
equal_range(3): 4 4

lower_bound(5): 5
upper_bound(5): 6
equal_range(5): 5 6
g++ ./cont/setrange1.cpp -std=c++2a -Wall
lower_bound(3): 4
upper_bound(3): 4
equal_range(3): 4 4

lower_bound(5): 5
upper_bound(5): 6
equal_range(5): 5 6
clang++ ./cont/sortset.cpp -std=c++2a -Wall
./cont/sortvec.cpp
./cont/unordinspect1.cpp
./cont/unordmultimap1.cpp
./cont/unordmultiset1.cpp
./cont/unordset1.cpp
./cont/vector1.cpp
g++ ./cont/sortset.cpp -std=c++2a -Wall

検討事項(agenda)

1) コンパイルエラーをなくす修正方法
2) 役に立つまたは意味のあるその他の出力
3) タスク終了待ちのプログラムを短時間で終了設定できるように
4) スクリプトを終了してしまうプログラムは、次のスクリプトに引き継ぐ

参考資料(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

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0