0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

9.4.5 List-initialization [dcl.init.list] C++N4910:2022 (106) p212.cpp

Posted at

はじめに(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.5 List-initialization [dcl.init.list] C++N4910:2022 (106) p212.cpp

算譜(source code)

p212.cpp
// C++N4910 Committee Draft, Standard for Programming Language C++
// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/n4910.pdf
const char * n4910 = "9.4.5 List-initialization [dcl.init.list] C++N4910:2022 (106) p212.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>
#include <vector>
#include <complex>
#include <map>

using namespace std;

// Example 1
int a = {1};
std::complex<double> z{1,2};
new std::vector<std::string> {"once", "upon", "a", "time"}; // 4 string elements
f( {"Nicholas","Annemarie"} ); // pass list of two elements
return { "Norah" }; // return list of one element
int* e {}; // initialization to zero / null pointer
x = double{1}; // explicitly construct a double
std::map<std::string,int> anim = { {"bear",4}, {"cassowary",2}, {"tiger",7} };
// [Example 2 :
struct A {
    int x2;
    int y;
    int z;
};
A a2{.y = 2, .x = 1}; // error: designator order does not match declaration order
A b{.x2 = 1, .z = 2}; // OK, b.y initialized to 0
// [Example 3 :
double ad[] = { 1, 2.0 }; // OK
int ai[] = { 1, 2.0 }; // error: narrowing
struct S2 {
    int m1;
    double m2, m3;
};
S2 s21 = { 1, 2, 3.0 }; // OK
S2 s22 { 1.0, 2, 3 }; // error: narrowing
S2 s23 { }; // OK, default to 0,0,0
// [Example 4 :
struct S4 {
    S4(std::initializer_list<double>); // #1
    S4(std::initializer_list<int>); // #2
    S4(); // #3
// ...
};
S4 s14 = { 1.0, 2.0, 3.0 }; // invoke #1
S4 s24 = { 1, 2, 3 }; // invoke #2
S4 s34 = { }; // invoke #3
// [Example 5 :
struct Map {
    Map(std::initializer_list<std::pair<std::string,int>>);
};
Map ship = {{"Sophie",14}, {"Surprise",28}};
// [Example 6 :
struct S6 {
// no initializer-list constructors
    S6(int, double, double); // #1
    S6(); // #2
// ...
};
S6 s16 = { 1, 2, 3.0 }; // OK, invoke #1
S6 s26 { 1.0, 2, 3 }; // error: narrowing
S6 s36 { }; // OK, invoke #2
// [Example 7 :
enum byte : unsigned char { };
byte b7 { 42 }; // OK
byte c7 = { 42 }; // error
byte d7 = byte{ 42 }; // OK; same value as b
byte e7 { -1 }; // error
struct A7 {
    byte b7;
};
A7 a17 = { { 42 } }; // error
A7 a27 = { byte{ 42 } }; // OK
void f7(byte);
f7({ 42 }); // error
enum class Handle : uint32_t { Invalid = 0 };
Handle h7 { 42 }; // OK
// [Example 8 :
int x18 {2}; // OK
int x28 {2.0}; // error: narrowing
// [Example 9 :
struct S9 {
    S9(std::initializer_list<double>); // #1
    S9(const std::string&); // #2
// ...
};
const S9& r19 = { 1, 2, 3.0 }; // OK, invoke #1
const S9& r29 { "Spinach" }; // OK, invoke #2
S9& r39 = { 1, 2, 3 }; // error: initializer is not an lvalue
const int& i19 = { 1 }; // OK
const int& i29 = { 1.1 }; // error: narrowing
const int (&iar)[2] = { 1, 2 }; // OK, iar is bound to temporary array
struct A9 { } a9;
struct B9 {
    explicit B9(const A9&);
};
const B9& b29{a9}; // error: cannot copy-list-initialize B temporary from A
// [Example 10 :
int** pp {}; // initialized to null pointer
// [Example 11 :
struct Ab {
    int ib;
    int jb;
};
Ab a1b { 1, 2 }; // aggregate initialization
Ab a2b { 1.2 }; // error: narrowing
struct Bb {
    Bb(std::initializer_list<int>);
};
Bb b1b { 1, 2 }; // creates initializer_list<int> and calls constructor
Bb b2b { 1, 2.0 }; // error: narrowing
struct Cb {
    Cb(int ib, double jb);
};
Cb c1b = { 1, 2.2 }; // calls constructor with arguments (1, 2.2)
Cb c2b = { 1.1, 2 }; // error: narrowing
int jb { 1 }; // initialize to 1
int kb { }; // initialize to 0
// [Example 12 :
struct Xc {
    Xc(std::initializer_list<double> v);
};
Xc xc{ 1,2,3 };
// The initialization will be implemented in a way roughly equivalent to this: const double __a[3] = {double{1}, double{2}, double{3}};
Xc xc(std::initializer_list<double>(__a, __a+3));
// assuming that the implementation can construct an initializer_list object with a pair of pointers.
// [Example 13 :
typedef std::complex<double> cmplx;
std::vector<cmplx> v1d = { 1, 2, 3 };
void fd() {
    std::vector<cmplx> v2d{ 1, 2, 3 };
    std::initializer_list<int> i3d = { 1, 2, 3 };
}
struct Ad {
    std::initializer_list<int> i4d;
    Ad() : i4d{ 1, 2, 3 } {} // ill-formed, would create a dangling reference
};
// For v1 and v2, the initializer_list object is a parameter in a function call, so the array created for { 1, 2, 3 } has full-expression lifetime. For i3, the initializer_list object is a variable, so the array persists for the lifetime of the variable. For i4, the initializer_list object is initialized in the constructor’s ctor-initializer as if by binding a temporary array to a reference member, so the program is ill-formed (11.9.3).
// [Example 14 :
int xe = 999; // x is not a constant expression
const int ye = 999;
const int ze = 99;
char c1 = xe; // OK, though it potentially narrows (in this case, it does narrow)
char c2{xe}; // error: potentially narrows
char c3{ye}; // error: narrows (assuming char is 8 bits)
char c4{ze}; // OK, no narrowing needed
unsigned char uc1 = {5}; // OK, no narrowing needed
unsigned char uc2 = {-1}; // error: narrows
unsigned int ui1 = {-1}; // error: narrows
signed int si1 =
{ (unsigned int)-1 }; // error: narrows
int ii = {2.0}; // error: narrows
float f1e { xe }; // error: potentially narrows
float f2e { 7 }; // OK, 7 can be exactly represented as a float
bool be = {"meow"}; // error: narrows
int fe(int);
int ae[] = { 2, fe(2), fe(2.0) }; // OK, the double-to-int conversion is not at the top level
int main() {
    cout  <<  n4910 << endl;
    return EXIT_SUCCESS;
}

Script

clgc.sh
#!/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)

bash
# ./clgc.sh  p212
rm: cannot remove 'p212l': No such file or directory
rm: cannot remove 'p212g': No such file or directory
$ clang++ p212.cpp -std=03 -o p212l -I. -Wall
p212.cpp:24:23: error: expected ';' after top level declarator
std::complex<double> z{1,2};
                      ^
                      ;
p212.cpp:25:1: error: expected unqualified-id
new std::vector<std::string>{"once", "upon", "a", "time"}; // 4 string elements
^
p212.cpp:26:1: error: C++ requires a type specifier for all declarations
f( {"Nicholas","Annemarie"} ); // pass list of two elements
^
p212.cpp:26:4: error: expected expression
f( {"Nicholas","Annemarie"} ); // pass list of two elements
   ^
p212.cpp:27:1: error: expected unqualified-id
return { "Norah" }; // return list of one element
^
p212.cpp:28:7: error: expected ';' after top level declarator
int* e {}; // initialization to zero / null pointer
      ^
      ;
p212.cpp:29:1: error: C++ requires a type specifier for all declarations
x = double{1}; // explicitly construct a double
^
p212.cpp:29:11: error: expected '(' for function-style cast or type construction
x = double{1}; // explicitly construct a double
    ~~~~~~^
p212.cpp:30:27: error: non-aggregate type 'std::map<std::string, int>' (aka 'map<basic_string<char>, int>') cannot be initialized with an initializer list
std::map<std::string,int> anim = { {"bear",4}, {"cassowary",2}, {"tiger",7} };
                          ^      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
p212.cpp:33:5: error: expected ';' after top level declarator
A a2{.y = 2, .x = 1}; // error: designator order does not match declaration order
    ^
    ;
p212.cpp:34:4: error: expected ';' after top level declarator
A b{.x2 = 1, .z = 2}; // OK, b.y initialized to 0
   ^
   ;
p212.cpp:43:7: error: expected ';' after top level declarator
S2 s22 { 1.0, 2, 3 }; // error: narrowing
      ^
      ;
p212.cpp:44:7: error: expected ';' after top level declarator
S2 s23 { }; // OK, default to 0,0,0
      ^
      ;
p212.cpp:47:9: error: no template named 'initializer_list' in namespace 'std'
S4(std::initializer_list<double>); // #1
   ~~~~~^
p212.cpp:48:9: error: no template named 'initializer_list' in namespace 'std'
S4(std::initializer_list<int>); // #2
   ~~~~~^
p212.cpp:52:4: error: non-aggregate type 'S4' cannot be initialized with an initializer list
S4 s14 = { 1.0, 2.0, 3.0 }; // invoke #1
   ^     ~~~~~~~~~~~~~~~~~
p212.cpp:53:4: error: non-aggregate type 'S4' cannot be initialized with an initializer list
S4 s24 = { 1, 2, 3 }; // invoke #2
   ^     ~~~~~~~~~~~
p212.cpp:54:4: error: non-aggregate type 'S4' cannot be initialized with an initializer list
S4 s34 = { }; // invoke #3
   ^     ~~~
p212.cpp:57:10: error: no template named 'initializer_list' in namespace 'std'
Map(std::initializer_list<std::pair<std::string,int>>);
    ~~~~~^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
rm: cannot remove 'p212l': No such file or directory
$ clang++ p212.cpp -std=2b -o p212l -I. -Wall
p212.cpp:25:1: error: expected unqualified-id
new std::vector<std::string>{"once", "upon", "a", "time"}; // 4 string elements
^
p212.cpp:26:1: error: C++ requires a type specifier for all declarations
f( {"Nicholas","Annemarie"} ); // pass list of two elements
^
p212.cpp:27:1: error: expected unqualified-id
return { "Norah" }; // return list of one element
^
p212.cpp:29:1: error: C++ requires a type specifier for all declarations
x = double{1}; // explicitly construct a double
^
p212.cpp:33:15: error: field designator 'x' does not refer to any field in type 'A'
A a2{.y = 2, .x = 1}; // error: designator order does not match declaration order
              ^
p212.cpp:37:17: error: type 'double' cannot be narrowed to 'int' in initializer list [-Wc++11-narrowing]
int ai[] = { 1, 2.0 }; // error: narrowing
                ^~~
p212.cpp:37:17: note: insert an explicit cast to silence this issue
int ai[] = { 1, 2.0 }; // error: narrowing
                ^~~
                static_cast<int>( )
p212.cpp:43:10: error: type 'double' cannot be narrowed to 'int' in initializer list [-Wc++11-narrowing]
S2 s22 { 1.0, 2, 3 }; // error: narrowing
         ^~~
p212.cpp:43:10: note: insert an explicit cast to silence this issue
S2 s22 { 1.0, 2, 3 }; // error: narrowing
         ^~~
         static_cast<int>( )
p212.cpp:68:10: error: type 'double' cannot be narrowed to 'int' in initializer list [-Wc++11-narrowing]
S6 s26 { 1.0, 2, 3 }; // error: narrowing
         ^~~
p212.cpp:68:10: note: insert an explicit cast to silence this issue
S6 s26 { 1.0, 2, 3 }; // error: narrowing
         ^~~
         static_cast<int>( )
p212.cpp:72:1: error: reference to 'byte' is ambiguous
byte b7 { 42 }; // OK
^
p212.cpp:71:6: note: candidate found by name lookup is 'byte'
enum byte : unsigned char { };
     ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/cpp_type_traits.h:404:14: note: candidate found by name lookup is 'std::byte'
  enum class byte : unsigned char;
             ^
p212.cpp:73:1: error: reference to 'byte' is ambiguous
byte c7 = { 42 }; // error
^
p212.cpp:71:6: note: candidate found by name lookup is 'byte'
enum byte : unsigned char { };
     ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/cpp_type_traits.h:404:14: note: candidate found by name lookup is 'std::byte'
  enum class byte : unsigned char;
             ^
p212.cpp:73:13: error: cannot initialize a variable of type 'byte' with an rvalue of type 'int'
byte c7 = { 42 }; // error
            ^~
p212.cpp:74:1: error: reference to 'byte' is ambiguous
byte d7 = byte{ 42 }; // OK; same value as b
^
p212.cpp:71:6: note: candidate found by name lookup is 'byte'
enum byte : unsigned char { };
     ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/cpp_type_traits.h:404:14: note: candidate found by name lookup is 'std::byte'
  enum class byte : unsigned char;
             ^
p212.cpp:74:11: error: reference to 'byte' is ambiguous
byte d7 = byte{ 42 }; // OK; same value as b
          ^
p212.cpp:71:6: note: candidate found by name lookup is 'byte'
enum byte : unsigned char { };
     ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/cpp_type_traits.h:404:14: note: candidate found by name lookup is 'std::byte'
  enum class byte : unsigned char;
             ^
p212.cpp:75:1: error: reference to 'byte' is ambiguous
byte e7 { -1 }; // error
^
p212.cpp:71:6: note: candidate found by name lookup is 'byte'
enum byte : unsigned char { };
     ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/cpp_type_traits.h:404:14: note: candidate found by name lookup is 'std::byte'
  enum class byte : unsigned char;
             ^
p212.cpp:75:11: error: constant expression evaluates to -1 which cannot be narrowed to type 'byte' [-Wc++11-narrowing]
byte e7 { -1 }; // error
          ^~
p212.cpp:76:13: error: reference to 'byte' is ambiguous
struct A7 { byte b7; };
            ^
p212.cpp:71:6: note: candidate found by name lookup is 'byte'
enum byte : unsigned char { };
     ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/cpp_type_traits.h:404:14: note: candidate found by name lookup is 'std::byte'
  enum class byte : unsigned char;
             ^
p212.cpp:77:14: error: cannot initialize a member subobject of type 'byte' with an rvalue of type 'int'
A7 a17 = { { 42 } }; // error
             ^~
p212.cpp:78:12: error: reference to 'byte' is ambiguous
A7 a27 = { byte{ 42 } }; // OK
           ^
p212.cpp:71:6: note: candidate found by name lookup is 'byte'
enum byte : unsigned char { };
     ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/cpp_type_traits.h:404:14: note: candidate found by name lookup is 'std::byte'
  enum class byte : unsigned char;
             ^
p212.cpp:79:9: error: reference to 'byte' is ambiguous
void f7(byte);
        ^
p212.cpp:71:6: note: candidate found by name lookup is 'byte'
enum byte : unsigned char { };
     ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/cpp_type_traits.h:404:14: note: candidate found by name lookup is 'std::byte'
  enum class byte : unsigned char;
             ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.

$ g++ p212.cpp -std=03 -o p212g -I. -Wall
p212.cpp:24:23: warning: extended initializer lists only available with '-std=c++11' or '-std=gnu++11' [-Wc++11-extensions]
   24 | std::complex<double> z{1,2};
      |                       ^
p212.cpp:24:22: error: in C++98 'z' must be initialized by constructor, not by '{...}'
   24 | std::complex<double> z{1,2};
      |                      ^
p212.cpp:25:1: error: expected unqualified-id before 'new'
   25 | new std::vector<std::string>{"once", "upon", "a", "time"}; // 4 string elements
      | ^~~
p212.cpp:26:2: error: expected constructor, destructor, or type conversion before '(' token
   26 | f( {"Nicholas","Annemarie"} ); // pass list of two elements
      |  ^
p212.cpp:26:29: error: expected unqualified-id before ')' token
   26 | f( {"Nicholas","Annemarie"} ); // pass list of two elements
      |                             ^
p212.cpp:27:1: error: expected unqualified-id before 'return'
   27 | return { "Norah" }; // return list of one element
      | ^~~~~~
p212.cpp:28:8: warning: extended initializer lists only available with '-std=c++11' or '-std=gnu++11' [-Wc++11-extensions]
   28 | int* e {}; // initialization to zero / null pointer
      |        ^
p212.cpp:28:9: warning: extended initializer lists only available with '-std=c++11' or '-std=gnu++11' [-Wc++11-extensions]
   28 | int* e {}; // initialization to zero / null pointer
      |         ^
p212.cpp:29:1: error: 'x' does not name a type
   29 | x = double{1}; // explicitly construct a double
      | ^
p212.cpp:30:27: error: in C++98 'anim' must be initialized by constructor, not by '{...}'
   30 | std::map<std::string,int> anim = { {"bear",4}, {"cassowary",2}, {"tiger",7} };
      |                           ^~~~
p212.cpp:30:77: error: could not convert '{{"bear", 4}, {"cassowary", 2}, {"tiger", 7}}' from '<brace-enclosed initializer list>' to 'std::map<std::__cxx11::basic_string<char>, int>'
   30 | std::map<std::string,int> anim = { {"bear",4}, {"cassowary",2}, {"tiger",7} };
      |                                                                             ^
      |                                                                             |
      |                                                                             <brace-enclosed initializer list>
p212.cpp:33:5: warning: extended initializer lists only available with '-std=c++11' or '-std=gnu++11' [-Wc++11-extensions]
   33 | A a2{.y = 2, .x = 1}; // error: designator order does not match declaration order
      |     ^
p212.cpp:33:20: error: 'A' has no non-static data member named 'x'
   33 | A a2{.y = 2, .x = 1}; // error: designator order does not match declaration order
      |                    ^
p212.cpp:34:4: warning: extended initializer lists only available with '-std=c++11' or '-std=gnu++11' [-Wc++11-extensions]
   34 | A b{.x2 = 1, .z = 2}; // OK, b.y initialized to 0
      |    ^
p212.cpp:37:17: warning: narrowing conversion of '2.0e+0' from 'double' to 'int' is ill-formed in C++11 [-Wnarrowing]
   37 | int ai[] = { 1, 2.0 }; // error: narrowing
      |                 ^~~
p212.cpp:43:8: warning: extended initializer lists only available with '-std=c++11' or '-std=gnu++11' [-Wc++11-extensions]
   43 | S2 s22 { 1.0, 2, 3 }; // error: narrowing
      |        ^
p212.cpp:43:10: warning: narrowing conversion of '1.0e+0' from 'double' to 'int' is ill-formed in C++11 [-Wnarrowing]
   43 | S2 s22 { 1.0, 2, 3 }; // error: narrowing
      |          ^~~
p212.cpp:44:8: warning: extended initializer lists only available with '-std=c++11' or '-std=gnu++11' [-Wc++11-extensions]
   44 | S2 s23 { }; // OK, default to 0,0,0
      |        ^
p212.cpp:47:25: error: expected ')' before '<' token
   47 | S4(std::initializer_list<double>); // #1
      |   ~                     ^
      |                         )
