void ParseObjCTypeQualifierList(ObjCDeclSpec &DS);
void ParseEnumSpecifier(SourceLocation TagLoc, DeclSpec &DS,
- AccessSpecifier AS = AS_none);
+ const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(), AccessSpecifier AS = AS_none);
void ParseEnumBody(SourceLocation StartLoc, DeclPtrTy TagDecl);
void ParseStructUnionBody(SourceLocation StartLoc, unsigned TagType,
DeclPtrTy TagDecl);
// Parse this as a tag as if the missing tag were present.
if (TagKind == tok::kw_enum)
- ParseEnumSpecifier(Loc, DS, AS);
+ ParseEnumSpecifier(Loc, DS, TemplateInfo, AS);
else
ParseClassSpecifier(TagKind, Loc, DS, TemplateInfo, AS);
return true;
// enum-specifier:
case tok::kw_enum:
ConsumeToken();
- ParseEnumSpecifier(Loc, DS, AS);
+ ParseEnumSpecifier(Loc, DS, TemplateInfo, AS);
continue;
// cv-qualifier:
// enum-specifier:
case tok::kw_enum:
ConsumeToken();
- ParseEnumSpecifier(Loc, DS);
+ ParseEnumSpecifier(Loc, DS, TemplateInfo, AS_none);
return true;
// cv-qualifier:
/// [C++] 'enum' '::'[opt] nested-name-specifier[opt] identifier
///
void Parser::ParseEnumSpecifier(SourceLocation StartLoc, DeclSpec &DS,
+ const ParsedTemplateInfo &TemplateInfo,
AccessSpecifier AS) {
// Parse the tag portion of this.
if (Tok.is(tok::code_completion)) {
return;
}
+ // enums cannot be templates.
+ if (TemplateInfo.Kind != ParsedTemplateInfo::NonTemplate) {
+ Diag(Tok, diag::err_enum_template);
+
+ // Skip the rest of this declarator, up until the comma or semicolon.
+ SkipUntil(tok::comma, true);
+ return;
+ }
+
// If an identifier is present, consume and remember it.
IdentifierInfo *Name = 0;
SourceLocation NameLoc;
llvm::APSInt EnumVal(IntWidth);
QualType EltTy;
if (Val) {
- if (Enum->isDependentType())
+ if (Enum->isDependentType() || Val->isTypeDependent())
EltTy = Context.DependentTy;
else {
// C99 6.7.2.2p2: Make sure we have an integer constant expression.
SourceLocation ExpLoc;
- if (VerifyIntegerConstantExpression(Val, &EnumVal)) {
+ if (!Val->isValueDependent() &&
+ VerifyIntegerConstantExpression(Val, &EnumVal)) {
Val = 0;
} else {
if (!getLangOptions().CPlusPlus) {
}
}
- if (!Enum->isDependentType()) {
+ if (!EltTy->isDependentType()) {
// Make the enumerator value match the signedness and size of the
// enumerator's type.
EnumVal.zextOrTrunc(Context.getTypeSize(EltTy));