diff options
Diffstat (limited to 'clang/test/CXX/class/class.local')
-rw-r--r-- | clang/test/CXX/class/class.local/p1-0x.cpp | 18 | ||||
-rw-r--r-- | clang/test/CXX/class/class.local/p1.cpp | 18 | ||||
-rw-r--r-- | clang/test/CXX/class/class.local/p2.cpp | 11 | ||||
-rw-r--r-- | clang/test/CXX/class/class.local/p3.cpp | 30 | ||||
-rw-r--r-- | clang/test/CXX/class/class.local/p4.cpp | 10 |
5 files changed, 87 insertions, 0 deletions
diff --git a/clang/test/CXX/class/class.local/p1-0x.cpp b/clang/test/CXX/class/class.local/p1-0x.cpp new file mode 100644 index 0000000..49125f5 --- /dev/null +++ b/clang/test/CXX/class/class.local/p1-0x.cpp @@ -0,0 +1,18 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s + +void f() { + int x = 3; // expected-note{{'x' declared here}} + const int c = 2; + struct C { + int& x2 = x; // expected-error{{reference to local variable 'x' declared in enclosing function 'f'}} + int cc = c; + }; + (void)[]() mutable { + int x = 3; // expected-note{{'x' declared here}} + struct C { + int& x2 = x; // expected-error{{reference to local variable 'x' declared in enclosing lambda expression}} + }; + }; + C(); +} + diff --git a/clang/test/CXX/class/class.local/p1.cpp b/clang/test/CXX/class/class.local/p1.cpp new file mode 100644 index 0000000..62ade5c --- /dev/null +++ b/clang/test/CXX/class/class.local/p1.cpp @@ -0,0 +1,18 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +int x; +void f() +{ + static int s; + int x; // expected-note{{'x' declared here}} + extern int g(); + + struct local { + int g() { return x; } // expected-error{{reference to local variable 'x' declared in enclosing function 'f'}} + int h() { return s; } + int k() { return :: x; } + int l() { return g(); } + }; +} + +local* p = 0; // expected-error{{unknown type name 'local'}} diff --git a/clang/test/CXX/class/class.local/p2.cpp b/clang/test/CXX/class/class.local/p2.cpp new file mode 100644 index 0000000..db4c90f --- /dev/null +++ b/clang/test/CXX/class/class.local/p2.cpp @@ -0,0 +1,11 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +struct A { }; + +void f() { + struct B : private A {}; // expected-note{{declared private here}} + + B b; + + A *a = &b; // expected-error{{cannot cast 'B' to its private base class 'A'}} +} diff --git a/clang/test/CXX/class/class.local/p3.cpp b/clang/test/CXX/class/class.local/p3.cpp new file mode 100644 index 0000000..3753790 --- /dev/null +++ b/clang/test/CXX/class/class.local/p3.cpp @@ -0,0 +1,30 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +void f1() { + struct X { + struct Y; + }; + + struct X::Y { + void f() {} + }; +} + +void f2() { + struct X { + struct Y; + + struct Y { + void f() {} + }; + }; +} + +// A class nested within a local class is a local class. +void f3(int a) { // expected-note{{'a' declared here}} + struct X { + struct Y { + int f() { return a; } // expected-error{{reference to local variable 'a' declared in enclosing function 'f3'}} + }; + }; +} diff --git a/clang/test/CXX/class/class.local/p4.cpp b/clang/test/CXX/class/class.local/p4.cpp new file mode 100644 index 0000000..d780744 --- /dev/null +++ b/clang/test/CXX/class/class.local/p4.cpp @@ -0,0 +1,10 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +void f() { + struct X { + static int a; // expected-error {{static data member 'a' not allowed in local class 'X'}} + int b; + + static void f() { } + }; +} |