mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-08 02:14:43 +00:00
Bug 1226376 - Part 1: Allow non-trivial constexpr constructors in MOZ_TRIVIAL_CTOR_DTOR classes, r=ehsan
This commit is contained in:
parent
90d5395e71
commit
2b12d59585
@ -1200,7 +1200,11 @@ void DiagnosticsMatcher::TrivialCtorDtorChecker::run(
|
||||
"class %0 must have trivial constructors and destructors");
|
||||
const CXXRecordDecl *node = Result.Nodes.getNodeAs<CXXRecordDecl>("node");
|
||||
|
||||
bool badCtor = !node->hasTrivialDefaultConstructor();
|
||||
// We need to accept non-constexpr trivial constructors as well. This occurs
|
||||
// when a struct contains pod members, which will not be initialized. As
|
||||
// constexpr values are initialized, the constructor is non-constexpr.
|
||||
bool badCtor = !(node->hasConstexprDefaultConstructor() ||
|
||||
node->hasTrivialDefaultConstructor());
|
||||
bool badDtor = !node->hasTrivialDestructor();
|
||||
if (badCtor || badDtor)
|
||||
Diag.Report(node->getLocStart(), errorID) << node;
|
||||
|
@ -5,6 +5,15 @@ struct MOZ_TRIVIAL_CTOR_DTOR EmptyClass{};
|
||||
template <class T>
|
||||
struct MOZ_TRIVIAL_CTOR_DTOR TemplateEmptyClass{};
|
||||
|
||||
struct MOZ_TRIVIAL_CTOR_DTOR NonEmptyClass {
|
||||
void *m;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct MOZ_TRIVIAL_CTOR_DTOR TemplateNonEmptyClass {
|
||||
T* m;
|
||||
};
|
||||
|
||||
struct MOZ_TRIVIAL_CTOR_DTOR BadUserDefinedCtor { // expected-error {{class 'BadUserDefinedCtor' must have trivial constructors and destructors}}
|
||||
BadUserDefinedCtor() {}
|
||||
};
|
||||
@ -17,7 +26,7 @@ struct MOZ_TRIVIAL_CTOR_DTOR BadVirtualDtor { // expected-error {{class 'BadVirt
|
||||
virtual ~BadVirtualDtor() {}
|
||||
};
|
||||
|
||||
struct MOZ_TRIVIAL_CTOR_DTOR BadVirtualMember { // expected-error {{class 'BadVirtualMember' must have trivial constructors and destructors}}
|
||||
struct MOZ_TRIVIAL_CTOR_DTOR OkVirtualMember {
|
||||
virtual void f();
|
||||
};
|
||||
|
||||
@ -53,6 +62,22 @@ struct MOZ_TRIVIAL_CTOR_DTOR BadNonTrivialDtorInMember { // expected-error {{cla
|
||||
NonTrivialDtor m;
|
||||
};
|
||||
|
||||
struct MOZ_TRIVIAL_CTOR_DTOR BadVirtualMemberInMember { // expected-error {{class 'BadVirtualMemberInMember' must have trivial constructors and destructors}}
|
||||
struct MOZ_TRIVIAL_CTOR_DTOR OkVirtualMemberInMember {
|
||||
VirtualMember m;
|
||||
};
|
||||
|
||||
struct MOZ_TRIVIAL_CTOR_DTOR OkConstExprConstructor {
|
||||
constexpr OkConstExprConstructor() {}
|
||||
};
|
||||
|
||||
struct MOZ_TRIVIAL_CTOR_DTOR OkConstExprConstructorInMember {
|
||||
OkConstExprConstructor m;
|
||||
};
|
||||
|
||||
// XXX: This error is unfortunate, but is unlikely to come up in real code.
|
||||
// In this situation, it should be possible to define a constexpr constructor
|
||||
// which explicitly initializes the members.
|
||||
struct MOZ_TRIVIAL_CTOR_DTOR BadUnfortunateError { // expected-error {{class 'BadUnfortunateError' must have trivial constructors and destructors}}
|
||||
OkConstExprConstructor m;
|
||||
void *n;
|
||||
};
|
||||
|
@ -462,10 +462,12 @@
|
||||
* intended to prevent introducing static initializers. This attribute
|
||||
* currently makes it a compile-time error to instantiate these classes
|
||||
* anywhere other than at the global scope, or as a static member of a class.
|
||||
* In non-debug mode, it also prohibits non-trivial constructors and
|
||||
* destructors.
|
||||
* MOZ_TRIVIAL_CTOR_DTOR: Applies to all classes that must have both a trivial
|
||||
* constructor and a trivial destructor. Setting this attribute on a class
|
||||
* makes it a compile-time error for that class to get a non-trivial
|
||||
* constructor or destructor for any reason.
|
||||
* or constexpr constructor and a trivial destructor. Setting this attribute
|
||||
* on a class makes it a compile-time error for that class to get a
|
||||
* non-trivial constructor or destructor for any reason.
|
||||
* MOZ_HEAP_ALLOCATOR: Applies to any function. This indicates that the return
|
||||
* value is allocated on the heap, and will as a result check such allocations
|
||||
* during MOZ_STACK_CLASS and MOZ_NONHEAP_CLASS annotation checking.
|
||||
|
Loading…
Reference in New Issue
Block a user