[clang] ede75e5 - [clang][bytecode] Don't diagnose const assignments... (#192593)

via cfe-commits cfe-commits at lists.llvm.org
Thu Apr 16 23:29:50 PDT 2026


Author: Timm Baeder
Date: 2026-04-17T08:29:45+02:00
New Revision: ede75e5d5dfb9b9481c1ae2c332085d24d9744df

URL: https://github.com/llvm/llvm-project/commit/ede75e5d5dfb9b9481c1ae2c332085d24d9744df
DIFF: https://github.com/llvm/llvm-project/commit/ede75e5d5dfb9b9481c1ae2c332085d24d9744df.diff

LOG: [clang][bytecode] Don't diagnose const assignments... (#192593)

... when we're in CPCE mode.

Added: 
    

Modified: 
    clang/lib/AST/ByteCode/Interp.cpp
    clang/test/AST/ByteCode/cxx20.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/ByteCode/Interp.cpp b/clang/lib/AST/ByteCode/Interp.cpp
index 17d194355208d..f5fb9f6b7bbfa 100644
--- a/clang/lib/AST/ByteCode/Interp.cpp
+++ b/clang/lib/AST/ByteCode/Interp.cpp
@@ -579,9 +579,11 @@ bool CheckConst(InterpState &S, CodePtr OpPC, const Pointer &Ptr) {
   if (llvm::is_contained(S.InitializingBlocks, Ptr.block()))
     return true;
 
-  const QualType Ty = Ptr.getType();
-  const SourceInfo &Loc = S.Current->getSource(OpPC);
-  S.FFDiag(Loc, diag::note_constexpr_modify_const_type) << Ty;
+  if (!S.checkingPotentialConstantExpression()) {
+    const QualType Ty = Ptr.getType();
+    const SourceInfo &Loc = S.Current->getSource(OpPC);
+    S.FFDiag(Loc, diag::note_constexpr_modify_const_type) << Ty;
+  }
   return false;
 }
 

diff  --git a/clang/test/AST/ByteCode/cxx20.cpp b/clang/test/AST/ByteCode/cxx20.cpp
index 4c4624d7505e2..43115416451ec 100644
--- a/clang/test/AST/ByteCode/cxx20.cpp
+++ b/clang/test/AST/ByteCode/cxx20.cpp
@@ -1345,3 +1345,12 @@ namespace ExpandOnOPTEPointers {
   }
   static_assert(test());
 }
+
+namespace ConstIntPotentialConstantExpr {
+  /// NO error about a constexpr function that's never a constant expression.
+  constexpr int Const() {
+    const int a = 10; // both-note {{declared const here}}
+    a = 20; // both-error {{cannot assign to variable 'a' with const-qualified type 'const int'}}
+    return 1;
+  }
+}


        


More information about the cfe-commits mailing list