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.7 Default arguments [dcl.fct.default] C++N4910:2022 (101) p198.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.7 Default arguments [dcl.fct.default] C++N4910:2022 (101) p198.cpp

算譜(source code)

p198.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.7 Default arguments [dcl.fct.default] C++N4910:2022 (101) p198.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
void point(int = 3, int = 4);
//declares a function that can be called with zero, one, or two arguments of type int. It can be called in any of these ways:
void f1(){
point(1,2); point(1); point();
}
// The last two calls are equivalent to point(1,4) and point(3,4), respectively. 
// [Example 2 :
void g(int = 0, ...); // OK, ellipsis is not a parameter so it can follow
// a parameter with a default argument
void f(int, int);
void f(int, int = 7);
void h() {
f(3); // OK, calls f(3, 7)
void f(int = 1, int); // error: does not use default from surrounding scope
}
void m() {
void f(int, int); // has no defaults
f(4); // error: wrong number of arguments
void f(int, int = 5); // OK
f(4); // OK, calls f(4, 5);
void f(int, int = 5); // error: cannot redefine, even to same value
}
void n() {
f(6); // OK, calls f(6, 7)
}
template<class ... T> struct C {
void f(int n = 0, T...);
};
C<int> c; // OK, instantiates declaration void C::f(int n = 0, int)
// [Example 3 : In the following code, g will be called with the value f(2):
int a = 1;
int f3(int);
int g3(int x = f3(a)); // default argument: f(::a)
void h3() {
a = 2;
{
int a = 3;
g3(); // g(f(::a))
}
}
// [Example 4 :
class C {
void f4(int i = 3);
void g4(int i, int j = 99);
};
void C::f4(int i = 3) {} // error: default argument already specified in class scope
void C::g4(int i = 88, int j) {} // in this translation unit, C::g can be called with no argument
// [Example 5 :
void f5() {
int i;
extern void g5(int x = i); // error
extern void h5(int x = sizeof(i)); // OK
// ...
}
// [Note 5 : The keyword this cannot appear in a default argument of a member function; see 7.5.2.
// [Example 6 :
class A {
void f6(A* p = this) { } // error
};
// [Example 7 :
int a7;
int f7(int a7, int b = a7); // error: parameter a used as default argument
typedef int I;
int g7(float I, int b = I(2)); // error: parameter I found
int h7(int a7, int b = sizeof(a7)); // OK, unevaluated operand (7.2.3)
// [Example 8 : The declaration of X::mem1() in the following example is ill-formed because no object is supplied for the non-static member X::a used as an initializer.
int b;
class X {
int a8;
int mem1(int i = a8); // error: non-static member a used as default argument
int mem2(int i = b8); // OK; use X::b
static int b8;
};
// The declaration of X::mem2() is meaningful, however, since no object is needed to access the static member X::b. Classes, objects, and members are described in Clause 11.
// A default argument is not part of the type of a function.
// [Example 9 :
int f9(int = 0);
void h9() {
int j = f9(1);
int k = f9(); // OK, means f(0)
}
int (*p1)(int) = &f9;
int (*p2)() = &f9; // error: type mismatch
// [Example 10 :
struct A {
virtual void fa(int a = 7);
};
struct B : public A {
void fa(int a);
};
void ma() {
B* pb = new B;
A* pa = pb;
pa->fa(); // OK, calls pa->B::f(7)
pb->fa(); // error: wrong number of arguments for B::f()
}
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  p198
rm: cannot remove 'p198l': No such file or directory
rm: cannot remove 'p198g': No such file or directory
$ clang++ p198.cpp -std=03 -o p198l -I. -Wall
p198.cpp:33:20: error: missing default argument on parameter
void f(int = 1, int); // error: does not use default from surrounding scope
                   ^
p198.cpp:37:1: error: too few arguments to function call, expected 2, have 1; did you mean '::f'?
f(4); // error: wrong number of arguments
^
::f
p198.cpp:30:6: note: '::f' declared here
void f(int, int = 7);
     ^
p198.cpp:40:17: error: redefinition of default argument
void f(int, int = 5); // error: cannot redefine, even to same value
                ^ ~
