[PATCH] Put types defined in prototype into translation unit context

Serge Pavlov sepavloff at gmail.com
Tue May 27 10:53:14 PDT 2014


If a type is defined in a function prototype, put it into translation unit
rather than current context. This patch fixes PR19018, in which such type
was placed into class context, but as it did not have access specifier,
assertion violation occurred.

http://reviews.llvm.org/D3925

Files:
  lib/Sema/SemaDecl.cpp
  test/SemaCXX/type-definition-in-specifier.cpp

Index: lib/Sema/SemaDecl.cpp
===================================================================
--- lib/Sema/SemaDecl.cpp
+++ lib/Sema/SemaDecl.cpp
@@ -10739,7 +10739,8 @@
       while (isa<RecordDecl>(SearchDC) || isa<EnumDecl>(SearchDC))
         SearchDC = SearchDC->getParent();
     }
-  } else if (S->isFunctionPrototypeScope()) {
+  }
+  if (S->isFunctionPrototypeScope() && TUK == TUK_Definition) {
     // If this is an enum declaration in function prototype scope, set its
     // initial context to the translation unit.
     // FIXME: [citation needed]
Index: test/SemaCXX/type-definition-in-specifier.cpp
===================================================================
--- test/SemaCXX/type-definition-in-specifier.cpp
+++ test/SemaCXX/type-definition-in-specifier.cpp
@@ -23,3 +23,15 @@
 struct S5 { int x; } f1() { return S5(); } // expected-error{{result type}}
 
 void f2(struct S6 { int x; } p); // expected-error{{parameter type}}
+
+struct pr19018 {
+  short foo6 (enum bar0 {qq} bar3); // expected-error{{cannot be defined in a parameter type}}
+};
+
+struct pr19018a {
+  void func1(enum t19018 {qq} x); // expected-error{{cannot be defined in a parameter type}}
+  void func2(enum t19018 {qq} x); // expected-error{{cannot be defined in a parameter type}}
+  void func3(enum {qq} x);        // expected-error{{cannot be defined in a parameter type}}
+  void func4(struct t19018 {int qq;} x);  // expected-error{{cannot be defined in a parameter type}}
+  void func5(struct {int qq;} x); // expected-error{{cannot be defined in a parameter type}}
+};
\ No newline at end of file
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D3925.9841.patch
Type: text/x-patch
Size: 1606 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140527/3bc955ae/attachment.bin>


More information about the cfe-commits mailing list