C++N4606(123)10.2 Member name lookup [class.member.lookup]p260

#はじめに
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）との関係も調査中です。
何か、抜け漏れ、耳より情報がありましたらおしらせくださると幸いです。

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

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

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

###g++-7 --version
g++-7 (Homebrew GCC 7.3.0_1) 7.3.0
Copyright (C) 2017 Free Software Foundation, Inc.

#(123)10.2 Member name lookup [class.member.lookup]p260

```c++:p260.cpp
// N4606 Committee Draft, Standard for Programming Language C++
// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/n4606.pdf
#define msg "p260.cpp(123)10.2 Member name lookup [class.member.lookup]"

#include <iostream>

struct A {
  int x;
}; // S(x,A) = { { A::x }, { A } }
struct B {
  float x;
}; // S(x,B) = { { B::x }, { B } }
struct C: public A, public B { }; // S(x,C) = { invalid, { A in C, B in C } }
struct D: public virtual C { }; // S(x,D) = S(x,C)
struct E: public virtual C {
  char x;
}; // S(x,E) = { { E::x }, { E } }
struct F: public D, public E { }; // S(x,F) = S(x,E)
int main() {
  F f;
  f.x = 0; // OK, lookup finds E::x
  std::cout<< msg << std::endl;
  return EXIT_SUCCESS;
}

struct A2 {
  int f();
};
struct B2 {
  int f();
};
struct C2 : A2, B2 {
  int f() {
    return A2::f() + B2::f();
  }
};

struct V {
  int v;
};
struct A3 {
  int a;
  static int s;
  enum { e };
};
struct B3 : A3, virtual V { };
struct C3 : A3, virtual V { };
struct D3 : B3, C3 { };
void f3(D3* pd) {
  pd->v++; // OK: only one v (virtual)
  pd->s++; // OK: only one s (static)
  int i = pd->e; // OK: only one e (enumerator)
  pd->a++; // error, ambiguous: two as in D3
}

struct V4 {
  int f();
  int x;
};
struct W4 {
  int g();
  int y;
};
struct B4 : virtual V4, W4 {
  int f();
  int x;
  int g();
  int y;
};
struct C4 : virtual V4, W4 { };
struct D4 : B4, C4 {
  void glorp();
};

void D4::glorp() {
  x++; // OK: B4::x hides V4::x
  f(); // OK: B4::f() hides V4::f()
  y++; // error: B4::y and C4’s W4::y
  g(); // error: B4::g() and C4’s W4::g()
}

struct V5 { };
struct A5 { };
struct B5 : A5, virtual V5 { };
struct C5 : A5, virtual V5 { };
struct D5 : B5, C5 { };
void g() {
  D5 d;
  B5* pb = &d;
  A5* pa = &d; // error, ambiguous: C5’s A5 or B5’s A5?
  V5* pv = &d; // OK: only one V5 subobject
}

struct B1a {
  void f();
  static void f(int);
  int i;
};
struct B2a {
  void f(double);
};
struct I1: B1a { };
struct I2: B1a { };
struct Da: I1, I2, B2a {
  using B1a::f;
  using B2a::f;
  void g() {
    f(); // Ambiguous conversion of this
    f(0); // Unambiguous (static)
    f(0.0); // Unambiguous (only one B2a)
    int B1a::* mpB1 = &Da::i; // Unambiguous
    int Da::* mpD = &Da::i; // Ambiguous conversion
  }
};
```

