[clang] [clang][bytecode] Reject functions with dependent return type (PR #194114)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Apr 24 21:59:23 PDT 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Timm Baeder (tbaederr)
<details>
<summary>Changes</summary>
This unfortunately crashes the current interpreter as well.
---
Full diff: https://github.com/llvm/llvm-project/pull/194114.diff
2 Files Affected:
- (modified) clang/lib/AST/ByteCode/Compiler.cpp (+3)
- (modified) clang/test/AST/ByteCode/functions.cpp (+12-3)
``````````diff
diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp
index abdf4dca10cc2..5a0f90d514ad1 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -6882,6 +6882,9 @@ bool Compiler<Emitter>::compileUnionAssignmentOperator(
template <class Emitter>
bool Compiler<Emitter>::visitFunc(const FunctionDecl *F) {
+ if (F->getReturnType()->isDependentType())
+ return false;
+
// Classify the return type.
ReturnType = this->classify(F->getReturnType());
diff --git a/clang/test/AST/ByteCode/functions.cpp b/clang/test/AST/ByteCode/functions.cpp
index 5540ce0baf4bf..05dea564baec7 100644
--- a/clang/test/AST/ByteCode/functions.cpp
+++ b/clang/test/AST/ByteCode/functions.cpp
@@ -1,6 +1,6 @@
-// RUN: %clang_cc1 -pedantic -verify=expected,both %s -fexperimental-new-constant-interpreter
-// RUN: %clang_cc1 -std=c++14 -pedantic -verify=expected,both %s -fexperimental-new-constant-interpreter
-// RUN: %clang_cc1 -std=c++20 -pedantic -verify=expected,both %s -fexperimental-new-constant-interpreter
+// RUN: %clang_cc1 -pedantic -verify=expected,both %s -fexperimental-new-constant-interpreter -DINTERP
+// RUN: %clang_cc1 -std=c++14 -pedantic -verify=expected,both %s -fexperimental-new-constant-interpreter -DINTERP
+// RUN: %clang_cc1 -std=c++20 -pedantic -verify=expected,both %s -fexperimental-new-constant-interpreter -DINTERP
// RUN: %clang_cc1 -pedantic -verify=ref,both %s
// RUN: %clang_cc1 -std=c++14 -pedantic -verify=ref,both %s
// RUN: %clang_cc1 -std=c++20 -pedantic -verify=ref,both %s
@@ -765,3 +765,12 @@ namespace NestedDiags {
return true;
}
}
+
+#ifdef INTERP
+namespace DependentReturnType {
+ template <typename T> struct S {
+ int a = [] { return [](auto t) noexcept((zomg(f))) { return 0; }(0); }(); // both-error {{use of undeclared identifier 'zomg'}}
+ };
+ S<float> x;
+}
+#endif
``````````
</details>
https://github.com/llvm/llvm-project/pull/194114
More information about the cfe-commits
mailing list