p212.cpp:48:25: error: expected ')' before '<' token
   48 | S4(std::initializer_list<int>); // #2
      |   ~                     ^
      |                         )
p212.cpp:52:4: error: in C++98 's14' must be initialized by constructor, not by '{...}'
   52 | S4 s14 = { 1.0, 2.0, 3.0 }; // invoke #1
      |    ^~~
p212.cpp:52:26: error: could not convert '{1.0e+0, 2.0e+0, 3.0e+0}' from '<brace-enclosed initializer list>' to 'S4'
   52 | S4 s14 = { 1.0, 2.0, 3.0 }; // invoke #1
      |                          ^
      |                          |
      |                          <brace-enclosed initializer list>
p212.cpp:53:4: error: in C++98 's24' must be initialized by constructor, not by '{...}'
   53 | S4 s24 = { 1, 2, 3 }; // invoke #2
      |    ^~~
p212.cpp:53:20: error: could not convert '{1, 2, 3}' from '<brace-enclosed initializer list>' to 'S4'
   53 | S4 s24 = { 1, 2, 3 }; // invoke #2
      |                    ^
      |                    |
      |                    <brace-enclosed initializer list>
p212.cpp:54:4: error: in C++98 's34' must be initialized by constructor, not by '{...}'
   54 | S4 s34 = { }; // invoke #3
      |    ^~~
