[libc][NFC] Remove extra ; in exhaustive_test.h. (#124216)
[llvm-project.git] / lldb / test / API / lang / cpp / namespace / main.cpp
blob2edfab8437639e6a01599e3750201c46eab775f8
1 #include <cstdarg>
2 #include <cstdlib>
3 #include "ns.h"
5 namespace {
6 typedef unsigned int my_uint_t;
7 int i; // Find the line number for anonymous namespace variable i.
9 int myanonfunc (int a)
11 return a + a;
14 int
15 variadic_sum (int arg_count...)
17 int sum = 0;
18 std::va_list args;
19 va_start(args, arg_count);
21 for (int i = 0; i < arg_count; i++)
22 sum += va_arg(args, int);
24 va_end(args);
25 return sum;
29 namespace A {
30 typedef unsigned int uint_t;
31 namespace B {
32 typedef unsigned int uint_t;
33 int j; // Find the line number for named namespace variable j.
34 int myfunc (int a);
35 int myfunc2(int a)
37 return a + 2;
39 float myfunc (float f)
41 return f - 2.0;
46 namespace Y
48 typedef unsigned int uint_t;
49 using A::B::j;
50 int foo;
53 using A::B::j; // using declaration
55 namespace Foo = A::B; // namespace alias
57 using Foo::myfunc; // using declaration
59 using namespace Foo; // using directive
61 namespace A {
62 namespace B {
63 using namespace Y;
64 int k;
68 namespace ns1 {
69 int value = 100;
72 namespace ns2 {
73 int value = 200;
76 void test_namespace_scopes() {
77 do {
78 using namespace ns1;
79 printf("ns1::value = %d\n", value); // Evaluate ns1::value
80 } while(0);
82 do {
83 using namespace ns2;
84 printf("ns2::value = %d\n", value); // Evaluate ns2::value
85 } while(0);
88 int Foo::myfunc(int a)
90 test_namespace_scopes();
92 ::my_uint_t anon_uint = 0;
93 A::uint_t a_uint = 1;
94 B::uint_t b_uint = 2;
95 Y::uint_t y_uint = 3;
96 i = 3;
97 j = 4;
98 printf("::i=%d\n", ::i);
99 printf("A::B::j=%d\n", A::B::j);
100 printf("variadic_sum=%d\n", variadic_sum(3, 1, 2, 3));
101 myanonfunc(3);
102 return myfunc2(3) + j + i + a + 2 + anon_uint + a_uint + b_uint + y_uint; // Set break point at this line.
105 namespace B {
106 struct Bar {
107 int x() { return 42; }
109 Bar bar;
110 } // namespace B
112 namespace A::B {
113 struct Bar {
114 int y() { return 137; }
116 } // namespace A::B
118 namespace NS1::NS2 {
119 struct Foo {
120 int bar() { return -2; }
122 } // namespace NS1::NS2
124 namespace NS2 {
125 struct Foo {
126 int bar() { return -3; }
128 } // namespace NS2
130 namespace {
131 namespace InAnon1 {
132 int var_in_anon = 10;
133 namespace {
134 inline namespace inline_ns {
135 int var_in_anon = 15;
136 namespace InAnon2 {
137 namespace {
138 int var_in_anon = 5;
139 } // namespace
140 } // namespace InAnon2
141 } // namespace inline_ns
142 } // namespace
143 } // namespace InAnon1
144 } // namespace
147 main (int argc, char const *argv[])
149 test_lookup_at_global_scope();
150 test_lookup_at_file_scope();
151 A::test_lookup_at_ns_scope();
152 A::B::test_lookup_at_nested_ns_scope();
153 A::B::test_lookup_at_nested_ns_scope_after_using();
154 test_lookup_before_using_directive();
155 test_lookup_after_using_directive();
156 ::B::Bar bb;
157 A::B::Bar ab;
158 return Foo::myfunc(12) + bb.x() + ab.y() + NS1::NS2::Foo{}.bar() +
159 NS2::Foo{}.bar() + InAnon1::var_in_anon +
160 InAnon1::InAnon2::var_in_anon + InAnon1::inline_ns::var_in_anon;