// NOTE: VC++ treats enums as signed, avoid using the StorageClass enum
unsigned SClass : 2;
bool IsInline : 1;
+ bool IsVirtual : 1;
+ bool IsPure : 1;
// Move to DeclGroup when it is implemented.
SourceLocation TypeSpecStartLoc;
: ValueDecl(DK, DC, L, N, T, PrevDecl),
DeclContext(DK),
ParamInfo(0), Body(0), PreviousDeclaration(0),
- SClass(S), IsInline(isInline), TypeSpecStartLoc(TSSL) {}
+ SClass(S), IsInline(isInline), IsVirtual(false), IsPure(false),
+ TypeSpecStartLoc(TSSL) {}
virtual ~FunctionDecl();
virtual void Destroy(ASTContext& C);
bool isThisDeclarationADefinition() const { return Body != 0; }
void setBody(Stmt *B) { Body = B; }
-
+
+ bool isVirtual() { return IsVirtual; }
+ void setVirtual() { IsVirtual = true; }
+
+ bool isPure() { return IsPure; }
+ void setPure() { IsPure = true; }
+
/// getPreviousDeclaration - Return the previous declaration of this
/// function.
const FunctionDecl *getPreviousDeclaration() const {
"bit-field %0 with non-integral type")
DIAG(err_member_initialization, ERROR,
"%0 can only be initialized if it is a static const integral data member")
+DIAG(err_member_function_initialization, ERROR,
+ "initializer on function does not look like a pure-specifier")
+DIAG(err_non_virtual_pure, ERROR,
+ "%0 is not virtual and cannot be declared pure")
DIAG(err_implicit_object_parameter_init, ERROR,
"cannot initialize object parameter of type %0 with an expression of type %1")
Diag(DS.getVirtualSpecLoc(), diag::err_virtual_non_function);
InvalidDecl = true;
} else {
+ cast<CXXMethodDecl>(Member)->setVirtual();
CXXRecordDecl *CurClass = cast<CXXRecordDecl>(CurContext);
CurClass->setAggregate(false);
CurClass->setPOD(false);
}
}
+ // FIXME: The above definition of virtual is not sufficient. A function is
+ // also virtual if it overrides an already virtual function. This is important
+ // to do here because it decides the validity of a pure specifier.
+
if (BitWidth) {
// C++ 9.6p2: Only when declaring an unnamed bit-field may the
// constant-expression be a value equal to zero.
}
} else {
- // not static member.
- Diag(Loc, diag::err_member_initialization)
- << Name << Init->getSourceRange();
- InvalidDecl = true;
+ // not static member. perhaps virtual function?
+ if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(Member)) {
+ IntegerLiteral *IL;
+ if ((IL = dyn_cast<IntegerLiteral>(Init)) && IL->getValue() == 0 &&
+ Context.getCanonicalType(IL->getType()) == Context.IntTy) {
+ if (MD->isVirtual())
+ MD->setPure();
+ else {
+ Diag(Loc, diag::err_non_virtual_pure)
+ << Name << Init->getSourceRange();
+ InvalidDecl = true;
+ }
+ } else {
+ Diag(Loc, diag::err_member_function_initialization)
+ << Name << Init->getSourceRange();
+ InvalidDecl = true;
+ }
+ } else {
+ Diag(Loc, diag::err_member_initialization)
+ << Name << Init->getSourceRange();
+ InvalidDecl = true;
+ }
}
}
--- /dev/null
+// RUN: clang -fsyntax-only -verify %s
+
+class A {
+ virtual void f();
+ virtual void g() = 0;
+
+ void h() = 0; // expected-error {{'h' is not virtual and cannot be declared pure}}
+ void i() = 1; // expected-error {{initializer on function does not look like a pure-specifier}}
+ void j() = 0u; // expected-error {{initializer on function does not look like a pure-specifier}}
+
+public:
+ A(int);
+};
+
+class B : public A {
+ // Needs to recognize that overridden function is virtual.
+ //void g() = 0;
+
+ // Needs to recognize that function does not override.
+ //void g(int) = 0;
+};
+
+// Needs to recognize invalid uses of abstract classes.
+/*
+A fn(A)
+{
+ A a;
+ static_cast<A>(0);
+ try {
+ } catch(A) {
+ }
+}
+*/