p212.cpp:57:26: error: expected ')' before '<' token
   57 | Map(std::initializer_list<std::pair<std::string,int>>);
      |    ~                     ^
      |                          )
p212.cpp:59:43: error: too many initializers for 'Map'
   59 | Map ship = {{"Sophie",14}, {"Surprise",28}};
      |                                           ^
p212.cpp:67:4: error: in C++98 's16' must be initialized by constructor, not by '{...}'
   67 | S6 s16 = { 1, 2, 3.0 }; // OK, invoke #1
      |    ^~~
p212.cpp:68:8: warning: extended initializer lists only available with '-std=c++11' or '-std=gnu++11' [-Wc++11-extensions]
   68 | S6 s26 { 1.0, 2, 3 }; // error: narrowing
      |        ^
p212.cpp:68:4: error: in C++98 's26' must be initialized by constructor, not by '{...}'
   68 | S6 s26 { 1.0, 2, 3 }; // error: narrowing
      |    ^~~
p212.cpp:68:20: warning: narrowing conversion of '1.0e+0' from 'double' to 'int' is ill-formed in C++11 [-Wnarrowing]
   68 | S6 s26 { 1.0, 2, 3 }; // error: narrowing
      |                    ^
p212.cpp:69:8: warning: extended initializer lists only available with '-std=c++11' or '-std=gnu++11' [-Wc++11-extensions]
   69 | S6 s36 { }; // OK, invoke #2
      |        ^
