LoginSignup
1
0

N4606 Working Draft 2016, ISO/IEC 14882, C++ standard(17)3.4.3 Qualified name lookup [basic.lookup.qual] p.53

Last updated at Posted at 2018-04-15

はじめに

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.

#(17)3.4.3 Qualified name lookup [basic.lookup.qual]
p.53

p53.cpp
// N4606 Committee Draft, Standard for Programming Language C++
// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/n4606.pdf 
#define msg "p53.cpp (17)3.4.3 Qualified name lookup [basic.lookup.qual]"

#include <iostream>

class A {
  public:
  static int n;
};
int main() {
  int A;
  A::n = 42; // OK
  A b; // ill-formed: A does not name a type
  std::cout << msg << std::endl;
  return EXIT_SUCCESS;
}
$ ./cppgl.sh p53
$ clang++ p53.cpp
p53.cpp:14:3: error: must use 'class' tag to refer to type 'A' in this scope
  A b; // ill-formed: A does not name a type
  ^
  class 
p53.cpp:12:7: note: class 'A' is hidden by a non-type declaration of 'A' here
  int A;
      ^
1 error generated.

$ g++-7 p53.cpp
p53.cpp: In function 'int main()':
p53.cpp:14:5: error: expected ';' before 'b'
   A b; // ill-formed: A does not name a type
     ^
p53-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 "p53-2.cpp (17)3.4.3 Qualified name lookup [basic.lookup.qual]"

#include <iostream>

class X { };
class C {
  class X { };
  static const int number = 50;
  static X arr[number];
};
X C::arr[number]; // ill-formed:
// equivalent to: ::X C::arr[C::number];
// not to: C::X C::arr[C::number];
//$ clang++ p53-2.cpp
//p53-2.cpp:13:6: error: redefinition of 'arr' with a different type: 'X [50]' vs 'C::X [50]'
//X C::arr[number]; // ill-formed:
//     ^
//p53-2.cpp:11:12: note: previous declaration is here
//  static X arr[number];
//           ^
//$ g++-7 p53-2.cpp
//p53-2.cpp:13:16: error: conflicting declaration 'X C::arr [50]'
// X C::arr[number]; // ill-formed:
//                ^
//p53-2.cpp:11:12: note: previous declaration as 'C::X //C::arr [50]'
//   static X arr[number];
//            ^~~


struct C2 {
  typedef int I;
};
typedef int I1, I2;
extern int* p;
extern int* q;
p->C2::I::~I(); // I is looked up in the scope of C2
//$ clang++ p53-2.cpp
//p53-2.cpp:23:1: error: unknown type name 'p'
//p->C2::I::~I(); // I is looked up in the scope of C2
//^
//p53-2.cpp:23:2: error: cannot use arrow operator on a type
//p->C2::I::~I(); // I is looked up in the scope of C2
// ^
//$ g++-7 p53-2.cpp
//p53-2.cpp:23:1: error: 'p' does not name a type
// p->C2::I::~I(); // I is looked up in the scope of C2
// ^


q->I1::~I2(); // I2 is looked up in the scope of
// the postfix-expression
//$ clang++ p53-2.cpp
//p53-2.cpp:24:1: error: unknown type name 'q'
//q->I1::~I2(); // I2 is looked up in the scope of
//^
//p53-2.cpp:24:2: error: cannot use arrow operator on a type
//q->I1::~I2(); // I2 is looked up in the scope of
// ^
//$ g++-7 p53-2.cpp
//p53-2.cpp:24:1: error: 'q' does not name a type
// q->I1::~I2(); // I2 is looked up in the scope of
// ^

struct A {
  ~A();
};
typedef A AB;
int main() {
  AB* p;
  p->AB::~AB(); // explicitly calls the destructor for A
  std::cout << msg << std::endl;
  return EXIT_SUCCESS;
}

課題

題材の中身を出力する追記。

参考資料

コンパイル用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

文書履歴

ver. 0.10 初稿 2080415
ver. 0.11 URL追記 20230215

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

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

Thank you very much for reading to the last sentence.

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

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