12.2.4.1 General  [over.match.best.general]  C++N4910:2022 (185) p333.cpp

# はじめに(Introduction)

N4910  Working Draft, Standard for Programming Language C++

http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/n4910.pdf

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++でコンパイルエラーが出ると、途方にくれることがしばしばあります。
何回かに１回は、該当するエラーが検索できます。
ただ、条件が違っていて、そこでの修正方法では目的を達成しないこともしばしばです。いろいろな条件のコンパイルエラーとその対応方法について、広く記録することによって、いつか同じエラーに遭遇した時にやくに立つことを目指しています。

この半年の間で、三度、自分のネットでの記録に助けられたことがあります。
また過去に解決できなかった記録を１０種類以上、最近になって解決できたことがあります。それは、主に次の３つの情報に基づいています。

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の２種類
でコンパイルし、

１）コンパイルエラーを収集する。
２）コンパイルエラーをなくす方法を検討する。
コンパイルエラーになる例を示すだけが目的のコードは、コンパイルエラーをなくすのではなく、コンパイルエラーの種類を収集するだけにする。
文法を示すのが目的のコード場合に、コンパイルエラーをなくすのに手間がかかる場合は、順次作業します。
３）リンクエラーをなくす方法を検討する。
文法を示すのが目的のコード場合に、リンクエラーをなくすのに手間がかかる場合は、順次作業します。
４）意味のある出力を作る。
コンパイル、リンクが通っても、意味のある出力を示そうとすると、コンパイル・リンクエラーが出て収拾できそうにない場合がある。順次作業します。

１）だけのものから４）まで進んだものと色々ある状態です。一歩でも前に進むご助言をお待ちしています。「検討事項」の欄に現状を記録するようにしています。

### C++N4910:2022 Standard Working Draft on ISO/IEC 14882(0) sample code compile list  

https://qiita.com/kaizen_nagoya/items/fc957ddddd402004bb91

### 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
> 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.

# 12.2.4.1 General  [over.match.best.general]  C++N4910:2022 (185) p333.cpp

## 算譜(source code)

```c++:p333.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 = "12.2.4.1 General  [over.match.best.general]  C++N4910:2022 (185) p333.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>
#include <atomic>
#include <unordered_map>
#include <typeinfo>

using namespace std;

// Example 1
struct A {
    A();
    operator int();
    operator double();
} a;
int i = a;
floatx=a;
// a.operator int() followed by no conversion is better than
// a.operator double() followed by a conversion to int
// ambiguous: both possibilities require conversions,
// and neither is better than the other
// [Example 2:
template <class T> struct A2 {
    operator T&();
    operator T&&();
};
typedef int Fn();
A2<Fn> a2;
Fn& lf = a2;
Fn&& rf = a2;
// #1 // #2
// calls #1 // calls #2
// [Example 3:
struct A3 {
    A3(int = 0);
};
struct B3: A3 {
    using A3::A3;
    B3();
};
//  int main() {
//    B b;
// }
// OK, B::B()
// [Example 4:
struct S {
    friend auto operator<=>(const S&, const S&) = default;
    friend bool operator<(const S&, const S&);
    bool b = S() < S();
};
// #1 // #2
//calls#2
// [Example 5:
struct S5 {
    friend std::weak_ordering operator<=>(const S&, int);
    friend std::weak_ordering operator<=>(int, const S&);
    bool b = 1 < S5();
};
// #1 // #2
//calls#2
// #1 // #2 // #3
// uses #3, generated from a non-template constructor // #6, less specialized than #5
// uses #6 to deduce A<int> and #1 to initialize // uses #5 to deduce A<int> and #2 to initialize

// [Example 6:
template <class T> struct A6 {
    using value_type = T;
    A6(value_type);
    A6(const A6&);
    A6(T, T, int);
    template<class U>
    A6(int, T, U);
// #5 is the copy deduction candidate, A(A)
};
A6 x(1, 2, 3);
template <class T>
A6(T) -> A6<T>;
A6 a6(42);
A6 b = a6;
// #4
template <class T>
A6(A6<T>) -> A6<A6<T>>; // #7, as specialized as #5
A6 b2 = a6; // uses #7 to deduce A<A<int>> and #1 to initialize
// [Example 7:
void Fcn(const int*, short);
void Fcn(int*, int);
int i7;
short s = 0;
void f7() {
    Fcn(&i7, s);
// is ambiguous because &i → int* is better than &i → const int* // but s → short is also better than s → int
// calls Fcn(int*, int), because &i → int* is better than &i → const int* // and 1L → short and 1L → int are indistinguishable
// calls Fcn(int*, int), because &i → int* is better than &i → const int* // and c → int is better than c → short
    Fcn(&i7, 1L);
    Fcn(&i7, 'c');
}
// [Example 8:
namespace A8 {
extern "C" void f8(int = 5);
}
namespace B8 {
extern "C" void f8(int = 5);
}
using A8::f8;
using B8::f8;
void use() {
    f8(3); // OK, default argument was not used for viability f(); // error: found default argument twice
}
int main() {
// Example 6
    B3 b;
    cout  <<  n4910 << endl;
    return EXIT_SUCCESS;
}
```

