annotate clang/test/SemaCXX/namespace.cpp @ 150:1d019706d866

LLVM10
author anatofuz
date Thu, 13 Feb 2020 15:10:13 +0900
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
150
anatofuz
parents:
diff changeset
1 // RUN: %clang_cc1 -fsyntax-only -verify %s
anatofuz
parents:
diff changeset
2 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++98 %s
anatofuz
parents:
diff changeset
3 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
anatofuz
parents:
diff changeset
4
anatofuz
parents:
diff changeset
5 namespace A { // expected-note 2 {{previous definition is here}}
anatofuz
parents:
diff changeset
6 int A;
anatofuz
parents:
diff changeset
7 void f() { A = 0; }
anatofuz
parents:
diff changeset
8 }
anatofuz
parents:
diff changeset
9
anatofuz
parents:
diff changeset
10 void f() { A = 0; } // expected-error {{unexpected namespace name 'A': expected expression}}
anatofuz
parents:
diff changeset
11 int A; // expected-error {{redefinition of 'A' as different kind of symbol}}
anatofuz
parents:
diff changeset
12 class A; // expected-error {{redefinition of 'A' as different kind of symbol}}
anatofuz
parents:
diff changeset
13
anatofuz
parents:
diff changeset
14 class B {}; // expected-note {{previous definition is here}}
anatofuz
parents:
diff changeset
15 // expected-note@-1 {{candidate function (the implicit copy assignment operator) not viable}}
anatofuz
parents:
diff changeset
16 #if __cplusplus >= 201103L // C++11 or later
anatofuz
parents:
diff changeset
17 // expected-note@-3 {{candidate function (the implicit move assignment operator) not viable}}
anatofuz
parents:
diff changeset
18 #endif
anatofuz
parents:
diff changeset
19
anatofuz
parents:
diff changeset
20 void C(); // expected-note {{previous definition is here}}
anatofuz
parents:
diff changeset
21 namespace C {} // expected-error {{redefinition of 'C' as different kind of symbol}}
anatofuz
parents:
diff changeset
22
anatofuz
parents:
diff changeset
23 namespace D {
anatofuz
parents:
diff changeset
24 class D {};
anatofuz
parents:
diff changeset
25 }
anatofuz
parents:
diff changeset
26
anatofuz
parents:
diff changeset
27 namespace S1 {
anatofuz
parents:
diff changeset
28 int x;
anatofuz
parents:
diff changeset
29
anatofuz
parents:
diff changeset
30 namespace S2 {
anatofuz
parents:
diff changeset
31
anatofuz
parents:
diff changeset
32 namespace S3 {
anatofuz
parents:
diff changeset
33 B x;
anatofuz
parents:
diff changeset
34 }
anatofuz
parents:
diff changeset
35 }
anatofuz
parents:
diff changeset
36 }
anatofuz
parents:
diff changeset
37
anatofuz
parents:
diff changeset
38 namespace S1 {
anatofuz
parents:
diff changeset
39 void f() {
anatofuz
parents:
diff changeset
40 x = 0;
anatofuz
parents:
diff changeset
41 }
anatofuz
parents:
diff changeset
42
anatofuz
parents:
diff changeset
43 namespace S2 {
anatofuz
parents:
diff changeset
44
anatofuz
parents:
diff changeset
45 namespace S3 {
anatofuz
parents:
diff changeset
46 void f() {
anatofuz
parents:
diff changeset
47 x = 0; // expected-error {{no viable overloaded '='}}
anatofuz
parents:
diff changeset
48 }
anatofuz
parents:
diff changeset
49 }
anatofuz
parents:
diff changeset
50
anatofuz
parents:
diff changeset
51 int y;
anatofuz
parents:
diff changeset
52 }
anatofuz
parents:
diff changeset
53 }
anatofuz
parents:
diff changeset
54
anatofuz
parents:
diff changeset
55 namespace S1 {
anatofuz
parents:
diff changeset
56 namespace S2 {
anatofuz
parents:
diff changeset
57 namespace S3 {
anatofuz
parents:
diff changeset
58 void f3() {
anatofuz
parents:
diff changeset
59 y = 0;
anatofuz
parents:
diff changeset
60 }
anatofuz
parents:
diff changeset
61 }
anatofuz
parents:
diff changeset
62 }
anatofuz
parents:
diff changeset
63 }
anatofuz
parents:
diff changeset
64
anatofuz
parents:
diff changeset
65 namespace B {} // expected-error {{redefinition of 'B' as different kind of symbol}}
anatofuz
parents:
diff changeset
66
anatofuz
parents:
diff changeset
67
anatofuz
parents:
diff changeset
68 namespace foo {
anatofuz
parents:
diff changeset
69 enum x {
anatofuz
parents:
diff changeset
70 Y
anatofuz
parents:
diff changeset
71 };
anatofuz
parents:
diff changeset
72 }
anatofuz
parents:
diff changeset
73
anatofuz
parents:
diff changeset
74 static foo::x test1; // ok
anatofuz
parents:
diff changeset
75
anatofuz
parents:
diff changeset
76 static foo::X test2; // typo: expected-error {{no type named 'X' in}}
anatofuz
parents:
diff changeset
77
anatofuz
parents:
diff changeset
78 namespace PR6620 {
anatofuz
parents:
diff changeset
79 namespace numeric {
anatofuz
parents:
diff changeset
80 namespace op {
anatofuz
parents:
diff changeset
81 struct greater {};
anatofuz
parents:
diff changeset
82 }
anatofuz
parents:
diff changeset
83 namespace {
anatofuz
parents:
diff changeset
84 extern op::greater const greater;
anatofuz
parents:
diff changeset
85 }
anatofuz
parents:
diff changeset
86 }
anatofuz
parents:
diff changeset
87
anatofuz
parents:
diff changeset
88 namespace numeric {
anatofuz
parents:
diff changeset
89 namespace {
anatofuz
parents:
diff changeset
90 op::greater const greater = op::greater();
anatofuz
parents:
diff changeset
91 }
anatofuz
parents:
diff changeset
92
anatofuz
parents:
diff changeset
93 template<typename T, typename U>
anatofuz
parents:
diff changeset
94 int f(T& l, U& r)
anatofuz
parents:
diff changeset
95 { numeric::greater(l, r); }
anatofuz
parents:
diff changeset
96
anatofuz
parents:
diff changeset
97 }
anatofuz
parents:
diff changeset
98 }