forked from OSchip/llvm-project
[Sema] Unions cannot have virtual functions.
PR: PR23931 Differential Revision: http://reviews.llvm.org/D10752 Reviewed by: rsmith llvm-svn: 240889
This commit is contained in:
parent
21065ec50e
commit
43899d44c2
|
@ -1262,6 +1262,8 @@ def ext_mutable_reference : ExtWarn<
|
|||
def err_mutable_const : Error<"'mutable' and 'const' cannot be mixed">;
|
||||
def err_mutable_nonmember : Error<
|
||||
"'mutable' can only be applied to member variables">;
|
||||
def err_virtual_in_union : Error<
|
||||
"unions cannot have virtual functions">;
|
||||
def err_virtual_non_function : Error<
|
||||
"'virtual' can only appear on non-static member functions">;
|
||||
def err_virtual_out_of_class : Error<
|
||||
|
|
|
@ -7202,6 +7202,11 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator &D, DeclContext *DC,
|
|||
dyn_cast<CXXRecordDecl>(NewFD->getDeclContext())) {
|
||||
if (Parent->isInterface() && cast<CXXMethodDecl>(NewFD)->isUserProvided())
|
||||
NewFD->setPure(true);
|
||||
|
||||
// C++ [class.union]p2
|
||||
// A union can have member functions, but not virtual functions.
|
||||
if (isVirtual && Parent->isUnion())
|
||||
Diag(D.getDeclSpec().getVirtualSpecLoc(), diag::err_virtual_in_union);
|
||||
}
|
||||
|
||||
SetNestedNameSpecifier(NewFD, D);
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
// RUN: %clang_cc1 -fsyntax-only -verify %s
|
||||
|
||||
union x {
|
||||
virtual void f(); // expected-error {{unions cannot have virtual functions}}
|
||||
};
|
Loading…
Reference in New Issue