[clang] [clang][Sema] Add regression coverage for GH59558 (PR #246466)
Neil Thomas via cfe-commits
cfe-commits at lists.llvm.org
Thu Nov 26 09:56:32 PST 2026
https://github.com/neilthomass created https://github.com/llvm/llvm-project/pull/246466
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
>From 8e1dc39a0fa7900db03c9eaf09ea0ae92a677d91 Mon Sep 17 00:00:00 2001
From: Neil Thomas <neilthomas at berkeley.edu>
Date: Thu, 26 Nov 2026 09:49:46 -0800
Subject: [PATCH] [clang][Sema] Add regression coverage for GH59558
Check that an out-of-line member definition rejects modifying a const parameter even when the earlier declaration omits const. Preserve the original class-template reproducer.
---
clang/test/SemaTemplate/GH59558.cpp | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
create mode 100644 clang/test/SemaTemplate/GH59558.cpp
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);
+}
More information about the cfe-commits
mailing list