1 //===-- ns2.cpp ------------------------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #include "ns.h"
10 
11 static int func()
12 {
13   std::printf("static m2.cpp func()\n");
14   return 2;
15 }
16 void test_lookup_at_file_scope()
17 {
18   // BP_file_scope
19   std::printf("at file scope: func() = %d\n", func()); // eval func(), exp: 2
20   std::printf("at file scope: func(10) = %d\n", func(10)); // eval func(10), exp: 11
21 }
22 namespace A {
23     namespace B {
24         int func()
25         {
26           std::printf("A::B::func()\n");
27           return 4;
28         }
29         void test_lookup_at_nested_ns_scope()
30         {
31             // BP_nested_ns_scope
32             std::printf("at nested ns scope: func() = %d\n", func()); // eval func(), exp: 4
33 
34             //printf("func(10) = %d\n", func(10)); // eval func(10), exp: 13
35             // NOTE: Under the rules of C++, this test would normally get an error
36             // because A::B::func() hides A::func(), but lldb intentionally
37             // disobeys these rules so that the intended overload can be found
38             // by only removing duplicates if they have the same type.
39         }
40         void test_lookup_at_nested_ns_scope_after_using()
41         {
42             // BP_nested_ns_scope_after_using
43             using A::func;
44             std::printf("at nested ns scope after using: func() = %d\n", func()); // eval func(), exp: 3
45         }
46     }
47 }
48 int A::foo()
49 {
50   std::printf("A::foo()\n");
51   return 42;
52 }
53 int A::func(int a)
54 {
55   std::printf("A::func(int)\n");
56   return a + 3;
57 }
58 void A::test_lookup_at_ns_scope()
59 {
60   // BP_ns_scope
61   std::printf("at nested ns scope: func() = %d\n", func()); // eval func(), exp: 3
62   std::printf("at nested ns scope: func(10) = %d\n", func(10)); // eval func(10), exp: 13
63   std::printf("at nested ns scope: foo() = %d\n", foo()); // eval foo(), exp: 42
64 }
65