diff options
author | Douglas Gregor <dgregor@apple.com> | 2009-01-09 22:42:13 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2009-01-09 22:42:13 +0000 |
commit | 3218c4bb3b5d7250f12420de6db7ef3e3f805a75 (patch) | |
tree | f6826e25245398cff43f0546bbd58b338864fae2 /test/SemaCXX/elaborated-type-specifier.cpp | |
parent | ef64fcfbfb99495d7f9f64c7f0751c2827028733 (diff) |
When we see a reference to a struct, class, or union like "struct X"
that is neither a definition nor a forward declaration and where X has
not yet been declared as a tag, introduce a declaration
into the appropriate scope (which is likely *not* to be the current
scope). The rules for the placement of the declaration differ slightly
in C and C++, so we implement both and test the various corner
cases. This implementation isn't 100% correct due to some lingering
issues with the function prototype scope (for a function parameter
list) not being the same scope as the scope of the function
definition. Testcase is FIXME'd; this probably isn't an important issue.
Addresses <rdar://problem/6484805>.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@62014 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/SemaCXX/elaborated-type-specifier.cpp')
-rw-r--r-- | test/SemaCXX/elaborated-type-specifier.cpp | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/test/SemaCXX/elaborated-type-specifier.cpp b/test/SemaCXX/elaborated-type-specifier.cpp new file mode 100644 index 0000000000..b9ba508789 --- /dev/null +++ b/test/SemaCXX/elaborated-type-specifier.cpp @@ -0,0 +1,48 @@ +// RUN: clang -fsyntax-only -verify %s + +// Test the use of elaborated-type-specifiers to inject the names of +// structs (or classes or unions) into an outer scope as described in +// C++ [basic.scope.pdecl]p5. +typedef struct S1 { + union { + struct S2 *x; + struct S3 *y; + }; +} S1; + +bool test_elab(S1 *s1, struct S2 *s2, struct S3 *s3) { + if (s1->x == s2) return true; + if (s1->y == s3) return true; + return false; +} + +namespace NS { + class X { + public: + void test_elab2(struct S4 *s4); + }; + + void X::test_elab2(S4 *s4) { } +} + +void test_X_elab(NS::X x) { + struct S4 *s4 = 0; + x.test_elab2(s4); // expected-error{{incompatible type passing 'struct S4 *', expected 'struct S4 *'}} +} + +namespace NS { + S4 *get_S4(); +} + +void test_S5_scope() { + S4 *s4; // expected-error{{use of undeclared identifier 'S4'}} +} + +// FIXME: the warning below should be an error! +int test_funcparam_scope(struct S5 * s5) { + struct S5 { int y; } *s5_2 = 0; + if (s5 == s5_2) return 1; // expected-warning {{comparison of distinct pointer types ('struct S5 *' and 'struct S5 *')}} + return 0; +} + + |