## Script

```bash: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)

```ubuntu:bash
# ./clgc.sh p333
rm: cannot remove 'p333l': No such file or directory
rm: cannot remove 'p333g': No such file or directory
$ clang++ p333.cpp -std=c++03 -o p333l -I. -Wall
In file included from p333.cpp:19:
In file included from /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/atomic:38:
/usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/c++0x_warning.h:32:2: error: This file requires compiler and library support for the ISO C++ 2011 standard. This support must be enabled with the -std=c++11 or -std=gnu++11 compiler options.
#error This file requires compiler and library support \
 ^
p333.cpp:32:1: error: C++ requires a type specifier for all declarations
floatx=a;
^
p333.cpp:40:5: error: 'operator type-parameter-0-0' cannot be the name of a variable or data member
    operator T&&();
    ^
p333.cpp:40:15: error: expected ';' at end of declaration list
    operator T&&();
              ^
              ;
p333.cpp:45:5: warning: rvalue references are a C++11 extension [-Wc++11-extensions]
  Fn&& rf = a2;
    ^
p333.cpp:53:15: error: using declaration cannot refer to a constructor
    using A3::A3;
          ~~~~^
p333.cpp:62:10: warning: 'auto' type specifier is a C++11 extension [-Wc++11-extensions]
  friend auto operator<=>(const S&, const S&) = default;
         ^
p333.cpp:62:23: warning: '<=>' is a single token in C++20; add a space to avoid a change in behavior [-Wc++20-compat]
  friend auto operator<=>(const S&, const S&) = default;
                      ^
                         
p333.cpp:62:10: error: 'auto' not allowed in friend declaration
  friend auto operator<=>(const S&, const S&) = default;
         ^~~~
p333.cpp:62:15: error: friends can only be classes or functions
  friend auto operator<=>(const S&, const S&) = default;
              ^
p333.cpp:62:25: error: expected ';' at end of declaration list
  friend auto operator<=>(const S&, const S&) = default;
                        ^
                        ;
p333.cpp:64:8: warning: default member initializer for non-static data member is a C++11 extension [-Wc++11-extensions]
bool b = S() < S();
       ^
