This is an archive of the discontinued LLVM Phabricator instance.

[AST] Fix loss of enum forward decl from decl context
ClosedPublic

Authored by jdenny on May 14 2018, 1:39 PM.

Details

Summary

For example, given:

enum __attribute__((deprecated)) T *p;

-ast-print produced:

enum T *p;

The attribute was lost because the enum forward decl was lost.

Another example is the loss of enum forward decls from C++ namespaces
(in MS compatibility mode).

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.

Diff Detail

Event Timeline

jdenny created this revision.May 14 2018, 1:39 PM

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).

jdenny updated this revision to Diff 147130.May 16 2018, 10:55 AM
jdenny retitled this revision from [Attr] Fix printing attrs for enum forward decl at file scope to [Attr] Fix loss of enum forward decl from decl context.
jdenny edited the summary of this revision. (Show Details)

Made the suggested change. Thanks!

jdenny retitled this revision from [Attr] Fix loss of enum forward decl from decl context to [AST] Fix loss of enum forward decl from decl context.May 16 2018, 11:04 AM
jdenny set the repository for this revision to rC Clang.May 24 2018, 12:35 PM
jdenny updated this revision to Diff 149021.May 29 2018, 7:33 PM

Rebased. Ping.

rsmith accepted this revision.May 29 2018, 8:36 PM
This revision is now accepted and ready to land.May 29 2018, 8:36 PM
This revision was automatically updated to reflect the committed changes.