Skip to content

Commit 17712f5

Browse files
committed
[clang][Interp] Fix checking null pointers for initialization
1 parent bfd95a0 commit 17712f5

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

clang/lib/AST/Interp/EvaluationResult.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,9 @@ bool EvaluationResult::checkFullyInitialized(InterpState &S,
141141
const Pointer &Ptr) const {
142142
assert(Source);
143143
assert(empty());
144-
assert(!Ptr.isZero());
144+
145+
if (Ptr.isZero())
146+
return true;
145147

146148
SourceLocation InitLoc;
147149
if (const auto *D = Source.dyn_cast<const Decl *>())

clang/test/AST/Interp/cxx20.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -814,3 +814,16 @@ namespace GH64949 {
814814
// both-note {{subobject 'g' is not initialized}} \
815815
// both-warning {{expression result unused}}
816816
}
817+
818+
/// This used to cause an assertion failure inside EvaluationResult::checkFullyInitialized.
819+
namespace CheckingNullPtrForInitialization {
820+
struct X {
821+
consteval operator const char *() const {
822+
return nullptr;
823+
}
824+
};
825+
const char *f() {
826+
constexpr X x;
827+
return x;
828+
}
829+
}

0 commit comments

Comments
 (0)