We would crash trying to treat a property member as a field. These
shoudl be forbidden anyway, reject programs which contain them.
This fixes PR21840.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@224193
91177308-0d34-0410-b5e6-
96231b3b80d8
"expected name of accessor method">;
def err_ms_property_expected_comma_or_rparen : Error<
"expected ',' or ')' at end of property accessor list">;
+def err_ms_property_initializer : Error<
+ "property declaration cannot have an in-class initializer">;
/// C++ Templates
def err_expected_template : Error<"expected template">;
Diag(ConsumeToken(), diag::err_default_special_members);
return ExprError();
}
-
+ }
+ if (const auto *PD = dyn_cast_or_null<MSPropertyDecl>(D)) {
+ Diag(Tok, diag::err_ms_property_initializer) << PD;
+ return ExprError();
}
return ParseInitializer();
}
// Pop the notional constructor scope we created earlier.
PopFunctionScopeInfo(nullptr, D);
- FieldDecl *FD = cast<FieldDecl>(D);
- assert(FD->getInClassInitStyle() != ICIS_NoInit &&
+ FieldDecl *FD = dyn_cast<FieldDecl>(D);
+ assert((isa<MSPropertyDecl>(D) || FD->getInClassInitStyle() != ICIS_NoInit) &&
"must set init style when field is created");
if (!InitExpr) {
- FD->setInvalidDecl();
- FD->removeInClassInitializer();
+ D->setInvalidDecl();
+ if (FD)
+ FD->removeInClassInitializer();
return;
}
__declspec(property(get=GetV,)) int V10; // expected-error {{expected 'get' or 'put' in property declaration}}
__declspec(property(get=GetV,put=SetV)) int V11; // no-warning
__declspec(property(get=GetV,put=SetV,get=GetV)) int V12; // expected-error {{property declaration specifies 'get' accessor twice}}
+ __declspec(property(get=GetV)) int V13 = 3; // expected-error {{property declaration cannot have an in-class initializer}}
int GetV() { return 123; }
void SetV(int v) {}