```shell_session
$ ./cppgl17.sh p260
$ clang++ p260.cpp
p260.cpp:45:5: error: non-static member 'a' found in multiple base-class subobjects of type 'A3':
    struct D3 -> struct B3 -> struct A3
    struct D3 -> struct C3 -> struct A3
pd->a++; // error, ambiguous: two as in D3
    ^
p260.cpp:34:5: note: member found by ambiguous name lookup
int a;
    ^
p260.cpp:60:1: error: member 'y' found in multiple base classes of different types
y++; // error: B4::y and C4’s W4::y
^
p260.cpp:52:14: note: member found by ambiguous name lookup
int g(); int y;
             ^
p260.cpp:49:26: note: member found by ambiguous name lookup
struct W4 { int g(); int y; };
                         ^
p260.cpp:61:1: error: member 'g' found in multiple base classes of different types
g(); // error: B4::g() and C4’s W4::g()
^
p260.cpp:52:5: note: member found by ambiguous name lookup
int g(); int y;
    ^
p260.cpp:49:17: note: member found by ambiguous name lookup
struct W4 { int g(); int y; };
                ^
p260.cpp:72:10: error: ambiguous conversion from derived class 'D5' to base class 'A5':
    struct D5 -> struct B5 -> struct A5
    struct D5 -> struct C5 -> struct A5
A5* pa = &d; // error, ambiguous: C5’s A5 or B5’s A5?
         ^~
p260.cpp:90:1: error: ambiguous conversion from derived class 'Da' to base class 'B1a':
    struct Da -> struct I1 -> struct B1a
    struct Da -> struct I2 -> struct B1a
f(); // Ambiguous conversion of this
^
p260.cpp:93:24: error: non-static member 'i' found in multiple base-class subobjects of type 'B1a':
    struct Da -> struct I1 -> struct B1a
    struct Da -> struct I2 -> struct B1a
int B1a::* mpB1 = &Da::i; // Unambiguous
                   ~~~~^
p260.cpp:79:5: note: member found by ambiguous name lookup
int i;
    ^
p260.cpp:94:22: error: non-static member 'i' found in multiple base-class subobjects of type 'B1a':
    struct Da -> struct I1 -> struct B1a
    struct Da -> struct I2 -> struct B1a
int Da::* mpD = &Da::i; // Ambiguous conversion
                 ~~~~^
p260.cpp:79:5: note: member found by ambiguous name lookup
int i;
    ^
7 errors generated.

$ g++-7 p260.cpp
p260.cpp: In function 'int main()':
p260.cpp:15:3: error: request for member 'x' is ambiguous
 f.x = 0; // OK, lookup finds E::x
   ^
p260.cpp:8:18: note: candidates are: float B::x
 struct B { float x; }; // S(x,B) = { { B::x }, { B } }
                  ^
p260.cpp:7:16: note:                 int A::x
 struct A { int x; }; // S(x,A) = { { A::x }, { A } }
                ^
p260.cpp: In function 'void f3(D3*)':
p260.cpp:45:5: error: request for member 'a' is ambiguous
 pd->a++; // error, ambiguous: two as in D3
     ^
p260.cpp:34:5: note: candidates are: int A3::a
 int a;
     ^
p260.cpp:34:5: note:                 int A3::a
p260.cpp: In member function 'void D4::glorp()':
p260.cpp:60:1: error: reference to 'y' is ambiguous
 y++; // error: B4::y and C4’s W4::y
 ^
p260.cpp:49:26: note: candidates are: int W4::y
 struct W4 { int g(); int y; };
                          ^
p260.cpp:52:14: note:                 int B4::y
 int g(); int y;
              ^
p260.cpp:61:1: error: reference to 'g' is ambiguous
 g(); // error: B4::g() and C4’s W4::g()
 ^
p260.cpp:49:17: note: candidates are: int W4::g()
 struct W4 { int g(); int y; };
                 ^
p260.cpp:52:5: note:                 int B4::g()
 int g(); int y;
     ^
p260.cpp: In function 'void g()':
p260.cpp:72:11: error: 'A5' is an ambiguous base of 'D5'
 A5* pa = &d; // error, ambiguous: C5’s A5 or B5’s A5?
           ^
p260.cpp: In member function 'void Da::g()':
p260.cpp:90:3: error: 'B1a' is an ambiguous base of 'Da'
 f(); // Ambiguous conversion of this
   ^
p260.cpp:93:20: error: reference to 'i' is ambiguous
 int B1a::* mpB1 = &Da::i; // Unambiguous
                    ^~
p260.cpp:79:5: note: candidates are: int B1a::i
 int i;
     ^
p260.cpp:79:5: note:                 int B1a::i
p260.cpp:94:18: error: reference to 'i' is ambiguous
 int Da::* mpD = &Da::i; // Ambiguous conversion
                  ^~
p260.cpp:79:5: note: candidates are: int B1a::i
 int i;
     ^
p260.cpp:79:5: note:                 int B1a::i
```

