はじめに
N4606 Working Draft, Standard for Programming Language C++
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/#mailing2016-11
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/n4606.pdf
n4606は、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)との関係も調査中です。
何か、抜け漏れ、耳より情報がありましたらおしらせくださると幸いです。
作業方針
1)コンパイルエラーを収集する。
2)コンパイルエラーをなくす方法を検討する。
コンパイルエラーになる例を示すだけが目的のコードは、コンパイルエラーをなくすのではなく、コンパイルエラーの種類を収集するだけにする。
文法を示すのが目的のコード場合に、コンパイルエラーをなくすのに手間がかかる場合は、順次作業します。
3)リンクエラーをなくす方法を検討する。
文法を示すのが目的のコード場合に、リンクエラーをなくすのに手間がかかる場合は、順次作業します。
4)意味のある出力を作る。
コンパイル、リンクが通っても、意味のある出力を示そうとすると、コンパイル・リンクエラーが出て収拾できそうにない場合がある。順次作業します。
1)だけのものから4)まで進んだものと色々ある状態です。一歩でも前に進むご助言をお待ちしています。「検討事項」の欄に現状を記録するようにしています。
list
N4606 Working Draft 2016, ISO/IEC 14882, C++ standard(1) coding list
https://qiita.com/kaizen_nagoya/items/df5d62c35bd6ed1c3d43/
Compiler
###clang++ --version
clang version 6.0.0 (tags/RELEASE_600/final)
Target: x86_64-apple-darwin17.4.0
###g++-7 --version
g++-7 (Homebrew GCC 7.3.0_1) 7.3.0
Copyright (C) 2017 Free Software Foundation, Inc.
#(206)14.8.2.5 Deducing template arguments from a type [temp.deduct.type]p419
// N4606 Committee Draft, Standard for Programming Language C++
// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/n4606.pdf
#define msg "(206)14.8.2.5 Deducing template arguments from a type [temp.deduct.type]p419.cpp"
// Edited by Dr. Ogawa Kiyoshi. Compile procedure and results record.
#include <iostream>
template<class T> void g(T);
g({1,2,3}); // error: no argument deduced for T
template<class T> void f(T x, T y) { /* ... */ }
struct A { /* ... */ };
struct B : A { /* ... */ };
void g(A a, B b) {
f(a,b); // error: T could be A or B
f(b,a); // error: T could be A or B
f(a,a); // OK: T is A
f(b,b); // OK: T is B
}
template <class T, class U> void f( T (*)( T, U, U ) );
int g1( int, float, float);
char g2( int, float, float);
int g3( int, char, float);
void r() {
f(g1); // OK: T is int and U is float
f(g2); // error: T could be char or int
f(g3); // error: U could be char or float
}
template<class T> void f(const T*) { }
int* p;
void s() {
f(p); // f(const int*)
}
template <class T> struct B { };
template <class T> struct D : public B<T> {};
struct D2 : public B<int> {};
template <class T> void f(B<T>&){}
void t() {
D<int> d;
D2 d2;
f(d); // calls f(B<int>&)
f(d2); // calls f(B<int>&)
}
template<class T1, class... Z> class S; // #1
template<class T1, class... Z> class S<T1, const Z&...> { }; // #2
template<class T1, class T2> class S<T1, const T2&> { }; // #3
S<int, const int&> s; // both #2 and #3 match; #3 is more specialized
template<class T, class... U> struct A { }; // #1
template<class T1, class T2, class... U> struct A<T1, T2*, U...> { }; // #2
template<class T1, class T2> struct A<T1, T2> { }; // #3
template struct A<int, int*>; // selects #2
template <class T> void f(T&&);
template <> void f(int&) { } // #1
template <> void f(int&&) { } // #2
void g(int i) {
f(i); // calls f<int&>(int&), i.e., #1
f(0); // calls f<int>(int&&), i.e., #2
}
template<class T, class... U> void f(T*, U...) { } // #1
template<class T> void f(T) { } // #2
template void f(int*); // selects #1
//X<int> (*)(char[6])
int main() {
std::cout<< msg << std::endl;
return EXIT_SUCCESS;
}
i$ ./cppgl17.sh p419
$ clang++ p419.cpp -std=c++17
p419.cpp:9:1: error: C++ requires a type specifier for all declarations
g({1,2,3}); // error: no argument deduced for T
^
p419.cpp:15:1: error: no matching function for call to 'f'
f(a,b); // error: T could be A or B
^
p419.cpp:11:24: note: candidate template ignored: deduced conflicting types for parameter 'T' ('A' vs. 'B')
template<class T> void f(T x, T y) { /* ... */ }
^
p419.cpp:16:1: error: no matching function for call to 'f'
f(b,a); // error: T could be A or B
^
p419.cpp:11:24: note: candidate template ignored: deduced conflicting types for parameter 'T' ('B' vs. 'A')
template<class T> void f(T x, T y) { /* ... */ }
^
p419.cpp:27:1: error: no matching function for call to 'f'
f(g2); // error: T could be char or int
^
p419.cpp:21:34: note: candidate template ignored: deduced conflicting types for parameter 'T' ('char' vs. 'int')
template <class T, class U> void f( T (*)( T, U, U ) );
^
p419.cpp:11:24: note: candidate function template not viable: requires 2 arguments, but 1 was provided
template<class T> void f(T x, T y) { /* ... */ }
^
p419.cpp:28:1: error: no matching function for call to 'f'
f(g3); // error: U could be char or float
^
p419.cpp:21:34: note: candidate template ignored: deduced conflicting types for parameter 'U' ('char' vs. 'float')
template <class T, class U> void f( T (*)( T, U, U ) );
^
p419.cpp:11:24: note: candidate function template not viable: requires 2 arguments, but 1 was provided
template<class T> void f(T x, T y) { /* ... */ }
^
p419.cpp:44:1: error: use of undeclared identifier 'f3'
f3(d); // calls f3(B3<int>&)
^
p419.cpp:45:1: error: use of undeclared identifier 'f3'
f3(d2); // calls f3(B3<int>&)
^
p419.cpp:56:17: error: ambiguous partial specializations of 'A4<int, int *>'
template struct A4<int, int*>; // selects #2
^
p419.cpp:54:49: note: partial specialization matches [with T1 = int, T2 = int, U = <>]
template<class T1, class T2, class... U> struct A4<T1, T2*, U...> { }; // #2
^
p419.cpp:55:37: note: partial specialization matches [with T1 = int, T2 = int *]
template<class T1, class T2> struct A4<T1, T2> { }; // #3
^
8 errors generated.
$ g++-7 p419.cpp -std=c++17
p419.cpp:9:2: error: expected constructor, destructor, or type conversion before '(' token
g({1,2,3}); // error: no argument deduced for T
^
p419.cpp:9:10: error: expected unqualified-id before ')' token
g({1,2,3}); // error: no argument deduced for T
^
p419.cpp: In function 'void g(A, B)':
p419.cpp:15:6: error: no matching function for call to 'f(A&, B&)'
f(a,b); // error: T could be A or B
^
p419.cpp:11:24: note: candidate: template<class T> void f(T, T)
template<class T> void f(T x, T y) { /* ... */ }
^
p419.cpp:11:24: note: template argument deduction/substitution failed:
p419.cpp:15:6: note: deduced conflicting types for parameter 'T' ('A' and 'B')
f(a,b); // error: T could be A or B
^
p419.cpp:16:6: error: no matching function for call to 'f(B&, A&)'
f(b,a); // error: T could be A or B
^
p419.cpp:11:24: note: candidate: template<class T> void f(T, T)
template<class T> void f(T x, T y) { /* ... */ }
^
p419.cpp:11:24: note: template argument deduction/substitution failed:
p419.cpp:16:6: note: deduced conflicting types for parameter 'T' ('B' and 'A')
f(b,a); // error: T could be A or B
^
p419.cpp: In function 'void r()':
p419.cpp:27:5: error: no matching function for call to 'f(char (&)(int, float, float))'
f(g2); // error: T could be char or int
^
p419.cpp:11:24: note: candidate: template<class T> void f(T, T)
template<class T> void f(T x, T y) { /* ... */ }
^
p419.cpp:11:24: note: template argument deduction/substitution failed:
p419.cpp:27:5: note: candidate expects 2 arguments, 1 provided
f(g2); // error: T could be char or int
^
p419.cpp:21:34: note: candidate: template<class T, class U> void f(T (*)(T, U, U))
template <class T, class U> void f( T (*)( T, U, U ) );
^
p419.cpp:21:34: note: template argument deduction/substitution failed:
p419.cpp:27:5: note: deduced conflicting types for parameter 'T' ('char' and 'int')
f(g2); // error: T could be char or int
^
p419.cpp:28:5: error: no matching function for call to 'f(int (&)(int, char, float))'
f(g3); // error: U could be char or float
^
p419.cpp:11:24: note: candidate: template<class T> void f(T, T)
template<class T> void f(T x, T y) { /* ... */ }
^
p419.cpp:11:24: note: template argument deduction/substitution failed:
p419.cpp:28:5: note: candidate expects 2 arguments, 1 provided
f(g3); // error: U could be char or float
^
p419.cpp:21:34: note: candidate: template<class T, class U> void f(T (*)(T, U, U))
template <class T, class U> void f( T (*)( T, U, U ) );
^
p419.cpp:21:34: note: template argument deduction/substitution failed:
p419.cpp:28:5: note: deduced conflicting types for parameter 'U' ('char' and 'float')
f(g3); // error: U could be char or float
^
p419.cpp: In function 'void t()':
p419.cpp:44:1: error: 'f3' was not declared in this scope
f3(d); // calls f3(B3<int>&)
^~
p419.cpp:44:1: note: suggested alternative: 'f'
f3(d); // calls f3(B3<int>&)
^~
f
p419.cpp: At global scope:
p419.cpp:56:17: error: ambiguous template instantiation for 'struct A4<int, int*>'
template struct A4<int, int*>; // selects #2
^~~~~~~~~~~~~
p419.cpp:54:49: note: candidates are: template<class T1, class T2, class ... U> struct A4<T1, T2*, U ...> [with T1 = int; T2 = int; U = {}]
template<class T1, class T2, class... U> struct A4<T1, T2*, U...> { }; // #2
^~~~~~~~~~~~~~~~~
p419.cpp:55:37: note: template<class T1, class T2> struct A4<T1, T2> [with T1 = int; T2 = int*]
template<class T1, class T2> struct A4<T1, T2> { }; // #3
^~~~~~~~~~
p419.cpp:56:17: error: explicit instantiation of 'struct A4<int, int*>' before definition of template
template struct A4<int, int*>; // selects #2
^~~~~~~~~~~~~
// N4606 Committee Draft, Standard for Programming Language C++
// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/n4606.pdf
#define msg "(206)14.8.2.5 Deducing template arguments from a type [temp.deduct.type]p419-2.cpp"
// Edited by Dr. Ogawa Kiyoshi. Compile procedure and results record.
#include <iostream>
template<long n> struct A { };
template<typename T> struct C;
template<typename T, T n> struct C<A<n>> {
using Q = T;
};
using R = long;
using R = C<A<2>>::Q; // OK; T was deduced to long from the
// template argument value in the type A<2>
template<typename T> struct S;
template<typename T, T n> struct S<int[n]> {
using Q = T;
};
using V = decltype(sizeof 0);
using V = S<int[42]>::Q; // OK; T was deduced to std::size_t from the type int[42]
template<class T, T i> void f(int (&a)[i]);
int v[10];
void g() {
f(v); // OK: T is std::size_t
}
template<int i> void f1(int a[10][i]);
template<int i> void f2(int a[i][20]);
template<int i> void f3(int (&a)[i][20]);
void g() {
int v[10][20];
f1(v); // OK: i deduced to be 20
f1<20>(v); // OK
f2(v); // error: cannot deduce template-argument i
f2<10>(v); // OK
f3(v); // OK: i deduced to be 10
}
template <int i> class A { /* ... */ };
template <int i> void g(A<i+1>);
template <int i> void f(A<i>, A<i+1>);
void k() {
A<1> a1;
A<2> a2;
g(a1); // error: deduction fails for expression i+1
g<0>(a1); // OK
f(a1, a2); // OK
}
int main() {
std::cout<< msg << std::endl;
return EXIT_SUCCESS;
}
$ ./cppgl17.sh p419-2
$ clang++ p419-2.cpp -std=c++17
p419-2.cpp:37:1: error: no matching function for call to 'f2'
f2(v); // error: cannot deduce template-argument i
^~
p419-2.cpp:31:22: note: candidate template ignored: couldn't infer template argument 'i'
template<int i> void f2(int a[i][20]);
^
p419-2.cpp:48:1: error: no matching function for call to 'g4'
g4(a1); // error: deduction fails for expression i+1
^~
p419-2.cpp:43:23: note: candidate template ignored: couldn't infer template argument 'i'
template <int i> void g4(A4<i+1>);
^
2 errors generated.
$ g++-7 p419-2.cpp -std=c++17
p419-2.cpp: In function 'void g3()':
p419-2.cpp:37:5: error: no matching function for call to 'f2(int [10][20])'
f2(v); // error: cannot deduce template-argument i
^
p419-2.cpp:31:22: note: candidate: template<int i> void f2(int (*)[20])
template<int i> void f2(int a[i][20]);
^~
p419-2.cpp:31:22: note: template argument deduction/substitution failed:
p419-2.cpp:37:5: note: couldn't deduce template parameter 'i'
f2(v); // error: cannot deduce template-argument i
^
p419-2.cpp: In function 'void k()':
p419-2.cpp:48:6: error: no matching function for call to 'g4(A4<1>&)'
g4(a1); // error: deduction fails for expression i+1
^
p419-2.cpp:43:23: note: candidate: template<int i> void g4(A4<(i + 1)>)
template <int i> void g4(A4<i+1>);
^~
p419-2.cpp:43:23: note: template argument deduction/substitution failed:
p419-2.cpp:48:6: note: couldn't deduce template parameter 'i'
g4(a1); // error: deduction fails for expression i+1
^
// N4606 Committee Draft, Standard for Programming Language C++
// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/n4606.pdf
#define msg "(206)14.8.2.5 Deducing template arguments from a type [temp.deduct.type]p419-2.cpp"
// Edited by Dr. Ogawa Kiyoshi. Compile procedure and results record.
#include <iostream>
template<int i, typename T>
T deduce(typename A<T>::X x, // T is not deduced here
T t, // but T is deduced here
typename B<i>::Y y); // i is not deduced here
A<int> a;
B<77> b;
int x = deduce<77>(a.xm, 62, b.ym);
// T is deduced to be int, a.xm must be convertible to
// A<int>::X
// i is explicitly specified to be 77, b.ym must be convertible
// to B<77>::Y
template<int i> class A { /* ... */ };
template<short s> void f(A<s>);
void k1() {
A<1> a;
f(a); // error: deduction fails for conversion from int to short
f<1>(a); // OK
}
template<const short cs> class B { };
template<short s> void g(B<s>);
void k2() {
B<1> b;
g(b); // OK: cv-qualifiers are ignored on template parameter types
}
template<class T> void f(void(*)(T,int));
template<class T> void foo(T,int);
void g(int,int);
void g(char,int);
void h(int,int,int);
void h(char,int);
int m() {
f(&g); // error: ambiguous
f(&h); // OK: void h(char,int) is a unique match
f(&foo); // error: type deduction fails because foo is a template
}
template <class T> void f(T = 5, T = 7);
void g() {
f(1); // OK: call f<int>(1,7)
f(); // error: cannot deduce T
f<int>(); // OK: call f<int>(5,7)
}
template <template <class T> class X> struct A { };
template <template <class T> class X> void f(A<X>) { }
template<class T> struct B { };
A<B> ab;
f(ab); // calls f(A<B>)
template<class> struct X { };
template<class R, class ... ArgTypes> struct X<R(int, ArgTypes ...)> { };
template<class ... Types> struct Y { };
template<class T, class ... Types> struct Y<T, Types& ...> { };
template<class ... Types> int f(void (*)(Types ...));
void g(int, float);
X<int> x1; // uses primary template
X<int(int, float, double)> x2; // uses partial specialization; ArgTypes contains float, double
X<int(float, int)> x3; // uses primary template
Y<> y1; // use primary template; Types is empty
Y<int&, float&, double&> y2; // uses partial specialization; T is int&, Types contains float, double
Y<int, float, double> y3; // uses primary template; Types contains int, float, double
int fv = f(g); // OK; Types contains int, float
int main() {
std::cout<< msg << std::endl;
return EXIT_SUCCESS;
}
$ ./cppgl17.sh p419-3
$ clang++ p419-3.cpp -std=c++17
p419-3.cpp:8:19: error: expected a qualified name after 'typename'
T deduce(typename A<T>::X x, // T is not deduced here
^
p419-3.cpp:8:19: error: expected a qualified name after 'typename'
p419-3.cpp:8:20: error: expected ')'
T deduce(typename A<T>::X x, // T is not deduced here
^
p419-3.cpp:8:9: note: to match this '('
T deduce(typename A<T>::X x, // T is not deduced here
^
p419-3.cpp:11:1: error: no template named 'A'
A<int> a;
^
p419-3.cpp:12:1: error: no template named 'B'
B<77> b;
^
p419-3.cpp:22:1: error: no matching function for call to 'f'
f(a); // error: deduction fails for conversion from int to short
^
p419-3.cpp:19:24: note: candidate template ignored: substitution failure : deduced non-type template argument does not have the same type as
the corresponding template parameter ('int' vs 'short')
template<short s> void f(A<s>);
^
p419-3.cpp:39:1: error: no matching function for call to 'f'
f(&g); // error: ambiguous
^
p419-3.cpp:19:24: note: candidate template ignored: couldn't infer template argument 's'
template<short s> void f(A<s>);
^
p419-3.cpp:32:24: note: candidate template ignored: couldn't infer template argument 'T'
template<class T> void f(void(*)(T,int));
^
p419-3.cpp:41:1: error: no matching function for call to 'f'
f(&foo); // error: type deduction fails because foo is a template
^
p419-3.cpp:19:24: note: candidate template ignored: couldn't infer template argument 's'
template<short s> void f(A<s>);
^
p419-3.cpp:32:24: note: candidate template ignored: couldn't infer template argument 'T'
template<class T> void f(void(*)(T,int));
^
p419-3.cpp:47:1: error: no matching function for call to 'f'
f(); // error: cannot deduce T
^
p419-3.cpp:44:25: note: candidate template ignored: couldn't infer template argument 'T'
template <class T> void f(T = 5, T = 7);
^
p419-3.cpp:19:24: note: candidate function template not viable: requires 1 argument, but 0 were provided
template<short s> void f(A<s>);
^
p419-3.cpp:32:24: note: candidate function template not viable: requires 1 argument, but 0 were provided
template<class T> void f(void(*)(T,int));
^
p419-3.cpp:51:36: error: template parameter has a different kind in template redeclaration
template <template <class T> class X> struct A { };
^
p419-3.cpp:18:14: note: previous template declaration is here
template<int i> class A { /* ... */ };
^
p419-3.cpp:52:48: error: template argument for non-type template parameter must be an expression
template <template <class T> class X> void f(A<X>) { }
^
p419-3.cpp:18:14: note: template parameter is declared here
template<int i> class A { /* ... */ };
^
p419-3.cpp:53:16: error: template parameter has a different kind in template redeclaration
template<class T> struct B { };
^
p419-3.cpp:25:22: note: previous template declaration is here
template<const short cs> class B { };
^
p419-3.cpp:54:3: error: template argument for non-type template parameter must be an expression
A<B> ab;
^
p419-3.cpp:18:14: note: template parameter is declared here
template<int i> class A { /* ... */ };
^
p419-3.cpp:55:1: error: unknown type name 'f'
f(ab); // calls f(A<B>)
^
14 errors generated.
$ g++-7 p419-3.cpp -std=c++17
p419-3.cpp:8:19: error: expected nested-name-specifier before 'A'
T deduce(typename A<T>::X x, // T is not deduced here
^
p419-3.cpp:8:19: error: expected '(' before 'A'
p419-3.cpp:9:3: error: expected primary-expression before 't'
T t, // but T is deduced here
^
p419-3.cpp:10:10: error: expected nested-name-specifier before 'B'
typename B<i>::Y y); // i is not deduced here
^
p419-3.cpp:10:10: error: expected '(' before 'B'
p419-3.cpp:11:1: error: 'A' does not name a type
A<int> a;
^
p419-3.cpp:12:1: error: 'B' does not name a type
B<77> b;
^
p419-3.cpp:13:9: error: wrong number of template arguments (1, should be 2)
int x = deduce<77>(a.xm, 62, b.ym);
^~~~~~~~~~
p419-3.cpp:8:19: note: provided for 'template<int i, class T> T deduce<i, T>'
T deduce(typename A<T>::X x, // T is not deduced here
^
p419-3.cpp:13:20: error: 'a' was not declared in this scope
int x = deduce<77>(a.xm, 62, b.ym);
^
p419-3.cpp:13:30: error: 'b' was not declared in this scope
int x = deduce<77>(a.xm, 62, b.ym);
^
p419-3.cpp: In function 'void k1()':
p419-3.cpp:22:4: error: no matching function for call to 'f(A<1>&)'
f(a); // error: deduction fails for conversion from int to short
^
p419-3.cpp:19:24: note: candidate: template<short int s> void f(A<s>)
template<short s> void f(A<s>);
^
p419-3.cpp:19:24: note: template argument deduction/substitution failed:
p419-3.cpp:22:4: note: mismatched types 'short int' and 'int'
f(a); // error: deduction fails for conversion from int to short
^
p419-3.cpp: In function 'int m()':
p419-3.cpp:39:5: error: no matching function for call to 'f(<unresolved overloaded function type>)'
f(&g); // error: ambiguous
^
p419-3.cpp:19:24: note: candidate: template<short int s> void f(A<s>)
template<short s> void f(A<s>);
^
p419-3.cpp:19:24: note: template argument deduction/substitution failed:
p419-3.cpp:39:5: note: mismatched types 'A<s>' and 'void (*)(char, int)'
f(&g); // error: ambiguous
^
p419-3.cpp:39:5: note: mismatched types 'A<s>' and 'void (*)(int, int)'
p419-3.cpp:39:5: note: couldn't deduce template parameter 's'
p419-3.cpp:32:24: note: candidate: template<class T> void f(void (*)(T, int))
template<class T> void f(void(*)(T,int));
^
p419-3.cpp:32:24: note: template argument deduction/substitution failed:
p419-3.cpp:39:5: note: couldn't deduce template parameter 'T'
f(&g); // error: ambiguous
^
p419-3.cpp:41:7: error: no matching function for call to 'f(<unresolved overloaded function type>)'
f(&foo); // error: type deduction fails because foo is a template
^
p419-3.cpp:19:24: note: candidate: template<short int s> void f(A<s>)
template<short s> void f(A<s>);
^
p419-3.cpp:19:24: note: template argument deduction/substitution failed:
p419-3.cpp:41:7: note: couldn't deduce template parameter 's'
f(&foo); // error: type deduction fails because foo is a template
^
p419-3.cpp:32:24: note: candidate: template<class T> void f(void (*)(T, int))
template<class T> void f(void(*)(T,int));
^
p419-3.cpp:32:24: note: template argument deduction/substitution failed:
p419-3.cpp:41:7: note: couldn't deduce template parameter 'T'
f(&foo); // error: type deduction fails because foo is a template
^
p419-3.cpp: In function 'void g()':
p419-3.cpp:47:3: error: no matching function for call to 'f()'
f(); // error: cannot deduce T
^
p419-3.cpp:19:24: note: candidate: template<short int s> void f(A<s>)
template<short s> void f(A<s>);
^
p419-3.cpp:19:24: note: template argument deduction/substitution failed:
p419-3.cpp:47:3: note: candidate expects 1 argument, 0 provided
f(); // error: cannot deduce T
^
p419-3.cpp:32:24: note: candidate: template<class T> void f(void (*)(T, int))
template<class T> void f(void(*)(T,int));
^
p419-3.cpp:32:24: note: template argument deduction/substitution failed:
p419-3.cpp:47:3: note: candidate expects 1 argument, 0 provided
f(); // error: cannot deduce T
^
p419-3.cpp:44:25: note: candidate: template<class T> void f(T, T)
template <class T> void f(T = 5, T = 7);
^
p419-3.cpp:44:25: note: template argument deduction/substitution failed:
p419-3.cpp:47:3: note: couldn't deduce template parameter 'T'
f(); // error: cannot deduce T
^
p419-3.cpp: At global scope:
p419-3.cpp:18:14: error: template parameter 'int i'
template<int i> class A { /* ... */ };
^
p419-3.cpp:51:46: error: redeclared here as 'template<class T> class X'
template <template <class T> class X> struct A { };
^
p419-3.cpp:52:49: error: type/value mismatch at argument 1 in template parameter list for 'template<int i> class A'
template <template <class T> class X> void f(A<X>) { }
^
p419-3.cpp:52:49: note: expected a constant of type 'int', got 'X'
p419-3.cpp:25:22: error: template parameter 'short int cs'
template<const short cs> class B { };
^~
p419-3.cpp:53:26: error: redeclared here as 'class T'
template<class T> struct B { };
^
p419-3.cpp:54:4: error: type/value mismatch at argument 1 in template parameter list for 'template<int i> class A'
A<B> ab;
^
p419-3.cpp:54:4: note: expected a constant of type 'int', got 'B'
p419-3.cpp:55:2: error: expected constructor, destructor, or type conversion before '(' token
f(ab); // calls f(A<B>)
^
タブを2つの空白に変換しているスクリプトは下記。
#!/bin/bash
astyle -s2 -c < $1.cpp > $1s2.cpp
cat $1s2.cpp
#検討事項
コンパイルエラーをなくす修正方法
役に立つまたは意味のある出力
参考資料
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
Qiitaに投稿するCのStyle例(暫定)
https://qiita.com/kaizen_nagoya/items/946df1528a6a1ef2bc0d
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
文書履歴
ver. 0.01 初稿 2080422
ver. 0.02 URL追記 20230210
最後までおよみいただきありがとうございました。
いいね 💚、フォローをお願いします。
Thank you very much for reading to the last sentence.
Please press the like icon 💚 and follow me for your happy life.