Skip to content

Commit 2618154

Browse files
[clang][VarDecl] Reset un-evaluated constant for all C++ modes (#65818)
After commit 610ec95 ("[clang] allow const structs/unions/arrays to be constant expressions for C"), attempts to evaluate structs/unions/arrays as constants are also performed for C++98 and C++03. An assertion was getting tripped up since the potentially-partially evaluated value was not being reset for those 2 language modes. Make sure to reset it now for all C++ modes. Fixes: #65784
1 parent 46f3ea5 commit 2618154

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

clang/lib/AST/Decl.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2555,10 +2555,10 @@ APValue *VarDecl::evaluateValueImpl(SmallVectorImpl<PartialDiagnosticAt> &Notes,
25552555
bool Result = Init->EvaluateAsInitializer(Eval->Evaluated, Ctx, this, Notes,
25562556
IsConstantInitialization);
25572557

2558-
// In C++11, this isn't a constant initializer if we produced notes. In that
2558+
// In C++, this isn't a constant initializer if we produced notes. In that
25592559
// case, we can't keep the result, because it may only be correct under the
25602560
// assumption that the initializer is a constant context.
2561-
if (IsConstantInitialization && Ctx.getLangOpts().CPlusPlus11 &&
2561+
if (IsConstantInitialization && Ctx.getLangOpts().CPlusPlus &&
25622562
!Notes.empty())
25632563
Result = false;
25642564

clang/test/SemaCXX/constant-expression.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,3 +153,8 @@ namespace PR31701 {
153153
const C c = C::n<i>;
154154
}
155155
}
156+
157+
struct PR65784s{
158+
int *ptr;
159+
} const PR65784[] = {(int *)""};
160+
PR65784s PR65784f() { return *PR65784; }

0 commit comments

Comments
 (0)