p212.cpp:69:4: error: in C++98 's36' must be initialized by constructor, not by '{...}'
   69 | S6 s36 { }; // OK, invoke #2
      |    ^~~
p212.cpp:71:22: warning: scoped enums only available with '-std=c++11' or '-std=gnu++11' [-Wc++11-extensions]
   71 | enum byte : unsigned char { };
      |                      ^~~~
p212.cpp:72:9: warning: extended initializer lists only available with '-std=c++11' or '-std=gnu++11' [-Wc++11-extensions]
   72 | byte b7 { 42 }; // OK
      |         ^
p212.cpp:72:11: error: invalid conversion from 'int' to 'byte' [-fpermissive]
   72 | byte b7 { 42 }; // OK
      |           ^~
      |           |
      |           int
p212.cpp:73:13: error: invalid conversion from 'int' to 'byte' [-fpermissive]
   73 | byte c7 = { 42 }; // error
      |             ^~
      |             |
      |             int
p212.cpp:74:15: warning: extended initializer lists only available with '-std=c++11' or '-std=gnu++11' [-Wc++11-extensions]
   74 | byte d7 = byte{ 42 }; // OK; same value as b
      |               ^
p212.cpp:74:17: error: invalid conversion from 'int' to 'byte' [-fpermissive]
   74 | byte d7 = byte{ 42 }; // OK; same value as b
      |                 ^~
      |                 |
      |                 int
p212.cpp:75:9: warning: extended initializer lists only available with '-std=c++11' or '-std=gnu++11' [-Wc++11-extensions]
   75 | byte e7 { -1 }; // error
      |         ^
p212.cpp:75:11: error: invalid conversion from 'int' to 'byte' [-fpermissive]
   75 | byte e7 { -1 }; // error
      |           ^~
      |           |
      |           int
p212.cpp:77:19: error: braces around scalar initializer for type 'byte'
   77 | A7 a17 = { { 42 } }; // error
      |                   ^
p212.cpp:78:16: warning: extended initializer lists only available with '-std=c++11' or '-std=gnu++11' [-Wc++11-extensions]
   78 | A7 a27 = { byte{ 42 } }; // OK
      |                ^
p212.cpp:78:18: error: invalid conversion from 'int' to 'byte' [-fpermissive]
   78 | A7 a27 = { byte{ 42 } }; // OK
      |                  ^~
      |                  |
      |                  int
p212.cpp:80:3: error: expected constructor, destructor, or type conversion before '(' token
   80 | f7({ 42 }); // error
      |   ^
p212.cpp:80:10: error: expected unqualified-id before ')' token
   80 | f7({ 42 }); // error
      |          ^
p212.cpp:81:1: warning: scoped enums only available with '-std=c++11' or '-std=gnu++11' [-Wc++11-extensions]
   81 | enum class Handle : uint32_t { Invalid = 0 };
      | ^~~~
p212.cpp:81:6: warning: elaborated-type-specifier for a scoped enum must not use the 'class' keyword
   81 | enum class Handle : uint32_t { Invalid = 0 };
      | ~~~~ ^~~~~
      |      -----
p212.cpp:81:19: error: found ':' in nested-name-specifier, expected '::'
   81 | enum class Handle : uint32_t { Invalid = 0 };
      |                   ^
      |                   ::
p212.cpp:81:12: error: 'Handle' has not been declared
   81 | enum class Handle : uint32_t { Invalid = 0 };
      |            ^~~~~~
p212.cpp:81:30: error: expected unqualified-id before '{' token
   81 | enum class Handle : uint32_t { Invalid = 0 };
      |                              ^
p212.cpp:82:1: error: 'Handle' does not name a type
   82 | Handle h7 { 42 }; // OK
      | ^~~~~~
p212.cpp:84:9: warning: extended initializer lists only available with '-std=c++11' or '-std=gnu++11' [-Wc++11-extensions]
   84 | int x18 {2}; // OK
      |         ^
p212.cpp:85:9: warning: extended initializer lists only available with '-std=c++11' or '-std=gnu++11' [-Wc++11-extensions]
   85 | int x28 {2.0}; // error: narrowing
      |         ^
p212.cpp:85:10: warning: narrowing conversion of '2.0e+0' from 'double' to 'int' is ill-formed in C++11 [-Wnarrowing]
   85 | int x28 {2.0}; // error: narrowing
      |          ^~~
p212.cpp:88:25: error: expected ')' before '<' token
   88 | S9(std::initializer_list<double>); // #1
      |   ~                     ^
      |                         )
