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

Kingsley Leon via cfe-commits cfe-commits at lists.llvm.org
Sat Dec 5 07:47:50 PST 2026


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

>From ed339515069aa7910245ad5989d70703afddf6f4 Mon Sep 17 00:00:00 2001
From: Kingsley Leon <kingsleyl.dev at gmail.com>
Date: Sat, 5 Dec 2026 09:35:37 -0500
Subject: [PATCH 1/4] Regression test for #176710

**Summary**

Added a regression test in
SemaCXX/cxx2b-consteval-propagate.cpp

**Testing**

* bin/llvm-lit -sv ../clang/test/SemaCXX/cxx2b-consteval-propagate.cpp
  (ran in build directory, 1/1 passed)

Signed-off-by: Kingsley Leon <kingsleyl.dev at gmail.com>
---
 .../SemaCXX/cxx2b-consteval-propagate.cpp     | 24 +++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/clang/test/SemaCXX/cxx2b-consteval-propagate.cpp b/clang/test/SemaCXX/cxx2b-consteval-propagate.cpp
index 52ab5252b87809..4705e00beb945b 100644
--- a/clang/test/SemaCXX/cxx2b-consteval-propagate.cpp
+++ b/clang/test/SemaCXX/cxx2b-consteval-propagate.cpp
@@ -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}}
+      }
+  };
+  
+  int main() {
+    C<1>::f(); // expected-note {{in instantiation of member function 'GH176710::C<1>::f' requested here}}
+               // expected-note at -1 {{in instantiation of member function 'GH176710::C<1>::f' requested here}}
+  }
+} // namespace GH176710

>From c674aa44203bc2a5f8c97e2b1aa2de5889a08152 Mon Sep 17 00:00:00 2001
From: Kingsley Leon <kingsleyl.dev at gmail.com>
Date: Sat, 5 Dec 2026 10:26:04 -0500
Subject: [PATCH 2/4] Update clang/test/SemaCXX/cxx2b-consteval-propagate.cpp

rename int main() to void test() to prevent ambiguity

Co-authored-by: Chen Miao <chenmiao.ku at gmail.com>
---
 clang/test/SemaCXX/cxx2b-consteval-propagate.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/test/SemaCXX/cxx2b-consteval-propagate.cpp b/clang/test/SemaCXX/cxx2b-consteval-propagate.cpp
index 4705e00beb945b..f8581122154144 100644
--- a/clang/test/SemaCXX/cxx2b-consteval-propagate.cpp
+++ b/clang/test/SemaCXX/cxx2b-consteval-propagate.cpp
@@ -743,7 +743,7 @@ namespace GH176710 {
       }
   };
   
-  int main() {
+  void test() {
     C<1>::f(); // expected-note {{in instantiation of member function 'GH176710::C<1>::f' requested here}}
                // expected-note at -1 {{in instantiation of member function 'GH176710::C<1>::f' requested here}}
   }

>From a56e583f05b2bd2493027386c6f5ced84c6c0e78 Mon Sep 17 00:00:00 2001
From: Kingsley Leon <kingsleyl.dev at gmail.com>
Date: Sat, 5 Dec 2026 10:28:29 -0500
Subject: [PATCH 3/4] Removed trailing spaces on line 745 to match LLVM coding
 standards

---
 clang/test/SemaCXX/cxx2b-consteval-propagate.cpp | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/clang/test/SemaCXX/cxx2b-consteval-propagate.cpp b/clang/test/SemaCXX/cxx2b-consteval-propagate.cpp
index f8581122154144..de9fe4c6d4068c 100644
--- a/clang/test/SemaCXX/cxx2b-consteval-propagate.cpp
+++ b/clang/test/SemaCXX/cxx2b-consteval-propagate.cpp
@@ -744,6 +744,8 @@ namespace GH176710 {
   };
   
   void test() {
+  }; 
+  int main() {
     C<1>::f(); // expected-note {{in instantiation of member function 'GH176710::C<1>::f' requested here}}
                // expected-note at -1 {{in instantiation of member function 'GH176710::C<1>::f' requested here}}
   }

>From 127297f899b5a9667d8857f914745531912f384b Mon Sep 17 00:00:00 2001
From: Kingsley Leon <kingsleyl.dev at gmail.com>
Date: Sat, 5 Dec 2026 10:47:37 -0500
Subject: [PATCH 4/4] Fixed void test() issue of being another function to
 renaming int main() to void test()

---
 clang/test/SemaCXX/cxx2b-consteval-propagate.cpp | 2 --
 1 file changed, 2 deletions(-)

diff --git a/clang/test/SemaCXX/cxx2b-consteval-propagate.cpp b/clang/test/SemaCXX/cxx2b-consteval-propagate.cpp
index de9fe4c6d4068c..f8581122154144 100644
--- a/clang/test/SemaCXX/cxx2b-consteval-propagate.cpp
+++ b/clang/test/SemaCXX/cxx2b-consteval-propagate.cpp
@@ -744,8 +744,6 @@ namespace GH176710 {
   };
   
   void test() {
-  }; 
-  int main() {
     C<1>::f(); // expected-note {{in instantiation of member function 'GH176710::C<1>::f' requested here}}
                // expected-note at -1 {{in instantiation of member function 'GH176710::C<1>::f' requested here}}
   }



More information about the cfe-commits mailing list