C++ N4606(126)11 Member access control [class.access]p269
https://qiita.com/kaizen_nagoya/items/1ead00dff84aca76123f
で、間違えて1行、プログラム以外を紛れ込ませたら、
clang++
g++
でエラーの出方が極端に違った。記録。
<この項は書きかけです。順次追記します。>
// N4606 Committee Draft, Standard for Programming Language C++
// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/n4606.pdf
#define msg "p269.cpp(126)11 Member access control [class.access]"
#include <iostream>
union are public by default. [ Example:
class X {
int a; // X::a is private by default
};
struct S {
int a; // S::a is public by default
};
class A {
class B { };
public:
typedef B BB;
};
void f() {
A::BB x; // OK, typedef name A::BB is public
A::B y; // access error, A::B is private
}
class A {
typedef int I; // private member
I f();
friend I g(I);
static I x;
template<int> struct Q;
template<int> friend struct R;
protected:
struct B { };
};
A::I A::f() { return 0; }
A::I g(A::I p = A::x);
A::I g(A::I p) { return 0; }
A::I A::x = 0;
template<A::I> struct A::Q { };
template<A::I> struct R { };
struct D: A::B, A { };
class B { };
template <class T> class C {
protected:
typedef T TT;
};
template <class U, class V = typename U::TT>
class D : public U { };
D <C<B> >* d; // access error, C::TT is protected
int main(){
std::cout<< msg << std::endl;
return EXIT_SUCCESS;
}
$ ./cppgl17.sh p269
$ clang++ p269.cpp
p269.cpp:7:11: error: expected unqualified-id
union are public by default. [ Example:
^
1 error generated.
$ g++-7 p269.cpp
p269.cpp:7:11: error: expected unqualified-id before 'public'
union are public by default. [ Example:
^~~~~~
p269.cpp: In function 'void f()':
p269.cpp:22:4: error: 'class A::B' is private within this context
A::B y; // access error, A::B is private
^
p269.cpp:16:7: note: declared private here
class B { };
^
p269.cpp: At global scope:
p269.cpp:25:7: error: redefinition of 'class A'
class A {
^
p269.cpp:15:7: note: previous definition of 'class A'
class A {
^
p269.cpp:35:4: error: 'I' in 'class A' does not name a type
A::I A::f() { return 0; }
^
p269.cpp:36:4: error: 'I' in 'class A' does not name a type
A::I g(A::I p = A::x);
^
p269.cpp:37:4: error: 'I' in 'class A' does not name a type
A::I g(A::I p) { return 0; }
^
p269.cpp:38:4: error: 'I' in 'class A' does not name a type
A::I A::x = 0;
^
p269.cpp:39:10: error: 'A::I' has not been declared
template<A::I> struct A::Q { };
^
p269.cpp:39:28: error: qualified name does not name a class before '{' token
template<A::I> struct A::Q { };
^
p269.cpp:40:10: error: 'A::I' has not been declared
template<A::I> struct R { };
^
p269.cpp:41:14: error: 'class A::B' is private within this context
struct D: A::B, A { };
^
p269.cpp:16:7: note: declared private here
class B { };
^
p269.cpp:50:7: error: 'D' is not a template
class D : public U { };
^
p269.cpp:41:8: note: previous declaration here
struct D: A::B, A { };
^
p269.cpp:51:1: error: 'D' is not a template
D <C<B> >* d; // access error, C::TT is protected
^
わかったこと
clang++致命的なエラーがある場合はそれ以降をコンパイルしない。
clang++はエラー20を超えたらそれ以上はコンパイルしない。
Reference
Error一覧 error(0)
https://qiita.com/kaizen_nagoya/items/48b6cbc8d68eae2c42b8
<この記事は個人の過去の経験に基づく個人の感想です。現在所属する組織、業務とは関係がありません。>
This article is an individual impression based on the individual's experience. It has nothing to do with the organization or business to which I currently belong.
文書履歴
ver 0.10 初稿 20180419
ver 0.11 初めの説明追記 20180420
ver. 0.12 ありがとう追記 20230312
最後までおよみいただきありがとうございました。
いいね 💚、フォローをお願いします。
Thank you very much for reading to the last sentence.
Please press the like icon 💚 and follow me for your happy life.