p212.cpp:92:29: warning: extended initializer lists only available with '-std=c++11' or '-std=gnu++11' [-Wc++11-extensions]
   92 | const S9& r19 = { 1, 2, 3.0 }; // OK, invoke #1
      |                             ^
p212.cpp:92:29: error: invalid initialization of reference of type 'const S9&' from expression of type '<brace-enclosed initializer list>'
p212.cpp:93:15: warning: extended initializer lists only available with '-std=c++11' or '-std=gnu++11' [-Wc++11-extensions]
   93 | const S9& r29 { "Spinach" }; // OK, invoke #2
      |               ^
p212.cpp:93:27: warning: extended initializer lists only available with '-std=c++11' or '-std=gnu++11' [-Wc++11-extensions]
   93 | const S9& r29 { "Spinach" }; // OK, invoke #2
      |                           ^
p212.cpp:94:21: warning: extended initializer lists only available with '-std=c++11' or '-std=gnu++11' [-Wc++11-extensions]
   94 | S9& r39 = { 1, 2, 3 }; // error: initializer is not an lvalue
      |                     ^
p212.cpp:94:21: error: invalid initialization of non-const reference of type 'S9&' from an rvalue of type '<brace-enclosed initializer list>'
p212.cpp:95:22: warning: extended initializer lists only available with '-std=c++11' or '-std=gnu++11' [-Wc++11-extensions]
   95 | const int& i19 = { 1 }; // OK
      |                      ^
p212.cpp:96:24: warning: extended initializer lists only available with '-std=c++11' or '-std=gnu++11' [-Wc++11-extensions]
   96 | const int& i29 = { 1.1 }; // error: narrowing
      |                        ^
p212.cpp:96:24: warning: narrowing conversion of '1.1000000000000001e+0' from 'double' to 'int' is ill-formed in C++11 [-Wnarrowing]
p212.cpp:97:30: warning: extended initializer lists only available with '-std=c++11' or '-std=gnu++11' [-Wc++11-extensions]
   97 | const int (&iar)[2] = { 1, 2 }; // OK, iar is bound to temporary array
      |                              ^
p212.cpp:100:14: warning: extended initializer lists only available with '-std=c++11' or '-std=gnu++11' [-Wc++11-extensions]
  100 | const B9& b29{a9}; // error: cannot copy-list-initialize B temporary from A
      |              ^
p212.cpp:100:17: warning: extended initializer lists only available with '-std=c++11' or '-std=gnu++11' [-Wc++11-extensions]
  100 | const B9& b29{a9}; // error: cannot copy-list-initialize B temporary from A
      |                 ^
p212.cpp:102:10: warning: extended initializer lists only available with '-std=c++11' or '-std=gnu++11' [-Wc++11-extensions]
  102 | int** pp {}; // initialized to null pointer
      |          ^
p212.cpp:102:11: warning: extended initializer lists only available with '-std=c++11' or '-std=gnu++11' [-Wc++11-extensions]
  102 | int** pp {}; // initialized to null pointer
      |           ^
p212.cpp:105:8: warning: extended initializer lists only available with '-std=c++11' or '-std=gnu++11' [-Wc++11-extensions]
  105 | Ab a1b { 1, 2 }; // aggregate initialization
      |        ^
p212.cpp:106:8: warning: extended initializer lists only available with '-std=c++11' or '-std=gnu++11' [-Wc++11-extensions]
  106 | Ab a2b { 1.2 }; // error: narrowing
      |        ^
p212.cpp:106:10: warning: narrowing conversion of '1.2e+0' from 'double' to 'int' is ill-formed in C++11 [-Wnarrowing]
  106 | Ab a2b { 1.2 }; // error: narrowing
      |          ^~~
p212.cpp:108:25: error: expected ')' before '<' token
  108 | Bb(std::initializer_list<int>);
      |   ~                     ^
      |                         )
p212.cpp:110:8: warning: extended initializer lists only available with '-std=c++11' or '-std=gnu++11' [-Wc++11-extensions]
  110 | Bb b1b { 1, 2 }; // creates initializer_list<int> and calls constructor
      |        ^
p212.cpp:110:15: error: too many initializers for 'Bb'
  110 | Bb b1b { 1, 2 }; // creates initializer_list<int> and calls constructor
      |               ^
p212.cpp:111:8: warning: extended initializer lists only available with '-std=c++11' or '-std=gnu++11' [-Wc++11-extensions]
  111 | Bb b2b { 1, 2.0 }; // error: narrowing
      |        ^
p212.cpp:111:17: error: too many initializers for 'Bb'
  111 | Bb b2b { 1, 2.0 }; // error: narrowing
      |                 ^
p212.cpp:115:4: error: in C++98 'c1b' must be initialized by constructor, not by '{...}'
  115 | Cb c1b = { 1, 2.2 }; // calls constructor with arguments (1, 2.2)
      |    ^~~
p212.cpp:116:4: error: in C++98 'c2b' must be initialized by constructor, not by '{...}'
  116 | Cb c2b = { 1.1, 2 }; // error: narrowing
      |    ^~~
p212.cpp:116:19: warning: narrowing conversion of '1.1000000000000001e+0' from 'double' to 'int' is ill-formed in C++11 [-Wnarrowing]
  116 | Cb c2b = { 1.1, 2 }; // error: narrowing
      |                   ^
p212.cpp:117:8: warning: extended initializer lists only available with '-std=c++11' or '-std=gnu++11' [-Wc++11-extensions]
  117 | int jb { 1 }; // initialize to 1
      |        ^
p212.cpp:118:8: warning: extended initializer lists only available with '-std=c++11' or '-std=gnu++11' [-Wc++11-extensions]
  118 | int kb { }; // initialize to 0
      |        ^
p212.cpp:118:10: warning: extended initializer lists only available with '-std=c++11' or '-std=gnu++11' [-Wc++11-extensions]
  118 | int kb { }; // initialize to 0
      |          ^
p212.cpp:121:25: error: expected ')' before '<' token
  121 | Xc(std::initializer_list<double> v);
      |   ~                     ^
      |                         )
p212.cpp:123:6: warning: extended initializer lists only available with '-std=c++11' or '-std=gnu++11' [-Wc++11-extensions]
  123 | Xc xc{ 1,2,3 };
      |      ^
p212.cpp:123:14: error: too many initializers for 'Xc'
  123 | Xc xc{ 1,2,3 };
      |              ^
p212.cpp:125:4: error: redefinition of 'Xc xc'
  125 | Xc xc(std::initializer_list<double>(__a, __a+3));
      |    ^~
p212.cpp:123:4: note: 'Xc xc' previously declared here
  123 | Xc xc{ 1,2,3 };
      |    ^~
