[clang] [clang][Sema] Add regression coverage for GH59558 (PR #246466)

via cfe-commits cfe-commits at lists.llvm.org
Thu Nov 26 09:57:25 PST 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Neil Thomas (neilthomass)

<details>
<summary>Changes</summary>

Add a SemaTemplate regression test for the original GH59558 reproducer.

Verify that modifying a const parameter is rejected when the out-of-line definition declares it const but the earlier declaration does not.

Closes #<!-- -->59558

---
Full diff: https://github.com/llvm/llvm-project/pull/246466.diff


1 Files Affected:

- (added) clang/test/SemaTemplate/GH59558.cpp (+20) 


``````````diff
diff --git a/clang/test/SemaTemplate/GH59558.cpp b/clang/test/SemaTemplate/GH59558.cpp
new file mode 100644
index 00000000000000..5b3c2ef836a8bb
--- /dev/null
+++ b/clang/test/SemaTemplate/GH59558.cpp
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
+
+// Diagnose modification of a parameter declared const in an out-of-line member
+// definition, even if the earlier declaration omits const.
+template <typename T>
+struct X {
+  int f(X &&, int);
+
+  int value;
+};
+
+template <typename T>
+int X<T>::f(X &&u, const int x) { // expected-note {{variable 'x' declared const here}}
+  x += u.value; // expected-error {{cannot assign to variable 'x' with const-qualified type 'const int'}}
+  return x;
+}
+
+void test() {
+  X<int>{}.f(X<int>{1}, 0);
+}

``````````

</details>


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


More information about the cfe-commits mailing list