Skip to content

PR for llvm/llvm-project#62266 #441

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -821,6 +821,10 @@ Bug Fixes to C++ Support
- Do not hide templated base members introduced via using-decl in derived class
(useful specially for constrained members). (`#50886 <https://github.com/llvm/llvm-project/issues/50886>`_)

- Fix default member initializers sometimes being ignored when performing
parenthesized aggregate initialization of templated types.
(`#62266 <https://github.com/llvm/llvm-project/issues/62266>`_)

Concepts Specific Fixes:

- Class member variables are now in scope when parsing a ``requires`` clause.
Expand Down
16 changes: 9 additions & 7 deletions clang/lib/Sema/SemaInit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5348,14 +5348,16 @@ static void TryOrBuildParenListInitialization(
// The remaining elements are initialized with their default member
// initializers, if any
auto *FD = cast<FieldDecl>(SubEntity.getDecl());
if (Expr *ICE = FD->getInClassInitializer(); ICE && !VerifyOnly) {
ExprResult DIE = S.BuildCXXDefaultInitExpr(FD->getLocation(), FD);
if (DIE.isInvalid())
return false;
S.checkInitializerLifetime(SubEntity, DIE.get());
InitExprs.push_back(DIE.get());
if (FD->hasInClassInitializer()) {
if (!VerifyOnly) {
ExprResult DIE = S.BuildCXXDefaultInitExpr(FD->getLocation(), FD);
if (DIE.isInvalid())
return false;
S.checkInitializerLifetime(SubEntity, DIE.get());
InitExprs.push_back(DIE.get());
}
continue;
};
}
}
// Remaining class elements without default member initializers and
// array elements are value initialized:
Expand Down
23 changes: 23 additions & 0 deletions clang/test/CodeGen/paren-list-agg-init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,15 @@ namespace gh61145 {
};
}

namespace gh62266 {
// CHECK-DAG: [[STRUCT_H:%.*H.*]] = type { i32, i32 }
template <int J>
struct H {
int i;
int j = J;
};
}

// CHECK-DAG: [[A1:@.*a1.*]] = internal constant [[STRUCT_A]] { i8 3, double 2.000000e+00 }, align 8
constexpr A a1(3.1, 2.0);
// CHECK-DAG: [[A2:@.*a2.*]] = internal constant [[STRUCT_A]] { i8 99, double 0.000000e+00 }, align 8
Expand Down Expand Up @@ -421,3 +430,17 @@ namespace gh61145 {
make2<0>();
}
}

namespace gh62266 {
// CHECK: define {{.*}} void {{.*foo20.*}}
// CHECK-NEXT: entry:
// CHECK-NEXT: [[H:%.*h.*]] = alloca [[STRUCT_H]], align 4
// CHECK-NEXT: [[I:%.*i.*]] = getelementptr inbounds [[STRUCT_H]], ptr [[H]], i32 0, i32 0
// CHECK-NEXT: store i32 1, ptr [[I]], align 4
// CHECK-NEXT: [[J:%.*j.*]] = getelementptr inbounds [[STRUCT_H]], ptr [[H]], i32 0, i32 1
// CHECK-NEXT: store i32 2, ptr [[J]], align 4
// CHECK-NEXT: ret void
void foo20() {
H<2> h(1);
}
}