p212.cpp:125:12: error: 'initializer_list' is not a member of 'std'; did you mean 'uninitialized_fill'?
  125 | Xc xc(std::initializer_list<double>(__a, __a+3));
      |            ^~~~~~~~~~~~~~~~
      |            uninitialized_fill
p212.cpp:125:29: error: expected primary-expression before 'double'
  125 | Xc xc(std::initializer_list<double>(__a, __a+3));
      |                             ^~~~~~
p212.cpp:129:20: error: in C++98 'v1d' must be initialized by constructor, not by '{...}'
  129 | std::vector<cmplx> v1d = { 1, 2, 3 };
      |                    ^~~
p212.cpp:129:36: error: could not convert '{1, 2, 3}' from '<brace-enclosed initializer list>' to 'std::vector<std::complex<double> >'
  129 | std::vector<cmplx> v1d = { 1, 2, 3 };
      |                                    ^
      |                                    |
      |                                    <brace-enclosed initializer list>
p212.cpp: In function 'void fd()':
p212.cpp:131:23: warning: extended initializer lists only available with '-std=c++11' or '-std=gnu++11' [-Wc++11-extensions]
  131 | std::vector<cmplx> v2d{ 1, 2, 3 };
      |                       ^
p212.cpp:131:20: error: in C++98 'v2d' must be initialized by constructor, not by '{...}'
  131 | std::vector<cmplx> v2d{ 1, 2, 3 };
      |                    ^~~
p212.cpp:131:33: error: no matching function for call to 'std::vector<std::complex<double> >::vector(<brace-enclosed initializer list>)'
  131 | std::vector<cmplx> v2d{ 1, 2, 3 };
      |                                 ^
In file included from /usr/local/include/c++/12.1.0/vector:64,
                 from p212.cpp:16:
