summaryrefslogtreecommitdiffstats
path: root/clang/test/Sema/nested-redef.c
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2009-01-08 20:45:30 +0000
committerDouglas Gregor <dgregor@apple.com>2009-01-08 20:45:30 +0000
commit82ac25e4a725517675f7cfdd464b46555f70a9f1 (patch)
treed41a91c7b5cc7907d884f306277811c5e895d65f /clang/test/Sema/nested-redef.c
parent40e1fd1f79ff6e2050bfcc4b49d1755d65451c0f (diff)
downloadbcm5719-llvm-82ac25e4a725517675f7cfdd464b46555f70a9f1.tar.gz
bcm5719-llvm-82ac25e4a725517675f7cfdd464b46555f70a9f1.zip
Unify the code for defining tags in C and C++, so that we always
introduce a Scope for the body of a tag. This reduces the number of semantic differences between C and C++ structs and unions, and will help with other features (e.g., anonymous unions) in C. Some important points: - Fields are now in the "member" namespace (IDNS_Member), to keep them separate from tags and ordinary names in C. See the new test in Sema/member-reference.c for an example of why this matters. In C++, ordinary and member name lookup will find members in both the ordinary and member namespace, so the difference between IDNS_Member and IDNS_Ordinary is erased by Sema::LookupDecl (but only in C++!). - We always introduce a Scope and push a DeclContext when we're defining a tag, in both C and C++. Previously, we had different actions and different Scope/CurContext behavior for enums, C structs/unions, and C++ structs/unions/classes. Now, it's one pair of actions. (Yay!) There's still some fuzziness in the handling of struct/union/enum definitions within other struct/union/enum definitions in C. We'll need to do some more cleanup to eliminate some reliance on CurContext before we can solve this issue for real. What we want is for something like this: struct X { struct T { int x; } t; }; to introduce T into translation unit scope (placing it at the appropriate point in the IdentifierResolver chain, too), but it should still have struct X as its lexical declaration context. PushOnScopeChains isn't smart enough to do that yet, though, so there's a FIXME test in nested-redef.c llvm-svn: 61940
Diffstat (limited to 'clang/test/Sema/nested-redef.c')
-rw-r--r--clang/test/Sema/nested-redef.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/clang/test/Sema/nested-redef.c b/clang/test/Sema/nested-redef.c
new file mode 100644
index 00000000000..83cd4209675
--- /dev/null
+++ b/clang/test/Sema/nested-redef.c
@@ -0,0 +1,22 @@
+// RUN: clang -fsyntax-only -verify %s
+struct X { // expected-note{{previous definition is here}}
+ struct X { } x; // expected-error{{nested redefinition of 'X'}}
+};
+
+struct Y { };
+void f(void) {
+ struct Y { }; // okay: this is a different Y
+}
+
+struct T;
+struct Z {
+ struct T { int x; } t;
+ struct U { int x; } u;
+};
+
+void f2(void) {
+ struct T t;
+ // FIXME: this is well-formed, but Clang breaks on it struct U u;
+}
+
+
OpenPOWER on IntegriCloud