aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Sema/SemaDecl.cpp
diff options
context:
space:
mode:
authorhigher-performance <higher.performance.github@gmail.com>2025-01-14 13:31:12 -0500
committerGitHub <noreply@github.com>2025-01-14 13:31:12 -0500
commit1594413d5edf6a47d4100cb6a2bc613cfbb92beb (patch)
treefc9743f336e09c4e40794ca00570b403ee73f718 /clang/lib/Sema/SemaDecl.cpp
parent576b53801fc3d721602ae0d8377af9950f356000 (diff)
downloadllvm-1594413d5edf6a47d4100cb6a2bc613cfbb92beb.zip
llvm-1594413d5edf6a47d4100cb6a2bc613cfbb92beb.tar.gz
llvm-1594413d5edf6a47d4100cb6a2bc613cfbb92beb.tar.bz2
Add Clang attribute to ensure that fields are initialized explicitly (#102040)
This is a new Clang-specific attribute to ensure that field initializations are performed explicitly. For example, if we have ``` struct B { [[clang::explicit]] int f1; }; ``` then the diagnostic would trigger if we do `B b{};`: ``` field 'f1' is left uninitialized, but was marked as requiring initialization ``` This prevents callers from accidentally forgetting to initialize fields, particularly when new fields are added to the class.
Diffstat (limited to 'clang/lib/Sema/SemaDecl.cpp')
-rw-r--r--clang/lib/Sema/SemaDecl.cpp2
1 files changed, 2 insertions, 0 deletions
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index fd3a5ec..704cb82 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -19232,6 +19232,8 @@ void Sema::ActOnFields(Scope *S, SourceLocation RecLoc, Decl *EnclosingDecl,
if (FT.hasNonTrivialToPrimitiveCopyCUnion() || Record->isUnion())
Record->setHasNonTrivialToPrimitiveCopyCUnion(true);
}
+ if (FD->hasAttr<ExplicitInitAttr>())
+ Record->setHasUninitializedExplicitInitFields(true);
if (FT.isDestructedType()) {
Record->setNonTrivialToPrimitiveDestroy(true);
Record->setParamDestroyedInCallee(true);