Skip to content

Commit

Permalink
[clang][Interp] Fix checking unions for initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
tbaederr committed May 22, 2024
1 parent bbc4c2e commit f685481
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions clang/lib/AST/Interp/EvaluationResult.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ static bool CheckFieldsInitialized(InterpState &S, SourceLocation Loc,
DiagnoseUninitializedSubobject(S, Loc, F.Decl);
Result = false;
}

// Only the first member of a union needs to be initialized.
if (R->isUnion())
break;
}

// Check Fields in all bases
Expand Down
14 changes: 14 additions & 0 deletions clang/test/AST/Interp/unions.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// RUN: %clang_cc1 -fexperimental-new-constant-interpreter -verify=expected,both %s
// RUN: %clang_cc1 -verify=ref,both %s

// both-no-diagnostics

union U {
int a;
int b;
};

constexpr U a = {12};
static_assert(a.a == 12, "");


0 comments on commit f685481

Please sign in to comment.