]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - packages/Python/lldbsuite/test/lang/cpp/namespace/ns2.cpp
Vendor import of lldb trunk r256945:
[FreeBSD/FreeBSD.git] / packages / Python / lldbsuite / test / lang / cpp / namespace / ns2.cpp
1 //===-- ns2.cpp ------------------------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #include "ns.h"
11
12 static int func()
13 {
14     printf("static m2.cpp func()\n");
15     return 2;
16 }
17 void test_lookup_at_file_scope()
18 {
19     // BP_file_scope
20     printf("at file scope: func() = %d\n", func()); // eval func(), exp: 2
21     printf("at file scope: func(10) = %d\n", func(10)); // eval func(10), exp: 11
22 }
23 namespace A {
24     namespace B {
25         int func()
26         {
27             printf("A::B::func()\n");
28             return 4;
29         }
30         void test_lookup_at_nested_ns_scope()
31         {
32             // BP_nested_ns_scope
33             printf("at nested ns scope: func() = %d\n", func()); // eval func(), exp: 4
34
35             //printf("func(10) = %d\n", func(10)); // eval func(10), exp: 13
36             // NOTE: Under the rules of C++, this test would normally get an error
37             // because A::B::func() hides A::func(), but lldb intentionally
38             // disobeys these rules so that the intended overload can be found
39             // by only removing duplicates if they have the same type.
40         }
41         void test_lookup_at_nested_ns_scope_after_using()
42         {
43             // BP_nested_ns_scope_after_using
44             using A::func;
45             printf("at nested ns scope after using: func() = %d\n", func()); // eval func(), exp: 3
46         }
47     }
48 }
49 int A::foo()
50 {
51     printf("A::foo()\n");
52     return 42;
53 }
54 int A::func(int a)
55 {
56     printf("A::func(int)\n");
57     return a + 3;
58 }
59 void A::test_lookup_at_ns_scope()
60 {
61     // BP_ns_scope
62     printf("at nested ns scope: func() = %d\n", func()); // eval func(), exp: 3
63     printf("at nested ns scope: func(10) = %d\n", func(10)); // eval func(10), exp: 13
64     printf("at nested ns scope: foo() = %d\n", foo()); // eval foo(), exp: 42
65 }