]> granicus.if.org Git - clang/commitdiff
Don't a.k.a. through the primary typedef of an anonymous tag decl.
authorJohn McCall <rjmccall@apple.com>
Wed, 13 Jan 2010 22:07:44 +0000 (22:07 +0000)
committerJohn McCall <rjmccall@apple.com>
Wed, 13 Jan 2010 22:07:44 +0000 (22:07 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@93362 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/Sema.cpp
test/Sema/anonymous-struct-union.c
test/Sema/enum.c

index fefe924bc46f7ccfb917807aa636dceaa771d4bb..171101bb96de6e68ae873944756ba108f09eeab6 100644 (file)
@@ -110,6 +110,12 @@ static bool ShouldAKA(ASTContext &Context, QualType QT,
     if (isa<VectorType>(Underlying))
       break;
 
+    // Don't desugar through the primary typedef of an anonymous type.
+    if (isa<TagType>(Underlying) && isa<TypedefType>(QT))
+      if (cast<TagType>(Underlying)->getDecl()->getTypedefForAnonDecl() ==
+          cast<TypedefType>(QT)->getDecl())
+        break;
+
     // Otherwise, we're tearing through something opaque; note that
     // we'll eventually need an a.k.a. clause and keep going.
     AKA = true;
index 47fb2b6fba0927d3202d9db870eac6a0e23cea43..78995a993a4f5116769e9043a0d37d63a0c3d6f7 100644 (file)
@@ -96,3 +96,9 @@ struct s2 {
     int a;
   }
 }; // expected-error{{expected member name or ';' after declaration specifiers}}
+
+// Make sure we don't a.k.a. anonymous structs.
+typedef struct {
+  int x;
+} a_struct;
+int tmp = (a_struct) { .x = 0 }; // expected-error {{incompatible type initializing 'a_struct', expected 'int'}}
index 262cab50a55f095b080cd544e74a910e4e2e71bc..916de41176bce8290d45a0dcc1ebff6ef11de42d 100644 (file)
@@ -84,3 +84,11 @@ enum e1 { YES, NO };
 static enum e1 badfunc(struct s1 *q) {
   return q->bar();
 }
+
+
+// Make sure we don't a.k.a. anonymous enums.
+typedef enum {
+  an_enumerator = 20
+} an_enum;
+// FIXME: why is this only a warning?
+char * s = (an_enum) an_enumerator; // expected-warning {{incompatible integer to pointer conversion initializing 'an_enum', expected 'char *'}}