Skip to content

Commit ebc9128

Browse files
nickdesaulniersahatanaka
authored andcommitted
[clang][VarDecl] Reset un-evaluated constant for all C++ modes (llvm#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: llvm#65784 (cherry picked from commit 2618154)
1 parent b414228 commit ebc9128

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
@@ -2520,10 +2520,10 @@ APValue *VarDecl::evaluateValueImpl(SmallVectorImpl<PartialDiagnosticAt> &Notes,
25202520
bool Result = Init->EvaluateAsInitializer(Eval->Evaluated, Ctx, this, Notes,
25212521
IsConstantInitialization);
25222522

2523-
// In C++11, this isn't a constant initializer if we produced notes. In that
2523+
// In C++, this isn't a constant initializer if we produced notes. In that
25242524
// case, we can't keep the result, because it may only be correct under the
25252525
// assumption that the initializer is a constant context.
2526-
if (IsConstantInitialization && Ctx.getLangOpts().CPlusPlus11 &&
2526+
if (IsConstantInitialization && Ctx.getLangOpts().CPlusPlus &&
25272527
!Notes.empty())
25282528
Result = false;
25292529

clang/test/SemaCXX/constant-expression.cpp

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

0 commit comments

Comments
 (0)