[clang] [Clang][Sema] Added Regression test for #176710 (PR #249241)

Chen Miao via cfe-commits cfe-commits at lists.llvm.org
Sat Dec 5 07:23:10 PST 2026


================
@@ -724,3 +724,27 @@ void test() {
                                  // ok, (outer) call to a (non-immediate) function template instantiation
 }
 }
+
+namespace GH176710 {
+  consteval void trigger_defect(); // expected-note {{declared here}}
+
+  template < int > struct C {
+    public:
+      static void f() {
+        auto lambda = [](auto &&obj) -> decltype(0) { // expected-note {{'operator()<int>' defined here}}
+          trigger_defect(); // expected-note {{undefined function 'trigger_defect' cannot be used in a constant expression}}
+                            // expected-note at -1 {{'operator()<int>' is an immediate function because its body contains a call to a consteval function 'trigger_defect' and that call is not a constant expression}}
+                            // expected-note at -2 {{'operator()<int>' is an immediate function because its body contains a call to a consteval function 'trigger_defect' and that call is not a constant expression}}
+        };
+        lambda(0); // expected-error {{immediate function 'operator()<int>' used before it is defined}}
+                   // expected-error at -1 {{call to immediate function 'GH176710::C<1>::f()::(lambda)::operator()<int>' is not a constant expression}}
+                   // expected-note at -2 {{in call to 'lambda.operator()<int>(0)'}}
+                   // expected-note at -3 {{in instantiation of function template specialization 'GH176710::C<1>::f()::(lambda)::operator()<int>' requested here}}
+      }
+  };
+  
----------------
ChenMiaoi wrote:

Nit: Could you remove the two trailing spaces here? Looks like there are extra spaces at the end of this line(L745, That said, this is a regression test, and we generally don’t ask for formatting changes in tests.). Ref: https://llvm.org/docs/CodingStandards.html#whitespace

https://github.com/llvm/llvm-project/pull/249241


More information about the cfe-commits mailing list