[PATCH] D46846: [Attr] Fix printing attrs for enum forward decl at file scope

2018-05-14 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added a comment.

Clang's current behavior is observably wrong in MS compatibility mode. For 
example:

  namespace N {
enum E *p;
exterm E e; // ok, finds E injected into scope by previous declaration
  }
  N::E e; // error, no E in N!
  namespace N {
extern E e; // error, no E in N!
  }

Please add something like the above to the test suite, to make sure we don't 
regress this (in some existing `-fms-compatibility` test for enum forward 
declarations).


https://reviews.llvm.org/D46846



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D46846: [Attr] Fix printing attrs for enum forward decl at file scope

2018-05-14 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny created this revision.
jdenny added reviewers: aaron.ballman, rsmith, hfinkel.

For example, given:

  enum __attribute__((deprecated)) T *p;

-ast-print produced:

  enum T *p;

The trouble was that the EnumDecl node was suppressed, as revealed by
-ast-dump.  The suppression of the EnumDecl was intentional in
r116122, but I don't understand why.  The suppression isn't needed for
the test suite to behave.


https://reviews.llvm.org/D46846

Files:
  lib/Sema/SemaDecl.cpp
  test/Sema/ast-print.c


Index: test/Sema/ast-print.c
===
--- test/Sema/ast-print.c
+++ test/Sema/ast-print.c
@@ -4,6 +4,8 @@
 // RUN: echo >> %t.c "// expected""-warning@* {{use of GNU old-style field 
designator extension}}"
 // RUN: echo >> %t.c "// expected""-warning@* {{'EnumWithAttributes' is 
deprecated}}"
 // RUN: echo >> %t.c "// expected""-note@* {{'EnumWithAttributes' has been 
explicitly marked deprecated here}}"
+// RUN: echo >> %t.c "// expected""-warning@* {{'EnumWithAttributes2' is 
deprecated}}"
+// RUN: echo >> %t.c "// expected""-note@* {{'EnumWithAttributes2' has been 
explicitly marked deprecated here}}"
 // RUN: echo >> %t.c "// expected""-warning@* {{'EnumWithAttributes3' is 
deprecated}}"
 // RUN: echo >> %t.c "// expected""-note@* {{'EnumWithAttributes3' has been 
explicitly marked deprecated here}}"
 // RUN: %clang_cc1 -fsyntax-only %t.c -verify
@@ -86,8 +88,7 @@
   // CHECK-NEXT: } *EnumWithAttributesPtr;
 } __attribute__((deprecated)) *EnumWithAttributesPtr; // expected-note 
{{'EnumWithAttributes' has been explicitly marked deprecated here}}
 
-// FIXME: If enum is forward-declared at file scope, attributes are lost.
-// CHECK-LABEL: enum EnumWithAttributes2 *EnumWithAttributes2Ptr;
+// CHECK-LABEL: enum __attribute__((deprecated(""))) EnumWithAttributes2 
*EnumWithAttributes2Ptr;
 // expected-warning@+2 {{'EnumWithAttributes2' is deprecated}}
 // expected-note@+1 {{'EnumWithAttributes2' has been explicitly marked 
deprecated here}}
 enum __attribute__((deprecated)) EnumWithAttributes2 *EnumWithAttributes2Ptr;
Index: lib/Sema/SemaDecl.cpp
===
--- lib/Sema/SemaDecl.cpp
+++ lib/Sema/SemaDecl.cpp
@@ -14273,7 +14273,6 @@
   // PrevDecl.
   TagDecl *New;
 
-  bool IsForwardReference = false;
   if (Kind == TTK_Enum) {
 // FIXME: Tag decls should be chained to any simultaneous vardecls, e.g.:
 // enum X { A, B, C } D;D should chain to X.
@@ -14303,12 +14302,6 @@
 else if (getLangOpts().CPlusPlus)
   DiagID = diag::err_forward_ref_enum;
 Diag(Loc, DiagID);
-
-// If this is a forward-declared reference to an enumeration, make a
-// note of it; we won't actually be introducing the declaration into
-// the declaration context.
-if (TUK == TUK_Reference)
-  IsForwardReference = true;
   }
 }
 
@@ -14466,9 +14459,7 @@
 PushOnScopeChains(New, EnclosingScope, /* AddToContext = */ false);
   } else if (Name) {
 S = getNonFieldDeclScope(S);
-PushOnScopeChains(New, S, !IsForwardReference);
-if (IsForwardReference)
-  SearchDC->makeDeclVisibleInContext(New);
+PushOnScopeChains(New, S, true);
   } else {
 CurContext->addDecl(New);
   }


Index: test/Sema/ast-print.c
===
--- test/Sema/ast-print.c
+++ test/Sema/ast-print.c
@@ -4,6 +4,8 @@
 // RUN: echo >> %t.c "// expected""-warning@* {{use of GNU old-style field designator extension}}"
 // RUN: echo >> %t.c "// expected""-warning@* {{'EnumWithAttributes' is deprecated}}"
 // RUN: echo >> %t.c "// expected""-note@* {{'EnumWithAttributes' has been explicitly marked deprecated here}}"
+// RUN: echo >> %t.c "// expected""-warning@* {{'EnumWithAttributes2' is deprecated}}"
+// RUN: echo >> %t.c "// expected""-note@* {{'EnumWithAttributes2' has been explicitly marked deprecated here}}"
 // RUN: echo >> %t.c "// expected""-warning@* {{'EnumWithAttributes3' is deprecated}}"
 // RUN: echo >> %t.c "// expected""-note@* {{'EnumWithAttributes3' has been explicitly marked deprecated here}}"
 // RUN: %clang_cc1 -fsyntax-only %t.c -verify
@@ -86,8 +88,7 @@
   // CHECK-NEXT: } *EnumWithAttributesPtr;
 } __attribute__((deprecated)) *EnumWithAttributesPtr; // expected-note {{'EnumWithAttributes' has been explicitly marked deprecated here}}
 
-// FIXME: If enum is forward-declared at file scope, attributes are lost.
-// CHECK-LABEL: enum EnumWithAttributes2 *EnumWithAttributes2Ptr;
+// CHECK-LABEL: enum __attribute__((deprecated(""))) EnumWithAttributes2 *EnumWithAttributes2Ptr;
 // expected-warning@+2 {{'EnumWithAttributes2' is deprecated}}
 // expected-note@+1 {{'EnumWithAttributes2' has been explicitly marked deprecated here}}
 enum __attribute__((deprecated)) EnumWithAttributes2 *EnumWithAttributes2Ptr;
Index: lib/Sema/SemaDecl.cpp