unsigned getNumInits() const { return InitExprs.size(); }
- const Expr* getInit(unsigned Init) const {
+ const Expr *getInit(unsigned Init) const {
assert(Init < getNumInits() && "Initializer access out of range!");
return cast_or_null<Expr>(InitExprs[Init]);
}
- Expr* getInit(unsigned Init) {
+ Expr *getInit(unsigned Init) {
assert(Init < getNumInits() && "Initializer access out of range!");
return cast_or_null<Expr>(InitExprs[Init]);
}
/// no declarator (e.g. "struct foo;") is parsed.
Decl *Sema::ParsedFreeStandingDeclSpec(Scope *S, AccessSpecifier AS,
DeclSpec &DS) {
- // FIXME: Error on auto/register at file scope
// FIXME: Error on inline/virtual/explicit
// FIXME: Warn on useless __thread
// FIXME: Warn on useless const/volatile
}
NamedDecl*
-Sema::ActOnVariableDeclarator(Scope* S, Declarator& D, DeclContext* DC,
+Sema::ActOnVariableDeclarator(Scope *S, Declarator &D, DeclContext *DC,
QualType R, TypeSourceInfo *TInfo,
LookupResult &Previous,
MultiTemplateParamsArg TemplateParamLists,
ProcessDeclAttributes(S, NewVD, D);
// Handle GNU asm-label extension (encoded as an attribute).
- if (Expr *E = (Expr*) D.getAsmLabel()) {
+ if (Expr *E = (Expr*)D.getAsmLabel()) {
// The parser guarantees this is a string.
StringLiteral *SE = cast<StringLiteral>(E);
NewVD->addAttr(::new (Context) AsmLabelAttr(SE->getStrTokenLoc(0),
// This includes arrays of objects with address space qualifiers, but not
// automatic variables that point to other address spaces.
// ISO/IEC TR 18037 S5.1.2
- if (NewVD->hasLocalStorage() && (T.getAddressSpace() != 0)) {
+ if (NewVD->hasLocalStorage() && T.getAddressSpace() != 0) {
Diag(NewVD->getLocation(), diag::err_as_qualified_auto_decl);
return NewVD->setInvalidDecl();
}
if (NewVD->hasLocalStorage() && T.isObjCGCWeak()
&& !NewVD->hasAttr<BlocksAttr>())
Diag(NewVD->getLocation(), diag::warn_attribute_weak_on_local);
-
+
bool isVM = T->isVariablyModifiedType();
if (isVM || NewVD->hasAttr<CleanupAttr>() ||
NewVD->hasAttr<BlocksAttr>())
Init->setType(DclT);
}
+
+ // If this variable is a local declaration with record type, make sure it
+ // doesn't have a flexible member initialization. We only support this as a
+ // global/static definition.
+ if (VDecl->hasLocalStorage())
+ if (const RecordType *RT = VDecl->getType()->getAs<RecordType>())
+ if (RT->getDecl()->hasFlexibleArrayMember() && isa<InitListExpr>(Init)) {
+ Diag(VDecl->getLocation(), diag::err_nonstatic_flexible_variable);
+ VDecl->setInvalidDecl();
+ }
+
// Check any implicit conversions within the expression.
CheckImplicitConversions(Init, VDecl->getLocation());
struct one x2 = { 5, 1, 2, 3 }; // expected-warning{{flexible array initialization is a GNU extension}}
void test() {
- struct one x3 = {5, {1, 2, 3}}; // expected-warning{{flexible array initialization is a GNU extension}}
+ struct one x3 = {5, {1, 2, 3}}; // \
+ // expected-warning{{flexible array initialization is a GNU extension}} \
+ // expected-error {{non-static initialization of a variable with flexible array member}}
}
struct foo {
int e;
struct X xs[]; // expected-warning{{'struct X' may not be used as an array element due to flexible array member}}
};
+
+
+// PR8217
+struct PR8217a {
+ int i;
+ char v[];
+};
+
+void PR8217() {
+ struct PR8217a foo1 = { .i = 0, .v = "foo" }; // expected-error {{non-static initialization of a variable with flexible array member}}
+ struct PR8217a foo2 = { .i = 0 }; // expected-error {{non-static initialization of a variable with flexible array member}}
+ struct PR8217a foo3 = { .i = 0, .v = { 'b', 'a', 'r', '\0' } }; // expected-error {{non-static initialization of a variable with flexible array member}}
+ struct PR8217a bar;
+}
+