]> granicus.if.org Git - clang/commit
Improve our handling of tag decls in function prototypes
authorReid Kleckner <rnk@google.com>
Wed, 14 Dec 2016 17:44:11 +0000 (17:44 +0000)
committerReid Kleckner <rnk@google.com>
Wed, 14 Dec 2016 17:44:11 +0000 (17:44 +0000)
commitd4596ba82e3d0226f0e524c89875f7a622088754
tree5579eaa0d3eda921430b49226bb2586bec0c1921
parentda7dce191aa2f209af1ca8e034a4f5d826ca4e3c
Improve our handling of tag decls in function prototypes

r289225 broke AST invariants by reparenting enumerators into function
decl contexts. This improves things by only reparenting TagDecls while
also attempting to preserve the lexical declcontext chain. The
interesting example here is:
  int f(struct S { enum E { a = 1 } b; } c);

The semantic contexts of E and S should be f, and the lexical context of
S should be f and the lexical context of E should be S. We didn't do
that with r289225, but now we should.

This change should also improve our behavior on this example:
  void f() {
    extern void ext(struct S { } o);
    // S injected here
  }

Before r289225 we would only remove 'S' from the surrounding tag
injection context if it was the TU, but now we properly reparent S from
f to ext.

Fixes PR31366

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@289678 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Sema/SemaDecl.cpp
test/CodeGen/decl-in-prototype.c
test/Sema/decl-in-prototype.c