0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

9.3.4.6 Functions [dcl.fct] C++N4910:2022 (100) p194.cpp

Posted at

はじめに(Introduction)

N4910 Working Draft, Standard for Programming Language C++

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

<この項は書きかけです。順次追記します。>

背景(back ground)

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

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

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

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

作業方針(sequence)

Clang++では-std=c++03, C++2bの2種類
g++では-std=c++03, c++2bの2種類
でコンパイルし、

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

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

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

C++N4741, 2018 Standard Working Draft on ISO/IEC 14882 sample code compile list

C++N4606, 2016符号断片編纂一覧(example code compile list)

C++N4606, 2016 Working Draft 2016, ISO/IEC 14882, C++ standard(1) Example code compile list
https://qiita.com/kaizen_nagoya/items/df5d62c35bd6ed1c3d43/

C++N3242, 2011 sample code compile list on clang++ and g++

編纂器(Compiler)

clang++ --version

Debian clang version 14.0.5-++20220610033153+c12386ae247c-1~exp1~20220610153237.151
Target: x86_64-pc-linux-gnu, Thread model: posix, InstalledDir: /usr/bin

g++- --version

g++ (GCC) 12.1.0 Copyright (C) 2022 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

9.3.4.6 Functions [dcl.fct] C++N4910:2022 (100) p194.cpp

算譜(source code)

p194.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 * msg="9.3.4.6 Functions [dcl.fct] C++N4910:2022 (100) p194.cpp";
// Debian clang version 14.0.5-++20220610033153+c12386ae247c-
// g++ (GCC) 12.1.0 Copyright (C) 2022 Free Software Foundation, Inc.
// Edited by Dr. Ogawa Kiyoshi. Compile procedure and results record.
// C++N4910:2022 Standard Working Draft on ISO/IEC 14882(0) sample code compile list
// https://qiita.com/kaizen_nagoya/items/fc957ddddd402004bb91

#include <iostream>
#include <cstdio>
#include <cstdlib> 
#include <cstring>
#include <cassert>
#include <coroutine>

using namespace std;

// Example 1  The declaration
int printf(const char*, ...);
// declares a function that can be called with varying numbers and types of arguments.
void f(){
printf("hello world");
printf("a=%d b=%d", a, b);
}
// However, the first argument must be of a type that can be converted to a const char*.
// [Example 2 :
void f2(char*); // #1
void f2(char[]) {} // defines #1
void f2(const char*) {} // OK, another overload
void f2(cchar *const) {} // error: redefines #1
void g(char(*)[2]); // #2
void g(char[3][2]) {} // defines #2
void g(char[3][3]) {} // OK, another overload
void h(int x(const int)); // #3
void h(int (*)(int)) {} // defines #3
// [Example 3 :
struct C {
void f3(this C& self);
template <typename Self> void g3(this Self&& self, int);
void h3(this C) const; // error: const not allowed here
};
void test(C c) {
c.f3(); // OK, calls C::f
c.g3(42); // OK, calls C::g<C&>
std::move(c).g3(42); // OK, calls C::g<C>
}
// [Example 4 :
typedef int FIC(int) const;
FIC f4; // error: does not declare a member function
struct S {
FIC f4; // OK
};
FIC S::*pm = &S::f4; // OK
// [Example 5 :
typedef void F();
struct S {
const F f5; // OK, equivalent to: void f();
};
// [Example 6 : The declaration
int fseek(FILE*, long, int);
// declares a function taking three arguments of the specified types, and returning int (9.2.9). 
// [Example 7 :
typedef void F();
F fv; // OK, equivalent to void fv();
F fv { } // error
void fv() { } // OK, definition of fv
// [Example 8 : The declaration
int i,
*pi,
f8(),
*fpi(int),
(*pif)(const char*, const char*),
(*fpif(int))(int);
// declares an integer i, a pointer pi to an integer, a function f taking no arguments and returning an integer, a function fpi taking an integer argument and returning a pointer to an integer, a pointer pif to a function which takes two pointers to constant characters and returns an integer, a function fpif taking an integer argument and returning a pointer to a function that takes an integer argument and returns an integer. It is especially useful to compare fpi and pif. The binding of *fpi(int) is *(fpi(int)), so the declaration suggests, and the same construction in an expression requires, the calling of a function fpi, and then using indirection through the (pointer) result to yield an integer. In the declarator (*pif)(const char*, const char*), the extra parentheses are necessary to indicate that indirection through a pointer to a function yields a function, which is then called. — end example]
// [Note 10 : Typedefs and trailing-return-types are sometimes convenient when the return type of a function is complex.For example, the function fpif above can be declared
typedef int IFUNC(int);
IFUNC* fpif(int);
// or
auto fpif(int)->int(*)(int);
// A trailing-return-type is most useful for a type that would be more  complicated to specify before the declarator-id:
template <class T, class U> auto add(T t, U u) -> decltype(t + u);
// rather than
template <class T, class U> decltype((*(T*)0) + (*(U*)0)) add(T t, U u);
// [Example 9 :
template<typename T> concept C1 = / ... /;
template<typename T> concept C2 = / ... /;
template<typename... Ts> concept C3 = / ... /;
void g1(const C1 auto*, C2 auto&);
void g2(C1 auto&...);
void g3(C3 auto...);
void g4(C3 auto);
// The declarations above are functionally equivalent (but not equivalent) to their respective declarations below:
template<C1 T, C2 U> void g1(const T*, U&);
template<C1... Ts> void g2(Ts&...);
template<C3... Ts> void g3(Ts...);
template<C3 T> void g4(T);
// Abbreviated function templates can be specialized like all function templates.
template<> void g1<int>(const int*, const double&); // OK, specialization of g1<int, const double>
// [Example 10 :
template<typename> concept C = / ... /;
template <typename T, C U>
void ga(T x, U y, C auto z);
// This is functionally equivalent to each of the following two declarations.
template<typename T, C U, C W>
void ga(T x, U y, W z);
template<typename T, typename U, typename W>
requires C<U> && C<W>
void ga(T x, U y, W z);
// [Example 11 :
template<typename... T> void f(T (* ...t)(int, int));
int add(int, int);
float subtract(int, int);
void gb() {
f(add, subtract);
}
int main(){
  cout  <<  msg << endl;
  return EXIT_SUCCESS;
}

