Skip to content

Commit 4eb66f7

Browse files
authored
[clang][bytecode] Allow memory leaks before C++20 (llvm#137445)
The expression allocating the memory wasn't valid in the first place. This matches the diagnostic behavior of the current interpreter.
1 parent b8f5e3c commit 4eb66f7

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

clang/lib/AST/ByteCode/InterpState.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,9 @@ bool InterpState::maybeDiagnoseDanglingAllocations() {
113113
<< (It.second.size() - 1) << Source->getSourceRange();
114114
}
115115
}
116-
return NoAllocationsLeft;
116+
// Keep evaluating before C++20, since the CXXNewExpr wasn't valid there
117+
// in the first place.
118+
return NoAllocationsLeft || !getLangOpts().CPlusPlus20;
117119
}
118120

119121
StdAllocatorCaller InterpState::getStdAllocatorCaller(StringRef Name) const {

clang/test/AST/ByteCode/cxx11-pedantic.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,10 @@ namespace DynamicCast {
2020
// both-note {{dynamic_cast}}
2121
};
2222
}
23+
24+
namespace NewDelete {
25+
struct T {
26+
int n : *new int(4); // both-warning {{constant expression}} \
27+
// both-note {{until C++20}}
28+
};
29+
}

0 commit comments

Comments
 (0)