Support anonymous unions and structs in C++ code.


Testcase for GNU anonymous struct extension:

union U {
  struct {
    //- @field defines/binding StructField
    int field;
  //- @field ref StructField
  static_assert(&U::field != nullptr, "");

Similar with s/struct/union for standard anonymous unions, which should also be tested in other kinds of scopes (e.g., in function scope).

jdennett created this task.Via WebNov 23 2015, 3:58 PM
jdennett claimed this task.
jdennett added a project: C++.
jdennett added a subscriber: jdennett.

One possible patch for


< const NamedDecl *const TargetDecl = FoundDecl;

const NamedDecl *TargetDecl = FoundDecl;
if (const auto* IFD = dyn_cast<clang::IndirectFieldDecl>(FoundDecl)) {
  // An IndirectFieldDecl is just an alias; we want to record this as a
  // reference to the underlying entity.
  // TODO(jdennett): Would this be better done in BuildNodeIdForDecl?
  TargetDecl = IFD->getAnonField();
jdennett added a comment.Via WebNov 24 2015, 2:10 PM

Patch D617 was committed as rK412c6703723c: "C++ Indexer: Support anonymous structs, a GNU extension."

Tests for anonymous unions are a work in progress.

See also T79, "Capture named edges implied by IndirectFieldDecls for fields of anonymous records."

schroederc changed the visibility of this Maniphest Task from "All Users" to "Public (No Login Required)".Via WebMay 16 2016, 3:28 PM

Add Comment