```c++:p260-2.cpp
// N4606 Committee Draft, Standard for Programming Language C++
// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/n4606.pdf
#define msg "p260.cpp(123)10.2 Member name lookup [class.member.lookup]"

#include <iostream>

struct A {
  int x;
}; // S(x,A) = { { A::x }, { A } }
struct B {
  float x;
}; // S(x,B) = { { B::x }, { B } }
struct C: public A, public B { }; // S(x,C) = { invalid, { A in C, B in C } }
struct D: public virtual C { }; // S(x,D) = S(x,C)
struct E: public virtual C {
  char x;
}; // S(x,E) = { { E::x }, { E } }
struct F: public D, public E { }; // S(x,F) = S(x,E)
int main() {
  F f;
  f.x = 0; // OK, lookup finds E::x
  std::cout<< msg << std::endl;
  return EXIT_SUCCESS;
}

struct A2 {
  int f();
};
struct B2 {
  int f();
};
struct C2 : A2, B2 {
  int f() {
    return A2::f() + B2::f();
  }
};

struct V {
  int v;
};
struct A3 {
  int a;
  static int s;
  enum { e };
};
struct B3 : A3, virtual V { };
struct C3 : A3, virtual V { };
struct D3 : B3, C3 { };
void f3(D3* pd) {
  pd->v++; // OK: only one v (virtual)
  pd->s++; // OK: only one s (static)
  int i = pd->e; // OK: only one e (enumerator)
//  pd->a++; // error, ambiguous: two as in D3
}

struct V4 {
  int f();
  int x;
};
struct W4 {
  int g();
  int y;
};
struct B4 : virtual V4, W4 {
  int f();
  int x;
  int g();
  int y;
};
struct C4 : virtual V4, W4 { };
struct D4 : B4, C4 {
  void glorp();
};

void D4::glorp() {
  x++; // OK: B4::x hides V4::x
  f(); // OK: B4::f() hides V4::f()
//  y++; // error: B4::y and C4’s W4::y
//  g(); // error: B4::g() and C4’s W4::g()
}

struct V5 { };
struct A5 { };
struct B5 : A5, virtual V5 { };
struct C5 : A5, virtual V5 { };
struct D5 : B5, C5 { };
void g() {
  D5 d;
  B5* pb = &d;
//  A5* pa = &d; // error, ambiguous: C5’s A5 or B5’s A5?
  V5* pv = &d; // OK: only one V5 subobject
}

struct B1a {
  void f();
  static void f(int);
  int i;
};
struct B2a {
  void f(double);
};
struct I1: B1a { };
struct I2: B1a { };
struct Da: I1, I2, B2a {
  using B1a::f;
  using B2a::f;
  void g() {
//    f(); // Ambiguous conversion of this
    f(0); // Unambiguous (static)
    f(0.0); // Unambiguous (only one B2a)
//    int B1a::* mpB1 = &Da::i; // Unambiguous
//    int Da::* mpD = &Da::i; // Ambiguous conversion
  }
};
```

```shell-session
$ ./cppgl17.sh p260-2
$ clang++ p260-2.cpp
Undefined symbols for architecture x86_64:
  "A3::s", referenced from:
      f3(D3*) in p260-2-978eab.o
  "B4::f()", referenced from:
      D4::glorp() in p260-2-978eab.o
ld: symbol(s) not found for architecture x86_64
clang-6.0: error: linker command failed with exit code 1 (use -v to see invocation)

$ g++-7 p260-2.cpp
p260-2.cpp: In function 'int main()':
p260-2.cpp:21:5: error: request for member 'x' is ambiguous
   f.x = 0; // OK, lookup finds E::x
     ^
p260-2.cpp:11:9: note: candidates are: float B::x
   float x;
         ^
p260-2.cpp:8:7: note:                 int A::x
   int x;
       ^
```

#検討事項
もっと意味のある処理と出力。
clang++とg++のエラーの有無


#参考資料

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 <misra_c.h>
https://qiita.com/kaizen_nagoya/items/f1a79a7cbd281607c7c9

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

#文書履歴
0.10 初稿 2080419