Author: Timm Baeder Date: 2025-04-26T07:13:44+02:00 New Revision: 4eb66f7462d0ea89f9354df1fcb63cdb614adc28
URL: https://github.com/llvm/llvm-project/commit/4eb66f7462d0ea89f9354df1fcb63cdb614adc28 DIFF: https://github.com/llvm/llvm-project/commit/4eb66f7462d0ea89f9354df1fcb63cdb614adc28.diff LOG: [clang][bytecode] Allow memory leaks before C++20 (#137445) The expression allocating the memory wasn't valid in the first place. This matches the diagnostic behavior of the current interpreter. Added: Modified: clang/lib/AST/ByteCode/InterpState.cpp clang/test/AST/ByteCode/cxx11-pedantic.cpp Removed: ################################################################################ diff --git a/clang/lib/AST/ByteCode/InterpState.cpp b/clang/lib/AST/ByteCode/InterpState.cpp index d6e6771f0a04f..7848f298cfec8 100644 --- a/clang/lib/AST/ByteCode/InterpState.cpp +++ b/clang/lib/AST/ByteCode/InterpState.cpp @@ -113,7 +113,9 @@ bool InterpState::maybeDiagnoseDanglingAllocations() { << (It.second.size() - 1) << Source->getSourceRange(); } } - return NoAllocationsLeft; + // Keep evaluating before C++20, since the CXXNewExpr wasn't valid there + // in the first place. + return NoAllocationsLeft || !getLangOpts().CPlusPlus20; } StdAllocatorCaller InterpState::getStdAllocatorCaller(StringRef Name) const { diff --git a/clang/test/AST/ByteCode/cxx11-pedantic.cpp b/clang/test/AST/ByteCode/cxx11-pedantic.cpp index a73f20ead1092..247c7ef1c77d8 100644 --- a/clang/test/AST/ByteCode/cxx11-pedantic.cpp +++ b/clang/test/AST/ByteCode/cxx11-pedantic.cpp @@ -20,3 +20,10 @@ namespace DynamicCast { // both-note {{dynamic_cast}} }; } + +namespace NewDelete { + struct T { + int n : *new int(4); // both-warning {{constant expression}} \ + // both-note {{until C++20}} + }; +} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits