This revision was automatically updated to reflect the committed changes.
Closed by commit rG7562c64197ac: [Sema] Mark virtual method declaration in
union as invalid (authored by ychen).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D113145/new/
https://reviews.llvm.org/D113145
Files:
clang/lib/Sema/SemaDecl.cpp
clang/test/SemaCXX/PR49534.cpp
clang/test/SemaCXX/virtual-function-in-union.cpp
Index: clang/test/SemaCXX/virtual-function-in-union.cpp
===================================================================
--- clang/test/SemaCXX/virtual-function-in-union.cpp
+++ clang/test/SemaCXX/virtual-function-in-union.cpp
@@ -1,5 +1,8 @@
// RUN: %clang_cc1 -fsyntax-only -verify %s
-union x {
- virtual void f(); // expected-error {{unions cannot have virtual functions}}
+union U {
+ int d;
+ virtual int f() { return d; }; // expected-error {{unions cannot have
virtual functions}}
};
+
+int foo() { U u; return u.d; }
Index: clang/test/SemaCXX/PR49534.cpp
===================================================================
--- clang/test/SemaCXX/PR49534.cpp
+++ clang/test/SemaCXX/PR49534.cpp
@@ -1,6 +1,5 @@
// RUN: %clang_cc1 -x c++ -fsyntax-only %s -verify
static union { // expected-warning {{declaration does not declare
anything}}
- virtual int a(); // expected-error {{unions cannot have virtual functions}} \
- // expected-error {{functions cannot be declared in an
anonymous union}}
+ virtual int a(); // expected-error {{unions cannot have virtual functions}}
};
Index: clang/lib/Sema/SemaDecl.cpp
===================================================================
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -5302,8 +5302,7 @@
// trivial in almost all cases, except if a union member has an in-class
// initializer:
// union { int n = 0; };
- if (!Invalid)
- ActOnUninitializedDecl(Anon);
+ ActOnUninitializedDecl(Anon);
}
Anon->setImplicit();
@@ -9109,8 +9108,10 @@
// C++ [class.union]p2
// A union can have member functions, but not virtual functions.
- if (isVirtual && Parent->isUnion())
+ if (isVirtual && Parent->isUnion()) {
Diag(D.getDeclSpec().getVirtualSpecLoc(), diag::err_virtual_in_union);
+ NewFD->setInvalidDecl();
+ }
}
SetNestedNameSpecifier(*this, NewFD, D);
Index: clang/test/SemaCXX/virtual-function-in-union.cpp
===================================================================
--- clang/test/SemaCXX/virtual-function-in-union.cpp
+++ clang/test/SemaCXX/virtual-function-in-union.cpp
@@ -1,5 +1,8 @@
// RUN: %clang_cc1 -fsyntax-only -verify %s
-union x {
- virtual void f(); // expected-error {{unions cannot have virtual functions}}
+union U {
+ int d;
+ virtual int f() { return d; }; // expected-error {{unions cannot have virtual functions}}
};
+
+int foo() { U u; return u.d; }
Index: clang/test/SemaCXX/PR49534.cpp
===================================================================
--- clang/test/SemaCXX/PR49534.cpp
+++ clang/test/SemaCXX/PR49534.cpp
@@ -1,6 +1,5 @@
// RUN: %clang_cc1 -x c++ -fsyntax-only %s -verify
static union { // expected-warning {{declaration does not declare anything}}
- virtual int a(); // expected-error {{unions cannot have virtual functions}} \
- // expected-error {{functions cannot be declared in an anonymous union}}
+ virtual int a(); // expected-error {{unions cannot have virtual functions}}
};
Index: clang/lib/Sema/SemaDecl.cpp
===================================================================
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -5302,8 +5302,7 @@
// trivial in almost all cases, except if a union member has an in-class
// initializer:
// union { int n = 0; };
- if (!Invalid)
- ActOnUninitializedDecl(Anon);
+ ActOnUninitializedDecl(Anon);
}
Anon->setImplicit();
@@ -9109,8 +9108,10 @@
// C++ [class.union]p2
// A union can have member functions, but not virtual functions.
- if (isVirtual && Parent->isUnion())
+ if (isVirtual && Parent->isUnion()) {
Diag(D.getDeclSpec().getVirtualSpecLoc(), diag::err_virtual_in_union);
+ NewFD->setInvalidDecl();
+ }
}
SetNestedNameSpecifier(*this, NewFD, D);
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits