2018年5月の記事一覧
link error collection
Undefined symbols:
"typeinfo for A", referenced from:
typeinfo for Bin cc8qkzDW.o
"vtable for A", referenced from:
A::A() in cc8qkzDW.o
0
C++ function collection (1) lambda 描きかけ
#目的
C++に限らず、コンパイルエラーがたくさん出るとめげる。
根本原因のエラーと、それに付属する関連エラーがあり、
根本原因エラーさえ取れば、みんなきれさっぱりなくなることがある。
複数のファイルにまたがるエラーは、相互に影響があり、どちらを直すとより効率的かを判断できないと無駄な作業が発生するかもしれない。
効率的にコンパイルエラーを取る方法を探るため、コンパイルエラー情報とその際の対応方法を収集する。
#成果
コンパイルエラーとその時の条件に従い、すぐにコンパイルエラーが取れるようになる。
コンパイルエラーが取れれば、printf(cout)デバッグができるかもしれない。
#関連
悲しいのはprintf(cout)デバッグをしようとすると、コンパイルエラーが出る時。
printf(cout)デバッグをしてもコンパイルエラーが出ない方法も順次追記する。
複雑な構造を持った新たなclassは、直接coutしようとせず、よく知った必要な型に変換して出力するのも手かも。
castしようとすると、castのコンパイルエラーが出るかもしれない。
castでコンパイルエラーが出ない方法を知っているとよい。
##一覧
C++ Error Message Collection(1)does not name a type, 11 articles
https://qiita.com/drafts/acb9f1a9b5aad6df06bd
C++ Error Message Collection(2)expected unqualified-id, 11 articles
https://qiita.com/kaizen_nagoya/items/bccd7341a5ce58e94370
C++ Error Message Collection(3)invalid operands to binary expression , 6 articles
https://qiita.com/drafts/dd7fd9266d2eb06a1283
#(4)expected ',' or ']' in lambda capture list
5.1.5 Lambda expressions
##3.1 error:Invalid operands to binary expression ('struct Number' and 'struct Number')
Invalid operands to binary expression エラーの対処方法
http://marycore.jp/prog/xcode/invalid-operands-to-binary-expression/
原因:構造体の比較
解決1:要素ごとの比較に変更。
解決2:演算子を定義。
##3.2 error: invalid operands to binary expression ('ostream' (aka 'basic_ostream<char>') and 'const std::__1::vector<int, std::__1::allocator<int> >')
c++のエラーについて @teratail 質問 freecss 回答 episteme
https://teratail.com/questions/67391
原因:「<<に対してconst vector<T>適用」。operandが違う。
解決:「2か所」「const」追記。
##3.3 invalid operands to binary expression ('double' and 'double')
浮動小数点の剰余計算をするための関数fmodf
http://memo755.blog.fc2.com/blog-entry-149.html
原因:「浮動小数で%演算子」
解決:fmodf関数を使用 うら紙のメモ hiiro
##3.4 error: invalid operands to binary expression ('int' and 'void')
第27回 条件演算子のちょっと便利な使い方 Theoride Technology
https://theolizer.com/cpp-school2/cpp-school2-27/
原因:「int型とvoid型の足し算はない」
解決:型を合わせる
上記サイトに、?:の三項演算子の後ろにthrow, voidという話を、
コンパイルエラーのMSGから展開しているところが興味深い。
関連コンパイルエラーの一覧を作るときに、また参照したい。
##3.5 : error: invalid operands to binary expression (std::_List_iterator<int> and std::_List_iterator<int>)
C++コンパイラ GCCとClangからのメッセージをお読みください
https://www.slideshare.net/digitalghost/bbk7
原因:listのbeginとendでsortできない。
解決:解説あり。最終的にどうしたか?
slideshareでコピペがし辛かった。再掲
###算譜(code)
```c++:err35.cpp
#include <list>
#include <algorithm>
int main(){
std::list<int> l;
std::sort(l.begin(), l.end());
}
```
###編纂・実行結果(compile and go)
```
$ clang++ err35.cpp
/Library/Developer/CommandLineTools/usr/include/c++/v1/algorithm:3898:40: error: invalid operands to binary expression ('std::__1::__list_iterator<int, void *>' and
'std::__1::__list_iterator<int, void *>')
difference_type __len = __last - __first;
~~~~~~ ^ ~~~~~~~
```
この後、膨大に続く。
##3.6 error: invalid operands to binary expression ('ostream' (aka 'basic_ostream<char>') and 'std::pair<std::string, int>')
C++N3242, 2011 (48) 6.6 Jump statements 6.6.3 The return statement"
https://researchmap.jp/jo68rg5gx-1797580/
原因:pairを出力する定義がない
解決:pair -> pair.first, pair.second 要素ごとの出力に変更
###同一・類似事例
C++N4606, 2016 (61)6.6.3 The return statement [stmt.return]p149
https://qiita.com/kaizen_nagoya/items/09918f1f62f3ed8e308a
C++N4741 (69)9.6.3 The return statement [stmt.return]p136
https://qiita.com/kaizen_nagoya/items/fe8a8c2a3f6a77d00cb7
#参考文献(reference)
C++N4741, 2018 Standard Working Draft on ISO/IEC 14882 sample code compile list
https://qiita.com/kaizen_nagoya/items/3294c014044550896010
C++N4606, 2016Working Draft 2016, ISO/IEC 14882,符号断片編纂一覧(example code compile list)
https://qiita.com/kaizen_nagoya/items/df5d62c35bd6ed1c3d43/
C++N3242, 2011 sample code compile list on clang++ and g++
https://qiita.com/kaizen_nagoya/items/685b5c1a2c17c1bf1318
#文書履歴(document history)
ver 0.10 初稿 20180522
0
111
C++N4741(111)8.5 Decomposition declarations [dcl.decomp] p219
#はじめに(Introduction)
C++N4741 Working Draft, Standard for Programming Language C++
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/n4741.pdf
C++N4741は、ISO/IEC JTC1 SC22 WG21の作業原案(Working Draft)です。
公式のISO/IEC 14882原本ではありません。
ISO/IEC JTC1 SC22 WG21では、可能な限り作業文書を公開し、幅広い意見を求めています。
一連の記事はコード断片をコンパイルできる形にする方法を検討してコンパイル、リンク、実行して、規格案の原文と処理系(g++, Clang++)との違いを確認し、技術内容を検討し、ISO/IEC JTC1 SC22 WG21にフィードバックするために用います。
また、CERT C++, MISRA C++等のコーディング標準のコード断片をコンパイルする際の参考にさせていただこうと考えています。CERT C++, MISRA C++が標準化の動きとの時間的なずれがあれば確認できれば幸いです。また、boostライブラリとの関連、Linux OS, TOPPERSカーネル、g++(GCC), clang++(LLVM)との関係も調査中です。
何か、抜け漏れ、耳より情報がありましたらおしらせくださると幸いです。
##背景(back ground)
C/C++でコンパイルエラーが出ると、途方にくれることがしばしばあります。
何回かに1回は、該当するエラーが検索できます。
ただ、条件が違っていて、そこでの修正方法では目的を達成しないこともしばしばです。いろいろな条件のコンパイルエラーとその対応方法について、広く記録することによって、いつか同じエラーに遭遇した時にやくに立つことを目指しています。
この半年の間で、三度、自分のネットでの記録に助けられたことがあります。
また過去に解決できなかった記録を10種類以上、最近になって解決できたことがあります。それは、主に次の4つの情報に基づいています。
https://stackoverflow.com
https://cpprefjp.github.io
http://ja.cppreference.com/
https://teratail.com/
また
https://researchmap.jp/joub9b3my-1797580/#_1797580
に記載したサイトのお世話になっています。
##作業方針(sequence)
Clang++では-std=c++03, c++17, C++2aの3種類
g++では-std=c++03, c++17の2種類
でコンパイルし、
1)コンパイルエラーを収集する。
2)コンパイルエラーをなくす方法を検討する。
コンパイルエラーになる例を示すだけが目的のコードは、コンパイルエラーをなくすのではなく、コンパイルエラーの種類を収集するだけにする。
文法を示すのが目的のコード場合に、コンパイルエラーをなくすのに手間がかかる場合は、順次作業します。
3)リンクエラーをなくす方法を検討する。
文法を示すのが目的のコード場合に、リンクエラーをなくすのに手間がかかる場合は、順次作業します。
4)意味のある出力を作る。
コンパイル、リンクが通っても、意味のある出力を示そうとすると、コンパイル・リンクエラーが出て収拾できそうにない場合がある。順次作業します。
1)だけのものから4)まで進んだものと色々ある状態です。一歩でも前に進むご助言をお待ちしています。「検討事項」の欄に現状を記録するようにしています。
初めての CEDD(Compile Error Driven Design) 8回直してコンパイル。
https://qiita.com/kaizen_nagoya/items/9494236aa1753f3fd1e1
https://qiita.com/kaizen_nagoya/items/85c0e92b206883140e89#_reference-f5ba2535f9b0e314ab73コンパイルエラーを記録するとよい理由7つ
##C++N4741, 2018 Standard Working Draft on ISO/IEC 14882 sample code compile list
https://qiita.com/kaizen_nagoya/items/3294c014044550896010
## C++N4606, 2016符号断片編纂一覧(example code compile list)
C++N4606, 2016 Working Draft 2016, ISO/IEC 14882, C++ standard(1) Example code compile list
https://qiita.com/kaizen_nagoya/items/df5d62c35bd6ed1c3d43/
##C++N3242, 2011 sample code compile list on clang++ and g++
https://qiita.com/kaizen_nagoya/items/685b5c1a2c17c1bf1318
## 編纂器(Compiler)
###clang++ --version
clang version 6.0.0 (tags/RELEASE_600/final)
Target: x86_64-apple-darwin17.4.0
###g++-7 --version
g++-7 (Homebrew GCC 7.3.0_1) 7.3.0
Copyright (C) 2017 Free Software Foundation, Inc.
#(111)8.5 Decomposition declarations [dcl.decomp] p219
C++N4606(102) 8.5 Decomposition declarations [dcl.decomp] p219
https://qiita.com/kaizen_nagoya/items/7de66746ded630f6950c
No examples at C++N3242, 2011
##p219.cpp
###算譜(source code)
```c++:p219.cpp
$ ../a.sh p219
// C++N4741 Committee Draft, Standard for Programming Language C++
// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/n741.pdf
const char* msg= "C++N4741(111)8.5 Decomposition declarations [dcl.decomp] p219.cpp";
// Edited by Dr. Ogawa Kiyoshi. Compile procedure and results record.
#include <iostream>
#include <cstdlib>
using namespace std;
auto f() -> int(&)[2] {};
auto [ x, y ] = f(); // x and y refer to elements in a copy of the array return value
auto& [ xr, yr ] = f(); // xr and yr refer to elements in the array referred to by f’s return value
namespace M {
struct S {
int x1 : 2;
volatile double y1;
};
S f() {};
const auto [ x, y ] = f();
}
int main() {
cout<< msg << endl;
return EXIT_SUCCESS;
}
```
###編纂・実行結果(compile and go)
```shell-session:cpla.sh
$ ../cpla.sh p219
$ clang++ p219.cpp -std=c++03 -Wall
p219.cpp:11:1: warning: 'auto' type specifier is a C++11 extension [-Wc++11-extensions]
auto f() -> int(&)[2]{};
^
p219.cpp:11:10: error: expected function body after function declarator
auto f() -> int(&)[2]{};
^
p219.cpp:12:1: warning: 'auto' type specifier is a C++11 extension [-Wc++11-extensions]
auto [ x, y ] = f(); // x and y refer to elements in a copy of the array return value
^
p219.cpp:12:6: warning: decomposition declarations are a C++17 extension [-Wc++17-extensions]
auto [ x, y ] = f(); // x and y refer to elements in a copy of the array return value
^~~~~~~~
p219.cpp:12:17: error: use of undeclared identifier 'f'
auto [ x, y ] = f(); // x and y refer to elements in a copy of the array return value
^
p219.cpp:13:1: warning: 'auto' type specifier is a C++11 extension [-Wc++11-extensions]
auto& [ xr, yr ] = f(); // xr and yr refer to elements in the array referred to by f’s r...
^
p219.cpp:13:7: warning: decomposition declarations are a C++17 extension [-Wc++17-extensions]
auto& [ xr, yr ] = f(); // xr and yr refer to elements in the array referred to by f’s r...
^~~~~~~~~~
p219.cpp:13:20: error: use of undeclared identifier 'f'
auto& [ xr, yr ] = f(); // xr and yr refer to elements in the array referred to by f’s r...
^
p219.cpp:18:7: warning: 'auto' type specifier is a C++11 extension [-Wc++11-extensions]
const auto [ x, y ] = f();
^
p219.cpp:18:12: warning: decomposition declarations are a C++17 extension [-Wc++17-extensions]
const auto [ x, y ] = f();
^~~~~~~~
In file included from p219.cpp:6:
In file included from /usr/local/Cellar/llvm/6.0.0/include/c++/v1/iostream:38:
In file included from /usr/local/Cellar/llvm/6.0.0/include/c++/v1/ios:216:
In file included from /usr/local/Cellar/llvm/6.0.0/include/c++/v1/__locale:15:
In file included from /usr/local/Cellar/llvm/6.0.0/include/c++/v1/string:477:
In file included from /usr/local/Cellar/llvm/6.0.0/include/c++/v1/string_view:176:
In file included from /usr/local/Cellar/llvm/6.0.0/include/c++/v1/__string:56:
In file included from /usr/local/Cellar/llvm/6.0.0/include/c++/v1/algorithm:642:
In file included from /usr/local/Cellar/llvm/6.0.0/include/c++/v1/utility:198:
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/__tuple:52:80: error: implicit instantiation of
undefined template 'std::__1::tuple_size<M::S>'
template <class _Tp> class _LIBCPP_TEMPLATE_VIS tuple_size<const _Tp> : public tuple_siz...
^
p219.cpp:18:12: note: in instantiation of template class 'std::__1::tuple_size<const M::S>'
requested here
const auto [ x, y ] = f();
^
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/__tuple:25:49: note: template is declared here
template <class _Tp> class _LIBCPP_TEMPLATE_VIS tuple_size;
^
p219.cpp:18:12: error: cannot decompose this type; 'std::tuple_size<const M::S>::value' is not a
valid integral constant expression
const auto [ x, y ] = f();
^
7 warnings and 5 errors generated.
$ clang++ p219.cpp -std=c++2a -Wall
p219.cpp:11:23: warning: control reaches end of non-void function [-Wreturn-type]
auto f() -> int(&)[2]{};
^
p219.cpp:17:7: warning: control reaches end of non-void function [-Wreturn-type]
S f(){};
^
2 warnings generated.
../cpla.sh: line 11: 27554 Illegal instruction: 4 ./$1l2a $2
$ g++-8 p219.cpp -std=c++03 -Wall
p219.cpp:11:1: warning: 'auto' changes meaning in C++11; please remove it [-Wc++11-compat]
auto f() -> int(&)[2]{};
^~~~
----
p219.cpp:11:21: error: ISO C++ forbids declaration of 'f' with no type [-fpermissive]
auto f() -> int(&)[2]{};
^
p219.cpp:11:21: error: top-level declaration of 'f' specifies 'auto'
p219.cpp:11:21: error: trailing return type only available with -std=c++11 or -std=gnu++11
p219.cpp:12:1: warning: 'auto' changes meaning in C++11; please remove it [-Wc++11-compat]
auto [ x, y ] = f(); // x and y refer to elements in a copy of the array return value
^~~~
----
p219.cpp:12:6: warning: structured bindings only available with -std=c++17 or -std=gnu++17
auto [ x, y ] = f(); // x and y refer to elements in a copy of the array return value
^
p219.cpp:12:13: error: ISO C++ forbids declaration of 'structured binding' with no type [-fpermissive]
auto [ x, y ] = f(); // x and y refer to elements in a copy of the array return value
^
p219.cpp:12:6: error: structured binding declaration cannot be C++98 'auto'
auto [ x, y ] = f(); // x and y refer to elements in a copy of the array return value
^~~~~~~~
p219.cpp:12:6: error: structured binding declaration cannot have type 'int'
p219.cpp:12:6: note: type must be cv-qualified 'auto' or reference to cv-qualified 'auto'
p219.cpp:12:17: error: 'f' was not declared in this scope
auto [ x, y ] = f(); // x and y refer to elements in a copy of the array return value
^
p219.cpp:13:1: warning: 'auto' changes meaning in C++11; please remove it [-Wc++11-compat]
auto& [ xr, yr ] = f(); // xr and yr refer to elements in the array referred to by f’s return value
^~~~
----
p219.cpp:13:7: warning: structured bindings only available with -std=c++17 or -std=gnu++17
auto& [ xr, yr ] = f(); // xr and yr refer to elements in the array referred to by f’s return value
^
p219.cpp:13:16: error: ISO C++ forbids declaration of 'structured binding' with no type [-fpermissive]
auto& [ xr, yr ] = f(); // xr and yr refer to elements in the array referred to by f’s return value
^
p219.cpp:13:7: error: structured binding declaration cannot be C++98 'auto'
auto& [ xr, yr ] = f(); // xr and yr refer to elements in the array referred to by f’s return value
^~~~~~~~~~
p219.cpp:13:7: error: structured binding declaration cannot have type 'int'
p219.cpp:13:7: note: type must be cv-qualified 'auto' or reference to cv-qualified 'auto'
p219.cpp:13:20: error: 'f' was not declared in this scope
auto& [ xr, yr ] = f(); // xr and yr refer to elements in the array referred to by f’s return value
^
p219.cpp: In function 'M::S M::f()':
p219.cpp:17:7: warning: no return statement in function returning non-void [-Wreturn-type]
S f(){};
^
p219.cpp: At global scope:
p219.cpp:18:7: warning: 'auto' changes meaning in C++11; please remove it [-Wc++11-compat]
const auto [ x, y ] = f();
^~~~
----
p219.cpp:18:12: warning: structured bindings only available with -std=c++17 or -std=gnu++17
const auto [ x, y ] = f();
^
p219.cpp:18:19: error: ISO C++ forbids declaration of 'structured binding' with no type [-fpermissive]
const auto [ x, y ] = f();
^
p219.cpp:18:12: error: structured binding declaration cannot be C++98 'auto'
const auto [ x, y ] = f();
^~~~~~~~
p219.cpp:18:12: error: structured binding declaration cannot have type 'const int'
p219.cpp:18:12: note: type must be cv-qualified 'auto' or reference to cv-qualified 'auto'
$ g++-8 p219.cpp -std=c++2a -Wall
p219.cpp: In function 'int (& f())[2]':
p219.cpp:11:23: warning: no return statement in function returning non-void [-Wreturn-type]
auto f() -> int(&)[2]{};
^
p219.cpp: In function 'M::S M::f()':
p219.cpp:17:7: warning: no return statement in function returning non-void [-Wreturn-type]
S f(){};
^
../cpla.sh: line 23: 27565 Segmentation fault: 11 ./$1g2a $2
```
#検討事項(agenda)
実行時エラーを修正する方法。
clang++, g++で実行時エラーの種類が違う。
役に立つまたは意味のあるその他の出力
#参考資料(reference)
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 <misra_c.h>
https://qiita.com/kaizen_nagoya/items/f1a79a7cbd281607c7c9
「C++完全理解ガイド」の同意できること上位10
https://qiita.com/kaizen_nagoya/items/aa5744e0c4a8618c7671
#文書履歴(document history)
ver. 0.10 初稿 20180525
0
109
C++N4741 (109)8.4.2 Explicitly-defaulted functions [dcl.fct.def.default]p217
#はじめに(Introduction)
C++N4741 Working Draft, Standard for Programming Language C++
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/n4741.pdf
C++N4741は、ISO/IEC JTC1 SC22 WG21の作業原案(Working Draft)です。
公式のISO/IEC 14882原本ではありません。
ISO/IEC JTC1 SC22 WG21では、可能な限り作業文書を公開し、幅広い意見を求めています。
一連の記事はコード断片をコンパイルできる形にする方法を検討してコンパイル、リンク、実行して、規格案の原文と処理系(g++, Clang++)との違いを確認し、技術内容を検討し、ISO/IEC JTC1 SC22 WG21にフィードバックするために用います。
また、CERT C++, MISRA C++等のコーディング標準のコード断片をコンパイルする際の参考にさせていただこうと考えています。CERT C++, MISRA C++が標準化の動きとの時間的なずれがあれば確認できれば幸いです。また、boostライブラリとの関連、Linux OS, TOPPERSカーネル、g++(GCC), clang++(LLVM)との関係も調査中です。
何か、抜け漏れ、耳より情報がありましたらおしらせくださると幸いです。
##背景(back ground)
C/C++でコンパイルエラーが出ると、途方にくれることがしばしばあります。
何回かに1回は、該当するエラーが検索できます。
ただ、条件が違っていて、そこでの修正方法では目的を達成しないこともしばしばです。いろいろな条件のコンパイルエラーとその対応方法について、広く記録することによって、いつか同じエラーに遭遇した時にやくに立つことを目指しています。
この半年の間で、三度、自分のネットでの記録に助けられたことがあります。
また過去に解決できなかった記録を10種類以上、最近になって解決できたことがあります。それは、主に次の4つの情報に基づいています。
https://stackoverflow.com
https://cpprefjp.github.io
http://ja.cppreference.com/
https://teratail.com/
また
https://researchmap.jp/joub9b3my-1797580/#_1797580
に記載したサイトのお世話になっています。
##作業方針(sequence)
Clang++では-std=c++03, c++17, C++2aの3種類
g++では-std=c++03, c++17の2種類
でコンパイルし、
1)コンパイルエラーを収集する。
2)コンパイルエラーをなくす方法を検討する。
コンパイルエラーになる例を示すだけが目的のコードは、コンパイルエラーをなくすのではなく、コンパイルエラーの種類を収集するだけにする。
文法を示すのが目的のコード場合に、コンパイルエラーをなくすのに手間がかかる場合は、順次作業します。
3)リンクエラーをなくす方法を検討する。
文法を示すのが目的のコード場合に、リンクエラーをなくすのに手間がかかる場合は、順次作業します。
4)意味のある出力を作る。
コンパイル、リンクが通っても、意味のある出力を示そうとすると、コンパイル・リンクエラーが出て収拾できそうにない場合がある。順次作業します。
1)だけのものから4)まで進んだものと色々ある状態です。一歩でも前に進むご助言をお待ちしています。「検討事項」の欄に現状を記録するようにしています。
初めての CEDD(Compile Error Driven Design) 8回直してコンパイル。
https://qiita.com/kaizen_nagoya/items/9494236aa1753f3fd1e1
https://qiita.com/kaizen_nagoya/items/85c0e92b206883140e89#_reference-f5ba2535f9b0e314ab73コンパイルエラーを記録するとよい理由7つ
##C++N4741, 2018 Standard Working Draft on ISO/IEC 14882 sample code compile list
https://qiita.com/kaizen_nagoya/items/3294c014044550896010
## C++N4606, 2016符号断片編纂一覧(example code compile list)
C++N4606, 2016 Working Draft 2016, ISO/IEC 14882, C++ standard(1) Example code compile list
https://qiita.com/kaizen_nagoya/items/df5d62c35bd6ed1c3d43/
##C++N3242, 2011 sample code compile list on clang++ and g++
https://qiita.com/kaizen_nagoya/items/685b5c1a2c17c1bf1318
## 編纂器(Compiler)
###clang++ --version
clang version 6.0.0 (tags/RELEASE_600/final)
Target: x86_64-apple-darwin17.4.0
###g++-7 --version
g++-7 (Homebrew GCC 7.3.0_1) 7.3.0
Copyright (C) 2017 Free Software Foundation, Inc.
#(109)8.4.2 Explicitly-defaulted functions [dcl.fct.def.default]p217
C++N4606(100) 8.4.2 Explicitly-defaulted functions [dcl.fct.def.default] p217
https://qiita.com/kaizen_nagoya/items/22a4d7eeae372d5240d3
C++N3242, 2011 (82) 8.4.2 Explicitly-defaulted functions
https://researchmap.jp/jozoovpxn-1797580/#_1797580
##p217.cpp
###算譜(source code)
```c++:p217.cpp
// C++N4741 Committee Draft, Standard for Programming Language C++
// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/n741.pdf
const char* msg= "C++N4741(109)8.4.2 Explicitly-defaulted functions [dcl.fct.def.default]p217.cpp";
// Edited by Dr. Ogawa Kiyoshi. Compile procedure and results record.
#include <iostream>
#include <cstdlib>
using namespace std;
struct trivial {
trivial() = default;
trivial(const trivial&) = default;
trivial(trivial&&) = default;
trivial& operator=(const trivial&) = default;
trivial& operator=(trivial&&) = default;
~trivial() = default;
};
struct nontrivial1 {
nontrivial1();
};
nontrivial1::nontrivial1() = default; // not first declaration
int main() {
cout<< msg << endl;
return EXIT_SUCCESS;
}
```
###編纂・実行結果(compile and go)
```shell-session:cpla.sh
$ ../c1.sh p217
$ clang++ p217.cpp -std=c++2a -Wall
p217.cpp:12:1: error: defaulted definition of default constructor is not constexpr
constexpr S() = default; // ill-formed: implicit S() is not constexpr
^
p217.cpp:13:1: error: an explicitly-defaulted constructor cannot have default arguments
S(int a = 0) = default; // ill-formed: default argument
^~~~~~~~~~~~~~~~~~~~~~
p217.cpp:14:6: error: explicitly-defaulted copy assignment operator must return 'S &'
void operator=(const S&) = default; // ill-formed: non-matching return type
^
p217.cpp:15:6: error: ISO C++17 does not allow dynamic exception specifications
[-Wdynamic-exception-spec]
~S() throw(int) = default; // deleted: exception specification does not match
^~~~~~~~~~
p217.cpp:15:6: note: use 'noexcept(false)' instead
~S() throw(int) = default; // deleted: exception specification does not match
^~~~~~~~~~
noexcept(false)
p217.cpp:15:1: error: exception specification of explicitly defaulted destructor does not match
the calculated one
~S() throw(int) = default; // deleted: exception specification does not match
^
p217.cpp:17:5: warning: private field 'i' is not used [-Wunused-private-field]
int i;
^
1 warning and 5 errors generated.
```
##p217a.cpp
コンパイルエラーを想定していた行を///註釈に。
###算譜(source code)
```c++:p217a.cpp
// C++N4741 Committee Draft, Standard for Programming Language C++
// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/n741.pdf
const char* msg= "C++N4741(109)8.4.2 Explicitly-defaulted functions [dcl.fct.def.default]p217.cpp";
// Edited by Dr. Ogawa Kiyoshi. Compile procedure and results record.
#include <iostream>
#include <cstdlib>
using namespace std;
struct S {
///constexpr S() = default; // ill-formed: implicit S() is not constexpr
///S(int a = 0) = default; // ill-formed: default argument
///void operator=(const S&) = default; // ill-formed: non-matching return type
///~S() throw(int) = default; // deleted: exception specification does not match
private:
int i;
S(S&); // OK: private copy constructor
};
S::S(S&) = default; // OK: defines copy constructor
struct trivial {
trivial() = default;
trivial(const trivial&) = default;
trivial(trivial&&) = default;
trivial& operator=(const trivial&) = default;
trivial& operator=(trivial&&) = default;
~trivial() = default;
};
struct nontrivial1 {
nontrivial1();
};
nontrivial1::nontrivial1() = default; // not first declaration
int main() {
cout<< msg << endl;
return EXIT_SUCCESS;
}
```
###編纂・実行結果(compile and go)
```shell-session:cpla.sh
$ ../c1.sh p217a
$ clang++ p217a.cpp -std=c++2a -Wall
p217a.cpp:17:5: warning: private field 'i' is not used [-Wunused-private-field]
int i;
^
1 warning generated.
```
#検討事項(agenda)
OKがコンパイルエラーになる背景。
役に立つまたは意味のあるその他の出力
#参考資料(reference)
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 <misra_c.h>
https://qiita.com/kaizen_nagoya/items/f1a79a7cbd281607c7c9
「C++完全理解ガイド」の同意できること上位10
https://qiita.com/kaizen_nagoya/items/aa5744e0c4a8618c7671
#文書履歴(document history)
ver. 0.10 初稿 20180524
0
110
C++N4741(110)8.4.3 Deleted definitions [dcl.fct.def.delete]p218
#はじめに(Introduction)
C++N4741 Working Draft, Standard for Programming Language C++
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/n4741.pdf
C++N4741は、ISO/IEC JTC1 SC22 WG21の作業原案(Working Draft)です。
公式のISO/IEC 14882原本ではありません。
ISO/IEC JTC1 SC22 WG21では、可能な限り作業文書を公開し、幅広い意見を求めています。
一連の記事はコード断片をコンパイルできる形にする方法を検討してコンパイル、リンク、実行して、規格案の原文と処理系(g++, Clang++)との違いを確認し、技術内容を検討し、ISO/IEC JTC1 SC22 WG21にフィードバックするために用います。
また、CERT C++, MISRA C++等のコーディング標準のコード断片をコンパイルする際の参考にさせていただこうと考えています。CERT C++, MISRA C++が標準化の動きとの時間的なずれがあれば確認できれば幸いです。また、boostライブラリとの関連、Linux OS, TOPPERSカーネル、g++(GCC), clang++(LLVM)との関係も調査中です。
何か、抜け漏れ、耳より情報がありましたらおしらせくださると幸いです。
##背景(back ground)
C/C++でコンパイルエラーが出ると、途方にくれることがしばしばあります。
何回かに1回は、該当するエラーが検索できます。
ただ、条件が違っていて、そこでの修正方法では目的を達成しないこともしばしばです。いろいろな条件のコンパイルエラーとその対応方法について、広く記録することによって、いつか同じエラーに遭遇した時にやくに立つことを目指しています。
この半年の間で、三度、自分のネットでの記録に助けられたことがあります。
また過去に解決できなかった記録を10種類以上、最近になって解決できたことがあります。それは、主に次の4つの情報に基づいています。
https://stackoverflow.com
https://cpprefjp.github.io
http://ja.cppreference.com/
https://teratail.com/
また
https://researchmap.jp/joub9b3my-1797580/#_1797580
に記載したサイトのお世話になっています。
##作業方針(sequence)
Clang++では-std=c++03, c++17, C++2aの3種類
g++では-std=c++03, c++17の2種類
でコンパイルし、
1)コンパイルエラーを収集する。
2)コンパイルエラーをなくす方法を検討する。
コンパイルエラーになる例を示すだけが目的のコードは、コンパイルエラーをなくすのではなく、コンパイルエラーの種類を収集するだけにする。
文法を示すのが目的のコード場合に、コンパイルエラーをなくすのに手間がかかる場合は、順次作業します。
3)リンクエラーをなくす方法を検討する。
文法を示すのが目的のコード場合に、リンクエラーをなくすのに手間がかかる場合は、順次作業します。
4)意味のある出力を作る。
コンパイル、リンクが通っても、意味のある出力を示そうとすると、コンパイル・リンクエラーが出て収拾できそうにない場合がある。順次作業します。
1)だけのものから4)まで進んだものと色々ある状態です。一歩でも前に進むご助言をお待ちしています。「検討事項」の欄に現状を記録するようにしています。
初めての CEDD(Compile Error Driven Design) 8回直してコンパイル。
https://qiita.com/kaizen_nagoya/items/9494236aa1753f3fd1e1
https://qiita.com/kaizen_nagoya/items/85c0e92b206883140e89#_reference-f5ba2535f9b0e314ab73コンパイルエラーを記録するとよい理由7つ
##C++N4741, 2018 Standard Working Draft on ISO/IEC 14882 sample code compile list
https://qiita.com/kaizen_nagoya/items/3294c014044550896010
## C++N4606, 2016符号断片編纂一覧(example code compile list)
C++N4606, 2016 Working Draft 2016, ISO/IEC 14882, C++ standard(1) Example code compile list
https://qiita.com/kaizen_nagoya/items/df5d62c35bd6ed1c3d43/
##C++N3242, 2011 sample code compile list on clang++ and g++
https://qiita.com/kaizen_nagoya/items/685b5c1a2c17c1bf1318
## 編纂器(Compiler)
###clang++ --version
clang version 6.0.0 (tags/RELEASE_600/final)
Target: x86_64-apple-darwin17.4.0
###g++-7 --version
g++-7 (Homebrew GCC 7.3.0_1) 7.3.0
Copyright (C) 2017 Free Software Foundation, Inc.
#(110)8.4.3 Deleted definitions [dcl.fct.def.delete]p218
C++N4606(101) 8.4.3 Deleted definitions [dcl.fct.def.delete] p218
https://qiita.com/kaizen_nagoya/items/605c6a7d1a2dc14c753a
C++N3242, 2011 (83) 8.4.3 Deleted definitions
https://researchmap.jp/jouqm52jp-1797580/#_1797580
##p218.cpp
###算譜(source code)
```c++:p218.cpp
// C++N4741 Committee Draft, Standard for Programming Language C++
// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/n741.pdf
const char* msg= "C++N4741(110)8.4.3 Deleted definitions [dcl.fct.def.delete]p218.cpp";
// Edited by Dr. Ogawa Kiyoshi. Compile procedure and results record.
#include <iostream>
#include <cstdlib>
using namespace std;
struct onlydouble {
onlydouble() = delete; // OK, but redundant
onlydouble(std::intmax_t) = delete;
onlydouble(double);
};
namespace N {
struct sometype {
void* operator new(std::size_t) = delete;
void* operator new[](std::size_t) = delete;
};
sometype* p = new sometype; // error, deleted class operator new
sometype* q = new sometype[3]; // error, deleted class operator new[]
}
namespace M {
struct moveonly {
moveonly() = default;
moveonly(const moveonly&) = delete;
moveonly(moveonly&&) = default;
moveonly& operator=(const moveonly&) = delete;
moveonly& operator=(moveonly&&) = default;
~moveonly() = default;
};
moveonly* p;
moveonly q(*p); // error, deleted copy constructor
}
struct sometype {
sometype();
};
sometype::sometype() = delete; // ill-formed; not first declaration
int main() {
double d;
onlydouble o(d);
M::moveonly m ;
cout << &m<<endl;
cout<< msg << endl;
return EXIT_SUCCESS;
}
```
###編纂・実行結果(compile and go)
```shell-session:cpla.sh
$ ../c1.sh p218
$ clang++ p218.cpp -std=c++2a -Wall
p218.cpp:22:15: error: call to deleted function 'operator new'
sometype* p = new sometype; // error, deleted class operator new
^
p218.cpp:19:7: note: candidate function has been explicitly deleted
void* operator new(std::size_t) = delete;
^
p218.cpp:23:15: error: call to deleted function 'operator new[]'
sometype* q = new sometype[3]; // error, deleted class operator new[]
^
p218.cpp:20:7: note: candidate function has been explicitly deleted
void* operator new[](std::size_t) = delete;
^
p218.cpp:36:10: error: call to deleted constructor of 'M::moveonly'
moveonly q(*p); // error, deleted copy constructor
^ ~~
p218.cpp:29:1: note: 'moveonly' has been explicitly marked deleted here
moveonly(const moveonly&) = delete;
^
p218.cpp:42:24: error: deleted definition must be first declaration
sometype::sometype() = delete; // ill-formed; not first declaration
^
p218.cpp:40:1: note: previous declaration is here
sometype();
^
4 errors generated.
```
##p217a.cpp
コンパイルエラーを想定していた行を///註釈に。
###算譜(source code)
```c++:p217a.cpp
// C++N4741 Committee Draft, Standard for Programming Language C++
// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/n741.pdf
const char* msg= "C++N4741(110)8.4.3 Deleted definitions [dcl.fct.def.delete]p218a.cpp";
// Edited by Dr. Ogawa Kiyoshi. Compile procedure and results record.
#include <iostream>
#include <cstdlib>
using namespace std;
struct onlydouble {
onlydouble() = delete; // OK, but redundant
onlydouble(std::intmax_t) = delete;
onlydouble(double d) {
cout<<"onlydouble="<<d<<endl;
}
};
namespace N {
struct sometype {
void* operator new(std::size_t) = delete;
void* operator new[](std::size_t) = delete;
};
///sometype* p = new sometype; // error, deleted class operator new
///sometype* q = new sometype[3]; // error, deleted class operator new[]
}
namespace M {
struct moveonly {
moveonly() = default;
moveonly(const moveonly&) = delete;
moveonly(moveonly&&) = default;
moveonly& operator=(const moveonly&) = delete;
moveonly& operator=(moveonly&&) = default;
~moveonly() = default;
};
moveonly* p;
///moveonly q(*p); // error, deleted copy constructor
}
struct sometype {
sometype() {
cout <<"sometype"<<endl;
}
};
///sometype::sometype() = delete; // ill-formed; not first declaration
int main() {
double d;
onlydouble o(d);
sometype s;
M::moveonly m ;
cout << &m<<" s="<<&s<<endl;
cout<< msg << endl;
return EXIT_SUCCESS;
}
```
###編纂・実行結果(compile and go)
```shell-session:cpla.sh
$ ../cpla.sh p218a
$ clang++ p218a.cpp -std=c++03 -Wall
p218a.cpp:12:16: warning: deleted function definitions are a C++11 extension
[-Wc++11-extensions]
onlydouble() = delete; // OK, but redundant
^
p218a.cpp:13:29: warning: deleted function definitions are a C++11 extension
[-Wc++11-extensions]
onlydouble(std::intmax_t) = delete;
^
p218a.cpp:19:35: warning: deleted function definitions are a C++11 extension
[-Wc++11-extensions]
void* operator new(std::size_t) = delete;
^
p218a.cpp:20:37: warning: deleted function definitions are a C++11 extension
[-Wc++11-extensions]
void* operator new[](std::size_t) = delete;
^
p218a.cpp:28:14: warning: defaulted function definitions are a C++11 extension
[-Wc++11-extensions]
moveonly() = default;
^
p218a.cpp:29:29: warning: deleted function definitions are a C++11 extension
[-Wc++11-extensions]
moveonly(const moveonly&) = delete;
^
p218a.cpp:30:18: warning: rvalue references are a C++11 extension [-Wc++11-extensions]
moveonly(moveonly&&) = default;
^
p218a.cpp:30:24: warning: defaulted function definitions are a C++11 extension
[-Wc++11-extensions]
moveonly(moveonly&&) = default;
^
p218a.cpp:31:40: warning: deleted function definitions are a C++11 extension
[-Wc++11-extensions]
moveonly& operator=(const moveonly&) = delete;
^
p218a.cpp:32:29: warning: rvalue references are a C++11 extension [-Wc++11-extensions]
moveonly& operator=(moveonly&&) = default;
^
p218a.cpp:32:35: warning: defaulted function definitions are a C++11 extension
[-Wc++11-extensions]
moveonly& operator=(moveonly&&) = default;
^
p218a.cpp:33:15: warning: defaulted function definitions are a C++11 extension
[-Wc++11-extensions]
~moveonly() = default;
^
p218a.cpp:46:16: warning: variable 'd' is uninitialized when used here [-Wuninitialized]
onlydouble o(d);
^
p218a.cpp:45:11: note: initialize the variable 'd' to silence this warning
double d;
^
= 0.0
13 warnings generated.
onlydouble=0
sometype
0x7ffeed613708 s=0x7ffeed613710
C++N4741(110)8.4.3 Deleted definitions [dcl.fct.def.delete]p218a.cpp
$ clang++ p218a.cpp -std=c++2a -Wall
p218a.cpp:46:16: warning: variable 'd' is uninitialized when used here [-Wuninitialized]
onlydouble o(d);
^
p218a.cpp:45:11: note: initialize the variable 'd' to silence this warning
double d;
^
= 0.0
1 warning generated.
onlydouble=0
sometype
0x7ffee07ed708 s=0x7ffee07ed710
C++N4741(110)8.4.3 Deleted definitions [dcl.fct.def.delete]p218a.cpp
$ g++-8 p218a.cpp -std=c++03 -Wall
p218a.cpp:12:16: warning: defaulted and deleted functions only available with -std=c++11 or -std=gnu++11
onlydouble() = delete; // OK, but redundant
^~~~~~
p218a.cpp:13:11: warning: unnecessary parentheses in declaration of 'intmax_t' [-Wparentheses]
onlydouble(std::intmax_t) = delete;
^
p218a.cpp:13:29: error: invalid use of '::'
onlydouble(std::intmax_t) = delete;
^~~~~~
p218a.cpp:19:35: warning: defaulted and deleted functions only available with -std=c++11 or -std=gnu++11
void* operator new(std::size_t) = delete;
^~~~~~
p218a.cpp:20:37: warning: defaulted and deleted functions only available with -std=c++11 or -std=gnu++11
void* operator new[](std::size_t) = delete;
^~~~~~
p218a.cpp:28:14: warning: defaulted and deleted functions only available with -std=c++11 or -std=gnu++11
moveonly() = default;
^~~~~~~
p218a.cpp:29:29: warning: defaulted and deleted functions only available with -std=c++11 or -std=gnu++11
moveonly(const moveonly&) = delete;
^~~~~~
p218a.cpp:30:18: error: expected ',' or '...' before '&&' token
moveonly(moveonly&&) = default;
^~
p218a.cpp:30:24: warning: defaulted and deleted functions only available with -std=c++11 or -std=gnu++11
moveonly(moveonly&&) = default;
^~~~~~~
p218a.cpp:30:24: error: invalid constructor; you probably meant 'M::moveonly (const M::moveonly&)'
p218a.cpp:31:40: warning: defaulted and deleted functions only available with -std=c++11 or -std=gnu++11
moveonly& operator=(const moveonly&) = delete;
^~~~~~
p218a.cpp:32:29: error: expected ',' or '...' before '&&' token
moveonly& operator=(moveonly&&) = default;
^~
p218a.cpp:32:35: warning: defaulted and deleted functions only available with -std=c++11 or -std=gnu++11
moveonly& operator=(moveonly&&) = default;
^~~~~~~
p218a.cpp:33:15: warning: defaulted and deleted functions only available with -std=c++11 or -std=gnu++11
~moveonly() = default;
^~~~~~~
p218a.cpp:32:11: error: defaulted declaration 'M::moveonly& M::moveonly::operator=(M::moveonly)' does not match the expected signature
moveonly& operator=(moveonly&&) = default;
^~~~~~~~
p218a.cpp:32:11: note: expected signature: 'M::moveonly& M::moveonly::operator=(M::moveonly&)'
$ g++-8 p218a.cpp -std=c++2a -Wall
p218a.cpp: In function 'int main()':
p218a.cpp:46:17: warning: 'd' is used uninitialized in this function [-Wuninitialized]
onlydouble o(d);
^
onlydouble=2.34378e-314
sometype
0x7ffee0d9b745 s=0x7ffee0d9b746
C++N4741(110)8.4.3 Deleted definitions [dcl.fct.def.delete]p218a.cpp
```
#検討事項(agenda)
役に立つまたは意味のあるその他の出力
#参考資料(reference)
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 <misra_c.h>
https://qiita.com/kaizen_nagoya/items/f1a79a7cbd281607c7c9
「C++完全理解ガイド」の同意できること上位10
https://qiita.com/kaizen_nagoya/items/aa5744e0c4a8618c7671
#文書履歴(document history)
ver. 0.10 初稿 20180525
0
108
C++N4741 (108)8.4 Function definitions [dcl.fct.def] 8.4.1 In general [dcl.fct.def.general]p215
#はじめに(Introduction)
C++N4741 Working Draft, Standard for Programming Language C++
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/n4741.pdf
C++N4741は、ISO/IEC JTC1 SC22 WG21の作業原案(Working Draft)です。
公式のISO/IEC 14882原本ではありません。
ISO/IEC JTC1 SC22 WG21では、可能な限り作業文書を公開し、幅広い意見を求めています。
一連の記事はコード断片をコンパイルできる形にする方法を検討してコンパイル、リンク、実行して、規格案の原文と処理系(g++, Clang++)との違いを確認し、技術内容を検討し、ISO/IEC JTC1 SC22 WG21にフィードバックするために用います。
また、CERT C++, MISRA C++等のコーディング標準のコード断片をコンパイルする際の参考にさせていただこうと考えています。CERT C++, MISRA C++が標準化の動きとの時間的なずれがあれば確認できれば幸いです。また、boostライブラリとの関連、Linux OS, TOPPERSカーネル、g++(GCC), clang++(LLVM)との関係も調査中です。
何か、抜け漏れ、耳より情報がありましたらおしらせくださると幸いです。
##背景(back ground)
C/C++でコンパイルエラーが出ると、途方にくれることがしばしばあります。
何回かに1回は、該当するエラーが検索できます。
ただ、条件が違っていて、そこでの修正方法では目的を達成しないこともしばしばです。いろいろな条件のコンパイルエラーとその対応方法について、広く記録することによって、いつか同じエラーに遭遇した時にやくに立つことを目指しています。
この半年の間で、三度、自分のネットでの記録に助けられたことがあります。
また過去に解決できなかった記録を10種類以上、最近になって解決できたことがあります。それは、主に次の4つの情報に基づいています。
https://stackoverflow.com
https://cpprefjp.github.io
http://ja.cppreference.com/
https://teratail.com/
また
https://researchmap.jp/joub9b3my-1797580/#_1797580
に記載したサイトのお世話になっています。
##作業方針(sequence)
Clang++では-std=c++03, c++17, C++2aの3種類
g++では-std=c++03, c++17の2種類
でコンパイルし、
1)コンパイルエラーを収集する。
2)コンパイルエラーをなくす方法を検討する。
コンパイルエラーになる例を示すだけが目的のコードは、コンパイルエラーをなくすのではなく、コンパイルエラーの種類を収集するだけにする。
文法を示すのが目的のコード場合に、コンパイルエラーをなくすのに手間がかかる場合は、順次作業します。
3)リンクエラーをなくす方法を検討する。
文法を示すのが目的のコード場合に、リンクエラーをなくすのに手間がかかる場合は、順次作業します。
4)意味のある出力を作る。
コンパイル、リンクが通っても、意味のある出力を示そうとすると、コンパイル・リンクエラーが出て収拾できそうにない場合がある。順次作業します。
1)だけのものから4)まで進んだものと色々ある状態です。一歩でも前に進むご助言をお待ちしています。「検討事項」の欄に現状を記録するようにしています。
初めての CEDD(Compile Error Driven Design) 8回直してコンパイル。
https://qiita.com/kaizen_nagoya/items/9494236aa1753f3fd1e1
https://qiita.com/kaizen_nagoya/items/85c0e92b206883140e89#_reference-f5ba2535f9b0e314ab73コンパイルエラーを記録するとよい理由7つ
##C++N4741, 2018 Standard Working Draft on ISO/IEC 14882 sample code compile list
https://qiita.com/kaizen_nagoya/items/3294c014044550896010
## C++N4606, 2016符号断片編纂一覧(example code compile list)
C++N4606, 2016 Working Draft 2016, ISO/IEC 14882, C++ standard(1) Example code compile list
https://qiita.com/kaizen_nagoya/items/df5d62c35bd6ed1c3d43/
##C++N3242, 2011 sample code compile list on clang++ and g++
https://qiita.com/kaizen_nagoya/items/685b5c1a2c17c1bf1318
## 編纂器(Compiler)
###clang++ --version
clang version 6.0.0 (tags/RELEASE_600/final)
Target: x86_64-apple-darwin17.4.0
###g++-7 --version
g++-7 (Homebrew GCC 7.3.0_1) 7.3.0
Copyright (C) 2017 Free Software Foundation, Inc.
#(108)8.4 Function definitions [dcl.fct.def] 8.4.1 In general [dcl.fct.def.general]p215
C++N4606, 2016 (97)8.3.5 Functions p209
https://qiita.com/kaizen_nagoya/items/100f54c22a539e9a5260
C++N3242, 2011 (79) 8.3.5 Functions
https://researchmap.jp/jo7dqs334-1797580/#_1797580
##p215.cpp
###算譜(source code)
```c++:p215.cpp
// C++N4741 Committee Draft, Standard for Programming Language C++
// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/n741.pdf
const char* msg= "C++N4741(108)8.4 Function definitions [dcl.fct.def] 8.4.1 In general [dcl.fct.def.general]p215.cpp";
// Edited by Dr. Ogawa Kiyoshi. Compile procedure and results record.
#include <iostream>
#include <cstdlib>
using namespace std;
//point(1,2); point(1); point();
namespace N {
void g(int = 0, ...); // OK, ellipsis is not a parameter so it can follow
// a parameter with a default argument
void f(int, int);
void f(int, int = 7);
void h() {
f(3); // OK, calls f(3, 7)
void f(int = 1, int); // error: does not use default
// from surrounding scope
}
void m() {
void f(int, int); // has no defaults
f(4); // error: wrong number of arguments
void f(int, int = 5); // OK
f(4); // OK, calls f(4, 5);
void f(int, int = 5); // error: cannot redefine, even to
// same value
}
void n() {
f(6); // OK, calls f(6, 7)
}
}
namespace A {
int a = 1;
int f(int);
int g(int x = f(a)); // default argument: f(::a)
void h() {
a = 2;
{
int a = 3;
g(); // g(f(::a))
}
}
}
namespace M {
class C {
void f(int i = 3);
void g(int i, int j = 99);
};
void C::f(int i = 3) { // error: default argument already
} // specified in class scope
void C::g(int i = 88, int j) { // in this translation unit,
} // C::g can be called with no argument
void f() {
int i;
extern void g(int x = i); // error
extern void h(int x = sizeof(i)); // OK
// ...
}
}
namespace E {
class A {
void f(A* p = this) { } // error
};
}
namespace S {
int a;
int f(int a, int b = a); // error: parameter a
// used as default argument
typedef int I;
int g(float I, int b = I(2)); // error: parameter I found
int h(int a, int b = sizeof(a)); // OK, unevaluated operand
int b;
class X {
int a;
int mem1(int i = a); // error: non-static member a
// used as default argument
int mem2(int i = b); // OK; use X::b
static int b;
};
}
namespace P {
int f(int = 0);
void h() {
int j = f(1);
int k = f(); // OK, means f(0)
}
int (*p1)(int) = &f;
int (*p2)() = &f; // error: type mismatch
}
namespace C {
struct A {
virtual void f(int a = 7);
};
struct B : public A {
void f(int a);
};
void m() {
B* pb = new B;
A* pa = pb;
pa->f(); // OK, calls pa->B::f(7)
pb->f(); // error: wrong number of arguments for B::f()
}
}
int main() {
cout<< msg << endl;
return EXIT_SUCCESS;
}
```
###編纂・実行結果(compile and go)
```shell-session:cpla.sh
$ ../c1.sh p209
$ clang++ p209.cpp -std=c++2a -Wall
p209.cpp:20:20: error: missing default argument on parameter
void f(int = 1, int); // error: does not use default
^
p209.cpp:26:1: error: too few arguments to function call, expected 2, have 1; did you mean
'::N::f'?
f(4); // error: wrong number of arguments
^
::N::f
p209.cpp:17:6: note: '::N::f' declared here
void f(int, int = 7);
^
p209.cpp:29:17: error: redefinition of default argument
void f(int, int = 5); // error: cannot redefine, even to
^ ~
p209.cpp:27:17: note: previous definition is here
void f(int, int = 5); // OK
^ ~
p209.cpp:44:5: warning: unused variable 'a' [-Wunused-variable]
int a = 3;
^
p209.cpp:55:15: error: redefinition of default argument
void C::f(int i = 3) { // error: default argument already
^ ~
p209.cpp:52:12: note: previous definition is here
void f(int i = 3);
^ ~
p209.cpp:62:23: error: default argument references local variable 'i' of enclosing function
extern void g(int x = i); // error
^
p209.cpp:63:30: error: default argument references local variable 'i' of enclosing function
extern void h(int x = sizeof(i)); // OK
~~~~~~~^~
p209.cpp:70:15: error: invalid use of 'this' outside of a non-static member function
void f(A* p = this) { } // error
^
p209.cpp:76:22: error: default argument references parameter 'a'
int f(int a, int b = a); // error: parameter a
^
p209.cpp:79:25: error: called object type 'float' is not a function or function pointer
int g(float I, int b = I(2)); // error: parameter I found
~^
p209.cpp:80:29: error: default argument references parameter 'a'
int h(int a, int b = sizeof(a)); // OK, unevaluated operand
~~~~~~~^~
p209.cpp:85:18: error: invalid use of non-static data member 'a'
int mem1(int i = a); // error: non-static member a
^
p209.cpp:95:5: warning: unused variable 'j' [-Wunused-variable]
int j = f(1);
^
p209.cpp:96:5: warning: unused variable 'k' [-Wunused-variable]
int k = f(); // OK, means f(0)
^
p209.cpp:99:7: error: cannot initialize a variable of type 'int (*)()' with an rvalue of type
'int (*)(int)': different number of parameters (0 vs 1)
int (*p2)() = &f; // error: type mismatch
^ ~~
p209.cpp:113:7: error: too few arguments to function call, single argument 'a' was not specified
pb->f(); // error: wrong number of arguments for B::f()
~~~~~ ^
p209.cpp:107:1: note: 'f' declared here
void f(int a);
^
3 warnings and 13 errors generated.
```
##p209a.cpp
コンパイルエラーを想定していた行を///註釈に。
###算譜(source code)
```c++:p209a.cpp
// C++N4741 Committee Draft, Standard for Programming Language C++
// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/n741.pdf
const char* msg= "C++N4741(106)8.3.5 Functions [dcl.fct]p209.cpp";
// Edited by Dr. Ogawa Kiyoshi. Compile procedure and results record.
#include <iostream>
#include <cstdlib>
using namespace std;
//point(1,2); point(1); point();
namespace N {
void g(int = 0, ...); // OK, ellipsis is not a parameter so it can follow
// a parameter with a default argument
void f(int, int);
void f(int, int = 7);
void h() {
f(3); // OK, calls f(3, 7)
/// void f(int = 1, int); // error: does not use default
// from surrounding scope
}
void m() {
void f(int, int); // has no defaults
/// f(4); // error: wrong number of arguments
void f(int, int = 5); // OK
f(4); // OK, calls f(4, 5);
/// void f(int, int = 5); // error: cannot redefine, even to
// same value
}
void n() {
f(6); // OK, calls f(6, 7)
}
}
namespace A {
int a = 1;
int f(int);
int g(int x = f(a)); // default argument: f(::a)
void h() {
a = 2;
{
int a = 3;
g(); // g(f(::a))
}
}
}
namespace M {
class C {
void f(int i = 3);
void g(int i, int j = 99);
};
/// void C::f(int i = 3) { // error: default argument already
/// } // specified in class scope
void M::C::g(int i = 88, int j) { // in this translation unit,
} // C::g can be called with no argument
void f() {
int i;
/// extern void g(int x = i); // error
extern void h(int x = sizeof(i)); // OK
// ...
}
}
namespace E {
class A {
/// void f(A* p = this) { } // error
};
}
namespace S {
int a;
/// int f(int a, int b = a); // error: parameter a
// used as default argument
typedef int I;
/// int g(float I, int b = I(2)); // error: parameter I found
int h(int a, int b = sizeof(a)); // OK, unevaluated operand
int b;
class X {
int a;
/// int mem1(int i = a); // error: non-static member a
// used as default argument
int mem2(int i = b); // OK; use X::b
static int b;
};
}
namespace P {
int f(int = 0);
void h() {
int j = f(1);
int k = f(); // OK, means f(0)
}
int (*p1)(int) = &f;
/// int (*p2)() = &f; // error: type mismatch
}
namespace C {
struct A {
virtual void f(int a = 7);
};
struct B : public A {
void f(int a);
};
void m() {
B* pb = new B;
A* pa = pb;
pa->f(); // OK, calls pa->B::f(7)
/// pb->f(); // error: wrong number of arguments for B::f()
}
}
int main() {
cout<< msg << endl;
return EXIT_SUCCESS;
}
```
###編纂・実行結果(compile and go)
```shell-session:cpla.sh
$ ../c1.sh p209a
$ clang++ p209a.cpp -std=c++2a -Wall
p209a.cpp:44:11: warning: unused variable 'a' [-Wunused-variable]
int a = 3;
^
p209a.cpp:63:34: error: default argument references local variable 'i' of enclosing function
extern void h(int x = sizeof(i)); // OK
~~~~~~~^~
p209a.cpp:80:31: error: default argument references parameter 'a'
int h(int a, int b = sizeof(a)); // OK, unevaluated operand
~~~~~~~^~
p209a.cpp:96:9: warning: unused variable 'k' [-Wunused-variable]
int k = f(); // OK, means f(0)
^
p209a.cpp:95:9: warning: unused variable 'j' [-Wunused-variable]
int j = f(1);
^
3 warnings and 2 errors generated.
```
#検討事項(agenda)
OKがコンパイルエラーになる背景。
役に立つまたは意味のあるその他の出力
#参考資料(reference)
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 <misra_c.h>
https://qiita.com/kaizen_nagoya/items/f1a79a7cbd281607c7c9
「C++完全理解ガイド」の同意できること上位10
https://qiita.com/kaizen_nagoya/items/aa5744e0c4a8618c7671
#文書履歴(document history)
ver. 0.10 初稿 20180524
0
107
C++N4741(107)8.3.6 Default arguments [dcl.fct.default] p211
#はじめに(Introduction)
C++N4741 Working Draft, Standard for Programming Language C++
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/n4741.pdf
C++N4741は、ISO/IEC JTC1 SC22 WG21の作業原案(Working Draft)です。
公式のISO/IEC 14882原本ではありません。
ISO/IEC JTC1 SC22 WG21では、可能な限り作業文書を公開し、幅広い意見を求めています。
一連の記事はコード断片をコンパイルできる形にする方法を検討してコンパイル、リンク、実行して、規格案の原文と処理系(g++, Clang++)との違いを確認し、技術内容を検討し、ISO/IEC JTC1 SC22 WG21にフィードバックするために用います。
また、CERT C++, MISRA C++等のコーディング標準のコード断片をコンパイルする際の参考にさせていただこうと考えています。CERT C++, MISRA C++が標準化の動きとの時間的なずれがあれば確認できれば幸いです。また、boostライブラリとの関連、Linux OS, TOPPERSカーネル、g++(GCC), clang++(LLVM)との関係も調査中です。
何か、抜け漏れ、耳より情報がありましたらおしらせくださると幸いです。
##背景(back ground)
C/C++でコンパイルエラーが出ると、途方にくれることがしばしばあります。
何回かに1回は、該当するエラーが検索できます。
ただ、条件が違っていて、そこでの修正方法では目的を達成しないこともしばしばです。いろいろな条件のコンパイルエラーとその対応方法について、広く記録することによって、いつか同じエラーに遭遇した時にやくに立つことを目指しています。
この半年の間で、三度、自分のネットでの記録に助けられたことがあります。
また過去に解決できなかった記録を10種類以上、最近になって解決できたことがあります。それは、主に次の4つの情報に基づいています。
https://stackoverflow.com
https://cpprefjp.github.io
http://ja.cppreference.com/
https://teratail.com/
また
https://researchmap.jp/joub9b3my-1797580/#_1797580
に記載したサイトのお世話になっています。
##作業方針(sequence)
Clang++では-std=c++03, c++17, C++2aの3種類
g++では-std=c++03, c++17の2種類
でコンパイルし、
1)コンパイルエラーを収集する。
2)コンパイルエラーをなくす方法を検討する。
コンパイルエラーになる例を示すだけが目的のコードは、コンパイルエラーをなくすのではなく、コンパイルエラーの種類を収集するだけにする。
文法を示すのが目的のコード場合に、コンパイルエラーをなくすのに手間がかかる場合は、順次作業します。
3)リンクエラーをなくす方法を検討する。
文法を示すのが目的のコード場合に、リンクエラーをなくすのに手間がかかる場合は、順次作業します。
4)意味のある出力を作る。
コンパイル、リンクが通っても、意味のある出力を示そうとすると、コンパイル・リンクエラーが出て収拾できそうにない場合がある。順次作業します。
1)だけのものから4)まで進んだものと色々ある状態です。一歩でも前に進むご助言をお待ちしています。「検討事項」の欄に現状を記録するようにしています。
初めての CEDD(Compile Error Driven Design) 8回直してコンパイル。
https://qiita.com/kaizen_nagoya/items/9494236aa1753f3fd1e1
https://qiita.com/kaizen_nagoya/items/85c0e92b206883140e89#_reference-f5ba2535f9b0e314ab73コンパイルエラーを記録するとよい理由7つ
##C++N4741, 2018 Standard Working Draft on ISO/IEC 14882 sample code compile list
https://qiita.com/kaizen_nagoya/items/3294c014044550896010
## C++N4606, 2016符号断片編纂一覧(example code compile list)
C++N4606, 2016 Working Draft 2016, ISO/IEC 14882, C++ standard(1) Example code compile list
https://qiita.com/kaizen_nagoya/items/df5d62c35bd6ed1c3d43/
##C++N3242, 2011 sample code compile list on clang++ and g++
https://qiita.com/kaizen_nagoya/items/685b5c1a2c17c1bf1318
## 編纂器(Compiler)
###clang++ --version
clang version 6.0.0 (tags/RELEASE_600/final)
Target: x86_64-apple-darwin17.4.0
###g++-7 --version
g++-7 (Homebrew GCC 7.3.0_1) 7.3.0
Copyright (C) 2017 Free Software Foundation, Inc.
#(107)8.3.6 Default arguments [dcl.fct.default] p211
(98) 8.3.6 Default arguments [dcl.fct.default] p212
https://qiita.com/kaizen_nagoya/items/bbbe3ba97f2b9bddaa3b
C++N3242, 2011 (80) 8.3.6 Default arguments
https://researchmap.jp/jotqc8ue5-1797580/#_1797580
##p211.cpp
###算譜(source code)
```c++:p211.cpp
// C++N4741 Committee Draft, Standard for Programming Language C++
// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/n741.pdf
const char* msg= "C++N4741(107)8.3.6 Default arguments [dcl.fct.default] p211.cpp";
// Edited by Dr. Ogawa Kiyoshi. Compile procedure and results record.
#include <iostream>
#include <cstdlib>
using namespace std;
void point(int = 3, int = 4);
void p(){
point(1,2); point(1); point();
}
namespace N {
void g(int = 0, ...); // OK, ellipsis is not a parameter so it can follow
// a parameter with a default argument
void f(int, int);
void f(int, int = 7);
void h() {
f(3); // OK, calls f(3, 7)
void f(int = 1, int); // error: does not use default
// from surrounding scope
}
void m() {
void f(int, int); // has no defaults
f(4); // error: wrong number of arguments
void f(int, int = 5); // OK
f(4); // OK, calls f(4, 5);
void f(int, int = 5); // error: cannot redefine, even to
// same value
}
void n() {
f(6); // OK, calls f(6, 7)
}
}
namespace A {
int a = 1;
int f(int);
int g(int x = f(a)); // default argument: f(::a)
void h() {
a = 2;
{
int a = 3;
g(); // g(f(::a))
}
}
}
namespace M {
class C {
void f(int i = 3);
void g(int i, int j = 99);
};
void C::f(int i = 3) { // error: default argument already
} // specified in class scope
void C::g(int i = 88, int j) { // in this translation unit,
} // C::g can be called with no argument
void f() {
int i;
extern void g(int x = i); // error
extern void h(int x = sizeof(i)); // OK
// ...
}
}
namespace E {
class A {
void f(A* p = this) { } // error
};
}
namespace S {
int a;
int f(int a, int b = a); // error: parameter a
// used as default argument
typedef int I;
int g(float I, int b = I(2)); // error: parameter I found
int h(int a, int b = sizeof(a)); // OK, unevaluated operand
int b;
class X {
int a;
int mem1(int i = a); // error: non-static member a
// used as default argument
int mem2(int i = b); // OK; use X::b
static int b;
};
}
namespace P {
int f(int = 0);
void h() {
int j = f(1);
int k = f(); // OK, means f(0)
}
int (*p1)(int) = &f;
int (*p2)() = &f; // error: type mismatch
}
namespace C {
struct A {
virtual void f(int a = 7);
};
struct B : public A {
void f(int a);
};
void m() {
B* pb = new B;
A* pa = pb;
pa->f(); // OK, calls pa->B::f(7)
pb->f(); // error: wrong number of arguments for B::f()
}
}
int main() {
cout<< msg << endl;
return EXIT_SUCCESS;
}
```
###編纂・実行結果(compile and go)
```shell-session:cpla.sh
$ ../c1.sh p211
$ clang++ p211.cpp -std=c++2a -Wall
p211.cpp:23:20: error: missing default argument on parameter
void f(int = 1, int); // error: does not use default
^
p211.cpp:29:1: error: too few arguments to function call, expected 2, have 1; did you mean
'::N::f'?
f(4); // error: wrong number of arguments
^
::N::f
p211.cpp:20:6: note: '::N::f' declared here
void f(int, int = 7);
^
p211.cpp:32:17: error: redefinition of default argument
void f(int, int = 5); // error: cannot redefine, even to
^ ~
p211.cpp:30:17: note: previous definition is here
void f(int, int = 5); // OK
^ ~
p211.cpp:47:5: warning: unused variable 'a' [-Wunused-variable]
int a = 3;
^
p211.cpp:58:15: error: redefinition of default argument
void C::f(int i = 3) { // error: default argument already
^ ~
p211.cpp:55:12: note: previous definition is here
void f(int i = 3);
^ ~
p211.cpp:65:23: error: default argument references local variable 'i' of enclosing function
extern void g(int x = i); // error
^
p211.cpp:66:30: error: default argument references local variable 'i' of enclosing function
extern void h(int x = sizeof(i)); // OK
~~~~~~~^~
p211.cpp:73:15: error: invalid use of 'this' outside of a non-static member function
void f(A* p = this) { } // error
^
p211.cpp:79:22: error: default argument references parameter 'a'
int f(int a, int b = a); // error: parameter a
^
p211.cpp:82:25: error: called object type 'float' is not a function or function pointer
int g(float I, int b = I(2)); // error: parameter I found
~^
p211.cpp:83:29: error: default argument references parameter 'a'
int h(int a, int b = sizeof(a)); // OK, unevaluated operand
~~~~~~~^~
p211.cpp:88:18: error: invalid use of non-static data member 'a'
int mem1(int i = a); // error: non-static member a
^
p211.cpp:99:5: warning: unused variable 'k' [-Wunused-variable]
int k = f(); // OK, means f(0)
^
p211.cpp:98:5: warning: unused variable 'j' [-Wunused-variable]
int j = f(1);
^
p211.cpp:102:7: error: cannot initialize a variable of type 'int (*)()' with an rvalue of type
'int (*)(int)': different number of parameters (0 vs 1)
int (*p2)() = &f; // error: type mismatch
^ ~~
p211.cpp:116:7: error: too few arguments to function call, single argument 'a' was not specified
pb->f(); // error: wrong number of arguments for B::f()
~~~~~ ^
p211.cpp:110:1: note: 'f' declared here
void f(int a);
^
3 warnings and 13 errors generated.
```
##p211a.cpp
コンパイルエラーを想定していた行を///註釈に。
###算譜(source code)
```c++:p211a.cpp
// C++N4741 Committee Draft, Standard for Programming Language C++
// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/n741.pdf
const char* msg= "C++N4741(106)8.3.5 Functions [dcl.fct]p209.cpp";
// Edited by Dr. Ogawa Kiyoshi. Compile procedure and results record.
#include <iostream>
#include <cstdlib>
using namespace std;
void point(int = 3, int = 4);
void p(){
point(1,2); point(1); point();
}
namespace N {
void g(int = 0, ...); // OK, ellipsis is not a parameter so it can follow
// a parameter with a default argument
void f(int, int);
void f(int, int = 7);
void h() {
f(3); // OK, calls f(3, 7)
/// void f(int = 1, int); // error: does not use default
// from surrounding scope
}
void m() {
void f(int, int); // has no defaults
/// f(4); // error: wrong number of arguments
void f(int, int = 5); // OK
f(4); // OK, calls f(4, 5);
/// void f(int, int = 5); // error: cannot redefine, even to
// same value
}
void n() {
f(6); // OK, calls f(6, 7)
}
}
namespace A {
int a = 1;
int f(int);
int g(int x = f(a)); // default argument: f(::a)
void h() {
a = 2;
{
int a = 3;
g(); // g(f(::a))
}
}
}
namespace M {
class C {
void f(int i = 3);
void g(int i, int j = 99);
};
/// void C::f(int i = 3) { // error: default argument already
/// } // specified in class scope
void M::C::g(int i = 88, int j) { // in this translation unit,
} // C::g can be called with no argument
void f() {
int i;
/// extern void g(int x = i); // error
extern void h(int x = sizeof(i)); // OK
// ...
}
}
namespace E {
class A {
/// void f(A* p = this) { } // error
};
}
namespace S {
int a;
/// int f(int a, int b = a); // error: parameter a
// used as default argument
typedef int I;
/// int g(float I, int b = I(2)); // error: parameter I found
int h(int a, int b = sizeof(a)); // OK, unevaluated operand
int b;
class X {
int a;
/// int mem1(int i = a); // error: non-static member a
// used as default argument
int mem2(int i = b); // OK; use X::b
static int b;
};
}
namespace P {
int f(int = 0);
void h() {
int j = f(1);
int k = f(); // OK, means f(0)
}
int (*p1)(int) = &f;
/// int (*p2)() = &f; // error: type mismatch
}
namespace C {
struct A {
virtual void f(int a = 7);
};
struct B : public A {
void f(int a);
};
void m() {
B* pb = new B;
A* pa = pb;
pa->f(); // OK, calls pa->B::f(7)
/// pb->f(); // error: wrong number of arguments for B::f()
}
}
int main() {
cout<< msg << endl;
return EXIT_SUCCESS;
}
```
###編纂・実行結果(compile and go)
```shell-session:cpla.sh
$ ../c1.sh p211a
$ clang++ p211a.cpp -std=c++2a -Wall
p211a.cpp:47:11: warning: unused variable 'a' [-Wunused-variable]
int a = 3;
^
p211a.cpp:66:34: error: default argument references local variable 'i' of enclosing function
extern void h(int x = sizeof(i)); // OK
~~~~~~~^~
p211a.cpp:83:31: error: default argument references parameter 'a'
int h(int a, int b = sizeof(a)); // OK, unevaluated operand
~~~~~~~^~
p211a.cpp:98:9: warning: unused variable 'j' [-Wunused-variable]
int j = f(1);
^
p211a.cpp:99:9: warning: unused variable 'k' [-Wunused-variable]
int k = f(); // OK, means f(0)
^
3 warnings and 2 errors generated.
```
#検討事項(agenda)
OKがコンパイルエラーになる背景。
役に立つまたは意味のあるその他の出力
#参考資料(reference)
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 <misra_c.h>
https://qiita.com/kaizen_nagoya/items/f1a79a7cbd281607c7c9
「C++完全理解ガイド」の同意できること上位10
https://qiita.com/kaizen_nagoya/items/aa5744e0c4a8618c7671
#文書履歴(document history)
ver. 0.10 初稿 20180524
0
105
C++N4741(105)8.3.4 Arrays [dcl.array]p207
#はじめに(Introduction)
C++N4741 Working Draft, Standard for Programming Language C++
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/n4741.pdf
C++N4741は、ISO/IEC JTC1 SC22 WG21の作業原案(Working Draft)です。
公式のISO/IEC 14882原本ではありません。
ISO/IEC JTC1 SC22 WG21では、可能な限り作業文書を公開し、幅広い意見を求めています。
一連の記事はコード断片をコンパイルできる形にする方法を検討してコンパイル、リンク、実行して、規格案の原文と処理系(g++, Clang++)との違いを確認し、技術内容を検討し、ISO/IEC JTC1 SC22 WG21にフィードバックするために用います。
また、CERT C++, MISRA C++等のコーディング標準のコード断片をコンパイルする際の参考にさせていただこうと考えています。CERT C++, MISRA C++が標準化の動きとの時間的なずれがあれば確認できれば幸いです。また、boostライブラリとの関連、Linux OS, TOPPERSカーネル、g++(GCC), clang++(LLVM)との関係も調査中です。
何か、抜け漏れ、耳より情報がありましたらおしらせくださると幸いです。
##背景(back ground)
C/C++でコンパイルエラーが出ると、途方にくれることがしばしばあります。
何回かに1回は、該当するエラーが検索できます。
ただ、条件が違っていて、そこでの修正方法では目的を達成しないこともしばしばです。いろいろな条件のコンパイルエラーとその対応方法について、広く記録することによって、いつか同じエラーに遭遇した時にやくに立つことを目指しています。
この半年の間で、三度、自分のネットでの記録に助けられたことがあります。
また過去に解決できなかった記録を10種類以上、最近になって解決できたことがあります。それは、主に次の4つの情報に基づいています。
https://stackoverflow.com
https://cpprefjp.github.io
http://ja.cppreference.com/
https://teratail.com/
また
https://researchmap.jp/joub9b3my-1797580/#_1797580
に記載したサイトのお世話になっています。
##作業方針(sequence)
Clang++では-std=c++03, c++17, C++2aの3種類
g++では-std=c++03, c++17の2種類
でコンパイルし、
1)コンパイルエラーを収集する。
2)コンパイルエラーをなくす方法を検討する。
コンパイルエラーになる例を示すだけが目的のコードは、コンパイルエラーをなくすのではなく、コンパイルエラーの種類を収集するだけにする。
文法を示すのが目的のコード場合に、コンパイルエラーをなくすのに手間がかかる場合は、順次作業します。
3)リンクエラーをなくす方法を検討する。
文法を示すのが目的のコード場合に、リンクエラーをなくすのに手間がかかる場合は、順次作業します。
4)意味のある出力を作る。
コンパイル、リンクが通っても、意味のある出力を示そうとすると、コンパイル・リンクエラーが出て収拾できそうにない場合がある。順次作業します。
1)だけのものから4)まで進んだものと色々ある状態です。一歩でも前に進むご助言をお待ちしています。「検討事項」の欄に現状を記録するようにしています。
初めての CEDD(Compile Error Driven Design) 8回直してコンパイル。
https://qiita.com/kaizen_nagoya/items/9494236aa1753f3fd1e1
https://qiita.com/kaizen_nagoya/items/85c0e92b206883140e89#_reference-f5ba2535f9b0e314ab73コンパイルエラーを記録するとよい理由7つ
##C++N4741, 2018 Standard Working Draft on ISO/IEC 14882 sample code compile list
https://qiita.com/kaizen_nagoya/items/3294c014044550896010
## C++N4606, 2016符号断片編纂一覧(example code compile list)
C++N4606, 2016 Working Draft 2016, ISO/IEC 14882, C++ standard(1) Example code compile list
https://qiita.com/kaizen_nagoya/items/df5d62c35bd6ed1c3d43/
##C++N3242, 2011 sample code compile list on clang++ and g++
https://qiita.com/kaizen_nagoya/items/685b5c1a2c17c1bf1318
## 編纂器(Compiler)
###clang++ --version
clang version 6.0.0 (tags/RELEASE_600/final)
Target: x86_64-apple-darwin17.4.0
###g++-7 --version
g++-7 (Homebrew GCC 7.3.0_1) 7.3.0
Copyright (C) 2017 Free Software Foundation, Inc.
#(105)8.3.4 Arrays [dcl.array]p207
C++N4606, 2016(96)8.3.4 Arrays [dcl.array]p207
https://qiita.com/kaizen_nagoya/items/0d7cbf18cb816f9f5178
C++N3242, 2011 (78) 8.3.4 Arrays
https://researchmap.jp/jo3oc10ot-1797580/#_1797580
##p207.cpp
###算譜(source code)
```c++:p207.cpp
// C++N4741 Committee Draft, Standard for Programming Language C++
// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/n741.pdf
const char* msg= "C++N4741(105)8.3.4 Arrays [dcl.array]p207.cpp";
// Edited by Dr. Ogawa Kiyoshi. Compile procedure and results record.
#include <iostream>
#include <cstdlib>
using namespace std;
typedef int A[5], AA[2][3];
typedef const A CA; // type is “array of 5 const int”
typedef const AA CAA; // type is “array of 2 array of 3 const int”
float fa[17], *afp[17];
static int x3d[3][5][7];
extern int x[10];
struct S {
static int y[10];
};
int x[]; // OK: bound is 10
int S::y[]; // OK: bound is 10
void f() {
extern int x[];
int i = sizeof(x); // error: incomplete object type
}
namespace N {
int x[3][5];
}
int main() {
cout<< msg << endl;
return EXIT_SUCCESS;
}
```
###編纂・実行結果(compile and go)
```shell-session:cpla.sh
$ ../c1.sh p207
$ clang++ p207.cpp -std=c++2a -Wall
p207.cpp:27:15: error: invalid application of 'sizeof' to an incomplete type 'int []'
int i = sizeof(x); // error: incomplete object type
^~~
1 error generated.
```
##p207a.cpp
コンパイルエラーを想定していた行を///註釈に。
###算譜(source code)
```c++:p207a.cpp
// C++N4741 Committee Draft, Standard for Programming Language C++
// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/n741.pdf
const char* msg= "C++N4741(105)8.3.4 Arrays [dcl.array]p207.cpp";
// Edited by Dr. Ogawa Kiyoshi. Compile procedure and results record.
#include <iostream>
#include <cstdlib>
using namespace std;
typedef int A[5], AA[2][3];
typedef const A CA; // type is “array of 5 const int”
typedef const AA CAA; // type is “array of 2 array of 3 const int”
float fa[17], *afp[17];
static int x3d[3][5][7];
extern int x[10];
struct S {
static int y[10];
};
int x[]; // OK: bound is 10
int S::y[]; // OK: bound is 10
void f() {
extern int x[];
///int i = sizeof(x); // error: incomplete object type
}
namespace N {
int x[3][5];
}
int main() {
f();
cout << fa <<" " << x3d<<" " << x <<endl;
cout<< msg << endl;
return EXIT_SUCCESS;
}
```
###編纂・実行結果(compile and go)
```shell-session:cpla.sh
$ ../cpla.sh p207a
$ clang++ p207a.cpp -std=c++03 -Wall
0x10d28c0f0 0x10d28c270 0x10d28c1d0
C++N4741(105)8.3.4 Arrays [dcl.array]p207.cpp
$ clang++ p207a.cpp -std=c++2a -Wall
0x1006d10f0 0x1006d1270 0x1006d11d0
C++N4741(105)8.3.4 Arrays [dcl.array]p207.cpp
$ g++-8 p207a.cpp -std=c++03 -Wall
p207a.cpp: In function 'void f()':
p207a.cpp:26:12: warning: unused variable 'x' [-Wunused-variable]
extern int x[];
^
0x10b436080 0x10b436240 0x10b436180
C++N4741(105)8.3.4 Arrays [dcl.array]p207.cpp
$ g++-8 p207a.cpp -std=c++2a -Wall
p207a.cpp: In function 'void f()':
p207a.cpp:26:12: warning: unused variable 'x' [-Wunused-variable]
extern int x[];
^
0x102c13080 0x102c13240 0x102c13180
C++N4741(105)8.3.4 Arrays [dcl.array]p207.cpp
```
#検討事項(agenda)
役に立つまたは意味のあるその他の出力
#参考資料(reference)
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 <misra_c.h>
https://qiita.com/kaizen_nagoya/items/f1a79a7cbd281607c7c9
「C++完全理解ガイド」の同意できること上位10
https://qiita.com/kaizen_nagoya/items/aa5744e0c4a8618c7671
#文書履歴(document history)
ver. 0.10 初稿 20180523
0
106
C++N4741(106)8.3.5 Functions [dcl.fct]p209
#はじめに(Introduction)
C++N4741 Working Draft, Standard for Programming Language C++
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/n4741.pdf
C++N4741は、ISO/IEC JTC1 SC22 WG21の作業原案(Working Draft)です。
公式のISO/IEC 14882原本ではありません。
ISO/IEC JTC1 SC22 WG21では、可能な限り作業文書を公開し、幅広い意見を求めています。
一連の記事はコード断片をコンパイルできる形にする方法を検討してコンパイル、リンク、実行して、規格案の原文と処理系(g++, Clang++)との違いを確認し、技術内容を検討し、ISO/IEC JTC1 SC22 WG21にフィードバックするために用います。
また、CERT C++, MISRA C++等のコーディング標準のコード断片をコンパイルする際の参考にさせていただこうと考えています。CERT C++, MISRA C++が標準化の動きとの時間的なずれがあれば確認できれば幸いです。また、boostライブラリとの関連、Linux OS, TOPPERSカーネル、g++(GCC), clang++(LLVM)との関係も調査中です。
何か、抜け漏れ、耳より情報がありましたらおしらせくださると幸いです。
##背景(back ground)
C/C++でコンパイルエラーが出ると、途方にくれることがしばしばあります。
何回かに1回は、該当するエラーが検索できます。
ただ、条件が違っていて、そこでの修正方法では目的を達成しないこともしばしばです。いろいろな条件のコンパイルエラーとその対応方法について、広く記録することによって、いつか同じエラーに遭遇した時にやくに立つことを目指しています。
この半年の間で、三度、自分のネットでの記録に助けられたことがあります。
また過去に解決できなかった記録を10種類以上、最近になって解決できたことがあります。それは、主に次の4つの情報に基づいています。
https://stackoverflow.com
https://cpprefjp.github.io
http://ja.cppreference.com/
https://teratail.com/
また
https://researchmap.jp/joub9b3my-1797580/#_1797580
に記載したサイトのお世話になっています。
##作業方針(sequence)
Clang++では-std=c++03, c++17, C++2aの3種類
g++では-std=c++03, c++17の2種類
でコンパイルし、
1)コンパイルエラーを収集する。
2)コンパイルエラーをなくす方法を検討する。
コンパイルエラーになる例を示すだけが目的のコードは、コンパイルエラーをなくすのではなく、コンパイルエラーの種類を収集するだけにする。
文法を示すのが目的のコード場合に、コンパイルエラーをなくすのに手間がかかる場合は、順次作業します。
3)リンクエラーをなくす方法を検討する。
文法を示すのが目的のコード場合に、リンクエラーをなくすのに手間がかかる場合は、順次作業します。
4)意味のある出力を作る。
コンパイル、リンクが通っても、意味のある出力を示そうとすると、コンパイル・リンクエラーが出て収拾できそうにない場合がある。順次作業します。
1)だけのものから4)まで進んだものと色々ある状態です。一歩でも前に進むご助言をお待ちしています。「検討事項」の欄に現状を記録するようにしています。
初めての CEDD(Compile Error Driven Design) 8回直してコンパイル。
https://qiita.com/kaizen_nagoya/items/9494236aa1753f3fd1e1
https://qiita.com/kaizen_nagoya/items/85c0e92b206883140e89#_reference-f5ba2535f9b0e314ab73コンパイルエラーを記録するとよい理由7つ
##C++N4741, 2018 Standard Working Draft on ISO/IEC 14882 sample code compile list
https://qiita.com/kaizen_nagoya/items/3294c014044550896010
## C++N4606, 2016符号断片編纂一覧(example code compile list)
C++N4606, 2016 Working Draft 2016, ISO/IEC 14882, C++ standard(1) Example code compile list
https://qiita.com/kaizen_nagoya/items/df5d62c35bd6ed1c3d43/
##C++N3242, 2011 sample code compile list on clang++ and g++
https://qiita.com/kaizen_nagoya/items/685b5c1a2c17c1bf1318
## 編纂器(Compiler)
###clang++ --version
clang version 6.0.0 (tags/RELEASE_600/final)
Target: x86_64-apple-darwin17.4.0
###g++-7 --version
g++-7 (Homebrew GCC 7.3.0_1) 7.3.0
Copyright (C) 2017 Free Software Foundation, Inc.
#(106)8.3.5 Functions [dcl.fct]p209
(97)8.3.5 Functions p209
https://qiita.com/kaizen_nagoya/items/100f54c22a539e9a5260
C++N3242, 2011 (79) 8.3.5 Functions
https://researchmap.jp/jo7dqs334-1797580/#_1797580
##p209.cpp
###算譜(source code)
```c++:p209.cpp
// C++N4741 Committee Draft, Standard for Programming Language C++
// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/n741.pdf
const char* msg= "C++N4741(106)8.3.5 Functions [dcl.fct]p209.cpp";
// Edited by Dr. Ogawa Kiyoshi. Compile procedure and results record.
#include <iostream>
#include <cstdlib>
using namespace std;
int printf(const char*, ...);
void h1() {
int a,b;
printf("hello world");
printf("a=%d b=%d", a, b);
}
typedef int FIC(int) const;
FIC f; // ill-formed: does not declare a member function
struct S {
FIC f; // OK
};
FIC S::*pm = &S::f; // OK
namespace M {
typedef void F();
struct S {
const F f; // OK: equivalent to: void f();
};
}
int fseek(FILE*, long, int);
typedef void F();
F fv; // OK: equivalent to void fv();
F fv { } // ill-formed
void fv() { } // OK: definition of fv
void h2() {
int i,
*pi,
f(),
*fpi(int),
(*pif)(const char*, const char*),
(*fpif(int))(int);
}
typedef int IFUNC(int);
IFUNC* fpif(int);
///or
auto fpif(int)->int(*)(int);
template <class T, class U> auto add(T t, U u) -> decltype(t + u);
//rather than
template <class T, class U> decltype((*(T*)0) + (*(U*)0)) add(T t, U u);
template<typename... T> void f(T (* ...t)(int, int));
int add(int, int);
float subtract(int, int);
void g() {
f(add, subtract);
}
int main() {
cout<< msg << endl;
return EXIT_SUCCESS;
}
```
###編纂・実行結果(compile and go)
```shell-session:cpla.sh
$ ../c1.sh p209
$ clang++ p209.cpp -std=c++2a -Wall
p209.cpp:16:21: warning: variable 'a' is uninitialized when used here [-Wuninitialized]
printf("a=%d b=%d", a, b);
^
p209.cpp:14:6: note: initialize the variable 'a' to silence this warning
int a,b;
^
= 0
p209.cpp:16:24: warning: variable 'b' is uninitialized when used here [-Wuninitialized]
printf("a=%d b=%d", a, b);
^
p209.cpp:14:8: note: initialize the variable 'b' to silence this warning
int a,b;
^
= 0
p209.cpp:20:1: error: non-member function of type 'FIC' (aka 'int (int) const') cannot have
'const' qualifier
FIC f; // ill-formed: does not declare a member function
^
p209.cpp:29:1: warning: 'const' qualifier on function type 'M::F' (aka 'void ()') has no effect
[-Wignored-qualifiers]
const F f; // OK: equivalent to: void f();
^~~~~~
p209.cpp:37:3: error: illegal initializer (only variables can be initialized)
F fv { } // ill-formed
^
p209.cpp:37:9: error: expected ';' after top level declarator
F fv { } // ill-formed
^
;
p209.cpp:43:2: warning: empty parentheses interpreted as a function declaration [-Wvexing-parse]
f(),
^~
p209.cpp:42:4: note: change this ',' to a ';' to call 'f'
*pi,
^
;
p209.cpp:43:2: note: replace parentheses with an initializer to declare a variable
f(),
^~
= 0
p209.cpp:45:3: warning: unused variable 'pif' [-Wunused-variable]
(*pif)(const char*, const char*),
^
p209.cpp:42:2: warning: unused variable 'pi' [-Wunused-variable]
*pi,
^
p209.cpp:41:5: warning: unused variable 'i' [-Wunused-variable]
int i,
^
p209.cpp:62:1: error: no matching function for call to 'f'
f(add, subtract);
^
p209.cpp:58:30: note: candidate template ignored: substitution failure : deduced incomplete pack
<(no value), float> for template parameter 'T'
template<typename... T> void f(T (* ...t)(int, int));
~ ^
p209.cpp:20:5: note: candidate function not viable: requires 1 argument, but 2 were provided
FIC f; // ill-formed: does not declare a member function
^
7 warnings and 4 errors generated.
```
##p209a.cpp
コンパイルエラーを想定していた行を///註釈に。
###算譜(source code)
```c++:p209a.cpp
/// C++N4741 Committee Draft, Standard for Programming Language C++
// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/n741.pdf
const char* msg= "C++N4741(106)8.3.5 Functions [dcl.fct]p209.cpp";
// Edited by Dr. Ogawa Kiyoshi. Compile procedure and results record.
#include <iostream>
#include <cstdlib>
using namespace std;
int printf(const char*, ...);
void h1() {
int a,b;
printf("hello world");
printf("a=%d b=%d", a, b);
}
typedef int FIC(int) const;
///FIC f; // ill-formed: does not declare a member function
struct S {
FIC f; // OK
};
FIC S::*pm = &S::f; // OK
namespace M {
typedef void F();
struct S {
const F f; // OK: equivalent to: void f();
};
}
int fseek(FILE*, long, int);
typedef void F();
F fv; // OK: equivalent to void fv();
///F fv { } // ill-formed
void fv() { } // OK: definition of fv
void h2() {
int i,
*pi,
f(),
*fpi(int),
(*pif)(const char*, const char*),
(*fpif(int))(int);
}
typedef int IFUNC(int);
IFUNC* fpif(int);
///or
auto fpif(int)->int(*)(int);
template <class T, class U> auto add(T t, U u) -> decltype(t + u);
//rather than
template <class T, class U> decltype((*(T*)0) + (*(U*)0)) add(T t, U u);
template<typename... T> void f(T (* ...t)(int, int));
int add(int, int);
float subtract(int, int);
void g() {
f(add, subtract);
}
int main() {
cout<< msg << endl;
return EXIT_SUCCESS;
}
```
###編纂・実行結果(compile and go)
```shell-session:c1.sh
$ ../c1.sh p209a
$ clang++ p209a.cpp -std=c++2a -Wall
p209a.cpp:16:21: warning: variable 'a' is uninitialized when used here [-Wuninitialized]
printf("a=%d b=%d", a, b);
^
p209a.cpp:14:6: note: initialize the variable 'a' to silence this warning
int a,b;
^
= 0
p209a.cpp:16:24: warning: variable 'b' is uninitialized when used here [-Wuninitialized]
printf("a=%d b=%d", a, b);
^
p209a.cpp:14:8: note: initialize the variable 'b' to silence this warning
int a,b;
^
= 0
p209a.cpp:29:1: warning: 'const' qualifier on function type 'M::F' (aka 'void ()') has no effect
[-Wignored-qualifiers]
const F f; // OK: equivalent to: void f();
^~~~~~
p209a.cpp:43:2: warning: empty parentheses interpreted as a function declaration
[-Wvexing-parse]
f(),
^~
p209a.cpp:43:2: note: replace parentheses with an initializer to declare a variable
f(),
^~
= 0
p209a.cpp:41:5: warning: unused variable 'i' [-Wunused-variable]
int i,
^
p209a.cpp:42:2: warning: unused variable 'pi' [-Wunused-variable]
*pi,
^
p209a.cpp:45:3: warning: unused variable 'pif' [-Wunused-variable]
(*pif)(const char*, const char*),
^
p209a.cpp:62:1: error: no matching function for call to 'f'
f(add, subtract);
^
p209a.cpp:58:30: note: candidate template ignored: substitution failure : deduced incomplete
pack <(no value), float> for template parameter 'T'
template<typename... T> void f(T (* ...t)(int, int));
~ ^
7 warnings and 1 error generated.
```
#検討事項(agenda)
予定以外のところがコンパイルエラーになる背景。
役に立つまたは意味のあるその他の出力
#参考資料(reference)
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 <misra_c.h>
https://qiita.com/kaizen_nagoya/items/f1a79a7cbd281607c7c9
「C++完全理解ガイド」の同意できること上位10
https://qiita.com/kaizen_nagoya/items/aa5744e0c4a8618c7671
#文書履歴(document history)
ver. 0.10 初稿 20180524
0
104
C++N4741(104)8.3.3 Pointers to members [dcl.mptr]p206
#はじめに(Introduction)
C++N4741 Working Draft, Standard for Programming Language C++
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/n4741.pdf
C++N4741は、ISO/IEC JTC1 SC22 WG21の作業原案(Working Draft)です。
公式のISO/IEC 14882原本ではありません。
ISO/IEC JTC1 SC22 WG21では、可能な限り作業文書を公開し、幅広い意見を求めています。
一連の記事はコード断片をコンパイルできる形にする方法を検討してコンパイル、リンク、実行して、規格案の原文と処理系(g++, Clang++)との違いを確認し、技術内容を検討し、ISO/IEC JTC1 SC22 WG21にフィードバックするために用います。
また、CERT C++, MISRA C++等のコーディング標準のコード断片をコンパイルする際の参考にさせていただこうと考えています。CERT C++, MISRA C++が標準化の動きとの時間的なずれがあれば確認できれば幸いです。また、boostライブラリとの関連、Linux OS, TOPPERSカーネル、g++(GCC), clang++(LLVM)との関係も調査中です。
何か、抜け漏れ、耳より情報がありましたらおしらせくださると幸いです。
##背景(back ground)
C/C++でコンパイルエラーが出ると、途方にくれることがしばしばあります。
何回かに1回は、該当するエラーが検索できます。
ただ、条件が違っていて、そこでの修正方法では目的を達成しないこともしばしばです。いろいろな条件のコンパイルエラーとその対応方法について、広く記録することによって、いつか同じエラーに遭遇した時にやくに立つことを目指しています。
この半年の間で、三度、自分のネットでの記録に助けられたことがあります。
また過去に解決できなかった記録を10種類以上、最近になって解決できたことがあります。それは、主に次の4つの情報に基づいています。
https://stackoverflow.com
https://cpprefjp.github.io
http://ja.cppreference.com/
https://teratail.com/
また
https://researchmap.jp/joub9b3my-1797580/#_1797580
に記載したサイトのお世話になっています。
##作業方針(sequence)
Clang++では-std=c++03, c++17, C++2aの3種類
g++では-std=c++03, c++17の2種類
でコンパイルし、
1)コンパイルエラーを収集する。
2)コンパイルエラーをなくす方法を検討する。
コンパイルエラーになる例を示すだけが目的のコードは、コンパイルエラーをなくすのではなく、コンパイルエラーの種類を収集するだけにする。
文法を示すのが目的のコード場合に、コンパイルエラーをなくすのに手間がかかる場合は、順次作業します。
3)リンクエラーをなくす方法を検討する。
文法を示すのが目的のコード場合に、リンクエラーをなくすのに手間がかかる場合は、順次作業します。
4)意味のある出力を作る。
コンパイル、リンクが通っても、意味のある出力を示そうとすると、コンパイル・リンクエラーが出て収拾できそうにない場合がある。順次作業します。
1)だけのものから4)まで進んだものと色々ある状態です。一歩でも前に進むご助言をお待ちしています。「検討事項」の欄に現状を記録するようにしています。
初めての CEDD(Compile Error Driven Design) 8回直してコンパイル。
https://qiita.com/kaizen_nagoya/items/9494236aa1753f3fd1e1
https://qiita.com/kaizen_nagoya/items/85c0e92b206883140e89#_reference-f5ba2535f9b0e314ab73コンパイルエラーを記録するとよい理由7つ
##C++N4741, 2018 Standard Working Draft on ISO/IEC 14882 sample code compile list
https://qiita.com/kaizen_nagoya/items/3294c014044550896010
## C++N4606, 2016符号断片編纂一覧(example code compile list)
C++N4606, 2016 Working Draft 2016, ISO/IEC 14882, C++ standard(1) Example code compile list
https://qiita.com/kaizen_nagoya/items/df5d62c35bd6ed1c3d43/
##C++N3242, 2011 sample code compile list on clang++ and g++
https://qiita.com/kaizen_nagoya/items/685b5c1a2c17c1bf1318
## 編纂器(Compiler)
###clang++ --version
clang version 6.0.0 (tags/RELEASE_600/final)
Target: x86_64-apple-darwin17.4.0
###g++-7 --version
g++-7 (Homebrew GCC 7.3.0_1) 7.3.0
Copyright (C) 2017 Free Software Foundation, Inc.
#(104)8.3.3 Pointers to members [dcl.mptr]p206
C++N4606, 2016(95)8.3.3 Pointers to members [dcl.mptr] p206
https://qiita.com/kaizen_nagoya/items/cc0156a5dc405c969186
C++N3242, 2011 (77) 8.3.3 Pointers to members
https://researchmap.jp/jofbeur4s-1797580/#_1797580
##p206.cpp
###算譜(source code)
```c++:p206.cpp
// C++N4741 Committee Draft, Standard for Programming Language C++
// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/n741.pdf
const char* msg= "C++N4741(104)8.3.3 Pointers to members [dcl.mptr]p206.cpp";
// Edited by Dr. Ogawa Kiyoshi. Compile procedure and results record.
#include <iostream>
#include <cstdlib>
using namespace std;
struct X {
void f(int) {};
int a;
};
struct Y;
int X::* pmi = &X::a;
void (X::* pmf)(int) = &X::f;
double X::* pmd;
char Y::* pmc;
void g() {
X obj;
// ...
obj.*pmi = 7; // assign 7 to an integer
// member of obj
(obj.*pmf)(7); // call a function member of obj
// with the argument 7
cout << obj.*pmi << endl;
}
int main() {
int i=3;
X x;
x.f(i);
g();
cout<< msg << endl;
return EXIT_SUCCESS;
}
```
###編纂・実行結果(compile and go)
```shell-session:cpla.sh
$ ../cpla.sh p206
$ clang++ p206.cpp -std=c++03 -Wall
7
C++N4741(104)8.3.3 Pointers to members [dcl.mptr]p206.cpp
$ clang++ p206.cpp -std=c++2a -Wall
7
C++N4741(104)8.3.3 Pointers to members [dcl.mptr]p206.cpp
$ g++-8 p206.cpp -std=c++03 -Wall
7
C++N4741(104)8.3.3 Pointers to members [dcl.mptr]p206.cpp
$ g++-8 p206.cpp -std=c++2a -Wall
7
C++N4741(104)8.3.3 Pointers to members [dcl.mptr]p206.cpp
```
#検討事項(agenda)
役に立つまたは意味のあるその他の出力
#参考資料(reference)
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 <misra_c.h>
https://qiita.com/kaizen_nagoya/items/f1a79a7cbd281607c7c9
「C++完全理解ガイド」の同意できること上位10
https://qiita.com/kaizen_nagoya/items/aa5744e0c4a8618c7671
#文書履歴(document history)
ver. 0.10 初稿 20180523
0