p333.cpp:61:8: error: default member initializer for 'b' needed within definition of enclosing class 'S' outside of member functions
struct S {
       ^
p333.cpp:64:10: note: in evaluation of exception specification for 'S::S' needed here
bool b = S() < S();
         ^
p333.cpp:64:6: note: default member initializer declared here
bool b = S() < S();
     ^
p333.cpp:70:15: error: no type named 'weak_ordering' in namespace 'std'
  friend std::weak_ordering operator<=>(const S&, int);
         ~~~~~^
p333.cpp:70:37: warning: '<=>' is a single token in C++20; add a space to avoid a change in behavior [-Wc++20-compat]
  friend std::weak_ordering operator<=>(const S&, int);
                                    ^
                                       
p333.cpp:70:29: error: friends can only be classes or functions
  friend std::weak_ordering operator<=>(const S&, int);
                            ^
p333.cpp:70:39: error: expected ';' at end of declaration list
  friend std::weak_ordering operator<=>(const S&, int);
                                      ^
                                      ;
p333.cpp:71:15: error: no type named 'weak_ordering' in namespace 'std'
  friend std::weak_ordering operator<=>(int, const S&);
         ~~~~~^
p333.cpp:71:37: warning: '<=>' is a single token in C++20; add a space to avoid a change in behavior [-Wc++20-compat]
  friend std::weak_ordering operator<=>(int, const S&);
                                    ^
                                       
p333.cpp:71:29: error: friends can only be classes or functions
  friend std::weak_ordering operator<=>(int, const S&);
                            ^
p333.cpp:71:39: error: expected ';' at end of declaration list
  friend std::weak_ordering operator<=>(int, const S&);
                                      ^
                                      ;
p333.cpp:72:8: warning: default member initializer for non-static data member is a C++11 extension [-Wc++11-extensions]
bool b = 1 < S5();
       ^
p333.cpp:69:8: error: default member initializer for 'b' needed within definition of enclosing class 'S5' outside of member functions
struct S5 {
       ^
p333.cpp:72:14: note: in evaluation of exception specification for 'S5::S5' needed here
bool b = 1 < S5();
             ^
p333.cpp:72:6: note: default member initializer declared here
bool b = 1 < S5();
     ^
p333.cpp:72:12: error: invalid operands to binary expression ('int' and 'S5')
bool b = 1 < S5();
         ~ ^ ~~~~
/usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/stl_pair.h:489:5: note: candidate template ignored: could not match 'pair<_T1, _T2>' against 'int'
    operator<(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y)
    ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/stl_iterator.h:391:5: note: candidate template ignored: could not match 'reverse_iterator<_Iterator>' against 'int'
    operator<(const reverse_iterator<_Iterator>& __x,
    ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/stl_iterator.h:429:5: note: candidate template ignored: could not match 'reverse_iterator<_IteratorL>' against 'int'
    operator<(const reverse_iterator<_IteratorL>& __x,
    ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/basic_string.h:6277:5: note: candidate template ignored: could not match 'basic_string<_CharT, _Traits, _Alloc>' against 'int'
    operator<(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
    ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/basic_string.h:6290:5: note: candidate template ignored: could not match 'basic_string<_CharT, _Traits, _Alloc>' against 'int'
    operator<(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
    ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/basic_string.h:6302:5: note: candidate template ignored: could not match 'const _CharT *' against 'int'
    operator<(const _CharT* __lhs,
    ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/stl_vector.h:1930:5: note: candidate template ignored: could not match 'vector<_Tp, _Alloc>' against 'int'
    operator<(const vector<_Tp, _Alloc>& __x, const vector<_Tp, _Alloc>& __y)
    ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/stl_map.h:1501:5: note: candidate template ignored: could not match 'map<_Key, _Tp, _Compare, _Alloc>' against 'int'
    operator<(const map<_Key, _Tp, _Compare, _Alloc>& __x,
    ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/stl_multimap.h:1166:5: note: candidate template ignored: could not match 'multimap<_Key, _Tp, _Compare, _Alloc>' against 'int'
    operator<(const multimap<_Key, _Tp, _Compare, _Alloc>& __x,
    ^
p333.cpp:82:27: warning: alias declarations are a C++11 extension [-Wc++11-extensions]
       using value_type = T;
                          ^
p333.cpp:90:1: error: use of class template 'A6' requires template arguments
A6 x(1, 2, 3);
^
p333.cpp:81:27: note: template is declared here
template <class T> struct A6 {
~~~~~~~~~~~~~~~~~~        ^
p333.cpp:92:1: error: use of class template 'A6' requires template arguments
A6(T) -> A6<T>;
^
p333.cpp:81:27: note: template is declared here
template <class T> struct A6 {
~~~~~~~~~~~~~~~~~~        ^
p333.cpp:92:4: warning: variable templates are a C++14 extension [-Wc++14-extensions]
A6(T) -> A6<T>;
   ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
9 warnings and 20 errors generated.
rm: cannot remove 'p333l': No such file or directory
$ clang++ p333.cpp -std=c++2b -o p333l -I. -Wall
p333.cpp:32:1: error: C++ requires a type specifier for all declarations
floatx=a;
^
p333.cpp:45:8: error: reference initialization of type 'Fn &&' (aka 'int (&&)()') with initializer of type 'A2<Fn>' (aka 'A2<int ()>') is ambiguous
  Fn&& rf = a2;
       ^    ~~
p333.cpp:39:5: note: candidate function
    operator T&();
    ^
p333.cpp:40:5: note: candidate function
    operator T&&();
    ^
p333.cpp:61:8: error: default member initializer for 'b' needed within definition of enclosing class 'S' outside of member functions
struct S {
       ^
p333.cpp:64:10: note: in evaluation of exception specification for 'S::S' needed here
bool b = S() < S();
         ^
p333.cpp:64:6: note: default member initializer declared here
bool b = S() < S();
     ^
p333.cpp:69:8: error: default member initializer for 'b' needed within definition of enclosing class 'S5' outside of member functions
struct S5 {
       ^
p333.cpp:72:14: note: in evaluation of exception specification for 'S5::S5' needed here
bool b = 1 < S5();
             ^
p333.cpp:72:6: note: default member initializer declared here
bool b = 1 < S5();
     ^
p333.cpp:72:12: error: invalid operands to binary expression ('int' and 'S5')
bool b = 1 < S5();
         ~ ^ ~~~~
p333.cpp:70:29: note: candidate function (with reversed parameter order) not viable: no known conversion from 'S5' to 'const S' for 2nd argument
  friend std::weak_ordering operator<=>(const S&, int);
                            ^
p333.cpp:71:29: note: candidate function not viable: no known conversion from 'S5' to 'const S' for 2nd argument
  friend std::weak_ordering operator<=>(int, const S&);
                            ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/system_error:244:3: note: candidate function not viable: no known conversion from 'int' to 'const std::error_code' for 1st argument
  operator<=>(const error_code& __lhs, const error_code& __rhs) noexcept
  ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/system_error:368:3: note: candidate function not viable: no known conversion from 'int' to 'const std::error_condition' for 1st argument
  operator<=>(const error_condition& __lhs,
  ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/coroutine:144:3: note: candidate function not viable: no known conversion from 'int' to 'coroutine_handle<>' for 1st argument
  operator<=>(coroutine_handle<> __a, coroutine_handle<> __b) noexcept
  ^
p333.cpp:70:29: note: candidate function not viable: no known conversion from 'int' to 'const S' for 1st argument
  friend std::weak_ordering operator<=>(const S&, int);
                            ^
p333.cpp:71:29: note: candidate function (with reversed parameter order) not viable: no known conversion from 'int' to 'const S' for 1st argument
  friend std::weak_ordering operator<=>(int, const S&);
                            ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/stl_pair.h:473:5: note: candidate template ignored: could not match 'pair<_T1, _T2>' against 'int'
    operator<=>(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y)
    ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/stl_iterator.h:473:5: note: candidate template ignored: could not match 'reverse_iterator<_IteratorL>' against 'int'
    operator<(const reverse_iterator<_IteratorL>& __x,
    ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/stl_iterator.h:502:5: note: candidate template ignored: could not match 'reverse_iterator<_IteratorL>' against 'int'
    operator<=>(const reverse_iterator<_IteratorL>& __x,
    ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/stl_iterator.h:502:5: note: candidate template ignored: could not match 'reverse_iterator<_IteratorL>' against 'S5'
/usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/stl_iterator.h:1471:5: note: candidate template ignored: could not match 'move_iterator<_IteratorL>' against 'int'
    operator<=>(const move_iterator<_IteratorL>& __x,
    ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/stl_iterator.h:1471:5: note: candidate template ignored: could not match 'move_iterator<_IteratorL>' against 'S5'
/usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/stl_iterator.h:1484:5: note: candidate template ignored: could not match 'move_iterator<_IteratorL>' against 'int'
    operator<(const move_iterator<_IteratorL>& __x,
    ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/string_view:501:5: note: candidate template ignored: could not match 'basic_string_view<_CharT, _Traits>' against 'int'
    operator<=>(basic_string_view<_CharT, _Traits> __x,
    ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/string_view:508:5: note: candidate template ignored: could not match 'basic_string_view<_CharT, _Traits>' against 'int'
    operator<=>(basic_string_view<_CharT, _Traits> __x,
    ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/string_view:508:5: note: candidate template ignored: could not match 'basic_string_view<_CharT, _Traits>' against 'S5'
/usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/basic_string.h:6199:5: note: candidate template ignored: could not match 'basic_string<_CharT, _Traits, _Alloc>' against 'int'
    operator<=>(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
    ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/basic_string.h:6213:5: note: candidate template ignored: could not match 'basic_string<_CharT, _Traits, _Alloc>' against 'int'
    operator<=>(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
    ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/basic_string.h:6213:5: note: candidate template ignored: could not match 'basic_string<_CharT, _Traits, _Alloc>' against 'S5'
/usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/stl_vector.h:1910:5: note: candidate template ignored: could not match 'vector<_Tp, _Alloc>' against 'int'
    operator<=>(const vector<_Tp, _Alloc>& __x, const vector<_Tp, _Alloc>& __y)
    ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/optional:1033:5: note: candidate template ignored: could not match 'optional<_Tp>' against 'int'
    operator<(const optional<_Tp>& __lhs, const optional<_Up>& __rhs)
    ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/optional:1066:5: note: candidate template ignored: could not match 'optional<_Tp>' against 'int'
    operator<=>(const optional<_Tp>& __x, const optional<_Up>& __y)
    ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/optional:1066:5: note: candidate template ignored: could not match 'optional<_Tp>' against 'S5'
/usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/optional:1081:5: note: candidate template ignored: could not match 'optional<_Tp>' against 'int'
    operator<=>(const optional<_Tp>& __x, nullopt_t) noexcept
    ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/optional:1081:5: note: candidate template ignored: could not match 'optional<_Tp>' against 'S5'
/usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/optional:1167:5: note: candidate template ignored: could not match 'optional<_Tp>' against 'int'
    operator<(const optional<_Tp>& __lhs, const _Up& __rhs)
    ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/optional:1173:5: note: candidate template ignored: could not match 'optional<_Tp>' against 'S5'
    operator<(const _Up& __lhs, const optional<_Tp>& __rhs)
    ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/optional:1216:5: note: candidate template ignored: could not match 'optional<_Tp>' against 'int'
    operator<=>(const optional<_Tp>& __x, const _Up& __v)
    ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/optional:1216:5: note: candidate template ignored: could not match 'optional<_Tp>' against 'S5'
/usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/array:259:5: note: candidate template ignored: could not match 'array<_Tp, _Nm>' against 'int'
    operator<=>(const array<_Tp, _Nm>& __a, const array<_Tp, _Nm>& __b)
    ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/tuple:1426:5: note: candidate template ignored: could not match 'tuple<_Tps...>' against 'int'
    operator<=>(const tuple<_Tps...>& __t, const tuple<_Ups...>& __u)
    ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/tuple:1426:5: note: candidate template ignored: could not match 'tuple<_Tps...>' against 'S5'
/usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/stl_map.h:1484:5: note: candidate template ignored: could not match 'map<_Key, _Tp, _Compare, _Alloc>' against 'int'
    operator<=>(const map<_Key, _Tp, _Compare, _Alloc>& __x,
    ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/stl_multimap.h:1149:5: note: candidate template ignored: could not match 'multimap<_Key, _Tp, _Compare, _Alloc>' against 'int'
    operator<=>(const multimap<_Key, _Tp, _Compare, _Alloc>& __x,
    ^
p333.cpp:90:4: error: ambiguous deduction for template arguments of 'A6'
A6 x(1, 2, 3);
   ^
p333.cpp:85:1: note: candidate function [with T = int]
A6(T, T, int);
^
p333.cpp:87:1: note: candidate function [with T = int, U = int]
A6(int, T, U);
^
p333.cpp:105:3: error: call to 'Fcn' is ambiguous
  Fcn(&i7, s);
  ^~~
p333.cpp:100:6: note: candidate function
void Fcn(const int*, short);
     ^
p333.cpp:101:11: note: candidate function
     void Fcn(int*, int);
          ^
7 errors generated.

$ g++ p333.cpp -std=c++03 -o p333g -I. -Wall
In file included from /usr/local/include/c++/12.1.0/atomic:38,
                 from p333.cpp:19:
/usr/local/include/c++/12.1.0/bits/c++0x_warning.h:32:2: error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support must be enabled with the -std=c++11 or -std=gnu++11 compiler options.
   32 | #error This file requires compiler and library support \
      |  ^~~~~
p333.cpp:32:1: error: 'floatx' does not name a type; did you mean 'float'?
   32 | floatx=a;
      | ^~~~~~
      | float
p333.cpp:40:5: error: 'operator T' does not name a type
   40 |     operator T&&();
      |     ^~~~~~~~
p333.cpp:45:5: error: expected unqualified-id before '&&' token
   45 |   Fn&& rf = a2;
      |     ^~
p333.cpp:53:15: warning: inheriting constructors only available with '-std=c++11' or '-std=gnu++11' [-Wc++11-extensions]
   53 |     using A3::A3;
      |               ^~
p333.cpp:62:10: warning: 'auto' changes meaning in C++11; please remove it [-Wc++11-compat]
   62 |   friend auto operator<=>(const S&, const S&) = default;
      |          ^~~~
      |          ----
p333.cpp:62:15: error: 'operator<=' does not name a type
   62 |   friend auto operator<=>(const S&, const S&) = default;
      |               ^~~~~~~~
p333.cpp:64:8: warning: non-static data member initializers only available with '-std=c++11' or '-std=gnu++11' [-Wc++11-extensions]
   64 | bool b = S() < S();
      |        ^
p333.cpp:64:12: error: default member initializer for 'S::b' required before the end of its enclosing class
   64 | bool b = S() < S();
      |            ^
p333.cpp:64:8: note: defined here
   64 | bool b = S() < S();
      |        ^~~~~~~~~~~~
p333.cpp:70:15: error: 'weak_ordering' in namespace 'std' does not name a type
   70 |   friend std::weak_ordering operator<=>(const S&, int);
      |               ^~~~~~~~~~~~~
p333.cpp:70:10: note: 'std::weak_ordering' is only available from C++20 onwards
   70 |   friend std::weak_ordering operator<=>(const S&, int);
      |          ^~~
p333.cpp:71:15: error: 'weak_ordering' in namespace 'std' does not name a type
   71 |   friend std::weak_ordering operator<=>(int, const S&);
      |               ^~~~~~~~~~~~~
p333.cpp:71:10: note: 'std::weak_ordering' is only available from C++20 onwards
   71 |   friend std::weak_ordering operator<=>(int, const S&);
      |          ^~~
p333.cpp:72:8: warning: non-static data member initializers only available with '-std=c++11' or '-std=gnu++11' [-Wc++11-extensions]
   72 | bool b = 1 < S5();
      |        ^
p333.cpp:72:17: error: default member initializer for 'S5::b' required before the end of its enclosing class
   72 | bool b = 1 < S5();
      |                 ^
p333.cpp:72:8: note: defined here
   72 | bool b = 1 < S5();
      |        ^~~~~~~~~~~
p333.cpp:72:12: error: no match for 'operator<' (operand types are 'int' and 'S5')
   72 | bool b = 1 < S5();
      |          ~ ^ ~~~~
      |          |   |
      |          int S5
In file included from /usr/local/include/c++/12.1.0/string:47,
                 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 p333.cpp:10:
/usr/local/include/c++/12.1.0/bits/stl_iterator.h:451:5: note: candidate: 'template<class _Iterator> bool std::operator<(const reverse_iterator<_Iterator>&, const reverse_iterator<_Iterator>&)'
  451 |     operator<(const reverse_iterator<_Iterator>& __x,
      |     ^~~~~~~~
/usr/local/include/c++/12.1.0/bits/stl_iterator.h:451:5: note:   template argument deduction/substitution failed:
p333.cpp:72:17: note:   mismatched types 'const std::reverse_iterator<_Iterator>' and 'int'
   72 | bool b = 1 < S5();
      |                 ^
/usr/local/include/c++/12.1.0/bits/stl_iterator.h:496:5: note: candidate: 'template<class _IteratorL, class _IteratorR> bool std::operator<(const reverse_iterator<_Iterator>&, const reverse_iterator<_IteratorR>&)'
  496 |     operator<(const reverse_iterator<_IteratorL>& __x,
      |     ^~~~~~~~
/usr/local/include/c++/12.1.0/bits/stl_iterator.h:496:5: note:   template argument deduction/substitution failed:
p333.cpp:72:17: note:   mismatched types 'const std::reverse_iterator<_Iterator>' and 'int'
   72 | bool b = 1 < S5();
      |                 ^
In file included from /usr/local/include/c++/12.1.0/bits/stl_algobase.h:64,
                 from /usr/local/include/c++/12.1.0/string:50:
/usr/local/include/c++/12.1.0/bits/stl_pair.h:663:5: note: candidate: 'template<class _T1, class _T2> bool std::operator<(const pair<_T1, _T2>&, const pair<_T1, _T2>&)'
  663 |     operator<(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y)
      |     ^~~~~~~~
/usr/local/include/c++/12.1.0/bits/stl_pair.h:663:5: note:   template argument deduction/substitution failed:
p333.cpp:72:17: note:   mismatched types 'const std::pair<_T1, _T2>' and 'int'
   72 | bool b = 1 < S5();
      |                 ^
In file included from /usr/local/include/c++/12.1.0/string:53:
/usr/local/include/c++/12.1.0/bits/basic_string.h:3691:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> bool std::operator<(const __cxx11::basic_string<_CharT, _Traits, _Alloc>&, const __cxx11::basic_string<_CharT, _Traits, _Alloc>&)'
 3691 |     operator<(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
      |     ^~~~~~~~
/usr/local/include/c++/12.1.0/bits/basic_string.h:3691:5: note:   template argument deduction/substitution failed:
p333.cpp:72:17: note:   mismatched types 'const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>' and 'int'
   72 | bool b = 1 < S5();
      |                 ^
/usr/local/include/c++/12.1.0/bits/basic_string.h:3704:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> bool std::operator<(const __cxx11::basic_string<_CharT, _Traits, _Alloc>&, const _CharT*)'
 3704 |     operator<(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
      |     ^~~~~~~~
/usr/local/include/c++/12.1.0/bits/basic_string.h:3704:5: note:   template argument deduction/substitution failed:
p333.cpp:72:17: note:   mismatched types 'const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>' and 'int'
   72 | bool b = 1 < S5();
      |                 ^
/usr/local/include/c++/12.1.0/bits/basic_string.h:3716:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> bool std::operator<(const _CharT*, const __cxx11::basic_string<_CharT, _Traits, _Alloc>&)'
 3716 |     operator<(const _CharT* __lhs,
      |     ^~~~~~~~
/usr/local/include/c++/12.1.0/bits/basic_string.h:3716:5: note:   template argument deduction/substitution failed:
p333.cpp:72:17: note:   mismatched types 'const _CharT*' and 'int'
   72 | bool b = 1 < S5();
      |                 ^
In file included from /usr/local/include/c++/12.1.0/vector:64,
                 from p333.cpp:16:
/usr/local/include/c++/12.1.0/bits/stl_vector.h:2074:5: note: candidate: 'template<class _Tp, class _Alloc> bool std::operator<(const vector<_Tp, _Alloc>&, const vector<_Tp, _Alloc>&)'
 2074 |     operator<(const vector<_Tp, _Alloc>& __x, const vector<_Tp, _Alloc>& __y)
      |     ^~~~~~~~
/usr/local/include/c++/12.1.0/bits/stl_vector.h:2074:5: note:   template argument deduction/substitution failed:
p333.cpp:72:17: note:   mismatched types 'const std::vector<_Tp, _Alloc>' and 'int'
   72 | bool b = 1 < S5();
      |                 ^
In file included from /usr/local/include/c++/12.1.0/map:61,
                 from p333.cpp:18:
/usr/local/include/c++/12.1.0/bits/stl_map.h:1549:5: note: candidate: 'template<class _Key, class _Tp, class _Compare, class _Alloc> bool std::operator<(const map<_Key, _Tp, _Compare, _Alloc>&, const map<_Key, _Tp, _Compare, _Alloc>&)'
 1549 |     operator<(const map<_Key, _Tp, _Compare, _Alloc>& __x,
      |     ^~~~~~~~
/usr/local/include/c++/12.1.0/bits/stl_map.h:1549:5: note:   template argument deduction/substitution failed:
p333.cpp:72:17: note:   mismatched types 'const std::map<_Key, _Tp, _Compare, _Alloc>' and 'int'
   72 | bool b = 1 < S5();
      |                 ^
In file included from /usr/local/include/c++/12.1.0/map:62:
/usr/local/include/c++/12.1.0/bits/stl_multimap.h:1170:5: note: candidate: 'template<class _Key, class _Tp, class _Compare, class _Alloc> bool std::operator<(const multimap<_Key, _Tp, _Compare, _Alloc>&, const multimap<_Key, _Tp, _Compare, _Alloc>&)'
 1170 |     operator<(const multimap<_Key, _Tp, _Compare, _Alloc>& __x,
      |     ^~~~~~~~
/usr/local/include/c++/12.1.0/bits/stl_multimap.h:1170:5: note:   template argument deduction/substitution failed:
p333.cpp:72:17: note:   mismatched types 'const std::multimap<_Key, _Tp, _Compare, _Alloc>' and 'int'
   72 | bool b = 1 < S5();
      |                 ^
p333.cpp:82:14: error: expected nested-name-specifier before 'value_type'
   82 |        using value_type = T;
      |              ^~~~~~~~~~
p333.cpp:83:3: warning: unnecessary parentheses in declaration of 'value_type' [-Wparentheses]
   83 | A6(value_type);
      |   ^~~~~~~~~~~~
p333.cpp:83:3: note: remove parentheses
   83 | A6(value_type);
      |   ^~~~~~~~~~~~
      |   -          -
p333.cpp:83:4: error: field 'value_type' has incomplete type 'A6<T>'
   83 | A6(value_type);
      |    ^~~~~~~~~~
p333.cpp:81:27: note: definition of 'struct A6<T>' is not complete until the closing brace
   81 | template <class T> struct A6 {
      |                           ^~
p333.cpp:90:1: error: invalid use of template-name 'A6' without an argument list
   90 | A6 x(1, 2, 3);
      | ^~
p333.cpp:90:1: note: class template argument deduction is only available with '-std=c++17' or '-std=gnu++17'
p333.cpp:81:27: note: 'template<class T> struct A6' declared here
   81 | template <class T> struct A6 {
      |                           ^~
p333.cpp:92:15: error: expected constructor, destructor, or type conversion before ';' token
   92 | A6(T) -> A6<T>;
      |               ^
p333.cpp:93:1: error: invalid use of template-name 'A6' without an argument list
   93 | A6 a6(42);
      | ^~
p333.cpp:93:1: note: class template argument deduction is only available with '-std=c++17' or '-std=gnu++17'
p333.cpp:81:27: note: 'template<class T> struct A6' declared here
   81 | template <class T> struct A6 {
      |                           ^~
p333.cpp:94:1: error: invalid use of template-name 'A6' without an argument list
   94 | A6 b = a6;
      | ^~
p333.cpp:94:1: note: class template argument deduction is only available with '-std=c++17' or '-std=gnu++17'
p333.cpp:81:27: note: 'template<class T> struct A6' declared here
   81 | template <class T> struct A6 {
      |                           ^~
p333.cpp:97:21: error: '>>' should be '> >' within a nested template argument list
   97 | A6(A6<T>) -> A6<A6<T>>; // #7, as specialized as #5
      |                     ^~
      |                     > >
p333.cpp:97:23: error: expected constructor, destructor, or type conversion before ';' token
   97 | A6(A6<T>) -> A6<A6<T>>; // #7, as specialized as #5
      |                       ^
p333.cpp:98:1: error: invalid use of template-name 'A6' without an argument list
   98 | A6 b2 = a6; // uses #7 to deduce A<A<int>> and #1 to initialize
      | ^~
p333.cpp:98:1: note: class template argument deduction is only available with '-std=c++17' or '-std=gnu++17'
p333.cpp:81:27: note: 'template<class T> struct A6' declared here
   81 | template <class T> struct A6 {
      |                           ^~
p333.cpp: In function 'void f7()':
p333.cpp:105:6: warning: ISO C++ says that these are ambiguous, even though the worst conversion for the first is better than the worst conversion for the second:
  105 |   Fcn(&i7, s);
      |   ~~~^~~~~~~~
p333.cpp:100:6: note: candidate 1: 'void Fcn(const int*, short int)'
  100 | void Fcn(const int*, short);
      |      ^~~
p333.cpp:101:11: note: candidate 2: 'void Fcn(int*, int)'
  101 |      void Fcn(int*, int);
      |           ^~~
rm: cannot remove 'p333g': No such file or directory

$ g++ p333.cpp -std=c++2b -o p333g -I. -Wall
p333.cpp:32:1: error: 'floatx' does not name a type; did you mean 'float'?
   32 | floatx=a;
      | ^~~~~~
      | float
p333.cpp:64:12: error: default member initializer for 'S::b' required before the end of its enclosing class
   64 | bool b = S() < S();
      |            ^
p333.cpp:64:8: note: defined here
   64 | bool b = S() < S();
      |        ^~~~~~~~~~~~
p333.cpp:72:17: error: default member initializer for 'S5::b' required before the end of its enclosing class
   72 | bool b = 1 < S5();
      |                 ^
p333.cpp:72:8: note: defined here
   72 | bool b = 1 < S5();
      |        ^~~~~~~~~~~
p333.cpp: In function 'void f7()':
p333.cpp:105:6: warning: ISO C++ says that these are ambiguous, even though the worst conversion for the first is better than the worst conversion for the second:
  105 |   Fcn(&i7, s);
      |   ~~~^~~~~~~~
p333.cpp:100:6: note: candidate 1: 'void Fcn(const int*, short int)'
  100 | void Fcn(const int*, short);
      |      ^~~
p333.cpp:101:11: note: candidate 2: 'void Fcn(int*, int)'
  101 |      void Fcn(int*, int);
      |           ^~~
```

## 検討事項(agenda)
コンパイルエラーを取るか、コンパイルエラーの理由を解説する。

<!-- リンクエラーの解説をする。clang++とg++の比較。意味のある出力。
コンパイルエラーを取るか、コンパイルエラーの理由を解説する。-->


# 参考資料(reference)

cpprefjp - C++日本語リファレンス

https://cpprefjp.github.io/

コンパイラの実装状況

https://cpprefjp.github.io/implementation-status.html


typedef は C++11 ではオワコン

https://qiita.com/Linda_pp/items/44a67c64c14cba00eef1

C99からC++14を駆け抜けるC++講座

https://qiita.com/yumetodo/items/e49a673afd9a3ecb81a8

## 自己参照(self reference)

コピペコンパイルエラーあるある

https://qiita.com/kaizen_nagoya/items/29c832de9d762aed2761

C++ Error Message Collection(1)does not name a type, 11 articles

https://qiita.com/kaizen_nagoya/items/acb9f1a9b5aad6df06bd

dockerにclang

https://qiita.com/kaizen_nagoya/items/8829ffeee397eda50e80

docker gnu(gcc/g++) and llvm(clang/clang++)

https://qiita.com/drafts/059874ea39c4de64c0f7

コンパイル用shell script C版(clangとgcc)とC++版(clang++とg++)

https://qiita.com/kaizen_nagoya/items/74220c0577a512c2d7da

Compare the contents of C++N4910:2022, C++N4741:2018 and C++N4606:2015

https://qiita.com/kaizen_nagoya/items/483246d40f98abff7ded

C++ sample list

https://qiita.com/kaizen_nagoya/items/54ad75b73825b7c04f86


clang++, g++コンパイルエラー方針の違いの例

https://qiita.com/kaizen_nagoya/items/ea6e5009fe126d270a82

astyle 使ってみた

https://qiita.com/kaizen_nagoya/items/3c9a87a781d53a1a23f3

C++N4606 Working Draft 2016, ISO/IEC 14882, C++ standardのコード断片をコンパイルするためにしていること
https://qiita.com/kaizen_nagoya/items/a8d7ee2f2e29e76c19c1

コンパイル用shell script C版(clangとgcc)とC++版(clang++とg++)
https://qiita.com/kaizen_nagoya/items/74220c0577a512c2d7da

Clang/Clang++(LLVM) gcc/g++(GNU) コンパイラ警告等比較
https://qiita.com/kaizen_nagoya/items/9a82b958cc3aeef0403f

C++2003とC++2017でコンパイルエラーになるならない事例集
https://qiita.com/kaizen_nagoya/items/a13ea3823441c430edff

Qiitaに投稿するCのStyle例(暫定)
https://qiita.com/kaizen_nagoya/items/946df1528a6a1ef2bc0d

cpprefjpのdecltypeをコンパイル試験
https://qiita.com/kaizen_nagoya/items/090909af702f0d5d8a67

MISRA C++ 5-0-16
https://qiita.com/kaizen_nagoya/items/7df2d4e05db724752a74

C++ Templates Part1 BASICS Chapter 3. Class Templates 3.2 Use of Class Template Stack stack1test.cpp
https://qiita.com/kaizen_nagoya/items/cd5fc49106fad5a4e9ed

ISO/IEC TS 17961:2013 C Secure Coding Rules(1) All list(to be confirmed)
https://qiita.com/kaizen_nagoya/items/54e056195c4f11b850a1

C言語（C++)に対する誤解、曲解、無理解、爽快。
https://qiita.com/kaizen_nagoya/items/3f3992c9722c1cee2e3a

C Puzzle Bookの有り難み5つ、C言語規格及びCコンパイラの特性を認識
https://qiita.com/kaizen_nagoya/items/d89a48c1536a02ecdec9

'wchar.h' file not found で困った clang++ macOS
https://qiita.com/kaizen_nagoya/items/de15cd46d657517fac11

Open POSIX Test Suiteの使い方を調べはじめました
https://qiita.com/kaizen_nagoya/items/644d5e407f5faf96e6dc

MISRA-C 2012 Referenceに掲載している文献の入手可能性を確認
https://qiita.com/kaizen_nagoya/items/96dc8b125e462d5575bb

どうやって MISRA Example Suiteをコンパイルするか
https://qiita.com/kaizen_nagoya/items/fbdbff5ff696e2ca7f00

MISRA C まとめ #include <misra_c.h>
https://qiita.com/kaizen_nagoya/items/f1a79a7cbd281607c7c9

「C++完全理解ガイド」の同意できること上位10
https://qiita.com/kaizen_nagoya/items/aa5744e0c4a8618c7671


 ＜この記事は個人の過去の経験に基づく個人の感想です。現在所属する組織、業務とは関係がありません。＞

# 文書履歴(document history)
ver. 0.01 初稿 　20220702