https://github.com/tbaederr created 
https://github.com/llvm/llvm-project/pull/175013

Otherwise, we will ultimately create dummy pointers for them and possibly not 
diagnose anything.

>From cf06ea86814c0c3a8712e5361fcbbabf9be2197d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <[email protected]>
Date: Thu, 8 Jan 2026 17:16:05 +0100
Subject: [PATCH] [clang][bytecode] Diagnose unknown reference params pre-C++23

Otherwise, we will ultimately create dummy pointers for them and
possibly not diagnose anything.
---
 clang/lib/AST/ByteCode/Compiler.cpp |  4 ++++
 clang/lib/AST/ByteCode/Interp.cpp   |  5 +++--
 clang/test/AST/ByteCode/cxx23.cpp   | 17 +++++++++++++++++
 3 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/clang/lib/AST/ByteCode/Compiler.cpp 
b/clang/lib/AST/ByteCode/Compiler.cpp
index e85ccafc0e53b..cbee7691565a9 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -7076,6 +7076,10 @@ bool Compiler<Emitter>::visitDeclRef(const ValueDecl *D, 
const Expr *E) {
 
       return this->emitGetPtrParam(It->second.Offset, E);
     }
+
+    if (!Ctx.getLangOpts().CPlusPlus23 && IsReference)
+      return this->emitInvalidDeclRef(cast<DeclRefExpr>(E),
+                                      /*InitializerFailed=*/false, E);
   }
   // Local variables.
   if (auto It = Locals.find(D); It != Locals.end()) {
diff --git a/clang/lib/AST/ByteCode/Interp.cpp 
b/clang/lib/AST/ByteCode/Interp.cpp
index 6444025d6fcf8..5394466dd72e3 100644
--- a/clang/lib/AST/ByteCode/Interp.cpp
+++ b/clang/lib/AST/ByteCode/Interp.cpp
@@ -144,9 +144,10 @@ static bool diagnoseUnknownDecl(InterpState &S, CodePtr 
OpPC,
   if (isa<ParmVarDecl>(D)) {
     if (D->getType()->isReferenceType()) {
       if (S.inConstantContext() && S.getLangOpts().CPlusPlus &&
-          !S.getLangOpts().CPlusPlus11)
+          !S.getLangOpts().CPlusPlus11) {
         diagnoseNonConstVariable(S, OpPC, D);
-      return false;
+        return false;
+      }
     }
 
     const SourceInfo &Loc = S.Current->getSource(OpPC);
diff --git a/clang/test/AST/ByteCode/cxx23.cpp 
b/clang/test/AST/ByteCode/cxx23.cpp
index 4a4ff4b48e8b5..4b87f44d14345 100644
--- a/clang/test/AST/ByteCode/cxx23.cpp
+++ b/clang/test/AST/ByteCode/cxx23.cpp
@@ -520,3 +520,20 @@ namespace InactiveLocalsInConditionalOp {
 
 }
 #endif
+
+namespace UnknownParams {
+  class X {
+  public:
+    constexpr operator bool(){ return true; }
+  };
+  int foo(X x) {
+    static_assert(x);
+    return 1;
+  }
+
+  int foo2(X &x) { // all20-note {{declared here}}
+    static_assert(x); // all20-error {{not an integral constant expression}} \
+                      // all20-note {{function parameter 'x' with unknown 
value cannot be used in a constant expression}}
+    return 1;
+  }
+}

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to