/usr/local/include/c++/12.1.0/bits/stl_vector.h:711:9: note: candidate: 'template<class _InputIterator> std::vector<_Tp, _Alloc>::vector(_InputIterator, _InputIterator, const allocator_type&) [with _Tp = std::complex<double>; _Alloc = std::allocator<std::complex<double> >]'
  711 |         vector(_InputIterator __first, _InputIterator __last,
      |         ^~~~~~
/usr/local/include/c++/12.1.0/bits/stl_vector.h:711:9: note:   template argument deduction/substitution failed:
p212.cpp:131:31: note:   cannot convert '3' (type 'int') to type 'const std::vector<std::complex<double> >::allocator_type&' {aka 'const std::allocator<std::complex<double> >&'}
  131 | std::vector<cmplx> v2d{ 1, 2, 3 };
      |                               ^
/usr/local/include/c++/12.1.0/bits/stl_vector.h:596:7: note: candidate: 'std::vector<_Tp, _Alloc>::vector(const std::vector<_Tp, _Alloc>&) [with _Tp = std::complex<double>; _Alloc = std::allocator<std::complex<double> >]'
  596 |       vector(const vector& __x)
      |       ^~~~~~
/usr/local/include/c++/12.1.0/bits/stl_vector.h:596:7: note:   candidate expects 1 argument, 3 provided
/usr/local/include/c++/12.1.0/bits/stl_vector.h:578:7: note: candidate: 'std::vector<_Tp, _Alloc>::vector(size_type, const value_type&, const allocator_type&) [with _Tp = std::complex<double>; _Alloc = std::allocator<std::complex<double> >; size_type = long unsigned int; value_type = std::complex<double>; allocator_type = std::allocator<std::complex<double> >]'
  578 |       vector(size_type __n, const value_type& __value = value_type(),
      |       ^~~~~~
/usr/local/include/c++/12.1.0/bits/stl_vector.h:579:36: note:   no known conversion for argument 3 from 'int' to 'const std::vector<std::complex<double> >::allocator_type&' {aka 'const std::allocator<std::complex<double> >&'}
  579 |              const allocator_type& __a = allocator_type())
      |              ~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
/usr/local/include/c++/12.1.0/bits/stl_vector.h:537:7: note: candidate: 'std::vector<_Tp, _Alloc>::vector(const allocator_type&) [with _Tp = std::complex<double>; _Alloc = std::allocator<std::complex<double> >; allocator_type = std::allocator<std::complex<double> >]'
  537 |       vector(const allocator_type& __a) _GLIBCXX_NOEXCEPT
      |       ^~~~~~
/usr/local/include/c++/12.1.0/bits/stl_vector.h:537:7: note:   candidate expects 1 argument, 3 provided
/usr/local/include/c++/12.1.0/bits/stl_vector.h:528:7: note: candidate: 'std::vector<_Tp, _Alloc>::vector() [with _Tp = std::complex<double>; _Alloc = std::allocator<std::complex<double> >'
  528 |       vector() { }
      |       ^~~~~~
/usr/local/include/c++/12.1.0/bits/stl_vector.h:528:7: note:   candidate expects 0 arguments, 3 provided
p212.cpp:132:6: error: 'initializer_list' is not a member of 'std'; did you mean 'uninitialized_fill'?
  132 | std::initializer_list<int> i3d = { 1, 2, 3 };
      |      ^~~~~~~~~~~~~~~~
      |      uninitialized_fill
p212.cpp:132:23: error: expected primary-expression before 'int'
  132 | std::initializer_list<int> i3d = { 1, 2, 3 };
      |                       ^~~
p212.cpp: At global scope:
p212.cpp:135:6: error: 'initializer_list' in namespace 'std' does not name a template type; did you mean 'uninitialized_fill'?
  135 | std::initializer_list<int> i4d;
      |      ^~~~~~~~~~~~~~~~
      |      uninitialized_fill
p212.cpp: In constructor 'Ad::Ad()':
p212.cpp:136:8: error: class 'Ad' does not have any field named 'i4d'
  136 | Ad() : i4d{ 1, 2, 3 } {} // ill-formed, would create a dangling reference
      |        ^~~
p212.cpp:136:11: warning: extended initializer lists only available with '-std=c++11' or '-std=gnu++11' [-Wc++11-extensions]
  136 | Ad() : i4d{ 1, 2, 3 } {} // ill-formed, would create a dangling reference
      |           ^
p212.cpp: At global scope:
p212.cpp:144:8: warning: extended initializer lists only available with '-std=c++11' or '-std=gnu++11' [-Wc++11-extensions]
  144 | char c2{xe}; // error: potentially narrows
      |        ^
p212.cpp:144:9: warning: narrowing conversion of 'xe' from 'int' to 'char' is ill-formed in C++11 [-Wnarrowing]
  144 | char c2{xe}; // error: potentially narrows
      |         ^~
p212.cpp:145:8: warning: extended initializer lists only available with '-std=c++11' or '-std=gnu++11' [-Wc++11-extensions]
  145 | char c3{ye}; // error: narrows (assuming char is 8 bits)
      |        ^
p212.cpp:145:9: warning: narrowing conversion of '999' from 'int' to 'char' is ill-formed in C++11 [-Wnarrowing]
  145 | char c3{ye}; // error: narrows (assuming char is 8 bits)
      |         ^~
p212.cpp:145:9: warning: overflow in conversion from 'int' to 'char' changes value from '999' to ''\37777777747'' [-Woverflow]
p212.cpp:146:8: warning: extended initializer lists only available with '-std=c++11' or '-std=gnu++11' [-Wc++11-extensions]
  146 | char c4{ze}; // OK, no narrowing needed
      |        ^
p212.cpp:148:22: warning: narrowing conversion of '-1' from 'int' to 'unsigned char' is ill-formed in C++11 [-Wnarrowing]
  148 | unsigned char uc2 = {-1}; // error: narrows
      |                      ^~
p212.cpp:149:21: warning: narrowing conversion of '-1' from 'int' to 'unsigned int' is ill-formed in C++11 [-Wnarrowing]
  149 | unsigned int ui1 = {-1}; // error: narrows
      |                     ^~
p212.cpp:151:3: warning: narrowing conversion of '4294967295' from 'unsigned int' to 'int' is ill-formed in C++11 [-Wnarrowing]
  151 | { (unsigned int)-1 }; // error: narrows
      |   ^~~~~~~~~~~~~~~~
p212.cpp:152:11: warning: narrowing conversion of '2.0e+0' from 'double' to 'int' is ill-formed in C++11 [-Wnarrowing]
  152 | int ii = {2.0}; // error: narrows
      |           ^~~
p212.cpp:153:11: warning: extended initializer lists only available with '-std=c++11' or '-std=gnu++11' [-Wc++11-extensions]
  153 | float f1e { xe }; // error: potentially narrows
      |           ^
p212.cpp:153:13: warning: narrowing conversion of 'xe' from 'int' to 'float' is ill-formed in C++11 [-Wnarrowing]
  153 | float f1e { xe }; // error: potentially narrows
      |             ^~
p212.cpp:154:11: warning: extended initializer lists only available with '-std=c++11' or '-std=gnu++11' [-Wc++11-extensions]
  154 | float f2e { 7 }; // OK, 7 can be exactly represented as a float
      |           ^
p212.cpp:155:12: warning: narrowing conversion of '(const char*)"meow"' from 'const char*' to 'bool' is ill-formed in C++11 [-Wnarrowing]
  155 | bool be = {"meow"}; // error: narrows
      |            ^~~~~~
rm: cannot remove 'p212g': No such file or directory

$ g++ p212.cpp -std=2b -o p212g -I. -Wall
p212.cpp:25:1: error: expected unqualified-id before 'new'
   25 | new std::vector<std::string>{"once", "upon", "a", "time"}; // 4 string elements
      | ^~~
p212.cpp:26:2: error: expected constructor, destructor, or type conversion before '(' token
   26 | f( {"Nicholas","Annemarie"} ); // pass list of two elements
      |  ^
p212.cpp:26:29: error: expected unqualified-id before ')' token
   26 | f( {"Nicholas","Annemarie"} ); // pass list of two elements
      |                             ^
p212.cpp:27:1: error: expected unqualified-id before 'return'
   27 | return { "Norah" }; // return list of one element
      | ^~~~~~
p212.cpp:29:1: error: 'x' does not name a type
   29 | x = double{1}; // explicitly construct a double
      | ^
p212.cpp:33:20: error: 'A' has no non-static data member named 'x'
   33 | A a2{.y = 2, .x = 1}; // error: designator order does not match declaration order
      |                    ^
p212.cpp:37:17: error: narrowing conversion of '2.0e+0' from 'double' to 'int' [-Wnarrowing]
   37 | int ai[] = { 1, 2.0 }; // error: narrowing
      |                 ^~~
p212.cpp:43:10: error: narrowing conversion of '1.0e+0' from 'double' to 'int' [-Wnarrowing]
   43 | S2 s22 { 1.0, 2, 3 }; // error: narrowing
      |          ^~~
p212.cpp:68:20: error: narrowing conversion of '1.0e+0' from 'double' to 'int' [-Wnarrowing]
   68 | S6 s26 { 1.0, 2, 3 }; // error: narrowing
      |                    ^
p212.cpp:72:1: error: reference to 'byte' is ambiguous
   72 | byte b7 { 42 }; // OK
      | ^~~~
In file included from /usr/local/include/c++/12.1.0/string:42,
                 from /usr/local/include/c++/12.1.0/bits/locale_classes.h:40,
                 from /usr/local/include/c++/12.1.0/bits/ios_base.h:41,
                 from /usr/local/include/c++/12.1.0/ios:42,
                 from /usr/local/include/c++/12.1.0/ostream:38,
                 from /usr/local/include/c++/12.1.0/iostream:39,
                 from p212.cpp:10:
/usr/local/include/c++/12.1.0/bits/cpp_type_traits.h:406:30: note: candidates are: 'enum class std::byte'
  406 |   enum class byte : unsigned char;
      |                              ^~~~
p212.cpp:71:6: note:                 'enum byte'
   71 | enum byte : unsigned char { };
      |      ^~~~
p212.cpp:73:1: error: reference to 'byte' is ambiguous
   73 | byte c7 = { 42 }; // error
      | ^~~~
/usr/local/include/c++/12.1.0/bits/cpp_type_traits.h:406:30: note: candidates are: 'enum class std::byte'
  406 |   enum class byte : unsigned char;
      |                              ^~~~
p212.cpp:71:6: note:                 'enum byte'
   71 | enum byte : unsigned char { };
      |      ^~~~
p212.cpp:74:1: error: reference to 'byte' is ambiguous
   74 | byte d7 = byte{ 42 }; // OK; same value as b
      | ^~~~
/usr/local/include/c++/12.1.0/bits/cpp_type_traits.h:406:30: note: candidates are: 'enum class std::byte'
  406 |   enum class byte : unsigned char;
      |                              ^~~~
p212.cpp:71:6: note:                 'enum byte'
   71 | enum byte : unsigned char { };
      |      ^~~~
p212.cpp:75:1: error: reference to 'byte' is ambiguous
   75 | byte e7 { -1 }; // error
      | ^~~~
/usr/local/include/c++/12.1.0/bits/cpp_type_traits.h:406:30: note: candidates are: 'enum class std::byte'
  406 |   enum class byte : unsigned char;
      |                              ^~~~
p212.cpp:71:6: note:                 'enum byte'
   71 | enum byte : unsigned char { };
      |      ^~~~
p212.cpp:76:13: error: reference to 'byte' is ambiguous
   76 | struct A7 { byte b7; };
      |             ^~~~
/usr/local/include/c++/12.1.0/bits/cpp_type_traits.h:406:30: note: candidates are: 'enum class std::byte'
  406 |   enum class byte : unsigned char;
      |                              ^~~~
p212.cpp:71:6: note:                 'enum byte'
   71 | enum byte : unsigned char { };
      |      ^~~~
p212.cpp:77:19: error: too many initializers for 'A7'
   77 | A7 a17 = { { 42 } }; // error
      |                   ^
p212.cpp:78:12: error: reference to 'byte' is ambiguous
   78 | A7 a27 = { byte{ 42 } }; // OK
      |            ^~~~
/usr/local/include/c++/12.1.0/bits/cpp_type_traits.h:406:30: note: candidates are: 'enum class std::byte'
  406 |   enum class byte : unsigned char;
      |                              ^~~~
p212.cpp:71:6: note:                 'enum byte'
   71 | enum byte : unsigned char { };
      |      ^~~~
p212.cpp:78:16: error: expected '}' before '{' token
   78 | A7 a27 = { byte{ 42 } }; // OK
      |          ~     ^
p212.cpp:78:16: error: expected ',' or ';' before '{' token
p212.cpp:78:23: error: expected declaration before '}' token
   78 | A7 a27 = { byte{ 42 } }; // OK
      |                       ^
p212.cpp:79:6: error: variable or field 'f7' declared void
   79 | void f7(byte);
      |      ^~
p212.cpp:79:9: error: reference to 'byte' is ambiguous
   79 | void f7(byte);
      |         ^~~~
/usr/local/include/c++/12.1.0/bits/cpp_type_traits.h:406:30: note: candidates are: 'enum class std::byte'
  406 |   enum class byte : unsigned char;
      |                              ^~~~
p212.cpp:71:6: note:                 'enum byte'
   71 | enum byte : unsigned char { };
      |      ^~~~
p212.cpp:80:3: error: expected constructor, destructor, or type conversion before '(' token
   80 | f7({ 42 }); // error
      |   ^
p212.cpp:80:10: error: expected unqualified-id before ')' token
   80 | f7({ 42 }); // error
      |          ^
p212.cpp:85:10: error: narrowing conversion of '2.0e+0' from 'double' to 'int' [-Wnarrowing]
   85 | int x28 {2.0}; // error: narrowing
      |          ^~~
p212.cpp:94:21: error: cannot bind non-const lvalue reference of type 'S9&' to an rvalue of type 'S9'
   94 | S9& r39 = { 1, 2, 3 }; // error: initializer is not an lvalue
      |                     ^
p212.cpp:88:1: note:   after user-defined conversion: 'S9::S9(std::initializer_list<double>)'
   88 | S9(std::initializer_list<double>); // #1
      | ^~
p212.cpp:96:24: error: narrowing conversion of '1.1000000000000001e+0' from 'double' to 'int' [-Wnarrowing]
   96 | const int& i29 = { 1.1 }; // error: narrowing
      |                        ^
p212.cpp:100:17: error: converting to 'const B9' from initializer list would use explicit constructor 'B9::B9(const A9&)'
  100 | const B9& b29{a9}; // error: cannot copy-list-initialize B temporary from A
      |                 ^
p212.cpp:106:10: error: narrowing conversion of '1.2e+0' from 'double' to 'int' [-Wnarrowing]
  106 | Ab a2b { 1.2 }; // error: narrowing
      |          ^~~
p212.cpp:111:17: error: narrowing conversion of '2.0e+0' from 'double' to 'int' [-Wnarrowing]
  111 | Bb b2b { 1, 2.0 }; // error: narrowing
      |                 ^
p212.cpp:116:19: error: narrowing conversion of '1.1000000000000001e+0' from 'double' to 'int' [-Wnarrowing]
  116 | Cb c2b = { 1.1, 2 }; // error: narrowing
      |                   ^
p212.cpp:125:4: error: redefinition of 'Xc xc'
  125 | Xc xc(std::initializer_list<double>(__a, __a+3));
      |    ^~
p212.cpp:123:4: note: 'Xc xc' previously declared here
  123 | Xc xc{ 1,2,3 };
      |    ^~
p212.cpp:125:37: error: '__a' was not declared in this scope
  125 | Xc xc(std::initializer_list<double>(__a, __a+3));
      |                                     ^~~
p212.cpp:125:42: error: '__a' was not declared in this scope
  125 | Xc xc(std::initializer_list<double>(__a, __a+3));
      |                                          ^~~
p212.cpp: In function 'void fd()':
p212.cpp:132:28: warning: unused variable 'i3d' [-Wunused-variable]
  132 | std::initializer_list<int> i3d = { 1, 2, 3 };
      |                            ^~~
p212.cpp: At global scope:
p212.cpp:144:9: warning: narrowing conversion of 'xe' from 'int' to 'char' [-Wnarrowing]
  144 | char c2{xe}; // error: potentially narrows
      |         ^~
p212.cpp:145:9: error: narrowing conversion of '999' from 'int' to 'char' [-Wnarrowing]
  145 | char c3{ye}; // error: narrows (assuming char is 8 bits)
      |         ^~
p212.cpp:148:22: error: narrowing conversion of '-1' from 'int' to 'unsigned char' [-Wnarrowing]
  148 | unsigned char uc2 = {-1}; // error: narrows
      |                      ^~
p212.cpp:149:21: error: narrowing conversion of '-1' from 'int' to 'unsigned int' [-Wnarrowing]
  149 | unsigned int ui1 = {-1}; // error: narrows
      |                     ^~
p212.cpp:151:3: error: narrowing conversion of '4294967295' from 'unsigned int' to 'int' [-Wnarrowing]
  151 | { (unsigned int)-1 }; // error: narrows
      |   ^~~~~~~~~~~~~~~~
p212.cpp:152:11: error: narrowing conversion of '2.0e+0' from 'double' to 'int' [-Wnarrowing]
  152 | int ii = {2.0}; // error: narrows
      |           ^~~
p212.cpp:153:13: warning: narrowing conversion of 'xe' from 'int' to 'float' [-Wnarrowing]
  153 | float f1e { xe }; // error: potentially narrows
      |             ^~
p212.cpp:155:12: warning: narrowing conversion of '(const char*)"meow"' from 'const char*' to 'bool' [-Wnarrowing]
  155 | bool be = {"meow"}; // error: narrows
      |            ^~~~~~

検討事項(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

0
0
0

Register as a new user and use Qiita more conveniently

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?