return *I;
}
+/// getNonFieldDeclScope - Retrieves the innermost scope, starting
+/// from S, where a non-field would be declared. This routine copes
+/// with the difference between C and C++ scoping rules in structs and
+/// unions. For example, the following code is well-formed in C but
+/// ill-formed in C++:
+/// @code
+/// struct S6 {
+/// enum { BAR } e;
+/// };
+///
+/// void test_S6() {
+/// struct S6 a;
+/// a.e = BAR;
+/// }
+/// @endcode
+/// For the declaration of BAR, this routine will return a different
+/// scope. The scope S will be the scope of the unnamed enumeration
+/// within S6. In C++, this routine will return the scope associated
+/// with S6, because the enumeration's scope is a transparent
+/// context but structures can contain non-field names. In C, this
+/// routine will return the translation unit scope, since the
+/// enumeration's scope is a transparent context and structures cannot
+/// contain non-field names.
+Scope *Sema::getNonFieldDeclScope(Scope *S) {
+ while (((S->getFlags() & Scope::DeclScope) == 0) ||
+ (S->getEntity() &&
+ ((DeclContext *)S->getEntity())->isTransparentContext()) ||
+ (S->isClassScope() && !getLangOptions().CPlusPlus))
+ S = S->getParent();
+ return S;
+}
+
/// LookupDecl - Look up the inner-most declaration in the specified
/// namespace. NamespaceNameOnly - during lookup only namespace names
/// are considered as required in C++ [basic.lookup.udir] 3.4.6.p1
// Find the scope where we'll be declaring the tag.
while (S->isClassScope() ||
(getLangOptions().CPlusPlus && S->isFunctionPrototypeScope()) ||
- ((S->getFlags() & Scope::DeclScope) == 0))
+ ((S->getFlags() & Scope::DeclScope) == 0) ||
+ (S->getEntity() &&
+ ((DeclContext *)S->getEntity())->isTransparentContext()))
S = S->getParent();
}
// If this has an identifier, add it to the scope stack.
if (Name) {
- // The scope passed in may not be a decl scope. Zip up the scope tree until
- // we find one that is.
- while ((S->getFlags() & Scope::DeclScope) == 0)
- S = S->getParent();
+ S = getNonFieldDeclScope(S);
// Add it to the decl chain.
if (LexicalContext != CurContext) {
// The scope passed in may not be a decl scope. Zip up the scope tree until
// we find one that is.
- while ((S->getFlags() & Scope::DeclScope) == 0)
- S = S->getParent();
+ S = getNonFieldDeclScope(S);
// Verify that there isn't already something declared with this name in this
// scope.
--- /dev/null
+// RUN: clang -fsyntax-only -verify %s
+// FIXME: must also compile as Objective-C++
+
+// <rdar://problem/6487662>
+typedef struct objc_selector *SEL;
+typedef signed char BOOL;
+typedef unsigned int NSUInteger;
+typedef struct _NSZone NSZone;
+@class NSInvocation, NSMethodSignature, NSCoder, NSString, NSEnumerator;
+@protocol NSObject
+- (BOOL)isEqual:(id)object;
+- (BOOL)respondsToSelector:(SEL)aSelector;
+@end
+@protocol NSCopying
+- (id)copyWithZone:(NSZone *)zone;
+@end
+@protocol NSMutableCopying
+- (id)mutableCopyWithZone:(NSZone *)zone;
+@end
+@protocol NSCoding
+- (void)encodeWithCoder:(NSCoder *)aCoder;
+@end
+@interface NSObject <NSObject> {}
+@end
+@class NSString, NSData;
+typedef struct _NSPoint {}
+NSRange;
+@interface NSString : NSObject <NSCopying, NSMutableCopying, NSCoding>
+- (NSUInteger)length;
+@end
+@interface NSMutableString : NSString
+- (void)replaceCharactersInRange:(NSRange)range withString:(NSString *)aString;
+@end
+@class NSArray, NSDictionary, NSMapTable;
+@interface NSResponder : NSObject <NSCoding> {}
+@end
+@protocol NSAnimatablePropertyContainer
+- (id)animator;
+@end
+extern NSString *NSAnimationTriggerOrderIn ;
+@interface NSView : NSResponder <NSAnimatablePropertyContainer> {
+ struct __VFlags2 {} _vFlags2;
+}
+@end
+@class NSAttributedString, NSEvent, NSFont, NSFormatter, NSImage, NSMenu, NSText, NSView;
+@interface FooiagramView : NSView {
+id _delegate;
+}
+@end
+@class FooiagramView;
+@interface _FooiagramViewReserved : NSObject {
+@public
+ NSMutableString *_typeToSelectString;
+ struct _FooiagramViewFlags {
+ unsigned int delegateRespondsToPrintInfoForBarView : 1;
+ } _dvFlags;
+}
+@end
+extern _FooiagramViewReserved *_FooiagramViewBarViewReserved(FooiagramView *BarView);
+@interface FooiagramView (FooiagramViewPrivate)
++ (Class)_defaultBarToolManagerClass;
+@end
+@implementation FooiagramView
+static NSMapTable *_defaultMenuForClass = 0;
+- (void)setDelegate:(id)delegate {
+ if (_delegate != delegate) {
+ struct _FooiagramViewFlags *dvFlags =
+ &_FooiagramViewBarViewReserved(self)->_dvFlags;
+ if (_delegate != ((void *)0)) {
+ dvFlags->delegateRespondsToPrintInfoForBarView = [_delegate respondsToSelector:@selector(printInfoForBarView:)];
+ }
+ }
+}
+@end
+
+// <rdar://problem/6487684>
+@interface WizKing_MIKeep {
+struct __LoreStuffNode *_historyStuff;
+}
+@end
+typedef struct __LoreStuffNode {} LoreStuffNode;
+@implementation WizKing_MIKeep
+- init {
+ LoreStuffNode *node;
+ node = &(_historyStuff[1]);
+}
+@end
+
+// <rdar://problem/6487702>
+typedef long unsigned int __darwin_size_t;
+typedef __darwin_size_t size_t;
+void *memset(void *, int, size_t);
+@class NSString, NSURL, NSError;
+@interface OingoWerdnaPeon : NSObject {}
+@end typedef enum {
+OingoPT_SmashOK, OingoPT_NoSuchFile, }
+OingoWerdnaPeonIOMethod;
+@interface OingoWerdnaPeonSmashDrivel : NSObject <NSCopying> {}
+@end
+@interface OingoBoingoContraptionPeon : OingoWerdnaPeon {
+struct _OingoBoingoContraptionPeonFlags {}
+_nfttFlags;
+}
+@end
+@implementation OingoBoingoContraptionPeon
++ (void)initialize {}
+- (id)initWithSmashDrivel:(OingoWerdnaPeonSmashDrivel *)info {
+ if (self != ((void *)0)) {
+ (void)memset(&_nfttFlags, 0, sizeof(struct _OingoBoingoContraptionPeonFlags));
+ }
+}
+@end
+
+@interface Blah {
+ struct X {
+ int x;
+ } value;
+}
+@end
+
+@implementation Blah
+- (int)getValue {
+ struct X *xp = &value;
+ return xp->x;
+}
+@end