Script

clgc.sh
#!/bin/sh
rm $1l
rm $1g
echo "$ clang++ $1.cpp -std=03 -o $1l -I. -Wall" 
clang++ $1.cpp -std=c++03 -o $1l -I. -Wall
if [  -e $1l ]; then
./$1l 
fi
rm $1l
echo "$ clang++ $1.cpp -std=2b -o $1l -I. -Wall"
clang++ $1.cpp -std=c++2b -o $1l -I. -Wall
if [  -e $1l ]; then
./$1l
fi
echo "\r"
echo "$ g++ $1.cpp -std=03 -o $1g -I. -Wall"
g++ $1.cpp -std=c++03 -o $1g -I. -Wall
if [ -e $1g ]; then
./$1g
fi
rm $1g
echo "\r"
echo "$ g++ $1.cpp -std=2b -o $1g -I. -Wall"
g++ $1.cpp -std=c++2b -o $1g -I. -Wall
if [ -e $1g ]; then
./$1g 
fi

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

bash
# ./clgc.sh  p194
rm: cannot remove 'p194l': No such file or directory
rm: cannot remove 'p194g': No such file or directory
$ clang++ p194.cpp -std=03 -o p194l -I. -Wall
p194.cpp:24:21: error: use of undeclared identifier 'a'
printf("a=%d b=%d", a, b);
                    ^
p194.cpp:24:24: error: use of undeclared identifier 'b'
printf("a=%d b=%d", a, b);
                       ^
p194.cpp:31:9: error: use of undeclared identifier 'cchar'; did you mean 'char'?
void f2(cchar *const) {} // error: redefines #1
        ^~~~~
        char
p194.cpp:31:6: error: redefinition of 'f2'
void f2(cchar *const) {} // error: redefines #1
     ^
p194.cpp:29:6: note: previous definition is here
void f2(char[]) {} // defines #1
     ^
p194.cpp:39:9: error: expected parameter declarator
void f3(this C& self);
        ^
p194.cpp:39:9: error: expected ')'
p194.cpp:39:8: note: to match this '('
void f3(this C& self);
       ^
p194.cpp:40:34: error: expected parameter declarator
template <typename Self> void g3(this Self&& self, int);
                                 ^
p194.cpp:40:34: error: expected ')'
p194.cpp:40:33: note: to match this '('
template <typename Self> void g3(this Self&& self, int);
                                ^
p194.cpp:41:9: error: expected parameter declarator
void h3(this C) const; // error: const not allowed here
        ^
p194.cpp:41:9: error: expected ')'
p194.cpp:41:8: note: to match this '('
void h3(this C) const; // error: const not allowed here
       ^
p194.cpp:45:3: error: no matching member function for call to 'g3'
c.g3(42); // OK, calls C::g<C&>
~~^~
p194.cpp:40:31: note: candidate function template not viable: requires 0 arguments, but 1 was provided
template <typename Self> void g3(this Self&& self, int);
                              ^
