diff options
Diffstat (limited to 'lldb/packages/Python/lldbsuite/test')
6 files changed, 169 insertions, 2 deletions
diff --git a/lldb/packages/Python/lldbsuite/test/lang/cpp/namespace/Makefile b/lldb/packages/Python/lldbsuite/test/lang/cpp/namespace/Makefile index 314f1cb2f07..7dd5eb4c11f 100644 --- a/lldb/packages/Python/lldbsuite/test/lang/cpp/namespace/Makefile +++ b/lldb/packages/Python/lldbsuite/test/lang/cpp/namespace/Makefile @@ -1,5 +1,5 @@ LEVEL = ../../../make -CXX_SOURCES := main.cpp +CXX_SOURCES := main.cpp ns.cpp ns2.cpp ns3.cpp include $(LEVEL)/Makefile.rules diff --git a/lldb/packages/Python/lldbsuite/test/lang/cpp/namespace/main.cpp b/lldb/packages/Python/lldbsuite/test/lang/cpp/namespace/main.cpp index 4de7a1ada8d..560ec40f473 100644 --- a/lldb/packages/Python/lldbsuite/test/lang/cpp/namespace/main.cpp +++ b/lldb/packages/Python/lldbsuite/test/lang/cpp/namespace/main.cpp @@ -8,6 +8,7 @@ //===----------------------------------------------------------------------===// #include <cstdarg> +#include "ns.h" namespace { typedef unsigned int my_uint_t; @@ -80,7 +81,6 @@ namespace ns2 { int value = 200; } -#include <stdio.h> void test_namespace_scopes() { do { using namespace ns1; @@ -113,5 +113,12 @@ int Foo::myfunc(int a) int main (int argc, char const *argv[]) { + test_lookup_at_global_scope(); + test_lookup_at_file_scope(); + A::test_lookup_at_ns_scope(); + A::B::test_lookup_at_nested_ns_scope(); + A::B::test_lookup_at_nested_ns_scope_after_using(); + test_lookup_before_using_directive(); + test_lookup_after_using_directive(); return Foo::myfunc(12); } diff --git a/lldb/packages/Python/lldbsuite/test/lang/cpp/namespace/ns.cpp b/lldb/packages/Python/lldbsuite/test/lang/cpp/namespace/ns.cpp new file mode 100644 index 00000000000..9e5637d02b4 --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/lang/cpp/namespace/ns.cpp @@ -0,0 +1,32 @@ +//===-- ns.cpp ------------------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "ns.h" + +int foo() +{ + printf("global foo()\n"); + return 42; +} +int func() +{ + printf("global func()\n"); + return 1; +} +int func(int a) +{ + printf("global func(int)\n"); + return a + 1; +} +void test_lookup_at_global_scope() +{ + // BP_global_scope + printf("at global scope: foo() = %d\n", foo()); // eval foo(), exp: 42 + printf("at global scope: func() = %d\n", func()); // eval func(), exp: 1 +} diff --git a/lldb/packages/Python/lldbsuite/test/lang/cpp/namespace/ns.h b/lldb/packages/Python/lldbsuite/test/lang/cpp/namespace/ns.h new file mode 100644 index 00000000000..a07b600efa3 --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/lang/cpp/namespace/ns.h @@ -0,0 +1,36 @@ +//===-- ns.h ------------------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include <stdio.h> + +void test_lookup_at_global_scope(); +void test_lookup_at_file_scope(); +void test_lookup_before_using_directive(); +void test_lookup_after_using_directive(); +int func(int a); +namespace A { + int foo(); + int func(int a); + inline int func() + { + printf("A::func()\n"); + return 3; + } + inline int func2() + { + printf("A::func2()\n"); + return 3; + } + void test_lookup_at_ns_scope(); + namespace B { + int func(); + void test_lookup_at_nested_ns_scope(); + void test_lookup_at_nested_ns_scope_after_using(); + } +} diff --git a/lldb/packages/Python/lldbsuite/test/lang/cpp/namespace/ns2.cpp b/lldb/packages/Python/lldbsuite/test/lang/cpp/namespace/ns2.cpp new file mode 100644 index 00000000000..04046ad9b7f --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/lang/cpp/namespace/ns2.cpp @@ -0,0 +1,65 @@ +//===-- ns2.cpp ------------------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "ns.h" + +static int func() +{ + printf("static m2.cpp func()\n"); + return 2; +} +void test_lookup_at_file_scope() +{ + // BP_file_scope + printf("at file scope: func() = %d\n", func()); // eval func(), exp: 2 + printf("at file scope: func(10) = %d\n", func(10)); // eval func(10), exp: 11 +} +namespace A { + namespace B { + int func() + { + printf("A::B::func()\n"); + return 4; + } + void test_lookup_at_nested_ns_scope() + { + // BP_nested_ns_scope + printf("at nested ns scope: func() = %d\n", func()); // eval func(), exp: 4 + + //printf("func(10) = %d\n", func(10)); // eval func(10), exp: 13 + // NOTE: Under the rules of C++, this test would normally get an error + // because A::B::func() hides A::func(), but lldb intentionally + // disobeys these rules so that the intended overload can be found + // by only removing duplicates if they have the same type. + } + void test_lookup_at_nested_ns_scope_after_using() + { + // BP_nested_ns_scope_after_using + using A::func; + printf("at nested ns scope after using: func() = %d\n", func()); // eval func(), exp: 3 + } + } +} +int A::foo() +{ + printf("A::foo()\n"); + return 42; +} +int A::func(int a) +{ + printf("A::func(int)\n"); + return a + 3; +} +void A::test_lookup_at_ns_scope() +{ + // BP_ns_scope + printf("at nested ns scope: func() = %d\n", func()); // eval func(), exp: 3 + printf("at nested ns scope: func(10) = %d\n", func(10)); // eval func(10), exp: 13 + printf("at nested ns scope: foo() = %d\n", foo()); // eval foo(), exp: 42 +} diff --git a/lldb/packages/Python/lldbsuite/test/lang/cpp/namespace/ns3.cpp b/lldb/packages/Python/lldbsuite/test/lang/cpp/namespace/ns3.cpp new file mode 100644 index 00000000000..10b0df78422 --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/lang/cpp/namespace/ns3.cpp @@ -0,0 +1,27 @@ +//===-- ns3.cpp ------------------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "ns.h" +extern int func(); + +// Note: the following function must be before the using. +void test_lookup_before_using_directive() +{ + // BP_before_using_directive + printf("before using directive: func() = %d\n", func()); // eval func(), exp: 1 +} +using namespace A; +void test_lookup_after_using_directive() +{ + // BP_after_using_directive + //printf("func() = %d\n", func()); // eval func(), exp: error, amiguous + printf("after using directive: func2() = %d\n", func2()); // eval func2(), exp: 3 + printf("after using directive: ::func() = %d\n", ::func()); // eval ::func(), exp: 1 + printf("after using directive: B::func() = %d\n", B::func()); // eval B::func(), exp: 4 +} |