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
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
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits