はじめに(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種類以上、最近になって解決できたことがあります。それは、主に次の3つの情報に基づいています。
https://stackoverflow.com
https://cpprefjp.github.io
http://ja.cppreference.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
##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.
#(40)8.4.5.2 Captures [expr.prim.lambda.capture]p91
No section on C++ N4606, but same samples are in
37)5.1.5 Lambda expressions [expr.prim.lambda]p97
https://qiita.com/kaizen_nagoya/items/f0c78ed1d43514053070
No section on C++N3242, 2011, but same samples are in
C++N3242, 2011 (29) 5.1.2 Lambda expressions
https://researchmap.jp/joo8p5759-1797580/#_1797580
p.91.cpp
算譜(source code)
// 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(40)8.4.5.2 Captures [expr.prim.lambda.capture]p91.cpp";
// Edited by Dr. Ogawa Kiyoshi. Compile procedure and results record.
#include <iostream>
#include <cstdlib>
using namespace std;
struct S2 { void f(int i); };
void S2::f(int i) {
[&, i]{ }; // OK
[&, this, i]{ }; // OK, equivalent to [&, i]
[&, &i]{ }; // error: i preceded by & when & is the default
[=, *this]{ }; // OK
[=, this]{ }; // OK, equivalent to [=]
[i, i]{ }; // error: i repeated
[this, *this]{ }; // error: this appears twice
}
void f() {
int x = 0;
auto g = [x](int x) { return 0; } // error: parameter and simple-capture have the same name
}
int x = 4;
auto y = [&r = x, x = x+1]()->int {
r += 2;
return x+2;
}(); // Updates ::x to 6, and initializes y to 7.
auto z = [a = 42](int a) { return 1; } // error: parameter and local variable have the same name
void f(int, const int (&)[2] = {}); // #1
void f(const int&, const int (&)[1]); // #2
void test() {
const int x = 17;
auto g = [](auto a) {
f(x); // OK: calls #1, does not capture x
};
auto g1 = [=](auto a) {
f(x); // OK: calls #1, captures x
};
auto g2 = [=](auto a) {
int selector[sizeof(a) == 1 ? 1 : 2]{};
f(x, selector); // OK: captures x, might call #1 or #2
};
auto g3 = [=](auto a) {
typeid(a + x); // captures x regardless of whether a + x is an unevaluated operand
};
}
template<bool B>
void f(int n) {
[=](auto a) {
if constexpr (B && sizeof(a) > 4) {
(void)n; // captures n regardless of the value of B and sizeof(int)
}
}(0);
}
void f1(int i) {
int const N = 20;
auto m1 = [=]{
int const M = 30;
auto m2 = [i]{
int x[N][M]; // OK: N and M are not odr-used
x[0][0] = i; // OK: i is explicitly captured by m2 and implicitly captured by m1
};
};
struct s1 {
int f;
void work(int n) {
int m = n*n;
int j = 40;
auto m3 = [this,m] {
auto m4 = [&,j] { // error: j not odr-usable due to intervening lambda m3
int x = n; // error: n is odr-used but not odr-usable due to intervening lambda m3
x += m; // OK: m implicitly captured by m4 and explicitly captured by m3
x += i; // error: i is odr-used but not odr-usable
// due to intervening function and class scopes
x += f; // OK: this captured implicitly by m4 and explicitly by m3
};
};
}
};
}
struct s2 {
double ohseven = .007;
auto f() {
return [this] {
return [*this] {
return ohseven; // OK
}
}();
}
auto g() {
return [] {
return [*this] { }; // error: *this not captured by outer lambda-expression
}();
}
};
void f2() {
int i = 1;
void g1(int = ([i]{ return i; })()); // ill-formed
void g2(int = ([i]{ return 0; })()); // ill-formed
void g3(int = ([=]{ return i; })()); // ill-formed
void g4(int = ([=]{ return 0; })()); // OK
void g5(int = ([]{ return sizeof i; })()); // OK
}
void f(const int*);
void g() {
const int N = 10;
[=] {
int arr[N]; // OK: not an odr-use, refers to automatic variable
f(&N); // OK: causes N to be captured; &N points to
// the corresponding member of the closure type
};
}
auto h(int &r) {
return [&] {
++r; // Valid after h returns if the lifetime of the
// object to which r is bound has not ended
};
}
int a = 1, b = 1, c = 1;
auto m1 = [a, &b, &c]() mutable {
auto m2 = [a, b, &c]() mutable {
std::cout << a << b << c;
a = 4; b = 4; c = 4;
};
a = 3; b = 3; c = 3;
m2();
};
a = 2; b = 2; c = 2;
m1();
std::cout << a << b << c;
template<class... Args>
void f(Args... args) {
auto lm = [&, args...] { return g(args...); };
lm();
auto lm2 = [...xs=std::move(args)] { return g(xs...); };
lm2();
}
int main() {
cout<< msg << endl;
return EXIT_SUCCESS;
}
編纂・実行結果(compile and go)
$ ../c1.sh p91
$ clang++ p91.cpp -std=c++2a -Wall
p91.cpp:3:16: error: expected ';' after top level declarator
const char* msg "C++N4741(40)8.4.5.2 Captures [expr.prim.lambda.capture]p91.cpp"
^
;
p91.cpp:13:5: warning: lambda capture 'i' is not used [-Wunused-lambda-capture]
[&, i]{ }; // OK
^
p91.cpp:14:5: warning: lambda capture 'this' is not used [-Wunused-lambda-capture]
[&, this, i]{ }; // OK, equivalent to [&, i]
^
p91.cpp:14:11: warning: lambda capture 'i' is not used [-Wunused-lambda-capture]
[&, this, i]{ }; // OK, equivalent to [&, i]
^
p91.cpp:15:6: error: '&' cannot precede a capture when the capture default is '&'
[&, &i]{ }; // error: i preceded by & when & is the default
~~~^
p91.cpp:16:5: warning: lambda capture 'this' is not used [-Wunused-lambda-capture]
[=, *this]{ }; // OK
^
p91.cpp:17:5: warning: lambda capture 'this' is not used [-Wunused-lambda-capture]
[=, this]{ }; // OK, equivalent to [=]
^
p91.cpp:18:5: error: 'i' can appear only once in a capture list
[i, i]{ }; // error: i repeated
~~~^
p91.cpp:18:2: warning: lambda capture 'i' is not used [-Wunused-lambda-capture]
[i, i]{ }; // error: i repeated
^
p91.cpp:19:8: error: 'this' can appear only once in a capture list
[this, *this]{ }; // error: this appears twice
~~~~~~^
p91.cpp:19:2: warning: lambda capture 'this' is not used [-Wunused-lambda-capture]
[this, *this]{ }; // error: this appears twice
^
p91.cpp:13:1: warning: expression result unused [-Wunused-value]
[&, i]{ }; // OK
^~~~~~~~~
p91.cpp:14:1: warning: expression result unused [-Wunused-value]
[&, this, i]{ }; // OK, equivalent to [&, i]
^~~~~~~~~~~~~~~
p91.cpp:15:1: warning: expression result unused [-Wunused-value]
[&, &i]{ }; // error: i preceded by & when & is the default
^~~~~~~~~~
p91.cpp:16:1: warning: expression result unused [-Wunused-value]
[=, *this]{ }; // OK
^~~~~~~~~~~~~
p91.cpp:17:1: warning: expression result unused [-Wunused-value]
[=, this]{ }; // OK, equivalent to [=]
^~~~~~~~~~~~
p91.cpp:18:1: warning: expression result unused [-Wunused-value]
[i, i]{ }; // error: i repeated
^~~~~~~~~
p91.cpp:19:1: warning: expression result unused [-Wunused-value]
[this, *this]{ }; // error: this appears twice
^~~~~~~~~~~~~~~~
p91.cpp:24:11: warning: lambda capture 'x' is not used [-Wunused-lambda-capture]
auto g = [x](int x) { return 0; } // error: parameter and simple-capture have the same name
^
p91.cpp:24:34: error: expected ';' at end of declaration
auto g = [x](int x) { return 0; } // error: parameter and simple-capture have the same name
^
;
p91.cpp:28:12: warning: lambda capture 'r' is not required to be captured for this use
[-Wunused-lambda-capture]
auto y = [&r = x, x = x+1]()->int {
^
p91.cpp:32:11: warning: lambda capture 'a' is not used [-Wunused-lambda-capture]
auto z = [a = 42](int a) { return 1; } // error: parameter and local variable have the same name
^
p91.cpp:32:39: error: expected ';' after top level declarator
auto z = [a = 42](int a) { return 1; } // error: parameter and local variable have the same name
^
;
p91.cpp:49:1: warning: expression result unused [-Wunused-value]
typeid(a + x); // captures x regardless of whether a + x is an unevaluated operand
^~~~~~~~~~~~~
p91.cpp:48:6: warning: unused variable 'g3' [-Wunused-variable]
auto g3 = [=](auto a) {
^
p91.cpp:41:6: warning: unused variable 'g1' [-Wunused-variable]
auto g1 = [=](auto a) {
^
p91.cpp:38:6: warning: unused variable 'g' [-Wunused-variable]
auto g = [](auto a) {
^
p91.cpp:44:6: warning: unused variable 'g2' [-Wunused-variable]
auto g2 = [=](auto a) {
^
p91.cpp:66:6: warning: unused variable 'm2' [-Wunused-variable]
auto m2 = [i]{
^
p91.cpp:77:14: error: variable 'j' cannot be implicitly captured in a lambda with no capture-default
specified
auto m4 = [&,j] { // error: j not odr-usable due to intervening lambda m3
^
p91.cpp:75:5: note: 'j' declared here
int j = 40;
^
p91.cpp:76:11: note: lambda expression begins here
auto m3 = [this,m] {
^
p91.cpp:78:9: error: variable 'n' cannot be implicitly captured in a lambda with no capture-default
specified
int x = n; // error: n is odr-used but not odr-usable due to intervening lambda m3
^
p91.cpp:73:15: note: 'n' declared here
void work(int n) {
^
p91.cpp:76:11: note: lambda expression begins here
auto m3 = [this,m] {
^
p91.cpp:80:6: error: variable 'i' cannot be implicitly captured in a lambda with no capture-default
specified
x += i; // error: i is odr-used but not odr-usable
^
p91.cpp:62:13: note: 'i' declared here
void f1(int i) {
^
p91.cpp:76:11: note: lambda expression begins here
auto m3 = [this,m] {
^
p91.cpp:94:2: error: expected ';' after return statement
}
^
;
p91.cpp:99:9: error: 'this' cannot be implicitly captured in this context
return [*this] { }; // error: *this not captured by outer lambda-expression
^
p91.cpp:106:16: error: lambda expression in default argument cannot capture any entity
void g1(int = ([i]{ return i; })()); // ill-formed
^
p91.cpp:107:17: warning: lambda capture 'i' is not used [-Wunused-lambda-capture]
void g2(int = ([i]{ return 0; })()); // ill-formed
^
p91.cpp:107:16: error: lambda expression in default argument cannot capture any entity
void g2(int = ([i]{ return 0; })()); // ill-formed
^
p91.cpp:108:16: error: lambda expression in default argument cannot capture any entity
void g3(int = ([=]{ return i; })()); // ill-formed
^
p91.cpp:117:5: warning: unused variable 'arr' [-Wunused-variable]
int arr[N]; // OK: not an odr-use, refers to automatic variable
^
p91.cpp:116:1: warning: expression result unused [-Wunused-value]
[=] {
^~~~~
p91.cpp:131:12: error: 'a' cannot be captured because it does not have automatic storage duration
auto m1 = [a, &b, &c]() mutable {
^
p91.cpp:130:5: note: 'a' declared here
int a = 1, b = 1, c = 1;
^
p91.cpp:131:16: error: 'b' cannot be captured because it does not have automatic storage duration
auto m1 = [a, &b, &c]() mutable {
^
p91.cpp:130:12: note: 'b' declared here
int a = 1, b = 1, c = 1;
^
p91.cpp:131:20: error: 'c' cannot be captured because it does not have automatic storage duration
auto m1 = [a, &b, &c]() mutable {
^
p91.cpp:130:19: note: 'c' declared here
int a = 1, b = 1, c = 1;
^
p91.cpp:132:12: error: 'a' cannot be captured because it does not have automatic storage duration
auto m2 = [a, b, &c]() mutable {
^
p91.cpp:130:5: note: 'a' declared here
int a = 1, b = 1, c = 1;
^
p91.cpp:132:15: error: 'b' cannot be captured because it does not have automatic storage duration
auto m2 = [a, b, &c]() mutable {
^
p91.cpp:130:12: note: 'b' declared here
int a = 1, b = 1, c = 1;
^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
#コンパイルエラー想定箇所注釈に
算譜(source code)
// 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(40)8.4.5.2 Captures [expr.prim.lambda.capture]p91-2.cpp";
// Edited by Dr. Ogawa Kiyoshi. Compile procedure and results record.
#include <iostream>
#include <cstdlib>
using namespace std;
struct S2 {
void f(int i);
};
void S2::f(int i) {
[&, i] { }; // OK
[&, this, i] { }; // OK, equivalent to [&, i]
//[&, &i]{ }; // error: i preceded by & when & is the default
[=, *this] { }; // OK
[=, this] { }; // OK, equivalent to [=]
//[i, i]{ }; // error: i repeated
//[this, *this]{ }; // error: this appears twice
}
void f() {
int x = 0;
//auto g = [x](int x) { return 0; } // error: parameter and simple-capture have the same name
}
int x = 4;
auto y = [&r = x, x = x+1]()->int {
r += 2;
return x+2;
}
(); // Updates ::x to 6, and initializes y to 7.
//auto z = [a = 42](int a) { return 1; } // error: parameter and local variable have the same name
void f(int, const int (&)[2] = {}); // #1
void f(const int&, const int (&)[1]); // #2
void test() {
const int x = 17;
auto g = [](auto a) {
f(x); // OK: calls #1, does not capture x
};
auto g1 = [=](auto a) {
f(x); // OK: calls #1, captures x
};
auto g2 = [=](auto a) {
int selector[sizeof(a) == 1 ? 1 : 2] {};
f(x, selector); // OK: captures x, might call #1 or #2
};
auto g3 = [=](auto a) {
typeid(a + x); // captures x regardless of whether a + x is an unevaluated operand
};
}
template<bool B>
void f(int n) {
[=](auto a) {
if constexpr (B && sizeof(a) > 4) {
(void)n; // captures n regardless of the value of B and sizeof(int)
}
}
(0);
}
void f1(int i) {
int const N = 20;
auto m1 = [=] {
int const M = 30;
auto m2 = [i]{
int x[N][M]; // OK: N and M are not odr-used
x[0][0] = i; // OK: i is explicitly captured by m2 and implicitly captured by m1
};
};
struct s1 {
int f;
void work(int n) {
int m = n*n;
int j = 40;
auto m3 = [this,m] {
//auto m4 = [&,j] { // error: j not odr-usable due to intervening lambda m3
//int x = n; // error: n is odr-used but not odr-usable due to intervening lambda m3
x += m; // OK: m implicitly captured by m4 and explicitly captured by m3
//x += i; // error: i is odr-used but not odr-usable
// due to intervening function and class scopes
x += f; // OK: this captured implicitly by m4 and explicitly by m3
};
};
}
};
}
struct s2 {
double ohseven = .007;
auto f() {
return [this] {
return [*this] {
return ohseven; // OK
}
}();
}
auto g() {
return [] {
//return [*this] { }; // error: *this not captured by outer lambda-expression
}();
}
};
void f2() {
int i = 1;
//void g1(int = ([i]{ return i; })()); // ill-formed
//void g2(int = ([i]{ return 0; })()); // ill-formed
//void g3(int = ([=]{ return i; })()); // ill-formed
void g4(int = ([=] { return 0; })()); // OK
void g5(int = ([] { return sizeof i; })()); // OK
}
void f(const int*);
void g() {
const int N = 10;
[=] {
int arr[N]; // OK: not an odr-use, refers to automatic variable
f(&N); // OK: causes N to be captured; &N points to
// the corresponding member of the closure type
};
}
auto h(int &r) {
return [&] {
++r; // Valid after h returns if the lifetime of the
// object to which r is bound has not ended
};
}
int a = 1, b = 1, c = 1;
auto m1 = [a, &b, &c]() mutable {
auto m2 = [a, b, &c]() mutable {
std::cout << a << b << c;
a = 4;
b = 4;
c = 4;
};
a = 3;
b = 3;
c = 3;
m2();
};
a = 2;
b = 2;
c = 2;
m1();
std::cout << a << b << c;
template<class... Args>
void f(Args... args) {
auto lm = [&, args...] { return g(args...); };
lm();
auto lm2 = [...xs=std::move(args)] { return g(xs...); };
lm2();
}
int main() {
cout<< msg << endl;
return EXIT_SUCCESS;
}
編纂・実行結果(compile and go)
$ ../c1.sh p91-2
$ clang++ p91-2.cpp -std=c++2a -Wall
p91-2.cpp:13:5: warning: lambda capture 'i' is not used [-Wunused-lambda-capture]
[&, i]{ }; // OK
^
p91-2.cpp:14:5: warning: lambda capture 'this' is not used [-Wunused-lambda-capture]
[&, this, i]{ }; // OK, equivalent to [&, i]
^
p91-2.cpp:14:11: warning: lambda capture 'i' is not used [-Wunused-lambda-capture]
[&, this, i]{ }; // OK, equivalent to [&, i]
^
p91-2.cpp:16:5: warning: lambda capture 'this' is not used [-Wunused-lambda-capture]
[=, *this]{ }; // OK
^
p91-2.cpp:17:5: warning: lambda capture 'this' is not used [-Wunused-lambda-capture]
[=, this]{ }; // OK, equivalent to [=]
^
p91-2.cpp:13:1: warning: expression result unused [-Wunused-value]
[&, i]{ }; // OK
^~~~~~~~~
p91-2.cpp:14:1: warning: expression result unused [-Wunused-value]
[&, this, i]{ }; // OK, equivalent to [&, i]
^~~~~~~~~~~~~~~
p91-2.cpp:16:1: warning: expression result unused [-Wunused-value]
[=, *this]{ }; // OK
^~~~~~~~~~~~~
p91-2.cpp:17:1: warning: expression result unused [-Wunused-value]
[=, this]{ }; // OK, equivalent to [=]
^~~~~~~~~~~~
p91-2.cpp:23:5: warning: unused variable 'x' [-Wunused-variable]
int x = 0;
^
p91-2.cpp:28:12: warning: lambda capture 'r' is not required to be captured for this use
[-Wunused-lambda-capture]
auto y = [&r = x, x = x+1]()->int {
^
p91-2.cpp:49:1: warning: expression result unused [-Wunused-value]
typeid(a + x); // captures x regardless of whether a + x is an unevaluated operand
^~~~~~~~~~~~~
p91-2.cpp:41:6: warning: unused variable 'g1' [-Wunused-variable]
auto g1 = [=](auto a) {
^
p91-2.cpp:48:6: warning: unused variable 'g3' [-Wunused-variable]
auto g3 = [=](auto a) {
^
p91-2.cpp:44:6: warning: unused variable 'g2' [-Wunused-variable]
auto g2 = [=](auto a) {
^
p91-2.cpp:38:6: warning: unused variable 'g' [-Wunused-variable]
auto g = [](auto a) {
^
p91-2.cpp:66:6: warning: unused variable 'm2' [-Wunused-variable]
auto m2 = [i]{
^
p91-2.cpp:75:5: warning: unused variable 'j' [-Wunused-variable]
int j = 40;
^
p91-2.cpp:76:6: warning: unused variable 'm3' [-Wunused-variable]
auto m3 = [this,m] {
^
p91-2.cpp:85:2: error: expected ';' after struct
}
^
;
p91-2.cpp:87:1: error: extraneous closing brace ('}')
}
^
p91-2.cpp:94:2: error: expected ';' after return statement
}
^
;
p91-2.cpp:117:5: warning: unused variable 'arr' [-Wunused-variable]
int arr[N]; // OK: not an odr-use, refers to automatic variable
^
p91-2.cpp:116:1: warning: expression result unused [-Wunused-value]
[=] {
^~~~~
p91-2.cpp:131:12: error: 'a' cannot be captured because it does not have automatic storage duration
auto m1 = [a, &b, &c]() mutable {
^
p91-2.cpp:130:5: note: 'a' declared here
int a = 1, b = 1, c = 1;
^
p91-2.cpp:131:16: error: 'b' cannot be captured because it does not have automatic storage duration
auto m1 = [a, &b, &c]() mutable {
^
p91-2.cpp:130:12: note: 'b' declared here
int a = 1, b = 1, c = 1;
^
p91-2.cpp:131:20: error: 'c' cannot be captured because it does not have automatic storage duration
auto m1 = [a, &b, &c]() mutable {
^
p91-2.cpp:130:19: note: 'c' declared here
int a = 1, b = 1, c = 1;
^
p91-2.cpp:132:12: error: 'a' cannot be captured because it does not have automatic storage duration
auto m2 = [a, b, &c]() mutable {
^
p91-2.cpp:130:5: note: 'a' declared here
int a = 1, b = 1, c = 1;
^
p91-2.cpp:132:15: error: 'b' cannot be captured because it does not have automatic storage duration
auto m2 = [a, b, &c]() mutable {
^
p91-2.cpp:130:12: note: 'b' declared here
int a = 1, b = 1, c = 1;
^
p91-2.cpp:132:19: error: 'c' cannot be captured because it does not have automatic storage duration
auto m2 = [a, b, &c]() mutable {
^
p91-2.cpp:130:19: note: 'c' declared here
int a = 1, b = 1, c = 1;
^
p91-2.cpp:139:1: error: C++ requires a type specifier for all declarations
a = 2; b = 2; c = 2;
^
p91-2.cpp:139:8: error: C++ requires a type specifier for all declarations
a = 2; b = 2; c = 2;
^
p91-2.cpp:139:15: error: C++ requires a type specifier for all declarations
a = 2; b = 2; c = 2;
^
p91-2.cpp:140:1: error: C++ requires a type specifier for all declarations
m1();
^
p91-2.cpp:141:6: error: no type named 'cout' in namespace 'std'
std::cout << a << b << c;
~~~~~^
p91-2.cpp:141:11: error: expected unqualified-id
std::cout << a << b << c;
^
p91-2.cpp:147:13: error: expected variable name or 'this' in lambda capture list
auto lm2 = [...xs=std::move(args)] { return g(xs...); };
^
p91-2.cpp:148:1: error: C++ requires a type specifier for all declarations
lm2();
^
p91-2.cpp:149:1: error: extraneous closing brace ('}')
}
^
21 warnings and 18 errors generated.
$ $ g++ p91-2.cpp -std=c++17 -Wall
p91-2.cpp: In member function 'void S2::f(int)':
p91-2.cpp:18:7: error: expected identifier before '*' token
[=, *this] { }; // OK
^
p91-2.cpp:19:7: warning: explicit by-copy capture of 'this' redundant with by-copy capture default
[=, this] { }; // OK, equivalent to [=]
^~~~
p91-2.cpp: In function 'void f()':
p91-2.cpp:25:7: warning: unused variable 'x' [-Wunused-variable]
int x = 0;
^
p91-2.cpp: In lambda function:
p91-2.cpp:52:16: error: must #include <typeinfo> before using typeid
typeid(a + x); // captures x regardless of whether a + x is an unevaluated operand
^
p91-2.cpp: In lambda function:
p91-2.cpp:59:8: error: expected '(' before 'constexpr'
if constexpr (B && sizeof(a) > 4) {
^~~~~~~~~
p91-2.cpp: In function 'void f1(int)':
p91-2.cpp:89:3: error: expected ';' after struct definition
}
^
p91-2.cpp: In member function 'void f1(int)::s1::work(int)':
p91-2.cpp:79:11: warning: unused variable 'j' [-Wunused-variable]
int j = 40;
^
p91-2.cpp: At global scope:
p91-2.cpp:91:1: error: expected declaration before '}' token
}
^
#検討事項(agenda) coding C++N4741
clang++でコンパイルエラー18、g++は5つ。
役に立つまたは意味のあるその他の出力
参考資料(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
https://qiita.com/kaizen_nagoya/items/f1a79a7cbd281607c7c9
「C++完全理解ガイド」の同意できること上位10
https://qiita.com/kaizen_nagoya/items/aa5744e0c4a8618c7671
文書履歴(document history)
ver. 0.10 初稿 20180508 コンパイルエラーが十分取れていない。
clang++でコンパイルエラー18、g++は5つ。
ver. 0.02 URL追記 20230215
最後までおよみいただきありがとうございました。
いいね 💚、フォローをお願いします。
Thank you very much for reading to the last sentence.
Please press the like icon 💚 and follow me for your happy life.