[clang] [clang] Fix-it hint for `++this` -> `++*this` when deref is modifiable (PR #94159)

via cfe-commits cfe-commits at lists.llvm.org
Tue Jun 11 10:07:13 PDT 2024


================
@@ -0,0 +1,49 @@
+// RUN: %clang_cc1 -std=c++23 -fsyntax-only -verify %s
+
+struct S {
+  void f() {
+    ++this; // expected-error {{expression is not assignable}}
+    // expected-note at -1 {{add '*' to dereference it}}
+  }
+
+  void g() const {
+    ++this; // expected-error {{expression is not assignable}}
+  }
+};
+
+void f(int* a, int* const b, const int* const c, __UINTPTR_TYPE__ d) {
+  (int*)d = 4; // expected-error {{assignment to cast is illegal, lvalue casts are not supported}}
+  // expected-note at -1 {{add '*' to dereference it}}
+    
+  ++a;
+  ++b; // expected-error {{cannot assign to variable 'b' with const-qualified type 'int *const'}}
+  // expected-note at -1 {{add '*' to dereference it}}
+  // expected-note@* {{variable 'b' declared const here}}
----------------
Sirraide wrote:

I only just happened to notice these now, but please try not to use `@*` if you can avoid it (sometimes it’s pretty infeasible not to use `@*` because the location is e.g. in a (precompiled) header, but that isn’t the case here)

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


More information about the cfe-commits mailing list