Skip to content

Conversation

@tbaederr
Copy link
Contributor

The expression allocating the memory wasn't valid in the first place. This matches the diagnostic behavior of the current interpreter.

The expression allocating the memory wasn't valid in the first place.
This matches the diagnostic behavior of the current interpreter.
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" clang:bytecode Issues for the clang bytecode constexpr interpreter labels Apr 26, 2025
@llvmbot
Copy link
Member

llvmbot commented Apr 26, 2025

@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)

Changes

The expression allocating the memory wasn't valid in the first place. This matches the diagnostic behavior of the current interpreter.


Full diff: https://github.com/llvm/llvm-project/pull/137445.diff

2 Files Affected:

  • (modified) clang/lib/AST/ByteCode/InterpState.cpp (+3-1)
  • (modified) clang/test/AST/ByteCode/cxx11-pedantic.cpp (+7)
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}}
+  };
+}

@tbaederr tbaederr merged commit 4eb66f7 into llvm:main Apr 26, 2025
15 checks passed
IanWood1 pushed a commit to IanWood1/llvm-project that referenced this pull request May 6, 2025
The expression allocating the memory wasn't valid in the first place.
This matches the diagnostic behavior of the current interpreter.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clang:bytecode Issues for the clang bytecode constexpr interpreter clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants