[all-commits] [llvm/llvm-project] bef345: [clang] Fix default initializers being ignored whe...
Alan Zhao via All-commits
all-commits at lists.llvm.org
Mon May 15 11:04:54 PDT 2023
Branch: refs/heads/release/16.x
Home: https://github.com/llvm/llvm-project
Commit: bef3459fcde7f0be0341a76bcc782799021bae70
https://github.com/llvm/llvm-project/commit/bef3459fcde7f0be0341a76bcc782799021bae70
Author: Alan Zhao <ayzhao at google.com>
Date: 2023-05-15 (Mon, 15 May 2023)
Changed paths:
M clang/docs/ReleaseNotes.rst
M clang/lib/Sema/SemaInit.cpp
M clang/test/CodeGen/paren-list-agg-init.cpp
Log Message:
-----------
[clang] Fix default initializers being ignored when initializing templated aggregate types
Previously, when checking whether an in-class initializer exists when
performing parenthesized aggregate initialization, Clang checks that the
output of FieldDecl::getInClassInitializer() is non-null. This is
incorrect; if the field is part of a templated type, then
getInClassInitializer() will return nullptr if we haven't called
Sem::BuildCXXDefaultInitExpr(...) before, even if
FieldDecl::hasInClassInitializer() returns true. The end result is that
Clang incorrectly ignores the in class initializer and
value-initializes the field. The fix therefore is to instead call
FieldDecl::hasInClassInitializer(), which is what we do for braced init
lists [0].
Before this patch, Clang does correctly recognize the in-class field
initializer in certain cases. This is Sema::BuildCXXDefaultInitExpr(...)
populates the in class initializer of the corresponding FieldDecl
object. Therefore, if that method was previously called with the same
FieldDecl object, as can happen with a decltype(...) or a braced list
initialization, FieldDecl::getInClassInitializer() will return a
non-null expression, and the field becomes properly initialized.
Fixes 62266
[0]: https://github.com/llvm/llvm-project/blob/be5f35e24f4c15caf3c4aeccddc54c52560c28a0/clang/lib/Sema/SemaInit.cpp#L685
Reviewed By: shafik
Differential Revision: https://reviews.llvm.org/D149389
More information about the All-commits
mailing list