Skip to content

Commit

Permalink
Hyperobject struct members must be initialized
Browse files Browse the repository at this point in the history
  • Loading branch information
VoxSciurorum committed Sep 6, 2024
1 parent 8fab1be commit d2bea2a
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 9 deletions.
2 changes: 1 addition & 1 deletion clang/include/clang/Basic/DiagnosticSemaKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -5896,7 +5896,7 @@ def note_deleted_special_member_class_subobject : Note<
def note_deleted_default_ctor_uninit_field : Note<
"%select{default constructor of|constructor inherited by}0 "
"%1 is implicitly deleted because field %2 of "
"%select{reference|const-qualified}4 type %3 would not be initialized">;
"%select{reference|const-qualified|reducer}4 type %3 would not be initialized">;
def note_deleted_default_ctor_all_const : Note<
"%select{default constructor of|constructor inherited by}0 "
"%1 is implicitly deleted because all "
Expand Down
4 changes: 2 additions & 2 deletions clang/lib/AST/DeclCXX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1088,8 +1088,8 @@ void CXXRecordDecl::addedMember(Decl *D) {
// suppress hyperobject registration.
data().Aggregate = false;
data().HasIrrelevantDestructor = false;
data().HasTrivialSpecialMembers &= ~SMF_Destructor;
data().HasTrivialSpecialMembersForCall &= ~SMF_Destructor;
data().HasTrivialSpecialMembers &= ~SMF_All;
data().HasTrivialSpecialMembersForCall &= ~SMF_All;
}

if (!Field->hasInClassInitializer() && !Field->isMutable()) {
Expand Down
6 changes: 6 additions & 0 deletions clang/lib/Sema/SemaDeclCXX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9595,6 +9595,12 @@ bool SpecialMemberDeletionInfo::shouldDeleteForField(FieldDecl *FD) {
<< !!ICI << MD->getParent() << FD << FieldType << /*Reference*/0;
return true;
}
if (FieldType->isHyperobjectType() && !FD->hasInClassInitializer()) {
if (Diagnose)
S.Diag(FD->getLocation(), diag::note_deleted_default_ctor_uninit_field)
<< !!ICI << MD->getParent() << FD << FieldType << /*Reducer*/2;
return true;
}
// C++11 [class.ctor]p5 (modified by DR2394): any non-variant non-static
// data member of const-qualified type (or array thereof) with no
// brace-or-equal-initializer is not const-default-constructible.
Expand Down
2 changes: 1 addition & 1 deletion clang/test/Cilk/hyper-errors.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// RUN: %clang_cc1 %s -x c++ -fopencilk -verify -fsyntax-only
struct C { int _Hyperobject c; };
struct C { int _Hyperobject c = 0; };
struct C _Hyperobject c; // expected-error{{type 'struct C', which contains a hyperobject, may not be a hyperobject}}
long _Hyperobject d; // expected-note{{previous definition}}
void f() {
Expand Down
14 changes: 11 additions & 3 deletions clang/test/Cilk/hyper-init-error.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
// RUN: %clang_cc1 %s -fopencilk -verify -fsyntax-only
extern void id(void *), reduce(void *, void *);
struct one_hyperobject {
struct uninit_hyperobject {
// expected-note@-1{{implicit copy}}
// expected-note@-2{{implicit move}}
// expected-note@-3{{implicit default}}
int _Hyperobject(id, reduce) field;
// expected-note@-1{{would not be initialized}}
};

// braced initializer lists do not work
one_hyperobject h1 = {-1};
uninit_hyperobject h1 = {-1};
// expected-error@-1{{no matching constructor for initialization}}

one_hyperobject h2;
uninit_hyperobject h2;
// expected-error@-1{{implicitly-deleted default constructor}}

struct init_hyperobject {
int _Hyperobject(id, reduce) field = 0;
};

init_hyperobject h3;
2 changes: 1 addition & 1 deletion clang/test/Cilk/hyper-register.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
struct S {
static void identity(void *);
static void reduce(void *, void *);
int _Hyperobject(identity, reduce) member;
int _Hyperobject(identity, reduce) member = 0;
S();
~S();
};
Expand Down
3 changes: 2 additions & 1 deletion clang/test/Cilk/hyper-template-errors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ struct reducer
// expected-error@-1{{type 'long _Hyperobject', which contains a hyperobject, may not be a hyperobject}}
// expected-error@-2{{type 'reducer<char>', which contains a hyperobject, may not be a hyperobject}}
// expected-error@-3{{type 'wrap<int _Hyperobject>', which contains a hyperobject, may not be a hyperobject}}
int _Hyperobject value2;
int _Hyperobject value2 = 0;
reducer();
};

reducer<long _Hyperobject> r_hl; // expected-note{{in instantiation}}
Expand Down

0 comments on commit d2bea2a

Please sign in to comment.