0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

N4606 Working Draft 2016, ISO/IEC 14882, C++ standard(15) 3.4 Name lookup [basic.lookup] p.47

Last updated at Posted at 2018-04-14

はじめに

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++が標準化の動きとの時間的な擦れの確認が結果としてできれば幸いです。

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.

#(15)3.4 Name lookup [basic.lookup]
3.4.1 Unqualified name lookup [basic.lookup.unqual]
p.47

p47.cpp
// N4606 Committee Draft, Standard for Programming Language C++
// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/n4606.pdf 
#define msg "p47.cpp #(15)3.4.1 Unqualified name lookup [basic.lookup.unqual]"

#include <iostream>

typedef int f;
namespace N {
  struct A {
    friend void f(A &);
    operator int();
    void g(A a) {
      int i = f(a); // f is the typedef, not the friend
      // function: equivalent to int(a)
    }
  };
}


namespace A2 {
  namespace N {
    void f();
  }
}
void A2::N::f() {
  i = 5;
  // The following scopes are searched for a declaration of i:
  // 1) outermost block scope of A2::N::f, before the use of i
  // 2) scope of namespace N
  // 3) scope of namespace A2
  // 4) global scope, before the definition of A::N::f
}

namespace M {
  class B { };
}
namespace N {
  class Y : public M::B {
    class X {
      int a[i];
    };
  };
}
// The following scopes are searched for a declaration of i:
// 1) scope of class N::Y::X, before the use of i
// 2) scope of class N::Y, before the definition of N::Y::X
// 3) scope of N::Y’s base class M::B
// 4) scope of namespace N, before the definition of N::Y
// 5) global scope, before the definition of N


class B2 { };
namespace M {
  namespace N {
    class X : public B2 {
      void f();
    };
  }
}
void M::N::X::f() {
  i = 16;
}
// The following scopes are searched for a declaration of i:
// 1) outermost block scope of M::N::X::f, before the use of i
// 2) scope of class M::N::X
// 3) scope of M::N::X’s base class B
// 4) scope of namespace M::N
// 5) scope of namespace M
// 6) global scope, before the definition of M::N::X::f

struct A3 {
  typedef int AT;
  void f1(AT);
  void f2(float);
  template <class T> void f3();
};
struct B3 {
  typedef char AT;
  typedef float BT;
  friend void A3::f1(AT); // parameter type is A3::AT
  friend void A3::f2(BT); // parameter type is B3::BT
  friend void A3::f3<AT>(); // template argument is B3::AT
};

namespace N {
  int i2 = 4;
  extern int j;
}
int i2 = 2;
namespace N {
  int i2 = 4;
  extern int j;
}
int i2 = 2;

int main(int argc, char *argv[], char *envp[]){
  std::cout << msg << std::endl;
  return EXIT_SUCCESS;
}
$ ./cppgl.sh p47
$ clang++ p47.cpp
p47.cpp:26:3: error: use of undeclared identifier 'i'
  i = 5;
  ^
p47.cpp:40:13: error: use of undeclared identifier 'i'
      int a[i];
            ^
p47.cpp:61:3: error: use of undeclared identifier 'i'
  i = 16;
  ^
p47.cpp:91:7: error: redefinition of 'i2'
  int i2 = 4;
      ^
p47.cpp:86:7: note: previous definition is here
  int i2 = 4;
      ^
p47.cpp:94:5: error: redefinition of 'i2'
int i2 = 2;
    ^
p47.cpp:89:5: note: previous definition is here
int i2 = 2;
    ^
5 errors generated.

$ g++-7 p47.cpp
p47.cpp: In function 'void A2::N::f()':
p47.cpp:26:3: error: 'i' was not declared in this scope
   i = 5;
   ^
p47.cpp: At global scope:
p47.cpp:40:13: error: 'i' was not declared in this scope
       int a[i];
             ^
p47.cpp: In member function 'void M::N::X::f()':
p47.cpp:61:3: error: 'i' was not declared in this scope
   i = 16;
   ^
p47.cpp: At global scope:
p47.cpp:91:7: error: redefinition of 'int N::i2'
   int i2 = 4;
       ^~
p47.cpp:86:7: note: 'int N::i2' previously defined here
   int i2 = 4;
       ^~
p47.cpp:94:5: error: redefinition of 'int i2'
 int i2 = 2;
     ^~
p47.cpp:89:5: note: 'int i2' previously defined here
 int i2 = 2;
     ^~

#検討事項
コンパイルエラーが出るのがExampleの意図通りか。

#参考資料

コンパイル用shell script C版(clangとgcc)とC++版(clang++とg++)
https://qiita.com/kaizen_nagoya/items/74220c0577a512c2d7da
Qiitaに投稿するCのStyle例(暫定)
https://qiita.com/kaizen_nagoya/items/946df1528a6a1ef2bc0d

文書履歴

0.10 初稿 2080415

最後までおよみいただきありがとうございました。

いいね 💚、フォローをお願いします。

Thank you very much for reading to the last sentence.

Please press the like icon 💚 and follow me for your happy life.

0
1
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
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?