summaryrefslogtreecommitdiff
path: root/clang/test/CXX/dcl.dcl/basic.namespace/namespace.def
diff options
context:
space:
mode:
authorZancanaro; Carlo <czan8762@plang3.cs.usyd.edu.au>2012-09-24 09:58:17 +1000
committerZancanaro; Carlo <czan8762@plang3.cs.usyd.edu.au>2012-09-24 09:58:17 +1000
commit222e2a7620e6520ffaf4fc4e69d79c18da31542e (patch)
tree7bfbc05bfa3b41c8f9d2e56d53a0bc3e310df239 /clang/test/CXX/dcl.dcl/basic.namespace/namespace.def
parent3d206f03985b50beacae843d880bccdc91a9f424 (diff)
Add the clang library to the repo (with some of my changes, too).
Diffstat (limited to 'clang/test/CXX/dcl.dcl/basic.namespace/namespace.def')
-rw-r--r--clang/test/CXX/dcl.dcl/basic.namespace/namespace.def/namespace.memdef/p3.cpp93
-rw-r--r--clang/test/CXX/dcl.dcl/basic.namespace/namespace.def/namespace.unnamed/p1.cpp42
-rw-r--r--clang/test/CXX/dcl.dcl/basic.namespace/namespace.def/p1.cpp9
-rw-r--r--clang/test/CXX/dcl.dcl/basic.namespace/namespace.def/p2.cpp24
-rw-r--r--clang/test/CXX/dcl.dcl/basic.namespace/namespace.def/p7.cpp13
-rw-r--r--clang/test/CXX/dcl.dcl/basic.namespace/namespace.def/p8.cpp118
6 files changed, 299 insertions, 0 deletions
diff --git a/clang/test/CXX/dcl.dcl/basic.namespace/namespace.def/namespace.memdef/p3.cpp b/clang/test/CXX/dcl.dcl/basic.namespace/namespace.def/namespace.memdef/p3.cpp
new file mode 100644
index 0000000..069ca0a
--- /dev/null
+++ b/clang/test/CXX/dcl.dcl/basic.namespace/namespace.def/namespace.memdef/p3.cpp
@@ -0,0 +1,93 @@
+// RUN: %clang_cc1 -fsyntax-only %s -verify
+
+// C++'0x [namespace.memdef] p3:
+// Every name first declared in a namespace is a member of that namespace. If
+// a friend declaration in a non-local class first declares a class or
+// function the friend class or function is a member of the innermost
+// enclosing namespace.
+
+namespace N {
+ struct S0 {
+ friend struct F0;
+ friend void f0(int);
+ struct F0 member_func();
+ };
+ struct F0 { };
+ F0 f0() { return S0().member_func(); }
+}
+N::F0 f0_var = N::f0();
+
+// Ensure we can handle attaching friend declarations to an enclosing namespace
+// with multiple contexts.
+namespace N { struct S1 { struct IS1; }; }
+namespace N {
+ struct S1::IS1 {
+ friend struct F1;
+ friend void f1(int);
+ struct F1 member_func();
+ };
+ struct F1 { };
+ F1 f1() { return S1::IS1().member_func(); }
+}
+N::F1 f1_var = N::f1();
+
+// The name of the friend is not found by unqualified lookup (3.4.1) or by
+// qualified lookup (3.4.3) until a matching declaration is provided in that
+// namespace scope (either before or after the class definition granting
+// friendship). If a friend function is called, its name may be found by the
+// name lookup that considers functions from namespaces and classes
+// associated with the types of the function arguments (3.4.2). If the name
+// in a friend declaration is neither qualified nor a template-id and the
+// declaration is a function or an elaborated-type-specifier, the lookup to
+// determine whether the entity has been previously declared shall not
+// consider any scopes outside the innermost enclosing namespace.
+
+template<typename T> struct X0 { };
+struct X1 { };
+
+struct Y {
+ template<typename T> union X0;
+ template<typename T> friend union X0;
+
+ union X1;
+ friend union X1;
+};
+
+namespace N {
+ namespace M {
+ template<typename T> class X;
+ }
+}
+
+namespace N3 {
+ class Y {
+ template<typename T> friend class N::M::X;
+ };
+}
+
+// FIXME: Woefully inadequate for testing
+
+// Friends declared as template-ids aren't subject to the restriction
+// on innermost namespaces.
+// rdar://problem/8552377
+namespace test5 {
+ template <class T> void f(T);
+ namespace ns {
+ class A {
+ friend void f<int>(int);
+ static void foo(); // expected-note 2 {{declared private here}}
+ };
+
+ // Note that this happens without instantiation.
+ template <class T> void f(T) {
+ A::foo(); // expected-error {{'foo' is a private member of 'test5::ns::A'}}
+ }
+ }
+
+ template <class T> void f(T) {
+ ns::A::foo(); // expected-error {{'foo' is a private member of 'test5::ns::A'}}
+ }
+
+ template void f<int>(int);
+ template void f<long>(long); //expected-note {{instantiation}}
+}
diff --git a/clang/test/CXX/dcl.dcl/basic.namespace/namespace.def/namespace.unnamed/p1.cpp b/clang/test/CXX/dcl.dcl/basic.namespace/namespace.def/namespace.unnamed/p1.cpp
new file mode 100644
index 0000000..b4ec585
--- /dev/null
+++ b/clang/test/CXX/dcl.dcl/basic.namespace/namespace.def/namespace.unnamed/p1.cpp
@@ -0,0 +1,42 @@
+// RUN: %clang_cc1 -emit-llvm-only -verify %s
+
+// This lame little test was ripped straight from the standard.
+namespace {
+ int i; // expected-note {{candidate}}
+}
+void test0() { i++; }
+
+namespace A {
+ namespace {
+ int i; // expected-note {{candidate}}
+ int j;
+ }
+ void test1() { i++; }
+}
+
+using namespace A;
+
+void test2() {
+ i++; // expected-error {{reference to 'i' is ambiguous}}
+ A::i++;
+ j++;
+}
+
+
+// Test that all anonymous namespaces in a translation unit are
+// considered the same context.
+namespace {
+ class Test3 {}; // expected-note {{previous definition}}
+}
+namespace {
+ class Test3 {}; // expected-error {{redefinition of 'Test3'}}
+}
+
+namespace test4 {
+ namespace {
+ class Test4 {}; // expected-note {{previous definition}}
+ }
+ namespace {
+ class Test4 {}; // expected-error {{redefinition of 'Test4'}}
+ }
+}
diff --git a/clang/test/CXX/dcl.dcl/basic.namespace/namespace.def/p1.cpp b/clang/test/CXX/dcl.dcl/basic.namespace/namespace.def/p1.cpp
new file mode 100644
index 0000000..6ffa873
--- /dev/null
+++ b/clang/test/CXX/dcl.dcl/basic.namespace/namespace.def/p1.cpp
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++98 -pedantic %s
+
+// Intentionally compiled as C++03 to test the extension warning.
+
+namespace a {} // original
+namespace a {} // ext
+inline namespace b {} // inline original expected-warning {{inline namespaces are}}
+inline namespace b {} // inline ext expected-warning {{inline namespaces are}}
+inline namespace {} // inline unnamed expected-warning {{inline namespaces are}}
diff --git a/clang/test/CXX/dcl.dcl/basic.namespace/namespace.def/p2.cpp b/clang/test/CXX/dcl.dcl/basic.namespace/namespace.def/p2.cpp
new file mode 100644
index 0000000..411c16c
--- /dev/null
+++ b/clang/test/CXX/dcl.dcl/basic.namespace/namespace.def/p2.cpp
@@ -0,0 +1,24 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+// PR8430
+namespace N {
+ class A { };
+}
+
+namespace M { }
+
+using namespace M;
+
+namespace N {
+ namespace M {
+ }
+}
+
+namespace M {
+ namespace N {
+ }
+}
+
+namespace N {
+ A *getA();
+}
diff --git a/clang/test/CXX/dcl.dcl/basic.namespace/namespace.def/p7.cpp b/clang/test/CXX/dcl.dcl/basic.namespace/namespace.def/p7.cpp
new file mode 100644
index 0000000..98d12f9
--- /dev/null
+++ b/clang/test/CXX/dcl.dcl/basic.namespace/namespace.def/p7.cpp
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
+
+namespace NIL {} // expected-note {{previous definition}}
+inline namespace NIL {} // expected-error {{cannot be reopened as inline}}
+inline namespace IL {} // expected-note {{previous definition}}
+namespace IL {} // expected-warning{{inline namespace cannot be re-opened as a non-inline namespace}}
+
+namespace {} // expected-note {{previous definition}}
+inline namespace {} // expected-error {{cannot be reopened as inline}}
+namespace X {
+ inline namespace {} // expected-note {{previous definition}}
+ namespace {} // expected-error {{cannot be reopened as non-inline}}
+}
diff --git a/clang/test/CXX/dcl.dcl/basic.namespace/namespace.def/p8.cpp b/clang/test/CXX/dcl.dcl/basic.namespace/namespace.def/p8.cpp
new file mode 100644
index 0000000..3bc4856
--- /dev/null
+++ b/clang/test/CXX/dcl.dcl/basic.namespace/namespace.def/p8.cpp
@@ -0,0 +1,118 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
+
+// Fun things you can do with inline namespaces:
+
+inline namespace X {
+ void f1();
+
+ inline namespace Y {
+ void f2();
+
+ template <typename T> class C {};
+ }
+
+ // Specialize and partially specialize somewhere else.
+ template <> class C<int> {};
+ template <typename T> class C<T*> {};
+}
+
+// Qualified and unqualified lookup as if member of enclosing NS.
+void foo1() {
+ f1();
+ ::f1();
+ X::f1();
+ Y::f1(); // expected-error {{no member named 'f1' in namespace 'X::Y'}}
+
+ f2();
+ ::f2();
+ X::f2();
+ Y::f2();
+}
+
+template <> class C<float> {};
+template <typename T> class C<T&> {};
+
+template class C<double>;
+
+
+// As well as all the fun with ADL.
+
+namespace ADL {
+ struct Outer {};
+
+ inline namespace IL {
+ struct Inner {};
+
+ void fo(Outer);
+ }
+
+ void fi(Inner);
+
+ inline namespace IL2 {
+ void fi2(Inner);
+ }
+}
+
+void foo2() {
+ ADL::Outer o;
+ ADL::Inner i;
+ fo(o);
+ fi(i);
+ fi2(i);
+}
+
+// Let's not forget overload sets.
+struct Distinct {};
+inline namespace Over {
+ void over(Distinct);
+}
+void over(int);
+
+void foo3() {
+ Distinct d;
+ ::over(d);
+}
+
+// Don't forget to do correct lookup for redeclarations.
+namespace redecl { inline namespace n1 {
+
+ template <class Tp> class allocator;
+
+ template <>
+ class allocator<void>
+ {
+ public:
+ typedef const void* const_pointer;
+ };
+
+ template <class Tp>
+ class allocator
+ {
+ public:
+ typedef Tp& reference;
+
+ void allocate(allocator<void>::const_pointer = 0);
+ };
+
+} }
+
+// Normal redeclarations (not for explicit instantiations or
+// specializations) are distinct in an inline namespace vs. not in an
+// inline namespace.
+namespace redecl2 {
+ inline namespace n1 {
+ void f(int) { }
+ struct X1 { };
+ template<typename T> void f(T) { }
+ template<typename T> struct X2 { };
+ int i = 71;
+ enum E { e };
+ }
+
+ void f(int) { }
+ struct X1 { };
+ template<typename T> void f(T) { }
+ template<typename T> struct X2 { };
+ int i = 71;
+ enum E { e };
+}