C++N4741(224)17.9.2.1 Deducing template arguments from a function call [temp.deduct.call]p376

#はじめに(Introduction)
C++N4741 Working Draft, Standard for Programming Language C++
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/n4741.pdf

C++N4741は、ISO/IEC JTC1 SC22 WG21の作業原案(Working Draft)です。
公式のISO/IEC 14882原本ではありません。
ISO/IEC JTC1 SC22 WG21では、可能な限り作業文書を公開し、幅広い意見を求めています。
一連の記事はコード断片をコンパイルできる形にする方法を検討してコンパイル、リンク、実行して、規格案の原文と処理系(g++, Clang++)との違いを確認し、技術内容を検討し、ISO/IEC JTC1 SC22 WG21にフィードバックするために用います。
Linux OSなどのhosted環境, TOPPERSカーネルなどのfreestanding環境におけるC++の機能と役割を確認したり、system CによるCPUの記述のtemplateによる再利用を検討しています。
CERT C++, MISRA C++等のコーディング標準のコード断片をコンパイルする際の参考にさせていただこうと考えています。CERT C++, MISRA C++が標準化の動きとの時間的なずれがあれば確認できれば幸いです。また、boostライブラリとの関連、g++(GCC), clang++(LLVM）との関係も調査中です。
何か、抜け漏れ、耳より情報がありましたらおしらせくださると幸いです。

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

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

https://stackoverflow.com
https://cpprefjp.github.io
http://ja.cppreference.com/
https://teratail.com/

また
https://researchmap.jp/joub9b3my-1797580/#_1797580
に記載したサイトのお世話になっています。

##作業方針(sequence)
Clang++では-std=c++03, c++17, C++2aの３種類
g++では-std=c++03, c++17の２種類
でコンパイルし、

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

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

### コーディング標準対応
コーディング標準の検討の下準備のコードとして、
コーディング標準を守って初期化をしてある方がいいという
考え方があります。
ここでは、逆に、コンパイラの警告がどれくらいコーディング標準の検査に役立つかを確かめたいという目的があります。

何か特別なコンパイラを使っていても、将来の可搬性を考えて、
g++, clang++, visual C++の三種類のコンパイラでコンパイルできるか、
三種類のコンパイラの警告は役立たないかを確認したい。

###初期化をしない理由
しばしば変数は初期化していません。
初期化したとしても、なるべく0,1ではなく、それ以外の数を代入するようにしています。コンパイラが、どういう警告を出すか、あるいは場合によってはコンパイルエラーにするかなどを確かめるためです。
こういうコードを実際に書いて欲しいという例ではありません。

###実行する理由
実行する意味があまりなさそうなコードを実行しているのは、実行時のエラーを収集する目的です。コンパイル・リンクは通っても、実行時のエラーに何が発生する可能性があるかを収集します。
万が一、実行時にリンクする仕組みや、空間を確保するとしたら、実行しないと振る舞いがわからないことがあります。

初めての　CEDD(Compile Error Driven Design) ８回直してコンパイル。
https://qiita.com/kaizen_nagoya/items/9494236aa1753f3fd1e1

コンパイルエラーを記録するとよい理由7つ
https://qiita.com/kaizen_nagoya/items/85c0e92b206883140e89

##C++N4741, 2018 Standard Working Draft on ISO/IEC 14882 sample code compile list
https://qiita.com/kaizen_nagoya/items/3294c014044550896010

## C++N4606, 2016符号断片編纂一覧(example code compile list)
C++N4606, 2016 Working Draft 2016, ISO/IEC 14882, C++ standard(1) Example code compile list
https://qiita.com/kaizen_nagoya/items/df5d62c35bd6ed1c3d43/

##C++N3242, 2011 sample code compile list on clang++ and g++
https://qiita.com/kaizen_nagoya/items/685b5c1a2c17c1bf1318

## 編纂器(Compiler)
###clang++ --version
clang version 6.0.0 (tags/RELEASE_600/final)
Target: x86_64-apple-darwin17.4.0

###g++-8 --version
g++-8 (Homebrew GCC 8.1.0) 8.1.0
Copyright (C) 2018 Free Software Foundation, Inc.

#(224)17.9.2.1 Deducing template arguments from a function call [temp.deduct.call]p376

C++N4606, 2016(203)14.8.2.1 Deducing template arguments from a function call [temp.deduct.call]p412
https://qiita.com/kaizen_nagoya/items/a5e431cb7850557d8358

C++N3242 have no example code.

##p376.cpp
###算譜(source code)

```c++:p376.cpp
// C++N4741 Committee Draft, Standard for Programming Language C++
// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/n741.pdf
const char* msg= "C++N4741(224)17.9.2.1 Deducing template arguments from a function call [temp.deduct.call]p376.cpp";
// Edited by Dr. Ogawa Kiyoshi. Compile procedure and results record.

#include <iostream>
#include <cstdlib>

using namespace std;

namespace N {
  template<class T> void f(std::initializer_list<T>);
  void h1() {
    f({1,2,3}); // T deduced to int
    f({1,"asdf"}); // error: T deduced to both int and const char*
  }
  template<class T> void g(T);
  void h2() {
    g({1,2,3}); // error: no argument deduced for T
  }
  template<class T, int N> void h(T const(&)[N]);
  void h3() {
    h({1,2,3}); // T deduced to int, N deduced to 3
  }
  template<class T> void j(T const(&)[3]);
  void h4() {
    j({42}); // T deduced to int, array bound not considered
  }
  struct Aggr {
    int i;
    int j;
  };
  template<int N> void k(Aggr const(&)[N]);
  void h5() {
    k({1,2,3}); // error: deduction fails, no conversion from int to Aggr
    k({{1},{2},{3}}); // OK, N deduced to 3
  }
  template<int M, int N> void m(int const(&)[M][N]);
  void h6() {
    m({{1,2},{3,4}}); // M and N both deduced to 2
  }
  template<class T, int N> void n(T const(&)[N], T);
  void h7() {
    n({{1},{2},{3}},Aggr()); // OK, T is Aggr, N is 3
  }
}

namespace M {
  template<class ... Types> void f(Types& ...);
  template<class T1, class ... Types> void g(T1, Types ...);
  template<class T1, class ... Types> void g1(Types ..., T1);
  void h(int x, float& y) {
    const int z = x;
    f(x, y, z); // Types is deduced to int, float, const int
    g(x, y, z); // T1 is deduced to int; Types is deduced to float, int
    g1(x, y, z); // error: Types is not deduced
    g1<int, int, int>(x, y, z); // OK, no deduction occurs
  }
}

namespace P {
  template<class T> int f(const T&);
  int n1 = f(5); // calls f<int>(const int&)
  const int i = 0;
  int n2 = f(i); // calls f<int>(const int&)
  template <class T> int g(volatile T&);
  int n3 = g(i); // calls g<const int>(const volatile int&)
}

namespace Q {
  template <class T> int f(T&& heisenreference);
  template <class T> int g(const T&&);
  void h1() {
    int i;
    int n1 = f(i); // calls f<int&>(int&)
    int n2 = f(0); // calls f<int>(int&&)
    int n3 = g(i); // error: would call g<int>(const int&&), which
  }
// would bind an rvalue reference to an lvalue
  template <class T> struct A {
    template <class U>
    A(T&&, U&&, int*); // #1: T&& is not a forwarding reference.
// U&& is a forwarding reference.
    A(T&&, int*); // #2
  };
  template <class T> A(T&&, int*) -> A<T>; // #3: T&& is a forwarding reference.
  void h2() {
    int i;
    int *ip;
    A a{i, 0, ip}; // error: cannot deduce from #1
    A a0{0, 0, ip}; // uses #1 to deduce A<int> and #1 to initialize
    A a2{i, ip}; // uses #3 to deduce A<int&> and #2 to initialize
  }
}

namespace R {
// Only one function of an overload set matches the call so the function parameter is a deduced context.
  template <class T> int f(T (*p)(T));
  int g(int);
  int g(char);
  int i = f(g); // calls f(int (*)(int))
}

namespace S {
// Ambiguous deduction causes the second function parameter to be a non-deduced context.
  template <class T> int f(T, T (*p)(T));
  int g(int);
  char g(char);
  int i = f(1, g); // calls f(int, int (*)(int))
}

namespace U {
// The overload set contains a template, causing the second function parameter to be a non-deduced context.
  template <class T> int f(T, T (*p)(T));
  char g(char);
  template <class T> T g(T);
  int i = f(1, g); // calls f(int, int (*)(int))
}

namespace V {
  template <class T> struct Z {
    typedef typename T::x xx;
  };
  template <class T> typename Z<T>::xx f(void *, T); // #1
  template <class T> void f(int, T); // #2
  struct A {} a;
  int main() {
    f(1, a); // OK, deduction fails for #1 because there is no conversion from int to void*
  }
}

int main() {

  cout << msg << endl;
  return EXIT_SUCCESS;
}
```
###編纂・実行結果(compile and go)

```shell-session:c1.sh
$ ../c1.sh p376
$ clang++ p376.cpp  -std=c++2a -Wall
p376.cpp:15:1: error: no matching function for call to 'f'
f({1,"asdf"}); // error: T deduced to both int and const char*
^
p376.cpp:12:24: note: candidate template ignored: deduced conflicting types for parameter
      'T' ('int' vs. 'const char *')
template<class T> void f(std::initializer_list<T>);
                       ^
p376.cpp:19:1: error: no matching function for call to 'g'
g({1,2,3}); // error: no argument deduced for T
^
p376.cpp:17:24: note: candidate template ignored: couldn't infer template argument 'T'
template<class T> void g(T);
                       ^
p376.cpp:32:1: error: no matching function for call to 'k'
k({1,2,3}); // error: deduction fails, no conversion from int to Aggr
^
p376.cpp:30:22: note: candidate function [with N = 3] not viable: no known conversion from
      'int' to 'const N::Aggr' for 1st argument
template<int N> void k(Aggr const(&)[N]);
                     ^
p376.cpp:53:1: error: no matching function for call to 'g1'
g1(x, y, z); // error: Types is not deduced
^~
p376.cpp:48:42: note: candidate function not viable: requires 1 argument, but 3 were
      provided
template<class T1, class ... Types> void g1(Types ..., T1);
                                         ^
p376.cpp:74:10: error: no matching function for call to 'g'
int n3 = g(i); // error: would call g<int>(const int&&), which
         ^
p376.cpp:69:24: note: candidate function [with T = int] not viable: no known conversion from
      'int' to 'const int &&' for 1st argument
template <class T> int g(const T&&);
                       ^
p376.cpp:87:3: error: no viable constructor or deduction guide for deduction of template
      arguments of 'A'
A a{i, 0, ip}; // error: cannot deduce from #1
  ^
p376.cpp:79:1: note: candidate function [with T = int, U = int] not viable: no known
      conversion from 'int' to 'int &&' for 1st argument
A(T&&, U&&, int*); // #1: T&& is not a forwarding reference.
^
p376.cpp:77:27: note: candidate function template not viable: requires 1 argument, but 3
      were provided
template <class T> struct A {
                          ^
p376.cpp:81:1: note: candidate function template not viable: requires 2 arguments, but 3
      were provided
A(T&&, int*); // #2
^
p376.cpp:83:20: note: candidate function template not viable: requires 2 arguments, but 3
      were provided
template <class T> A(T&&, int*) -> A<T>; // #3: T&& is a forwarding reference.
                   ^
6 errors generated.
```

#p376a.cpp
コンパイルエラーを想定していた行を///註釈に。
リンクエラーを生成する場合には定義{}を追記。
###算譜(source code)

```c++:p376a.cpp
// C++N4741 Committee Draft, Standard for Programming Language C++
// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/n741.pdf
const char* msg= "C++N4741(224)17.9.2.1 Deducing template arguments from a function call [temp.deduct.call]p376.cpp";
// Edited by Dr. Ogawa Kiyoshi. Compile procedure and results record.

#include <iostream>
#include <cstdlib>

using namespace std;

namespace N {
  template<class T> void f(std::initializer_list<T>) {}; /// add {} for link error
  void h1() {
    f({1,2,3}); // T deduced to int
///f({1,"asdf"}); // error: T deduced to both int and const char*
  }
  template<class T> void g(T);
  void h2() {
///g({1,2,3}); // error: no argument deduced for T
  }
  template<class T, int N> void h(T const(&)[N]) {}; /// add {} for link error
  void h3() {
    h({1,2,3}); // T deduced to int, N deduced to 3
  }
  template<class T> void j(T const(&)[3]) {}; /// add {} for link error
  void h4() {
    j({42}); // T deduced to int, array bound not considered
  }
  struct Aggr {
    int i;
    int j;
  };
  template<int N> void k(Aggr const(&)[N]) {}; /// add {} for link error
  void h5() {
///k({1,2,3}); // error: deduction fails, no conversion from int to Aggr
    k({{1},{2},{3}}); // OK, N deduced to 3
  }
  template<int M, int N> void m(int const(&)[M][N]) {}; /// add {} for link error
  void h6() {
    m({{1,2},{3,4}}); // M and N both deduced to 2
  }
  template<class T, int N> void n(T const(&)[N], T) {}; /// add {} for link error
  void h7() {
    n({{1},{2},{3}},Aggr()); // OK, T is Aggr, N is 3
  }
}

namespace M {
  template<class ... Types> void f(Types& ...) {}; /// add {} for link error
  template<class T1, class ... Types> void g(T1, Types ...) {}; /// add {} for link error
  template<class T1, class ... Types> void g1(Types ..., T1) {}; /// add {} for link error
  void h(int x, float& y) {
    const int z = x;
    f(x, y, z); // Types is deduced to int, float, const int
    g(x, y, z); // T1 is deduced to int; Types is deduced to float, int
///g1(x, y, z); // error: Types is not deduced
    g1<int, int, int>(x, y, z); // OK, no deduction occurs
  }
}

namespace P {
  template<class T> int f(const T&) {}; /// add {} for link error
  int n1 = f(5); // calls f<int>(const int&)
  const int i = 0;
  int n2 = f(i); // calls f<int>(const int&)
  template <class T> int g(volatile T&) {}; /// add {} for link error
  int n3 = g(i); // calls g<const int>(const volatile int&)
}

namespace Q {
  template <class T> int f(T&& heisenreference) {}; /// add {} for link error
  template <class T> int g(const T&&) {}; /// add {} for link error
  void h1() {
    int i;
    int n1 = f(i); // calls f<int&>(int&)
    int n2 = f(0); // calls f<int>(int&&)
///int n3 = g(i); // error: would call g<int>(const int&&), which
  }
// would bind an rvalue reference to an lvalue
  template <class T> struct A {
    template <class U>
    A(T&&, U&&, int*) {}; // #1: T&& is not a forwarding reference./// add {} for link error
// U&& is a forwarding reference.
    A(T&&, int*) {}; // #2 /// add {} for link error
  };
  template <class T> A(T&&, int*) -> A<T>; // #3: T&& is a forwarding reference.
  void h2() {
    int i;
    int *ip;
///A a{i, 0, ip}; // error: cannot deduce from #1
    A a0{0, 0, ip}; // uses #1 to deduce A<int> and #1 to initialize
    A a2{i, ip}; // uses #3 to deduce A<int&> and #2 to initialize
  }
}

namespace R {
// Only one function of an overload set matches the call so the function parameter is a deduced context.
  template <class T> int f(T (*p)(T)) {}; /// add {} for link error
  int g(int) {}; /// add {} for link error
  int g(char);
  int i = f(g); // calls f(int (*)(int))
}

namespace S {
// Ambiguous deduction causes the second function parameter to be a non-deduced context.
  template <class T> int f(T, T (*p)(T)) {}; /// add {} for link error
  int g(int) {}; /// add {} for link error
  char g(char);
  int i = f(1, g); // calls f(int, int (*)(int))
}

namespace U {
// The overload set contains a template, causing the second function parameter to be a non-deduced context.
  template <class T> int f(T, T (*p)(T)) {}; /// add {} for link error
  char g(char);
  template <class T> T g(T) {}; /// add {} for link error
  int i = f(1, g); // calls f(int, int (*)(int))
}

namespace V {
  template <class T> struct Z {
    typedef typename T::x xx;
  };
  template <class T> typename Z<T>::xx f(void *, T); // #1
  template <class T> void f(int, T) {}; // #2/// add {} for link error
  struct A {} a;
  int main() {
    f(1, a); // OK, deduction fails for #1 because there is no conversion from int to void*
  }
}

int main() {

  cout << msg << endl;
  return EXIT_SUCCESS;
}
```

###編纂・実行結果(compile and go)

```shell-session:cpla.sh
$ ../cpla.sh p376a
$ clang++ p376a.cpp -std=c++03 -Wall
p376a.cpp:12:24: warning: variable templates are a C++14 extension [-Wc++14-extensions]
template<class T> void f(std::initializer_list<T>){};/// add {} for link error
                       ^
p376a.cpp:12:24: error: variable has incomplete type 'void'
p376a.cpp:12:31: error: no member named 'initializer_list' in namespace 'std'
template<class T> void f(std::initializer_list<T>){};/// add {} for link error
                         ~~~~~^
p376a.cpp:12:48: error: 'T' does not refer to a value
template<class T> void f(std::initializer_list<T>){};/// add {} for link error
                                               ^
p376a.cpp:12:16: note: declared here
template<class T> void f(std::initializer_list<T>){};/// add {} for link error
               ^
p376a.cpp:12:50: error: expected expression
template<class T> void f(std::initializer_list<T>){};/// add {} for link error
                                                 ^
p376a.cpp:12:51: error: expected ';' at end of declaration
template<class T> void f(std::initializer_list<T>){};/// add {} for link error
                                                  ^
                                                  ;
p376a.cpp:12:51: error: expected unqualified-id
p376a.cpp:14:3: error: expected expression
f({1,2,3}); // T deduced to int
  ^
p376a.cpp:23:3: error: expected expression
h({1,2,3}); // T deduced to int, N deduced to 3
  ^
p376a.cpp:27:3: error: expected expression
j({42}); // T deduced to int, array bound not considered
  ^
p376a.cpp:33:3: error: expected expression
k({{1},{2},{3}}); // OK, N deduced to 3
  ^
p376a.cpp:37:3: error: expected expression
m({{1,2},{3,4}}); // M and N both deduced to 2
  ^
p376a.cpp:41:3: error: expected expression
n({{1},{2},{3}},Aggr()); // OK, T is Aggr, N is 3
  ^
p376a.cpp:46:16: warning: variadic templates are a C++11 extension [-Wc++11-extensions]
template<class ... Types> void f(Types& ...){};/// add {} for link error
               ^
p376a.cpp:47:26: warning: variadic templates are a C++11 extension [-Wc++11-extensions]
template<class T1, class ... Types> void g(T1, Types ...){};/// add {} for link error
                         ^
p376a.cpp:48:26: warning: variadic templates are a C++11 extension [-Wc++11-extensions]
template<class T1, class ... Types> void g1(Types ..., T1){};/// add {} for link error
                         ^
p376a.cpp:68:27: warning: rvalue references are a C++11 extension [-Wc++11-extensions]
template <class T> int f(T&& heisenreference){};/// add {} for link error
                          ^
p376a.cpp:69:33: warning: rvalue references are a C++11 extension [-Wc++11-extensions]
template <class T> int g(const T&&){};/// add {} for link error
                                ^
p376a.cpp:73:5: warning: unused variable 'n2' [-Wunused-variable]
int n2 = f(0); // calls f<int>(int&&)
    ^
p376a.cpp:72:5: warning: unused variable 'n1' [-Wunused-variable]
int n1 = f(i); // calls f<int&>(int&)
    ^
p376a.cpp:79:4: warning: rvalue references are a C++11 extension [-Wc++11-extensions]
A(T&&, U&&, int*){}; // #1: T&& is not a forwarding reference./// add {} for link error
   ^
p376a.cpp:79:9: warning: rvalue references are a C++11 extension [-Wc++11-extensions]
A(T&&, U&&, int*){}; // #1: T&& is not a forwarding reference./// add {} for link error
        ^
p376a.cpp:81:4: warning: rvalue references are a C++11 extension [-Wc++11-extensions]
A(T&&, int*){}; // #2 /// add {} for link error
   ^
p376a.cpp:83:23: warning: rvalue references are a C++11 extension [-Wc++11-extensions]
template <class T> A(T&&, int*) -> A<T>; // #3: T&& is a forwarding reference.
                      ^
p376a.cpp:83:20: error: C++ requires a type specifier for all declarations
template <class T> A(T&&, int*) -> A<T>; // #3: T&& is a forwarding reference.
                   ^
p376a.cpp:83:32: error: expected ';' at end of declaration
template <class T> A(T&&, int*) -> A<T>; // #3: T&& is a forwarding reference.
                               ^
                               ;
p376a.cpp:83:33: error: cannot use arrow operator on a type
template <class T> A(T&&, int*) -> A<T>; // #3: T&& is a forwarding reference.
                                ^
p376a.cpp:88:1: error: use of class template 'A' requires template arguments
A a0{0, 0, ip}; // uses #1 to deduce A<int> and #1 to initialize
^
p376a.cpp:77:27: note: template is declared here
template <class T> struct A {
~~~~~~~~~~~~~~~~~~        ^
p376a.cpp:88:5: error: expected ';' at end of declaration
A a0{0, 0, ip}; // uses #1 to deduce A<int> and #1 to initialize
    ^
    ;
p376a.cpp:89:1: error: use of class template 'A' requires template arguments
A a2{i, ip}; // uses #3 to deduce A<int&> and #2 to initialize
^
p376a.cpp:77:27: note: template is declared here
template <class T> struct A {
~~~~~~~~~~~~~~~~~~        ^
p376a.cpp:89:5: error: expected ';' at end of declaration
A a2{i, ip}; // uses #3 to deduce A<int&> and #2 to initialize
    ^
    ;
12 warnings and 19 errors generated.
$ clang++ p376a.cpp -std=c++2a -Wall
p376a.cpp:72:5: warning: unused variable 'n1' [-Wunused-variable]
int n1 = f(i); // calls f<int&>(int&)
    ^
p376a.cpp:73:5: warning: unused variable 'n2' [-Wunused-variable]
int n2 = f(0); // calls f<int>(int&&)
    ^
p376a.cpp:88:12: warning: variable 'ip' is uninitialized when used here [-Wuninitialized]
A a0{0, 0, ip}; // uses #1 to deduce A<int> and #1 to initialize
           ^~
p376a.cpp:86:8: note: initialize the variable 'ip' to silence this warning
int *ip;
       ^
        = nullptr
p376a.cpp:96:12: warning: control reaches end of non-void function [-Wreturn-type]
int g(int){};/// add {} for link error
           ^
p376a.cpp:104:12: warning: control reaches end of non-void function [-Wreturn-type]
int g(int){};/// add {} for link error
           ^
p376a.cpp:126:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
p376a.cpp:59:35: warning: control reaches end of non-void function [-Wreturn-type]
template<class T> int f(const T&){};/// add {} for link error
                                  ^
p376a.cpp:60:10: note: in instantiation of function template specialization 'P::f<int>'
      requested here
int n1 = f(5); // calls f<int>(const int&)
         ^
p376a.cpp:63:39: warning: control reaches end of non-void function [-Wreturn-type]
template <class T> int g(volatile T&){};/// add {} for link error
                                      ^
p376a.cpp:64:10: note: in instantiation of function template specialization
      'P::g<const int>' requested here
int n3 = g(i); // calls g<const int>(const volatile int&)
         ^
p376a.cpp:68:47: warning: control reaches end of non-void function [-Wreturn-type]
template <class T> int f(T&& heisenreference){};/// add {} for link error
                                              ^
p376a.cpp:72:10: note: in instantiation of function template specialization 'Q::f<int &>'
      requested here
int n1 = f(i); // calls f<int&>(int&)
         ^
p376a.cpp:68:47: warning: control reaches end of non-void function [-Wreturn-type]
template <class T> int f(T&& heisenreference){};/// add {} for link error
                                              ^
p376a.cpp:73:10: note: in instantiation of function template specialization 'Q::f<int>'
      requested here
int n2 = f(0); // calls f<int>(int&&)
         ^
p376a.cpp:95:37: warning: control reaches end of non-void function [-Wreturn-type]
template <class T> int f(T (*p)(T)){};/// add {} for link error
                                    ^
p376a.cpp:98:9: note: in instantiation of function template specialization 'R::f<int>'
      requested here
int i = f(g); // calls f(int (*)(int))
        ^
p376a.cpp:103:40: warning: control reaches end of non-void function [-Wreturn-type]
template <class T> int f(T, T (*p)(T)){};/// add {} for link error
                                       ^
p376a.cpp:106:9: note: in instantiation of function template specialization 'S::f<int>'
      requested here
int i = f(1, g); // calls f(int, int (*)(int))
        ^
p376a.cpp:111:40: warning: control reaches end of non-void function [-Wreturn-type]
template <class T> int f(T, T (*p)(T)){};/// add {} for link error
                                       ^
p376a.cpp:114:9: note: in instantiation of function template specialization 'U::f<int>'
      requested here
int i = f(1, g); // calls f(int, int (*)(int))
        ^
p376a.cpp:113:27: warning: control reaches end of non-void function [-Wreturn-type]
template <class T> T g(T){};/// add {} for link error
                          ^
p376a.cpp:114:14: note: in instantiation of function template specialization 'U::g<int>'
      requested here
int i = f(1, g); // calls f(int, int (*)(int))
             ^
14 warnings generated.
../cpla.sh: line 11: 10913 Illegal instruction: 4  ./$1l2a $2

$ g++-8 p376a.cpp -std=c++03  -Wall
p376a.cpp:12:31: error: variable or field 'f' declared void
 template<class T> void f(std::initializer_list<T>){};/// add {} for link error
                               ^~~~~~~~~~~~~~~~
p376a.cpp:12:31: error: 'initializer_list' is not a member of 'std'
p376a.cpp:12:49: error: expected primary-expression before '>' token
 template<class T> void f(std::initializer_list<T>){};/// add {} for link error
                                                 ^
p376a.cpp:12:50: error: expected primary-expression before ')' token
 template<class T> void f(std::initializer_list<T>){};/// add {} for link error
                                                  ^
p376a.cpp: In function 'void N::h1()':
p376a.cpp:14:3: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11
 f({1,2,3}); // T deduced to int
   ^
p376a.cpp:14:1: error: 'f' was not declared in this scope
 f({1,2,3}); // T deduced to int
 ^
p376a.cpp: In function 'void N::h3()':
p376a.cpp:23:3: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11
 h({1,2,3}); // T deduced to int, N deduced to 3
   ^
p376a.cpp:23:10: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11
 h({1,2,3}); // T deduced to int, N deduced to 3
          ^
p376a.cpp: In function 'void N::h4()':
p376a.cpp:27:3: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11
 j({42}); // T deduced to int, array bound not considered
   ^
p376a.cpp:27:7: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11
 j({42}); // T deduced to int, array bound not considered
       ^
p376a.cpp: In function 'void N::h5()':
p376a.cpp:33:3: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11
 k({{1},{2},{3}}); // OK, N deduced to 3
   ^
p376a.cpp:33:16: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11
 k({{1},{2},{3}}); // OK, N deduced to 3
                ^
p376a.cpp: In function 'void N::h6()':
p376a.cpp:37:3: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11
 m({{1,2},{3,4}}); // M and N both deduced to 2
   ^
p376a.cpp:37:16: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11
 m({{1,2},{3,4}}); // M and N both deduced to 2
                ^
p376a.cpp: In function 'void N::h7()':
p376a.cpp:41:3: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11
 n({{1},{2},{3}},Aggr()); // OK, T is Aggr, N is 3
   ^
p376a.cpp:41:23: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11
 n({{1},{2},{3}},Aggr()); // OK, T is Aggr, N is 3
                       ^
p376a.cpp: At global scope:
p376a.cpp:46:16: warning: variadic templates only available with -std=c++11 or -std=gnu++11
 template<class ... Types> void f(Types& ...){};/// add {} for link error
                ^~~
p376a.cpp:46:41: warning: variadic templates only available with -std=c++11 or -std=gnu++11
 template<class ... Types> void f(Types& ...){};/// add {} for link error
                                         ^~~
p376a.cpp:47:26: warning: variadic templates only available with -std=c++11 or -std=gnu++11
 template<class T1, class ... Types> void g(T1, Types ...){};/// add {} for link error
                          ^~~
p376a.cpp:47:54: warning: variadic templates only available with -std=c++11 or -std=gnu++11
 template<class T1, class ... Types> void g(T1, Types ...){};/// add {} for link error
                                                      ^~~
p376a.cpp:48:26: warning: variadic templates only available with -std=c++11 or -std=gnu++11
 template<class T1, class ... Types> void g1(Types ..., T1){};/// add {} for link error
                          ^~~
p376a.cpp:48:51: warning: variadic templates only available with -std=c++11 or -std=gnu++11
 template<class T1, class ... Types> void g1(Types ..., T1){};/// add {} for link error
                                                   ^~~
p376a.cpp: In function 'int P::f(const T&)':
p376a.cpp:59:35: warning: no return statement in function returning non-void [-Wreturn-type]
 template<class T> int f(const T&){};/// add {} for link error
                                   ^
p376a.cpp: In function 'int P::g(volatile T&)':
p376a.cpp:63:39: warning: no return statement in function returning non-void [-Wreturn-type]
 template <class T> int g(volatile T&){};/// add {} for link error
                                       ^
p376a.cpp: At global scope:
p376a.cpp:68:27: error: expected ',' or '...' before '&&' token
 template <class T> int f(T&& heisenreference){};/// add {} for link error
                           ^~
p376a.cpp: In function 'int Q::f(T)':
p376a.cpp:68:47: warning: no return statement in function returning non-void [-Wreturn-type]
 template <class T> int f(T&& heisenreference){};/// add {} for link error
                                               ^
p376a.cpp: At global scope:
p376a.cpp:69:33: error: expected ',' or '...' before '&&' token
 template <class T> int g(const T&&){};/// add {} for link error
                                 ^~
p376a.cpp: In function 'int Q::g(T)':
p376a.cpp:69:37: warning: no return statement in function returning non-void [-Wreturn-type]
 template <class T> int g(const T&&){};/// add {} for link error
                                     ^
p376a.cpp: In function 'void Q::h1()':
p376a.cpp:72:5: warning: unused variable 'n1' [-Wunused-variable]
 int n1 = f(i); // calls f<int&>(int&)
     ^~
p376a.cpp:73:5: warning: unused variable 'n2' [-Wunused-variable]
 int n2 = f(0); // calls f<int>(int&&)
     ^~
p376a.cpp: At global scope:
p376a.cpp:79:4: error: expected ',' or '...' before '&&' token
 A(T&&, U&&, int*){}; // #1: T&& is not a forwarding reference./// add {} for link error
    ^~
p376a.cpp:81:4: error: expected ',' or '...' before '&&' token
 A(T&&, int*){}; // #2 /// add {} for link error
    ^~
p376a.cpp:83:23: error: expected ',' or '...' before '&&' token
 template <class T> A(T&&, int*) -> A<T>; // #3: T&& is a forwarding reference.
                       ^~
p376a.cpp:83:40: error: expected constructor, destructor, or type conversion before ';' token
 template <class T> A(T&&, int*) -> A<T>; // #3: T&& is a forwarding reference.
                                        ^
p376a.cpp: In function 'void Q::h2()':
p376a.cpp:88:3: error: missing template arguments before 'a0'
 A a0{0, 0, ip}; // uses #1 to deduce A<int> and #1 to initialize
   ^~
p376a.cpp:89:3: error: missing template arguments before 'a2'
 A a2{i, ip}; // uses #3 to deduce A<int&> and #2 to initialize
   ^~
p376a.cpp:85:5: warning: unused variable 'i' [-Wunused-variable]
 int i;
     ^
p376a.cpp:86:6: warning: unused variable 'ip' [-Wunused-variable]
 int *ip;
      ^~
p376a.cpp: In function 'int R::f(T (*)(T))':
p376a.cpp:95:37: warning: no return statement in function returning non-void [-Wreturn-type]
 template <class T> int f(T (*p)(T)){};/// add {} for link error
                                     ^
p376a.cpp: In function 'int R::g(int)':
p376a.cpp:96:12: warning: no return statement in function returning non-void [-Wreturn-type]
 int g(int){};/// add {} for link error
            ^
p376a.cpp: In function 'int S::f(T, T (*)(T))':
p376a.cpp:103:40: warning: no return statement in function returning non-void [-Wreturn-typ]
 template <class T> int f(T, T (*p)(T)){};/// add {} for link error
                                        ^
p376a.cpp: In function 'int S::g(int)':
p376a.cpp:104:12: warning: no return statement in function returning non-void [-Wreturn-typ]
 int g(int){};/// add {} for link error
            ^
p376a.cpp: In function 'int U::f(T, T (*)(T))':
p376a.cpp:111:40: warning: no return statement in function returning non-void [-Wreturn-typ]
 template <class T> int f(T, T (*p)(T)){};/// add {} for link error
                                        ^
p376a.cpp: In function 'int V::main()':
p376a.cpp:126:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^
p376a.cpp: In instantiation of 'T U::g(T) [with T = int]':
p376a.cpp:114:15:   required from here
p376a.cpp:113:27: warning: no return statement in function returning non-void [-Wreturn-typ]
 template <class T> T g(T){};/// add {} for link error
                           ^

$ g++-8 p376a.cpp -std=c++2a  -Wall
p376a.cpp: In function 'int P::f(const T&)':
p376a.cpp:59:35: warning: no return statement in function returning non-void [-Wreturn-type]
 template<class T> int f(const T&){};/// add {} for link error
                                   ^
p376a.cpp: In function 'int P::g(volatile T&)':
p376a.cpp:63:39: warning: no return statement in function returning non-void [-Wreturn-type]
 template <class T> int g(volatile T&){};/// add {} for link error
                                       ^
p376a.cpp: In function 'int Q::f(T&&)':
p376a.cpp:68:47: warning: no return statement in function returning non-void [-Wreturn-type]
 template <class T> int f(T&& heisenreference){};/// add {} for link error
                                               ^
p376a.cpp: In function 'int Q::g(const T&&)':
p376a.cpp:69:37: warning: no return statement in function returning non-void [-Wreturn-type]
 template <class T> int g(const T&&){};/// add {} for link error
                                     ^
p376a.cpp: In function 'void Q::h1()':
p376a.cpp:72:5: warning: unused variable 'n1' [-Wunused-variable]
 int n1 = f(i); // calls f<int&>(int&)
     ^~
p376a.cpp:73:5: warning: unused variable 'n2' [-Wunused-variable]
 int n2 = f(0); // calls f<int>(int&&)
     ^~
p376a.cpp: In function 'int R::f(T (*)(T))':
p376a.cpp:95:37: warning: no return statement in function returning non-void [-Wreturn-type]
 template <class T> int f(T (*p)(T)){};/// add {} for link error
                                     ^
p376a.cpp: In function 'int R::g(int)':
p376a.cpp:96:12: warning: no return statement in function returning non-void [-Wreturn-type]
 int g(int){};/// add {} for link error
            ^
p376a.cpp: In function 'int S::f(T, T (*)(T))':
p376a.cpp:103:40: warning: no return statement in function returning non-void [-Wreturn-typ]
 template <class T> int f(T, T (*p)(T)){};/// add {} for link error
                                        ^
p376a.cpp: In function 'int S::g(int)':
p376a.cpp:104:12: warning: no return statement in function returning non-void [-Wreturn-typ]
 int g(int){};/// add {} for link error
            ^
p376a.cpp: In function 'int U::f(T, T (*)(T))':
p376a.cpp:111:40: warning: no return statement in function returning non-void [-Wreturn-typ]
 template <class T> int f(T, T (*p)(T)){};/// add {} for link error
                                        ^
p376a.cpp: In function 'int V::main()':
p376a.cpp:126:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^
p376a.cpp: In instantiation of 'T U::g(T) [with T = int]':
p376a.cpp:114:15:   required from here
p376a.cpp:113:27: warning: no return statement in function returning non-void [-Wreturn-typ]
 template <class T> T g(T){};/// add {} for link error
                           ^
p376a.cpp: In function 'void Q::h2()':
p376a.cpp:88:14: warning: 'ip' is used uninitialized in this function [-Wuninitialized]
 A a0{0, 0, ip}; // uses #1 to deduce A<int> and #1 to initialize
              ^
C++N4741(224)17.9.2.1 Deducing template arguments from a function call [temp.deduct.call]p376.cpp
```

#検討事項(agenda)
役に立つまたは意味のある警告の取り方
役に立つまたは意味のあるリンクエラーの取り方
役に立つまたは意味のある他の出力

#参考資料(reference)

docker gnu(gcc/g++) and llvm(clang/clang++)
https://qiita.com/drafts/059874ea39c4de64c0f7

[C][C++]の国際規格案の例題をコンパイルするときの課題７つ。
https://qiita.com/kaizen_nagoya/items/5f4b155030259497c4de

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


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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

#文書履歴(document history)
ver. 0.10 初稿 20180603