p194.cpp:46:6: error: no member named 'move' in namespace 'std'
std::move(c).g3(42); // OK, calls C::g<C>
~~~~~^
p194.cpp:50:1: error: non-member function of type 'FIC' (aka 'int (int) const') cannot have 'const' qualifier
FIC f4; // error: does not declare a member function
^
p194.cpp:57:8: error: redefinition of 'S'
struct S {
       ^
p194.cpp:51:8: note: previous definition is here
struct S {
       ^
p194.cpp:66:5: error: expected ';' after top level declarator
F fv { } // error
    ^
    ;
p194.cpp:80:1: warning: 'auto' type specifier is a C++11 extension [-Wc++11-extensions]
auto fpif(int)->int(*)(int);
^
p194.cpp:80:15: error: expected function body after function declarator
auto fpif(int)->int(*)(int);
              ^
p194.cpp:82:29: warning: 'auto' type specifier is a C++11 extension [-Wc++11-extensions]
template <class T, class U> auto add(T t, U u) -> decltype(t + u);
                            ^
p194.cpp:82:29: error: 'auto' not allowed in function return type
template <class T, class U> auto add(T t, U u) -> decltype(t + u);
                            ^~~~
p194.cpp:82:47: error: expected ';' at end of declaration
template <class T, class U> auto add(T t, U u) -> decltype(t + u);
                                              ^
                                              ;
p194.cpp:82:48: error: cannot use arrow operator on a type
template <class T, class U> auto add(T t, U u) -> decltype(t + u);
                                               ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
2 warnings and 20 errors generated.
rm: cannot remove 'p194l': No such file or directory
$ clang++ p194.cpp -std=2b -o p194l -I. -Wall
p194.cpp:24:21: error: use of undeclared identifier 'a'
printf("a=%d b=%d", a, b);
                    ^
p194.cpp:24:24: error: use of undeclared identifier 'b'
printf("a=%d b=%d", a, b);
                       ^
p194.cpp:31:9: error: use of undeclared identifier 'cchar'; did you mean 'char'?
void f2(cchar *const) {} // error: redefines #1
        ^~~~~
        char
p194.cpp:31:6: error: redefinition of 'f2'
void f2(cchar *const) {} // error: redefines #1
     ^
p194.cpp:29:6: note: previous definition is here
void f2(char[]) {} // defines #1
     ^
p194.cpp:39:9: error: expected parameter declarator
void f3(this C& self);
        ^
p194.cpp:39:9: error: expected ')'
p194.cpp:39:8: note: to match this '('
void f3(this C& self);
       ^
p194.cpp:40:34: error: expected parameter declarator
template <typename Self> void g3(this Self&& self, int);
                                 ^
p194.cpp:40:34: error: expected ')'
p194.cpp:40:33: note: to match this '('
template <typename Self> void g3(this Self&& self, int);
                                ^
p194.cpp:41:9: error: expected parameter declarator
void h3(this C) const; // error: const not allowed here
        ^
p194.cpp:41:9: error: expected ')'
p194.cpp:41:8: note: to match this '('
void h3(this C) const; // error: const not allowed here
       ^
p194.cpp:45:3: error: no matching member function for call to 'g3'
c.g3(42); // OK, calls C::g<C&>
~~^~
p194.cpp:40:31: note: candidate function template not viable: requires 0 arguments, but 1 was provided
template <typename Self> void g3(this Self&& self, int);
                              ^
p194.cpp:46:14: error: no matching member function for call to 'g3'
std::move(c).g3(42); // OK, calls C::g<C>
~~~~~~~~~~~~~^~
p194.cpp:40:31: note: candidate function template not viable: requires 0 arguments, but 1 was provided
template <typename Self> void g3(this Self&& self, int);
                              ^
p194.cpp:50:1: error: non-member function of type 'FIC' (aka 'int (int) const') cannot have 'const' qualifier
FIC f4; // error: does not declare a member function
^
p194.cpp:57:8: error: redefinition of 'S'
struct S {
       ^
p194.cpp:51:8: note: previous definition is here
struct S {
       ^
p194.cpp:66:3: error: illegal initializer (only variables can be initialized)
F fv { } // error
  ^
p194.cpp:66:9: error: expected ';' after top level declarator
F fv { } // error
        ^
        ;
p194.cpp:86:35: error: expected expression
template<typename T> concept C1 = /∗ ... ∗/;
                                  ^
p194.cpp:86:36: error: unexpected character <U+2217>
template<typename T> concept C1 = /∗ ... ∗/;
                                   ^
p194.cpp:86:44: error: unexpected character <U+2217>
template<typename T> concept C1 = /∗ ... ∗/;
                                         ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.

$ g++ p194.cpp -std=03 -o p194g -I. -Wall
p194.cpp:82:51: warning: identifier 'decltype' is a keyword in C++11 [-Wc++11-compat]
   82 | template <class T, class U> auto add(T t, U u) -> decltype(t + u);
      |                                                   ^~~~~~~~
p194.cpp:86:36: error: extended character ∗ is not valid in an identifier
   86 | template<typename T> concept C1 = /∗ ... ∗/;
      |                                    ^
p194.cpp:86:42: error: extended character ∗ is not valid in an identifier
   86 | template<typename T> concept C1 = /∗ ... ∗/;
      |                                          ^
p194.cpp:87:36: error: extended character ∗ is not valid in an identifier
   87 | template<typename T> concept C2 = /∗ ... ∗/;
      |                                    ^
p194.cpp:87:42: error: extended character ∗ is not valid in an identifier
   87 | template<typename T> concept C2 = /∗ ... ∗/;
      |                                          ^
p194.cpp:88:40: error: extended character ∗ is not valid in an identifier
   88 | template<typename... Ts> concept C3 = /∗ ... ∗/;
      |                                        ^
p194.cpp:88:46: error: extended character ∗ is not valid in an identifier
   88 | template<typename... Ts> concept C3 = /∗ ... ∗/;
      |                                              ^
p194.cpp:101:33: error: extended character ∗ is not valid in an identifier
  101 | template<typename> concept C = /∗ ... ∗/;
      |                                 ^
p194.cpp:101:39: error: extended character ∗ is not valid in an identifier
  101 | template<typename> concept C = /∗ ... ∗/;
      |                                       ^
p194.cpp: In function 'void f()':
p194.cpp:24:21: error: 'a' was not declared in this scope
   24 | printf("a=%d b=%d", a, b);
      |                     ^
p194.cpp:24:24: error: 'b' was not declared in this scope
   24 | printf("a=%d b=%d", a, b);
      |                        ^
p194.cpp: At global scope:
p194.cpp:31:6: error: variable or field 'f2' declared void
   31 | void f2(cchar *const) {} // error: redefines #1
      |      ^~
p194.cpp:31:9: error: 'cchar' was not declared in this scope; did you mean 'char'?
   31 | void f2(cchar *const) {} // error: redefines #1
      |         ^~~~~
      |         char
p194.cpp:31:16: error: expected primary-expression before 'const'
   31 | void f2(cchar *const) {} // error: redefines #1
      |                ^~~~~
p194.cpp:39:9: error: expected identifier before 'this'
   39 | void f3(this C& self);
      |         ^~~~
p194.cpp:39:9: error: expected ',' or '...' before 'this'
p194.cpp:40:34: error: expected identifier before 'this'
   40 | template <typename Self> void g3(this Self&& self, int);
      |                                  ^~~~
p194.cpp:40:34: error: expected ',' or '...' before 'this'
p194.cpp:41:9: error: expected identifier before 'this'
   41 | void h3(this C) const; // error: const not allowed here
      |         ^~~~
p194.cpp:41:9: error: expected ',' or '...' before 'this'
p194.cpp: In function 'void test(C)':
p194.cpp:44:5: error: no matching function for call to 'C::f3()'
   44 | c.f3(); // OK, calls C::f
      | ~~~~^~
p194.cpp:39:6: note: candidate: 'void C::f3(int)'
   39 | void f3(this C& self);
      |      ^~
p194.cpp:39:6: note:   candidate expects 1 argument, 0 provided
p194.cpp:45:5: error: no matching function for call to 'C::g3(int)'
   45 | c.g3(42); // OK, calls C::g<C&>
      | ~~~~^~~~
p194.cpp:40:31: note: candidate: 'template<class Self> void C::g3(int)'
   40 | template <typename Self> void g3(this Self&& self, int);
      |                               ^~
p194.cpp:40:31: note:   template argument deduction/substitution failed:
p194.cpp:45:5: note:   couldn't deduce template parameter 'Self'
   45 | c.g3(42); // OK, calls C::g<C&>
      | ~~~~^~~~
p194.cpp:46:6: error: 'move' is not a member of 'std'
   46 | std::move(c).g3(42); // OK, calls C::g<C>
      |      ^~~~
p194.cpp:46:6: note: 'std::move' is only available from C++11 onwards
p194.cpp: At global scope:
p194.cpp:50:5: error: non-member function 'int f4(int)' cannot have cv-qualifier
   50 | FIC f4; // error: does not declare a member function
      |     ^~
p194.cpp:57:8: error: redefinition of 'struct S'
   57 | struct S {
      |        ^
p194.cpp:51:8: note: previous definition of 'struct S'
   51 | struct S {
      |        ^
p194.cpp:66:6: warning: extended initializer lists only available with '-std=c++11' or '-std=gnu++11' [-Wc++11-extensions]
   66 | F fv { } // error
      |      ^
p194.cpp:66:3: error: function 'void fv()' is initialized like a variable
   66 | F fv { } // error
      |   ^~
p194.cpp:67:1: error: expected ',' or ';' before 'void'
   67 | void fv() { } // OK, definition of fv
      | ^~~~
p194.cpp:80:1: warning: 'auto' changes meaning in C++11; please remove it [-Wc++11-compat]
   80 | auto fpif(int)->int(*)(int);
      | ^~~~
      | ----
p194.cpp:80:6: error: ISO C++ forbids declaration of 'fpif' with no type [-fpermissive]
   80 | auto fpif(int)->int(*)(int);
      |      ^~~~
p194.cpp:80:1: error: top-level declaration of 'fpif' specifies 'auto'
   80 | auto fpif(int)->int(*)(int);
      | ^~~~
p194.cpp:80:27: error: trailing return type only available with '-std=c++11' or '-std=gnu++11'
   80 | auto fpif(int)->int(*)(int);
      |                           ^
p194.cpp:82:29: warning: 'auto' changes meaning in C++11; please remove it [-Wc++11-compat]
   82 | template <class T, class U> auto add(T t, U u) -> decltype(t + u);
      |                             ^~~~
      |                             ----
p194.cpp:82:51: error: expected type-specifier before 'decltype'
   82 | template <class T, class U> auto add(T t, U u) -> decltype(t + u);
      |                                                   ^~~~~~~~
p194.cpp:82:51: error: expected initializer before 'decltype'
p194.cpp:84:37: error: expected constructor, destructor, or type conversion before '(' token
   84 | template <class T, class U> decltype((*(T*)0) + (*(U*)0)) add(T t, U u);
      |                                     ^
p194.cpp:86:22: error: 'concept' does not name a type; did you mean 'const'?
   86 | template<typename T> concept C1 = /∗ ... ∗/;
      |                      ^~~~~~~
      |                      const
p194.cpp:86:22: note: 'concept' only available with '-std=c++20' or '-fconcepts'
p194.cpp:87:22: error: 'concept' does not name a type; did you mean 'const'?
   87 | template<typename T> concept C2 = /∗ ... ∗/;
      |                      ^~~~~~~
      |                      const
p194.cpp:87:22: note: 'concept' only available with '-std=c++20' or '-fconcepts'
p194.cpp:88:18: warning: variadic templates only available with '-std=c++11' or '-std=gnu++11' [-Wc++11-extensions]
   88 | template<typename... Ts> concept C3 = /∗ ... ∗/;
      |                  ^~~
p194.cpp:88:26: error: 'concept' does not name a type; did you mean 'const'?
   88 | template<typename... Ts> concept C3 = /∗ ... ∗/;
      |                          ^~~~~~~
      |                          const
p194.cpp:88:26: note: 'concept' only available with '-std=c++20' or '-fconcepts'
p194.cpp:89:15: error: 'C1' does not name a type; did you mean 'C'?
   89 | void g1(const C1 auto*, C2 auto&);
      |               ^~
      |               C
p194.cpp:89:18: error: expected ',' or '...' before 'auto'
   89 | void g1(const C1 auto*, C2 auto&);
      |                  ^~~~
p194.cpp:90:12: warning: 'auto' changes meaning in C++11; please remove it [-Wc++11-compat]
   90 | void g2(C1 auto&...);
      |            ^~~~
      |            ----
p194.cpp:90:6: error: variable or field 'g2' declared void
   90 | void g2(C1 auto&...);
      |      ^~
p194.cpp:90:9: error: 'C1' was not declared in this scope; did you mean 'g1'?
   90 | void g2(C1 auto&...);
      |         ^~
      |         g1
p194.cpp:91:12: warning: 'auto' changes meaning in C++11; please remove it [-Wc++11-compat]
   91 | void g3(C3 auto...);
      |            ^~~~
      |            ----
p194.cpp:91:6: error: variable or field 'g3' declared void
   91 | void g3(C3 auto...);
      |      ^~
p194.cpp:91:9: error: 'C3' was not declared in this scope; did you mean 'C'?
   91 | void g3(C3 auto...);
      |         ^~
      |         C
p194.cpp:92:12: warning: 'auto' changes meaning in C++11; please remove it [-Wc++11-compat]
   92 | void g4(C3 auto);
      |            ^~~~
      |            ----
p194.cpp:92:6: error: variable or field 'g4' declared void
   92 | void g4(C3 auto);
      |      ^~
p194.cpp:92:9: error: 'C3' was not declared in this scope; did you mean 'C'?
   92 | void g4(C3 auto);
      |         ^~
      |         C
p194.cpp:94:10: error: 'C1' has not been declared
   94 | template<C1 T, C2 U> void g1(const T*, U&);
      |          ^~
p194.cpp:94:16: error: 'C2' has not been declared
   94 | template<C1 T, C2 U> void g1(const T*, U&);
      |                ^~
p194.cpp:94:36: error: 'T' does not name a type
   94 | template<C1 T, C2 U> void g1(const T*, U&);
      |                                    ^
p194.cpp:94:40: error: 'U' has not been declared
   94 | template<C1 T, C2 U> void g1(const T*, U&);
      |                                        ^
p194.cpp:94:42: error: default template arguments may not be used in function templates without '-std=c++11' or '-std=gnu++11'
   94 | template<C1 T, C2 U> void g1(const T*, U&);
      |                                          ^
p194.cpp:95:10: error: 'C1' has not been declared
   95 | template<C1... Ts> void g2(Ts&...);
      |          ^~
p194.cpp:95:16: warning: variadic templates only available with '-std=c++11' or '-std=gnu++11' [-Wc++11-extensions]
   95 | template<C1... Ts> void g2(Ts&...);
      |                ^~
p194.cpp:95:25: error: variable or field 'g2' declared void
   95 | template<C1... Ts> void g2(Ts&...);
      |                         ^~
p194.cpp:95:28: error: 'Ts' was not declared in this scope
   95 | template<C1... Ts> void g2(Ts&...);
      |                            ^~
p194.cpp:96:10: error: 'C3' has not been declared
   96 | template<C3... Ts> void g3(Ts...);
      |          ^~
p194.cpp:96:16: warning: variadic templates only available with '-std=c++11' or '-std=gnu++11' [-Wc++11-extensions]
   96 | template<C3... Ts> void g3(Ts...);
      |                ^~
p194.cpp:96:25: error: variable or field 'g3' declared void
   96 | template<C3... Ts> void g3(Ts...);
      |                         ^~
p194.cpp:96:28: error: 'Ts' was not declared in this scope
   96 | template<C3... Ts> void g3(Ts...);
      |                            ^~
p194.cpp:97:10: error: 'C3' has not been declared
   97 | template<C3 T> void g4(T);
      |          ^~
p194.cpp:97:21: error: variable or field 'g4' declared void
   97 | template<C3 T> void g4(T);
      |                     ^~
p194.cpp:97:24: error: 'T' was not declared in this scope
   97 | template<C3 T> void g4(T);
      |                        ^
p194.cpp:99:17: error: template-id 'g1<int>' for 'void g1(const int*, const double&)' does not match any template declaration
   99 | template<> void g1<int>(const int*, const double&); // OK, specialization of g1<int, const double>
      |                 ^~~~~~~
p194.cpp:94:27: note: candidates are: 'template<<declaration error>, <declaration error> > void g1(const int*, int&)'
   94 | template<C1 T, C2 U> void g1(const T*, U&);
      |                           ^~
p194.cpp:89:6: note:                 'void g1(int)'
   89 | void g1(const C1 auto*, C2 auto&);
      |      ^~
p194.cpp:101:20: error: 'concept' does not name a type; did you mean 'const'?
  101 | template<typename> concept C = /∗ ... ∗/;
      |                    ^~~~~~~
      |                    const
p194.cpp:101:20: note: 'concept' only available with '-std=c++20' or '-fconcepts'
p194.cpp:102:25: error: non-type template parameters of class type only available with '-std=c++20' or '-std=gnu++20'
  102 | template <typename T, C U>
      |                         ^
p194.cpp:103:14: error: 'U' is not a type
  103 | void ga(T x, U y, C auto z);
      |              ^
p194.cpp:103:21: warning: 'auto' changes meaning in C++11; please remove it [-Wc++11-compat]
  103 | void ga(T x, U y, C auto z);
      |                     ^~~~
      |                     ----
p194.cpp:105:24: error: non-type template parameters of class type only available with '-std=c++20' or '-std=gnu++20'
  105 | template<typename T, C U, C W>
      |                        ^
p194.cpp:105:29: error: non-type template parameters of class type only available with '-std=c++20' or '-std=gnu++20'
  105 | template<typename T, C U, C W>
      |                             ^
p194.cpp:106:14: error: 'U' is not a type
  106 | void ga(T x, U y, W z);
      |              ^
p194.cpp:106:19: error: 'W' is not a type
  106 | void ga(T x, U y, W z);
      |                   ^
p194.cpp:108:1: error: 'requires' does not name a type
  108 | requires C<U> && C<W>
      | ^~~~~~~~
p194.cpp:108:1: note: 'requires' only available with '-std=c++20' or '-fconcepts'
p194.cpp:111:18: warning: variadic templates only available with '-std=c++11' or '-std=gnu++11' [-Wc++11-extensions]
  111 | template<typename... T> void f(T (* ...t)(int, int));
      |                  ^~~
p194.cpp:111:40: warning: variadic templates only available with '-std=c++11' or '-std=gnu++11' [-Wc++11-extensions]
  111 | template<typename... T> void f(T (* ...t)(int, int));
      |                                        ^
rm: cannot remove 'p194g': No such file or directory

$ g++ p194.cpp -std=2b -o p194g -I. -Wall
p194.cpp:86:36: error: extended character ∗ is not valid in an identifier
   86 | template<typename T> concept C1 = /∗ ... ∗/;
      |                                    ^
p194.cpp:86:42: error: extended character ∗ is not valid in an identifier
   86 | template<typename T> concept C1 = /∗ ... ∗/;
      |                                          ^
p194.cpp:87:36: error: extended character ∗ is not valid in an identifier
   87 | template<typename T> concept C2 = /∗ ... ∗/;
      |                                    ^
p194.cpp:87:42: error: extended character ∗ is not valid in an identifier
   87 | template<typename T> concept C2 = /∗ ... ∗/;
      |                                          ^
p194.cpp:88:40: error: extended character ∗ is not valid in an identifier
   88 | template<typename... Ts> concept C3 = /∗ ... ∗/;
      |                                        ^
p194.cpp:88:46: error: extended character ∗ is not valid in an identifier
   88 | template<typename... Ts> concept C3 = /∗ ... ∗/;
      |                                              ^
p194.cpp:101:33: error: extended character ∗ is not valid in an identifier
  101 | template<typename> concept C = /∗ ... ∗/;
      |                                 ^
p194.cpp:101:39: error: extended character ∗ is not valid in an identifier
  101 | template<typename> concept C = /∗ ... ∗/;
      |                                       ^
p194.cpp: In function 'void f()':
p194.cpp:24:21: error: 'a' was not declared in this scope
   24 | printf("a=%d b=%d", a, b);
      |                     ^
p194.cpp:24:24: error: 'b' was not declared in this scope
   24 | printf("a=%d b=%d", a, b);
      |                        ^
p194.cpp: At global scope:
p194.cpp:31:6: error: variable or field 'f2' declared void
   31 | void f2(cchar *const) {} // error: redefines #1
      |      ^~
p194.cpp:31:9: error: 'cchar' was not declared in this scope; did you mean 'char'?
   31 | void f2(cchar *const) {} // error: redefines #1
      |         ^~~~~
      |         char
p194.cpp:31:16: error: expected primary-expression before 'const'
   31 | void f2(cchar *const) {} // error: redefines #1
      |                ^~~~~
p194.cpp:39:9: error: expected identifier before 'this'
   39 | void f3(this C& self);
      |         ^~~~
p194.cpp:39:9: error: expected ',' or '...' before 'this'
p194.cpp:40:34: error: expected identifier before 'this'
   40 | template <typename Self> void g3(this Self&& self, int);
      |                                  ^~~~
p194.cpp:40:34: error: expected ',' or '...' before 'this'
p194.cpp:41:9: error: expected identifier before 'this'
   41 | void h3(this C) const; // error: const not allowed here
      |         ^~~~
p194.cpp:41:9: error: expected ',' or '...' before 'this'
p194.cpp: In function 'void test(C)':
p194.cpp:44:5: error: no matching function for call to 'C::f3()'
   44 | c.f3(); // OK, calls C::f
      | ~~~~^~
p194.cpp:39:6: note: candidate: 'void C::f3(int)'
   39 | void f3(this C& self);
      |      ^~
p194.cpp:39:6: note:   candidate expects 1 argument, 0 provided
p194.cpp:45:5: error: no matching function for call to 'C::g3(int)'
   45 | c.g3(42); // OK, calls C::g<C&>
      | ~~~~^~~~
p194.cpp:40:31: note: candidate: 'template<class Self> void C::g3(int)'
   40 | template <typename Self> void g3(this Self&& self, int);
      |                               ^~
p194.cpp:40:31: note:   template argument deduction/substitution failed:
p194.cpp:45:5: note:   couldn't deduce template parameter 'Self'
   45 | c.g3(42); // OK, calls C::g<C&>
      | ~~~~^~~~
p194.cpp:46:16: error: no matching function for call to 'C::g3(int)'
   46 | std::move(c).g3(42); // OK, calls C::g<C>
      | ~~~~~~~~~~~~~~~^~~~
p194.cpp:40:31: note: candidate: 'template<class Self> void C::g3(int)'
   40 | template <typename Self> void g3(this Self&& self, int);
      |                               ^~
p194.cpp:40:31: note:   template argument deduction/substitution failed:
p194.cpp:46:16: note:   couldn't deduce template parameter 'Self'
   46 | std::move(c).g3(42); // OK, calls C::g<C>
      | ~~~~~~~~~~~~~~~^~~~
p194.cpp: At global scope:
p194.cpp:50:5: error: non-member function 'int f4(int)' cannot have cv-qualifier
   50 | FIC f4; // error: does not declare a member function
      |     ^~
p194.cpp:57:8: error: redefinition of 'struct S'
   57 | struct S {
      |        ^
p194.cpp:51:8: note: previous definition of 'struct S'
   51 | struct S {
      |        ^
p194.cpp:66:3: error: function 'void fv()' is initialized like a variable
   66 | F fv { } // error
      |   ^~
p194.cpp:67:1: error: expected ',' or ';' before 'void'
   67 | void fv() { } // OK, definition of fv
      | ^~~~
p194.cpp:86:35: error: expected primary-expression before '/' token
   86 | template<typename T> concept C1 = /∗ ... ∗/;
      |                                   ^
p194.cpp:86:36: error: '\U00002217' was not declared in this scope
   86 | template<typename T> concept C1 = /∗ ... ∗/;
      |                                    ^
p194.cpp:87:35: error: expected primary-expression before '/' token
   87 | template<typename T> concept C2 = /∗ ... ∗/;
      |                                   ^
p194.cpp:87:36: error: '\U00002217' was not declared in this scope
   87 | template<typename T> concept C2 = /∗ ... ∗/;
      |                                    ^
p194.cpp:88:39: error: expected primary-expression before '/' token
   88 | template<typename... Ts> concept C3 = /∗ ... ∗/;
      |                                       ^
p194.cpp:88:40: error: '\U00002217' was not declared in this scope
   88 | template<typename... Ts> concept C3 = /∗ ... ∗/;
      |                                        ^
p194.cpp:99:17: error: template-id 'g1<int>' for 'void g1(const int*, const double&)' does not match any template declaration
   99 | template<> void g1<int>(const int*, const double&); // OK, specialization of g1<int, const double>
      |                 ^~~~~~~
p194.cpp:94:27: note: candidates are: 'template<class T, class U>  requires (C1<T>) && (C2<U>) void g1(const T*, U&)'
   94 | template<C1 T, C2 U> void g1(const T*, U&);
      |                           ^~
p194.cpp:89:6: note:                 'template<class auto:11, class auto:12>  requires (C1<auto:11>) && (C2<auto:12>) void g1(const auto:11*, auto:12&)'
   89 | void g1(const C1 auto*, C2 auto&);
      |      ^~
p194.cpp:101:32: error: expected primary-expression before '/' token
  101 | template<typename> concept C = /∗ ... ∗/;
      |                                ^
p194.cpp:101:33: error: '\U00002217' was not declared in this scope
  101 | template<typename> concept C = /∗ ... ∗/;
      |                                 ^
p194.cpp:101:41: error: 'template<class> concept C' redeclared as different kind of entity
  101 | template<typename> concept C = /∗ ... ∗/;
      |                                         ^
p194.cpp:38:8: note: previous declaration 'struct C'
   38 | struct C {
      |        ^
p194.cpp:103:14: error: 'U' is not a type
  103 | void ga(T x, U y, C auto z);
      |              ^
p194.cpp:103:19: error: two or more data types in declaration of 'z'
  103 | void ga(T x, U y, C auto z);
      |                   ^
p194.cpp:106:14: error: 'U' is not a type
  106 | void ga(T x, U y, W z);
      |              ^
p194.cpp:106:19: error: 'W' is not a type
  106 | void ga(T x, U y, W z);
      |                   ^
p194.cpp:108:11: error: expected primary-expression before '<' token
  108 | requires C<U> && C<W>
      |           ^
p194.cpp:108:11: error: expected unqualified-id before '<' token
p194.cpp: In function 'void gb()':
p194.cpp:115:2: error: no matching function for call to 'f(<unresolved overloaded function type>, float (&)(int, int))'
  115 | f(add, subtract);
      | ~^~~~~~~~~~~~~~~
p194.cpp:111:30: note: candidate: 'void f(T (*)(int, int) ...) [with T = {}]'
  111 | template<typename... T> void f(T (* ...t)(int, int));
      |                              ^
p194.cpp:111:30: note:   candidate expects 0 arguments, 2 provided
p194.cpp:22:6: note: candidate: 'void f()'
   22 | void f(){
      |      ^
p194.cpp:22:6: note:   candidate expects 0 arguments, 2 provided

検討事項(agenda)

コンパイルエラーの理由を解説する。

<|--コンパイルエラーを取るか、コンパイルエラーの理由を解説する。-->

参考資料(reference)

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

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

自己参照(self reference)

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

dockerにclang

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

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

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

C++ sample list

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

文書履歴(document history)

ver. 0.01 初稿  20220625

0
0
0

Register as a new user and use Qiita more conveniently

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?