はじめに(Introduction)
N4910 Working Draft, Standard for Programming Language C++
n4910は、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++2bの2種類
g++では-std=c++03, c++2bの2種類
でコンパイルし、
1)コンパイルエラーを収集する。
2)コンパイルエラーをなくす方法を検討する。
コンパイルエラーになる例を示すだけが目的のコードは、コンパイルエラーをなくすのではなく、コンパイルエラーの種類を収集するだけにする。
文法を示すのが目的のコード場合に、コンパイルエラーをなくすのに手間がかかる場合は、順次作業します。
3)リンクエラーをなくす方法を検討する。
文法を示すのが目的のコード場合に、リンクエラーをなくすのに手間がかかる場合は、順次作業します。
4)意味のある出力を作る。
コンパイル、リンクが通っても、意味のある出力を示そうとすると、コンパイル・リンクエラーが出て収拾できそうにない場合がある。順次作業します。
1)だけのものから4)まで進んだものと色々ある状態です。一歩でも前に進むご助言をお待ちしています。「検討事項」の欄に現状を記録するようにしています。
C++N4910:2022 Standard Working Draft on ISO/IEC 14882(0) sample code compile list
C++N4741, 2018 Standard Working Draft on ISO/IEC 14882 sample code compile list
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++
編纂器(Compiler)
clang++ --version
Debian clang version 14.0.5-++20220610033153+c12386ae247c-1~exp1~20220610153237.151
Target: x86_64-pc-linux-gnu, Thread model: posix, InstalledDir: /usr/bin
g++- --version
g++ (GCC) 12.1.0 Copyright (C) 2022 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
9.4.2 Aggregates [dcl.init.aggr] C++N4910:2022 (103) p205.cpp
算譜(source code)
// C++N4910 Committee Draft, Standard for Programming Language C++
// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/n4910.pdf
const char * msg="9.4.2 Aggregates [dcl.init.aggr] C++N4910:2022 (103) p205.cpp";
// Debian clang version 14.0.5-++20220610033153+c12386ae247c-
// g++ (GCC) 12.1.0 Copyright (C) 2022 Free Software Foundation, Inc.
// Edited by Dr. Ogawa Kiyoshi. Compile procedure and results record.
// C++N4910:2022 Standard Working Draft on ISO/IEC 14882(0) sample code compile list
// https://qiita.com/kaizen_nagoya/items/fc957ddddd402004bb91
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <coroutine>
using namespace std;
// Example 1
struct C {
union {
int a;
const char* p;
};
int x;
} c = { .a = 1, .x = 3 };
// initializes c.a with 1 and c.x with 3.
// [Example 2 :
struct A {
int x2;
struct B {
int i;
int j;
} b;
} a2 = { 1, { 2, 3 } };
initializes a2.x with 1, a2.b.i with 2, a2.b.j with 3.
struct base1 { int b1, b2 = 42; };
struct base2 {
base2() {
b3 = 42;
}
int b3;
};
struct derived : base1, base2 {
int d;
};
derived d1{{1, 2}, {}, 4};
derived d2{{}, {}, 4};
// initializes d1.b1 with 1, d1.b2 with 2, d1.b3 with 42, d1.d with 4, and d2.b1 with 0, d2.b2 with 42, d2.b3 with 42, d2.d with 4.
// [Example 3 :
struct S { int a3; const char* b3; int c3; int d3 = b3[a3]; };
S ss = { 1, "asdf" };
// initializes ss.a with 1, ss.b with "asdf", ss.c with the value of an expression of the form int{} (that is, 0), and ss.d with the value of ss.b[ss.a] (that is, ’s’), and in
struct X { int i, j, k = 42; };
X a3[] = { 1, 2, 3, 4, 5, 6 };
X b3[2] = { { 1, 2, 3 }, { 4, 5, 6 } };
// a and b have the same value
struct A3 {
string a3;
int b3 = 42;
int c3 = -1;
};
A3{.c3=21}; // has the following steps:
// (6.1) Initialize a with {}
// (6.2) Initialize b with = 42
// (6.3) Initialize c with = 21
// [Example 4 :
int x4[] = { 1, 3, 5 };
// declares and initializes x as a one-dimensional array that has three elements since no size was specified and there are three initializers.
// [Example 5 :
struct S5 {
int y[] = { 0 }; // error: non-static data member of incomplete type
};
// [Example 6 :
struct A6 {
int i;
static int s;
int j;
int :17;
int k;
} a6 = { 1, 2, 3 };
// Here, the second initializer 2 initializes a.j and not the static data member A::s, and the third initializer 3 initializes a.k and not the unnamed bit-field before it.
// [Example 7 :
char cv[4] = { 'a', 's', 'd', 'f', 0 }; // error
// is ill-formed.
// [Example 8 :
struct A8;
extern A8 a8;
struct A8 {
const A8& a18 { A8{a8,a8} }; // OK
const A8& a28 { A8{} }; // error
};
A8 a8{a8,a8}; // OK
struct B8 {
int n = B8{}.n; // error
};
// [Example 9 :
struct S9 { } s;
struct A9 {
S9 s1;
int i1;
S9 s2;
int i2;
S9 s3;
int i3;
} a9 = {
{ }, // Required initialization
0,
s, // Required initialization
0
}; // Initialization not required for A::s3 because A::i3 is also not initialized
// [Example 10 :
int xa[2][2] = { 3, 1, 4, 2 };
// initializes x[0][0] to 3, x[0][1] to 1, x[1][0] to 4, and x[1][1] to 2. On the other hand,
float ya[4][3] = {
{ 1 }, { 2 }, { 3 }, { 4 }
};
// initializes the first column of y (regarded as a two-dimensional array) and leaves the rest zero.
// [Example 11 :
float yb[4][3] = {
{ 1, 3, 5 },
{ 2, 4, 6 },
{ 3, 5, 7 },
};
// is a completely-braced initialization: 1, 3, and 5 initialize the first row of the array y[0], namely y[0][0], y[0][1], and y[0][2]. Likewise the next two lines initialize y[1] and y[2]. The initializer ends early and therefore y[3]s elements are initialized as if explicitly initialized with an expression of the form float(), that is, are initialized with 0.0. In the following example, braces in the initializer-list are elided; however the initializer-list has the same effect as the completely-braced initializer-list of the above example,
float yb[4][3] = {
1, 3, 5, 2, 4, 6, 3, 5, 7
};
// The initializer for y begins with a left brace, but the one for y[0] does not, therefore three elements from the list are used. Likewise the next three are taken successively for y[1] and y[2].
// [Example 12 :
struct AC {
int i;
operator int();
};
struct BC {
AC a1c, a2c;
int z;
};
AC ac;
BC b = { 4, ac, ac };
// Braces are elided around the initializer-clause for b.a1.i. b.a1.i is initialized with 4, b.a2 is initialized with a, b.z is initialized with whatever a.operator int() returns.
// [Example 13 :
union u { int ad; const char* bd; };
u ad = { 1 };
u bd = ad;
u cd = 1; // error
u dd = { 0, "asdf" }; // error
u ed = { "asdf" }; // error
u fd = { .bd = "asdf" };
u gd = { .ad = 1, .bd = "asdf" }; // error
int main(){
cout << msg << endl;
return EXIT_SUCCESS;
}
Script
#!/bin/sh
rm $1l
rm $1g
echo "$ clang++ $1.cpp -std=03 -o $1l -I. -Wall"
clang++ $1.cpp -std=c++03 -o $1l -I. -Wall
if [ -e $1l ]; then
./$1l
fi
rm $1l
echo "$ clang++ $1.cpp -std=2b -o $1l -I. -Wall"
clang++ $1.cpp -std=c++2b -o $1l -I. -Wall
if [ -e $1l ]; then
./$1l
fi
echo "\r"
echo "$ g++ $1.cpp -std=03 -o $1g -I. -Wall"
g++ $1.cpp -std=c++03 -o $1g -I. -Wall
if [ -e $1g ]; then
./$1g
fi
rm $1g
echo "\r"
echo "$ g++ $1.cpp -std=2b -o $1g -I. -Wall"
g++ $1.cpp -std=c++2b -o $1g -I. -Wall
if [ -e $1g ]; then
./$1g
fi
編纂・実行結果(compile and go)
# ./clgc.sh p205
rm: cannot remove 'p205l': No such file or directory
rm: cannot remove 'p205g': No such file or directory
$ clang++ p205.cpp -std=03 -o p205l -I. -Wall
p205.cpp:36:1: error: unknown type name 'initializes'
initializes a2.x with 1, a2.b.i with 2, a2.b.j with 3.
^
p205.cpp:36:15: error: expected ';' after top level declarator
initializes a2.x with 1, a2.b.i with 2, a2.b.j with 3.
^
;
p205.cpp:44:18: error: unknown class name 'base1'; did you mean 'base2'?
struct derived : base1, base2 {
^~~~~
base2
p205.cpp:38:8: note: 'base2' declared here
struct base2 {
^
p205.cpp:44:25: error: base class 'base2' specified more than once as a direct base class
struct derived : base1, base2 {
^~~~~
p205.cpp:47:11: error: expected ';' after top level declarator
derived d1{{1, 2}, {}, 4};
^
;
p205.cpp:48:11: error: expected ';' after top level declarator
derived d2{{}, {}, 4};
^
;
p205.cpp:51:51: warning: default member initializer for non-static data member is a C++11 extension [-Wc++11-extensions]
struct S { int a3; const char* b3; int c3; int d3 = b3[a3]; };
^
p205.cpp:52:3: error: non-aggregate type 'S' cannot be initialized with an initializer list
S ss = { 1, "asdf" };
^ ~~~~~~~~~~~~~
p205.cpp:54:24: warning: default member initializer for non-static data member is a C++11 extension [-Wc++11-extensions]
struct X { int i, j, k = 42; };
^
p205.cpp:55:12: error: no viable conversion from 'int' to 'X'
X a3[] = { 1, 2, 3, 4, 5, 6 };
^
p205.cpp:54:8: note: candidate constructor (the implicit copy constructor) not viable: no known conversion from 'int' to 'const X &' for 1st argument
struct X { int i, j, k = 42; };
^
p205.cpp:55:15: error: no viable conversion from 'int' to 'X'
X a3[] = { 1, 2, 3, 4, 5, 6 };
^
p205.cpp:54:8: note: candidate constructor (the implicit copy constructor) not viable: no known conversion from 'int' to 'const X &' for 1st argument
struct X { int i, j, k = 42; };
^
p205.cpp:55:18: error: no viable conversion from 'int' to 'X'
X a3[] = { 1, 2, 3, 4, 5, 6 };
^
p205.cpp:54:8: note: candidate constructor (the implicit copy constructor) not viable: no known conversion from 'int' to 'const X &' for 1st argument
struct X { int i, j, k = 42; };
^
p205.cpp:55:21: error: no viable conversion from 'int' to 'X'
X a3[] = { 1, 2, 3, 4, 5, 6 };
^
p205.cpp:54:8: note: candidate constructor (the implicit copy constructor) not viable: no known conversion from 'int' to 'const X &' for 1st argument
struct X { int i, j, k = 42; };
^
p205.cpp:55:24: error: no viable conversion from 'int' to 'X'
X a3[] = { 1, 2, 3, 4, 5, 6 };
^
p205.cpp:54:8: note: candidate constructor (the implicit copy constructor) not viable: no known conversion from 'int' to 'const X &' for 1st argument
struct X { int i, j, k = 42; };
^
p205.cpp:55:27: error: no viable conversion from 'int' to 'X'
X a3[] = { 1, 2, 3, 4, 5, 6 };
^
p205.cpp:54:8: note: candidate constructor (the implicit copy constructor) not viable: no known conversion from 'int' to 'const X &' for 1st argument
struct X { int i, j, k = 42; };
^
p205.cpp:56:13: error: non-aggregate type 'X' cannot be initialized with an initializer list
X b3[2] = { { 1, 2, 3 }, { 4, 5, 6 } };
^~~~~~~~~~~
p205.cpp:56:26: error: non-aggregate type 'X' cannot be initialized with an initializer list
X b3[2] = { { 1, 2, 3 }, { 4, 5, 6 } };
^~~~~~~~~~~
p205.cpp:60:8: warning: default member initializer for non-static data member is a C++11 extension [-Wc++11-extensions]
int b3 = 42;
^
p205.cpp:61:8: warning: default member initializer for non-static data member is a C++11 extension [-Wc++11-extensions]
int c3 = -1;
^
p205.cpp:63:3: error: expected unqualified-id
A3{.c3=21}; // has the following steps:
^
p205.cpp:72:9: warning: default member initializer for non-static data member is a C++11 extension [-Wc++11-extensions]
int y[] = { 0 }; // error: non-static data member of incomplete type
^
p205.cpp:72:9: error: array bound cannot be deduced from a default member initializer
p205.cpp:84:36: error: excess elements in array initializer
char cv[4] = { 'a', 's', 'd', 'f', 0 }; // error
^
p205.cpp:90:11: error: function definition does not declare parameters
const A8& a18 { A8{a8,a8} }; // OK
^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
5 warnings and 20 errors generated.
rm: cannot remove 'p205l': No such file or directory
$ clang++ p205.cpp -std=2b -o p205l -I. -Wall
p205.cpp:36:1: error: unknown type name 'initializes'
initializes a2.x with 1, a2.b.i with 2, a2.b.j with 3.
^
p205.cpp:36:15: error: expected ';' after top level declarator
initializes a2.x with 1, a2.b.i with 2, a2.b.j with 3.
^
;
p205.cpp:44:18: error: unknown class name 'base1'; did you mean 'base2'?
struct derived : base1, base2 {
^~~~~
base2
p205.cpp:38:8: note: 'base2' declared here
struct base2 {
^
p205.cpp:44:25: error: base class 'base2' specified more than once as a direct base class
struct derived : base1, base2 {
^~~~~
p205.cpp:47:12: error: no matching constructor for initialization of 'base2'
derived d1{{1, 2}, {}, 4};
^~~~~~
p205.cpp:38:8: note: candidate constructor (the implicit copy constructor) not viable: requires 1 argument, but 2 were provided
struct base2 {
^
p205.cpp:38:8: note: candidate constructor (the implicit move constructor) not viable: requires 1 argument, but 2 were provided
p205.cpp:39:1: note: candidate constructor not viable: requires 0 arguments, but 2 were provided
base2() {
^
p205.cpp:48:20: error: excess elements in struct initializer
derived d2{{}, {}, 4};
^
p205.cpp:55:12: warning: suggest braces around initialization of subobject [-Wmissing-braces]
X a3[] = { 1, 2, 3, 4, 5, 6 };
^~~~~~~
{ }
p205.cpp:55:21: warning: suggest braces around initialization of subobject [-Wmissing-braces]
X a3[] = { 1, 2, 3, 4, 5, 6 };
^~~~~~~
{ }
p205.cpp:63:3: error: expected unqualified-id
A3{.c3=21}; // has the following steps:
^
p205.cpp:72:9: error: array bound cannot be deduced from a default member initializer
int y[] = { 0 }; // error: non-static data member of incomplete type
^
p205.cpp:84:36: error: excess elements in array initializer
char cv[4] = { 'a', 's', 'd', 'f', 0 }; // error
^
p205.cpp:91:20: error: default member initializer for 'a28' needed within definition of enclosing class 'A8' outside of member functions
const A8& a28 { A8{} }; // error
^
p205.cpp:91:11: note: default member initializer declared here
const A8& a28 { A8{} }; // error
^
p205.cpp:95:12: error: default member initializer for 'n' needed within definition of enclosing class 'B8' outside of member functions
int n = B8{}.n; // error
^
p205.cpp:95:5: note: default member initializer declared here
int n = B8{}.n; // error
^
p205.cpp:113:18: warning: suggest braces around initialization of subobject [-Wmissing-braces]
int xa[2][2] = { 3, 1, 4, 2 };
^~~~
{ }
p205.cpp:113:24: warning: suggest braces around initialization of subobject [-Wmissing-braces]
int xa[2][2] = { 3, 1, 4, 2 };
^~~~
{ }
p205.cpp:126:7: error: redefinition of 'yb'
float yb[4][3] = {
^
p205.cpp:120:7: note: previous definition is here
float yb[4][3] = {
^
p205.cpp:140:10: warning: suggest braces around initialization of subobject [-Wmissing-braces]
BC b = { 4, ac, ac };
^
{}
p205.cpp:146:3: error: no viable conversion from 'int' to 'u'
u cd = 1; // error
^ ~
p205.cpp:143:7: note: candidate constructor (the implicit copy constructor) not viable: no known conversion from 'int' to 'const u &' for 1st argument
union u { int ad; const char* bd; };
^
p205.cpp:143:7: note: candidate constructor (the implicit move constructor) not viable: no known conversion from 'int' to 'u &&' for 1st argument
union u { int ad; const char* bd; };
^
p205.cpp:147:13: error: excess elements in union initializer
u dd = { 0, "asdf" }; // error
^~~~~~
p205.cpp:148:10: error: cannot initialize a member subobject of type 'int' with an lvalue of type 'const char[5]'
u ed = { "asdf" }; // error
^~~~~~
p205.cpp:150:19: warning: initializer overrides prior initialization of this subobject [-Winitializer-overrides]
u gd = { .ad = 1, .bd = "asdf" }; // error
^~~~~~~~~~~~
p205.cpp:150:16: note: previous initialization is here
u gd = { .ad = 1, .bd = "asdf" }; // error
^
6 warnings and 15 errors generated.
$ g++ p205.cpp -std=03 -o p205g -I. -Wall
p205.cpp:36:1: error: 'initializes' does not name a type
36 | initializes a2.x with 1, a2.b.i with 2, a2.b.j with 3.
| ^~~~~~~~~~~
p205.cpp:44:23: error: expected class-name before ',' token
44 | struct derived : base1, base2 {
| ^
p205.cpp:47:11: warning: extended initializer lists only available with '-std=c++11' or '-std=gnu++11' [-Wc++11-extensions]
47 | derived d1{{1, 2}, {}, 4};
| ^
p205.cpp:47:9: error: in C++98 'd1' must be initialized by constructor, not by '{...}'
47 | derived d1{{1, 2}, {}, 4};
| ^~
p205.cpp:47:25: error: no matching function for call to 'derived::derived(<brace-enclosed initializer list>)'
47 | derived d1{{1, 2}, {}, 4};
| ^
p205.cpp:44:8: note: candidate: 'derived::derived()'
44 | struct derived : base1, base2 {
| ^~~~~~~
p205.cpp:44:8: note: candidate expects 0 arguments, 3 provided
p205.cpp:44:8: note: candidate: 'derived::derived(const derived&)'
p205.cpp:44:8: note: candidate expects 1 argument, 3 provided
p205.cpp:48:11: warning: extended initializer lists only available with '-std=c++11' or '-std=gnu++11' [-Wc++11-extensions]
48 | derived d2{{}, {}, 4};
| ^
p205.cpp:48:9: error: in C++98 'd2' must be initialized by constructor, not by '{...}'
48 | derived d2{{}, {}, 4};
| ^~
p205.cpp:48:21: error: no matching function for call to 'derived::derived(<brace-enclosed initializer list>)'
48 | derived d2{{}, {}, 4};
| ^
p205.cpp:44:8: note: candidate: 'derived::derived()'
44 | struct derived : base1, base2 {
| ^~~~~~~
p205.cpp:44:8: note: candidate expects 0 arguments, 3 provided
p205.cpp:44:8: note: candidate: 'derived::derived(const derived&)'
p205.cpp:44:8: note: candidate expects 1 argument, 3 provided
p205.cpp:51:51: warning: non-static data member initializers only available with '-std=c++11' or '-std=gnu++11' [-Wc++11-extensions]
51 | struct S { int a3; const char* b3; int c3; int d3 = b3[a3]; };
| ^
p205.cpp:52:3: error: in C++98 'ss' must be initialized by constructor, not by '{...}'
52 | S ss = { 1, "asdf" };
| ^~
p205.cpp:52:20: error: could not convert '{1, "asdf"}' from '<brace-enclosed initializer list>' to 'S'
52 | S ss = { 1, "asdf" };
| ^
| |
| <brace-enclosed initializer list>
p205.cpp:54:24: warning: non-static data member initializers only available with '-std=c++11' or '-std=gnu++11' [-Wc++11-extensions]
54 | struct X { int i, j, k = 42; };
| ^
p205.cpp:55:12: error: conversion from 'int' to non-scalar type 'X' requested
55 | X a3[] = { 1, 2, 3, 4, 5, 6 };
| ^
p205.cpp:55:15: error: conversion from 'int' to non-scalar type 'X' requested
55 | X a3[] = { 1, 2, 3, 4, 5, 6 };
| ^
p205.cpp:55:18: error: conversion from 'int' to non-scalar type 'X' requested
55 | X a3[] = { 1, 2, 3, 4, 5, 6 };
| ^
p205.cpp:55:21: error: conversion from 'int' to non-scalar type 'X' requested
55 | X a3[] = { 1, 2, 3, 4, 5, 6 };
| ^
p205.cpp:55:24: error: conversion from 'int' to non-scalar type 'X' requested
55 | X a3[] = { 1, 2, 3, 4, 5, 6 };
| ^
p205.cpp:55:27: error: conversion from 'int' to non-scalar type 'X' requested
55 | X a3[] = { 1, 2, 3, 4, 5, 6 };
| ^
p205.cpp:56:38: warning: extended initializer lists only available with '-std=c++11' or '-std=gnu++11' [-Wc++11-extensions]
56 | X b3[2] = { { 1, 2, 3 }, { 4, 5, 6 } };
| ^
p205.cpp:56:38: warning: extended initializer lists only available with '-std=c++11' or '-std=gnu++11' [-Wc++11-extensions]
p205.cpp:56:38: error: could not convert '{1, 2, 3}' from '<brace-enclosed initializer list>' to 'X'
56 | X b3[2] = { { 1, 2, 3 }, { 4, 5, 6 } };
| ^
| |
| <brace-enclosed initializer list>
p205.cpp:56:38: error: could not convert '{4, 5, 6}' from '<brace-enclosed initializer list>' to 'X'
56 | X b3[2] = { { 1, 2, 3 }, { 4, 5, 6 } };
| ^
| |
| <brace-enclosed initializer list>
p205.cpp:60:8: warning: non-static data member initializers only available with '-std=c++11' or '-std=gnu++11' [-Wc++11-extensions]
60 | int b3 = 42;
| ^
p205.cpp:61:8: warning: non-static data member initializers only available with '-std=c++11' or '-std=gnu++11' [-Wc++11-extensions]
61 | int c3 = -1;
| ^
p205.cpp:63:3: error: expected unqualified-id before '{' token
63 | A3{.c3=21}; // has the following steps:
| ^
p205.cpp:72:9: warning: non-static data member initializers only available with '-std=c++11' or '-std=gnu++11' [-Wc++11-extensions]
72 | int y[] = { 0 }; // error: non-static data member of incomplete type
| ^
p205.cpp:72:5: error: flexible array member 'S5::y' in an otherwise empty 'struct S5'
72 | int y[] = { 0 }; // error: non-static data member of incomplete type
| ^
p205.cpp:72:15: warning: extended initializer lists only available with '-std=c++11' or '-std=gnu++11' [-Wc++11-extensions]
72 | int y[] = { 0 }; // error: non-static data member of incomplete type
| ^
p205.cpp:72:5: error: initializer for flexible array member 'int S5::y []'
72 | int y[] = { 0 }; // error: non-static data member of incomplete type
| ^
p205.cpp:84:38: error: too many initializers for 'char [4]'
84 | char cv[4] = { 'a', 's', 'd', 'f', 0 }; // error
| ^
p205.cpp:90:15: warning: non-static data member initializers only available with '-std=c++11' or '-std=gnu++11' [-Wc++11-extensions]
90 | const A8& a18 { A8{a8,a8} }; // OK
| ^
p205.cpp:91:15: warning: non-static data member initializers only available with '-std=c++11' or '-std=gnu++11' [-Wc++11-extensions]
91 | const A8& a28 { A8{} }; // error
| ^
p205.cpp:90:15: warning: extended initializer lists only available with '-std=c++11' or '-std=gnu++11' [-Wc++11-extensions]
90 | const A8& a18 { A8{a8,a8} }; // OK
| ^
p205.cpp:90:19: warning: extended initializer lists only available with '-std=c++11' or '-std=gnu++11' [-Wc++11-extensions]
90 | const A8& a18 { A8{a8,a8} }; // OK
| ^
p205.cpp:90:25: error: default member initializer for 'A8::a18' required before the end of its enclosing class
90 | const A8& a18 { A8{a8,a8} }; // OK
| ^
p205.cpp:90:15: note: defined here
90 | const A8& a18 { A8{a8,a8} }; // OK
| ^~~~~~~~~~~~~~
p205.cpp:90:25: error: default member initializer for 'A8::a28' required before the end of its enclosing class
90 | const A8& a18 { A8{a8,a8} }; // OK
| ^
p205.cpp:91:15: note: defined here
91 | const A8& a28 { A8{} }; // error
| ^~~~~~~~~
p205.cpp:90:25: error: no matching function for call to 'A8::A8(<brace-enclosed initializer list>)'
90 | const A8& a18 { A8{a8,a8} }; // OK
| ^
p205.cpp:89:8: note: candidate: 'A8::A8()'
89 | struct A8 {
| ^~
p205.cpp:89:8: note: candidate expects 0 arguments, 2 provided
p205.cpp:89:8: note: candidate: 'A8::A8(const A8&)'
p205.cpp:89:8: note: candidate expects 1 argument, 2 provided
p205.cpp:90:27: warning: extended initializer lists only available with '-std=c++11' or '-std=gnu++11' [-Wc++11-extensions]
90 | const A8& a18 { A8{a8,a8} }; // OK
| ^
p205.cpp:90:27: warning: extended initializer lists only available with '-std=c++11' or '-std=gnu++11' [-Wc++11-extensions]
p205.cpp:90:27: error: invalid initialization of reference of type 'const A8&' from expression of type '<brace-enclosed initializer list>'
p205.cpp:93:6: warning: extended initializer lists only available with '-std=c++11' or '-std=gnu++11' [-Wc++11-extensions]
93 | A8 a8{a8,a8}; // OK
| ^
p205.cpp:93:4: error: in C++98 'a8' must be initialized by constructor, not by '{...}'
93 | A8 a8{a8,a8}; // OK
| ^~
p205.cpp:93:12: error: no matching function for call to 'A8::A8(<brace-enclosed initializer list>)'
93 | A8 a8{a8,a8}; // OK
| ^
p205.cpp:89:8: note: candidate: 'A8::A8()'
89 | struct A8 {
| ^~
p205.cpp:89:8: note: candidate expects 0 arguments, 2 provided
p205.cpp:89:8: note: candidate: 'A8::A8(const A8&)'
p205.cpp:89:8: note: candidate expects 1 argument, 2 provided
p205.cpp:95:7: warning: non-static data member initializers only available with '-std=c++11' or '-std=gnu++11' [-Wc++11-extensions]
95 | int n = B8{}.n; // error
| ^
p205.cpp:95:11: warning: extended initializer lists only available with '-std=c++11' or '-std=gnu++11' [-Wc++11-extensions]
95 | int n = B8{}.n; // error
| ^
p205.cpp:95:12: error: default member initializer for 'B8::n' required before the end of its enclosing class
95 | int n = B8{}.n; // error
| ^
p205.cpp:95:7: note: defined here
95 | int n = B8{}.n; // error
| ^~~~~~~~~
p205.cpp:126:7: error: redefinition of 'float yb [4][3]'
126 | float yb[4][3] = {
| ^~
p205.cpp:120:7: note: 'float yb [4][3]' previously defined here
120 | float yb[4][3] = {
| ^~
p205.cpp:146:8: error: conversion from 'int' to non-scalar type 'u' requested
146 | u cd = 1; // error
| ^
p205.cpp:147:20: error: too many initializers for 'u'
147 | u dd = { 0, "asdf" }; // error
| ^
p205.cpp:148:10: error: invalid conversion from 'const char*' to 'int' [-fpermissive]
148 | u ed = { "asdf" }; // error
| ^~~~~~
| |
| const char*
p205.cpp:150:32: error: too many initializers for 'u'
150 | u gd = { .ad = 1, .bd = "asdf" }; // error
| ^
rm: cannot remove 'p205g': No such file or directory
$ g++ p205.cpp -std=2b -o p205g -I. -Wall
p205.cpp:36:1: error: 'initializes' does not name a type
36 | initializes a2.x with 1, a2.b.i with 2, a2.b.j with 3.
| ^~~~~~~~~~~
p205.cpp:44:23: error: expected class-name before ',' token
44 | struct derived : base1, base2 {
| ^
p205.cpp:47:25: error: too many initializers for 'derived'
47 | derived d1{{1, 2}, {}, 4};
| ^
p205.cpp:48:21: error: too many initializers for 'derived'
48 | derived d2{{}, {}, 4};
| ^
p205.cpp:63:3: error: expected unqualified-id before '{' token
63 | A3{.c3=21}; // has the following steps:
| ^
p205.cpp:72:5: error: flexible array member 'S5::y' in an otherwise empty 'struct S5'
72 | int y[] = { 0 }; // error: non-static data member of incomplete type
| ^
p205.cpp:72:5: error: initializer for flexible array member 'int S5::y []'
p205.cpp:84:38: error: too many initializers for 'char [4]'
84 | char cv[4] = { 'a', 's', 'd', 'f', 0 }; // error
| ^
p205.cpp:91:20: error: default member initializer for 'A8::a28' required before the end of its enclosing class
91 | const A8& a28 { A8{} }; // error
| ^
p205.cpp:91:15: note: defined here
91 | const A8& a28 { A8{} }; // error
| ^~~~~~~~~
p205.cpp:91:22: error: invalid initialization of reference of type 'const A8&' from expression of type '<brace-enclosed initializer list>'
91 | const A8& a28 { A8{} }; // error
| ^
p205.cpp:95:12: error: default member initializer for 'B8::n' required before the end of its enclosing class
95 | int n = B8{}.n; // error
| ^
p205.cpp:95:7: note: defined here
95 | int n = B8{}.n; // error
| ^~~~~~~~~
p205.cpp:126:7: error: redefinition of 'float yb [4][3]'
126 | float yb[4][3] = {
| ^~
p205.cpp:120:7: note: 'float yb [4][3]' previously defined here
120 | float yb[4][3] = {
| ^~
p205.cpp:146:8: error: conversion from 'int' to non-scalar type 'u' requested
146 | u cd = 1; // error
| ^
p205.cpp:147:20: error: too many initializers for 'u'
147 | u dd = { 0, "asdf" }; // error
| ^
p205.cpp:148:10: error: invalid conversion from 'const char*' to 'int' [-fpermissive]
148 | u ed = { "asdf" }; // error
| ^~~~~~
| |
| const char*
p205.cpp:150:32: error: too many initializers for 'u'
150 | u gd = { .ad = 1, .bd = "asdf" }; // error
| ^
検討事項(agenda)
コンパイルエラーの理由を解説する。
<|--コンパイルエラーを取るか、コンパイルエラーの理由を解説する。-->
参考資料(reference)
typedef は C++11 ではオワコン
C99からC++14を駆け抜けるC++講座
自己参照(self reference)
C++ Error Message Collection(1)does not name a type, 11 articles
dockerにclang
docker gnu(gcc/g++) and llvm(clang/clang++)
コンパイル用shell script C版(clangとgcc)とC++版(clang++とg++)
Compare the contents of C++N4910:2022, C++N4741:2018 and C++N4606:2015
C++ sample list
clang++, g++コンパイルエラー方針の違いの例
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.01 初稿 20220626