// C++0x override control
def ext_override_control_keyword : Extension<
"'%0' keyword accepted as a C++0x extension">, InGroup<CXX0x>;
+def ext_override_inline: Extension<
+ "'%0' keyword only allowed in declarations, allowed as an extension">;
def err_duplicate_virt_specifier : Error<
"class member already marked '%0'">;
void PopParsingClass();
Decl *ParseCXXInlineMethodDef(AccessSpecifier AS, Declarator &D,
- const ParsedTemplateInfo &TemplateInfo);
+ const ParsedTemplateInfo &TemplateInfo,
+ const VirtSpecifiers& VS);
void ParseLexedMethodDeclarations(ParsingClass &Class);
void ParseLexedMethodDeclaration(LateParsedMethodDeclaration &LM);
void ParseLexedMethodDefs(ParsingClass &Class);
bool isNewSpecified() const { return Specifiers & VS_New; }
SourceLocation getNewLoc() const { return VS_newLoc; }
+ void clear() { Specifiers = 0; }
+
static const char *getSpecifierName(Specifier VS);
private:
/// Declarator is a well formed C++ inline method definition. Now lex its body
/// and store its tokens for parsing after the C++ class is complete.
Decl *Parser::ParseCXXInlineMethodDef(AccessSpecifier AS, Declarator &D,
- const ParsedTemplateInfo &TemplateInfo) {
+ const ParsedTemplateInfo &TemplateInfo,
+ const VirtSpecifiers& VS) {
assert(D.isFunctionDeclarator() && "This isn't a function declarator!");
assert((Tok.is(tok::l_brace) || Tok.is(tok::colon) || Tok.is(tok::kw_try)) &&
"Current token not a '{', ':' or 'try'!");
// FIXME: Friend templates
FnD = Actions.ActOnFriendFunctionDecl(getCurScope(), D, true,
move(TemplateParams));
- else // FIXME: pass template information through
+ else { // FIXME: pass template information through
+ if (VS.isOverrideSpecified())
+ Diag(VS.getOverrideLoc(), diag::ext_override_inline) << "override";
+ if (VS.isFinalSpecified())
+ Diag(VS.getFinalLoc(), diag::ext_override_inline) << "final";
+ if (VS.isNewSpecified())
+ Diag(VS.getNewLoc(), diag::ext_override_inline) << "new";
+
FnD = Actions.ActOnCXXMemberDeclarator(getCurScope(), AS, D,
move(TemplateParams), 0,
- VirtSpecifiers(), 0,
- /*IsDefinition*/true);
+ VS, 0, /*IsDefinition*/true);
+ }
HandleMemberFunctionDefaultArgs(D, FnD);
}
ParsingDeclarator DeclaratorInfo(*this, DS, Declarator::MemberContext);
+ VirtSpecifiers VS;
if (Tok.isNot(tok::colon)) {
// Don't parse FOO:BAR as if it were a typo for FOO::BAR.
return;
}
+ ParseOptionalCXX0XVirtSpecifierSeq(VS);
+
// If attributes exist after the declarator, but before an '{', parse them.
MaybeParseGNUAttributes(DeclaratorInfo);
return;
}
- ParseCXXInlineMethodDef(AS, DeclaratorInfo, TemplateInfo);
+ ParseCXXInlineMethodDef(AS, DeclaratorInfo, TemplateInfo, VS);
// Consume the optional ';'
if (Tok.is(tok::semi))
ConsumeToken();
SkipUntil(tok::comma, true, true);
}
- VirtSpecifiers VS;
ParseOptionalCXX0XVirtSpecifierSeq(VS);
// pure-specifier:
// Parse the next declarator.
DeclaratorInfo.clear();
+ VS.clear();
BitfieldSize = 0;
Init = 0;
Deleted = false;
--- /dev/null
+// RUN: %clang_cc1 -fsyntax-only -std=c++0x -pedantic -verify %s
+
+namespace inline_extension {
+ struct Base1 {
+ virtual void f() {}
+ };
+
+ struct B : Base1 {
+ virtual void f() override {} // expected-warning {{'override' keyword only allowed in declarations, allowed as an extension}}
+ virtual void g() final {} // expected-warning {{'final' keyword only allowed in declarations, allowed as an extension}}
+ virtual void h() new {} // expected-warning {{'new' keyword only allowed in declarations, allowed as an extension}}
+ };
+}
+
};
struct Base2 {
+ virtual void e1(), e2();
virtual void f();
};
struct B : Base2 {
+ virtual void e1() override, e2(int); // No error.
virtual void f() override;
void g() override; // expected-error {{only virtual member functions can be marked 'override'}}
int h override; // expected-error {{only virtual member functions can be marked 'override'}}
void g() final; // expected-error {{only virtual member functions can be marked 'final'}}
int h final; // expected-error {{only virtual member functions can be marked 'final'}}
};
+
+namespace inline_extension {
+ struct Base1 {
+ virtual void g() {}
+ };
+
+ struct A : Base1 {
+ virtual void f() new new {} // expected-error {{class member already marked 'new'}}
+ virtual void g() override override {} // expected-error {{class member already marked 'override'}}
+ virtual void h() final final {} // expected-error {{class member already marked 'final'}}
+ };
+
+ struct Base2 {
+ virtual void f();
+ };
+
+ struct B : Base2 {
+ virtual void f() override {}
+ void g() override {} // expected-error {{only virtual member functions can be marked 'override'}}
+ };
+
+ struct C {
+ virtual void f() final {}
+ void g() final {} // expected-error {{only virtual member functions can be marked 'final'}}
+ };
+}