p198.cpp:38:17: note: previous definition is here
void f(int, int = 5); // OK
                ^ ~
p198.cpp:45:16: warning: variadic templates are a C++11 extension [-Wc++11-extensions]
template<class ... T> struct C {
               ^
p198.cpp:56:5: warning: unused variable 'a' [-Wunused-variable]
int a = 3;
    ^
p198.cpp:61:7: error: redefinition of 'C' as different kind of symbol
class C {
      ^
p198.cpp:45:30: note: previous definition is here
template<class ... T> struct C {
                             ^
p198.cpp:65:6: error: 'C' is not a class, namespace, or enumeration
void C::f4(int i = 3) {} // error: default argument already specified in class scope
     ^
p198.cpp:45:30: note: 'C' declared here
template<class ... T> struct C {
                             ^
p198.cpp:66:6: error: 'C' is not a class, namespace, or enumeration
void C::g4(int i = 88, int j) {} // in this translation unit, C::g can be called with no argument
     ^
p198.cpp:45:30: note: 'C' declared here
template<class ... T> struct C {
                             ^
p198.cpp:70:24: error: default argument references local variable 'i' of enclosing function
extern void g5(int x = i); // error
                       ^
p198.cpp:77:16: error: invalid use of 'this' outside of a non-static member function
void f6(A* p = this) { } // error
               ^
p198.cpp:81:24: error: default argument references parameter 'a7'
int f7(int a7, int b = a7); // error: parameter a used as default argument
                       ^~
p198.cpp:83:26: error: called object type 'float' is not a function or function pointer
int g7(float I, int b = I(2)); // error: parameter I found
                        ~^
p198.cpp:83:25: error: default argument references parameter 'I'
int g7(float I, int b = I(2)); // error: parameter I found
                        ^~~~
p198.cpp:89:18: error: invalid use of non-static data member 'a8'
int mem1(int i = a8); // error: non-static member a used as default argument
                 ^~
p198.cpp:98:5: warning: unused variable 'j' [-Wunused-variable]
int j = f9(1);
    ^
p198.cpp:99:5: warning: unused variable 'k' [-Wunused-variable]
int k = f9(); // OK, means f(0)
    ^
p198.cpp:102:7: error: cannot initialize a variable of type 'int (*)()' with an rvalue of type 'int (*)(int)': different number of parameters (0 vs 1)
int (*p2)() = &f9; // error: type mismatch
      ^       ~~~
p198.cpp:104:8: error: redefinition of 'A'
struct A {
       ^
p198.cpp:76:7: note: previous definition is here
class A {
      ^
p198.cpp:113:5: error: no member named 'fa' in 'A'
pa->fa(); // OK, calls pa->B::f(7)
~~  ^
p198.cpp:114:8: error: too few arguments to function call, single argument 'a' was not specified
pb->fa(); // error: wrong number of arguments for B::f()
~~~~~~ ^
p198.cpp:108:6: note: 'fa' declared here
void fa(int a);
     ^
4 warnings and 16 errors generated.
rm: cannot remove 'p198l': No such file or directory
$ clang++ p198.cpp -std=2b -o p198l -I. -Wall
p198.cpp:33:20: error: missing default argument on parameter
void f(int = 1, int); // error: does not use default from surrounding scope
                   ^
p198.cpp:37:1: error: too few arguments to function call, expected 2, have 1; did you mean '::f'?
f(4); // error: wrong number of arguments
^
::f
p198.cpp:30:6: note: '::f' declared here
void f(int, int = 7);
     ^
p198.cpp:40:17: error: redefinition of default argument
void f(int, int = 5); // error: cannot redefine, even to same value
                ^ ~
p198.cpp:38:17: note: previous definition is here
void f(int, int = 5); // OK
                ^ ~
p198.cpp:56:5: warning: unused variable 'a' [-Wunused-variable]
int a = 3;
    ^
p198.cpp:61:7: error: redefinition of 'C' as different kind of symbol
class C {
      ^
p198.cpp:45:30: note: previous definition is here
template<class ... T> struct C {
                             ^
p198.cpp:65:6: error: 'C' is not a class, namespace, or enumeration
void C::f4(int i = 3) {} // error: default argument already specified in class scope
     ^
p198.cpp:45:30: note: 'C' declared here
template<class ... T> struct C {
                             ^
p198.cpp:66:6: error: 'C' is not a class, namespace, or enumeration
void C::g4(int i = 88, int j) {} // in this translation unit, C::g can be called with no argument
     ^
p198.cpp:45:30: note: 'C' declared here
template<class ... T> struct C {
                             ^
p198.cpp:70:24: error: default argument references local variable 'i' of enclosing function
extern void g5(int x = i); // error
                       ^
p198.cpp:77:16: error: invalid use of 'this' outside of a non-static member function
void f6(A* p = this) { } // error
               ^
p198.cpp:81:24: error: default argument references parameter 'a7'
int f7(int a7, int b = a7); // error: parameter a used as default argument
                       ^~
p198.cpp:83:26: error: called object type 'float' is not a function or function pointer
int g7(float I, int b = I(2)); // error: parameter I found
                        ~^
p198.cpp:83:25: error: default argument references parameter 'I'
int g7(float I, int b = I(2)); // error: parameter I found
                        ^~~~
p198.cpp:89:18: error: invalid use of non-static data member 'a8'
int mem1(int i = a8); // error: non-static member a used as default argument
                 ^~
p198.cpp:98:5: warning: unused variable 'j' [-Wunused-variable]
int j = f9(1);
    ^
p198.cpp:99:5: warning: unused variable 'k' [-Wunused-variable]
int k = f9(); // OK, means f(0)
    ^
p198.cpp:102:7: error: cannot initialize a variable of type 'int (*)()' with an rvalue of type 'int (*)(int)': different number of parameters (0 vs 1)
int (*p2)() = &f9; // error: type mismatch
      ^       ~~~
p198.cpp:104:8: error: redefinition of 'A'
struct A {
       ^
p198.cpp:76:7: note: previous definition is here
class A {
      ^
p198.cpp:113:5: error: no member named 'fa' in 'A'
pa->fa(); // OK, calls pa->B::f(7)
~~  ^
p198.cpp:114:8: error: too few arguments to function call, single argument 'a' was not specified
pb->fa(); // error: wrong number of arguments for B::f()
~~~~~~ ^
p198.cpp:108:6: note: 'fa' declared here
void fa(int a);
     ^
3 warnings and 16 errors generated.

$ g++ p198.cpp -std=03 -o p198g -I. -Wall
p198.cpp: In function 'void h()':
p198.cpp:33:17: error: default argument missing for parameter 2 of 'void f(int, int)'
   33 | void f(int = 1, int); // error: does not use default from surrounding scope
      |                 ^~~
p198.cpp:33:8: note: ...following parameter 1 which has a default argument
   33 | void f(int = 1, int); // error: does not use default from surrounding scope
      |        ^~~~~~~
p198.cpp: In function 'void m()':
p198.cpp:37:2: error: too few arguments to function 'void f(int, int)'
   37 | f(4); // error: wrong number of arguments
      | ~^~~
p198.cpp:36:6: note: declared here
   36 | void f(int, int); // has no defaults
      |      ^
p198.cpp:40:6: error: default argument given for parameter 2 of 'void f(int, int)' [-fpermissive]
   40 | void f(int, int = 5); // error: cannot redefine, even to same value
      |      ^
p198.cpp:38:6: note: previous specification in 'void f(int, int)' here
   38 | void f(int, int = 5); // OK
      |      ^
p198.cpp: At global scope:
p198.cpp:45:16: warning: variadic templates only available with '-std=c++11' or '-std=gnu++11' [-Wc++11-extensions]
   45 | template<class ... T> struct C {
      |                ^~~
p198.cpp:46:20: warning: variadic templates only available with '-std=c++11' or '-std=gnu++11' [-Wc++11-extensions]
   46 | void f(int n = 0, T...);
      |                    ^~~
p198.cpp: In function 'void h3()':
p198.cpp:56:5: warning: unused variable 'a' [-Wunused-variable]
   56 | int a = 3;
      |     ^
p198.cpp: At global scope:
p198.cpp:61:7: error: class template 'C' redeclared as non-template
   61 | class C {
      |       ^
p198.cpp:45:30: note: previous declaration here
   45 | template<class ... T> struct C {
      |                              ^
p198.cpp:65:6: error: 'template<class ... T> struct C' used without template arguments
   65 | void C::f4(int i = 3) {} // error: default argument already specified in class scope
      |      ^
p198.cpp:66:6: error: 'template<class ... T> struct C' used without template arguments
   66 | void C::g4(int i = 88, int j) {} // in this translation unit, C::g can be called with no argument
      |      ^
p198.cpp:66:28: error: default argument missing for parameter 2 of 'void g4(int, int)'
   66 | void C::g4(int i = 88, int j) {} // in this translation unit, C::g can be called with no argument
      |                        ~~~~^
p198.cpp:66:16: note: ...following parameter 1 which has a default argument
   66 | void C::g4(int i = 88, int j) {} // in this translation unit, C::g can be called with no argument
      |            ~~~~^~~~~~
p198.cpp: In function 'void f5()':
p198.cpp:70:24: error: local variable 'i' may not appear in this context
   70 | extern void g5(int x = i); // error
      |                        ^
p198.cpp: At global scope:
p198.cpp:77:16: error: 'this' may not be used in this context
   77 | void f6(A* p = this) { } // error
      |                ^~~~
p198.cpp:81:24: error: parameter 'a7' may not appear in this context
   81 | int f7(int a7, int b = a7); // error: parameter a used as default argument
      |                        ^~
p198.cpp:83:25: error: parameter 'I' may not appear in this context
   83 | int g7(float I, int b = I(2)); // error: parameter I found
      |                         ^
p198.cpp:89:18: error: invalid use of non-static data member 'X::a8'
   89 | int mem1(int i = a8); // error: non-static member a used as default argument
      |                  ^~
p198.cpp:88:5: note: declared here
   88 | int a8;
      |     ^~
p198.cpp: In function 'void h9()':
p198.cpp:98:5: warning: unused variable 'j' [-Wunused-variable]
   98 | int j = f9(1);
      |     ^
p198.cpp:99:5: warning: unused variable 'k' [-Wunused-variable]
   99 | int k = f9(); // OK, means f(0)
      |     ^
p198.cpp: At global scope:
p198.cpp:102:15: error: invalid conversion from 'int (*)(int)' to 'int (*)()' [-fpermissive]
  102 | int (*p2)() = &f9; // error: type mismatch
      |               ^~~
      |               |
      |               int (*)(int)
p198.cpp:104:8: error: redefinition of 'struct A'
  104 | struct A {
      |        ^
p198.cpp:76:7: note: previous definition of 'struct A'
   76 | class A {
      |       ^
p198.cpp: In function 'void ma()':
p198.cpp:113:5: error: 'struct A' has no member named 'fa'; did you mean 'f6'?
  113 | pa->fa(); // OK, calls pa->B::f(7)
      |     ^~
      |     f6
p198.cpp:114:7: error: no matching function for call to 'B::fa()'
  114 | pb->fa(); // error: wrong number of arguments for B::f()
      | ~~~~~~^~
p198.cpp:108:6: note: candidate: 'void B::fa(int)'
  108 | void fa(int a);
      |      ^~
p198.cpp:108:6: note:   candidate expects 1 argument, 0 provided
rm: cannot remove 'p198g': No such file or directory

$ g++ p198.cpp -std=2b -o p198g -I. -Wall
p198.cpp: In function 'void h()':
p198.cpp:33:17: error: default argument missing for parameter 2 of 'void f(int, int)'
   33 | void f(int = 1, int); // error: does not use default from surrounding scope
      |                 ^~~
p198.cpp:33:8: note: ...following parameter 1 which has a default argument
   33 | void f(int = 1, int); // error: does not use default from surrounding scope
      |        ^~~~~~~
p198.cpp: In function 'void m()':
p198.cpp:37:2: error: too few arguments to function 'void f(int, int)'
   37 | f(4); // error: wrong number of arguments
      | ~^~~
p198.cpp:36:6: note: declared here
   36 | void f(int, int); // has no defaults
      |      ^
p198.cpp:40:6: error: default argument given for parameter 2 of 'void f(int, int)' [-fpermissive]
   40 | void f(int, int = 5); // error: cannot redefine, even to same value
      |      ^
p198.cpp:38:6: note: previous specification in 'void f(int, int)' here
   38 | void f(int, int = 5); // OK
      |      ^
p198.cpp: In function 'void h3()':
p198.cpp:56:5: warning: unused variable 'a' [-Wunused-variable]
   56 | int a = 3;
      |     ^
p198.cpp: At global scope:
p198.cpp:61:7: error: class template 'C' redeclared as non-template
   61 | class C {
      |       ^
p198.cpp:45:30: note: previous declaration here
   45 | template<class ... T> struct C {
      |                              ^
p198.cpp:65:6: error: 'template<class ... T> struct C' used without template arguments
   65 | void C::f4(int i = 3) {} // error: default argument already specified in class scope
      |      ^
p198.cpp:66:6: error: 'template<class ... T> struct C' used without template arguments
   66 | void C::g4(int i = 88, int j) {} // in this translation unit, C::g can be called with no argument
      |      ^
p198.cpp:66:28: error: default argument missing for parameter 2 of 'void g4(int, int)'
   66 | void C::g4(int i = 88, int j) {} // in this translation unit, C::g can be called with no argument
      |                        ~~~~^
p198.cpp:66:16: note: ...following parameter 1 which has a default argument
   66 | void C::g4(int i = 88, int j) {} // in this translation unit, C::g can be called with no argument
      |            ~~~~^~~~~~
p198.cpp: In function 'void f5()':
p198.cpp:70:24: error: local variable 'i' may not appear in this context
   70 | extern void g5(int x = i); // error
      |                        ^
p198.cpp: At global scope:
p198.cpp:77:16: error: 'this' may not be used in this context
   77 | void f6(A* p = this) { } // error
      |                ^~~~
p198.cpp:81:24: error: parameter 'a7' may not appear in this context
   81 | int f7(int a7, int b = a7); // error: parameter a used as default argument
      |                        ^~
p198.cpp:83:25: error: parameter 'I' may not appear in this context
   83 | int g7(float I, int b = I(2)); // error: parameter I found
      |                         ^
p198.cpp:89:18: error: invalid use of non-static data member 'X::a8'
   89 | int mem1(int i = a8); // error: non-static member a used as default argument
      |                  ^~
p198.cpp:88:5: note: declared here
   88 | int a8;
      |     ^~
p198.cpp: In function 'void h9()':
p198.cpp:98:5: warning: unused variable 'j' [-Wunused-variable]
   98 | int j = f9(1);
      |     ^
p198.cpp:99:5: warning: unused variable 'k' [-Wunused-variable]
   99 | int k = f9(); // OK, means f(0)
      |     ^
p198.cpp: At global scope:
p198.cpp:102:15: error: invalid conversion from 'int (*)(int)' to 'int (*)()' [-fpermissive]
  102 | int (*p2)() = &f9; // error: type mismatch
      |               ^~~
      |               |
      |               int (*)(int)
p198.cpp:104:8: error: redefinition of 'struct A'
  104 | struct A {
      |        ^
p198.cpp:76:7: note: previous definition of 'struct A'
   76 | class A {
      |       ^
p198.cpp: In function 'void ma()':
p198.cpp:113:5: error: 'struct A' has no member named 'fa'; did you mean 'f6'?
  113 | pa->fa(); // OK, calls pa->B::f(7)
      |     ^~
      |     f6
p198.cpp:114:7: error: no matching function for call to 'B::fa()'
  114 | pb->fa(); // error: wrong number of arguments for B::f()
      | ~~~~~~^~
p198.cpp:108:6: note: candidate: 'void B::fa(int)'
  108 | void fa(int a);
      |      ^~
p198.cpp:108:6: note:   candidate expects 1 argument, 0 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 初稿  20220626

0
0
0

Register as a new user and use Qiita more conveniently

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?