Skip to content

Commit 7dd7d57

Browse files
authored
Revert "[clang] Fix-it hint for ++this -> ++*this when deref is modifiable" (#95833)
Reverts #94159 @zygoloid had some concerns about the implementation of this, which make sense to me, so I’d like to revert this for now so we can have more time to think about how to best approach this (if at all...)
1 parent db394ed commit 7dd7d57

File tree

7 files changed

+2
-91
lines changed

7 files changed

+2
-91
lines changed

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8778,9 +8778,6 @@ def err_typecheck_incomplete_type_not_modifiable_lvalue : Error<
87788778
def err_typecheck_lvalue_casts_not_supported : Error<
87798779
"assignment to cast is illegal, lvalue casts are not supported">;
87808780

8781-
def note_typecheck_add_deref_star_not_modifiable_lvalue : Note<
8782-
"add '*' to dereference it">;
8783-
87848781
def err_typecheck_duplicate_vector_components_not_mlvalue : Error<
87858782
"vector is not assignable (contains duplicate components)">;
87868783
def err_block_decl_ref_not_modifiable_lvalue : Error<

clang/lib/Sema/SemaExpr.cpp

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13288,23 +13288,6 @@ enum {
1328813288
ConstUnknown, // Keep as last element
1328913289
};
1329013290

13291-
static void MaybeSuggestDerefFixIt(Sema &S, const Expr *E, SourceLocation Loc) {
13292-
ExprResult Deref;
13293-
Expr *TE = const_cast<Expr *>(E);
13294-
{
13295-
Sema::TentativeAnalysisScope Trap(S);
13296-
Deref = S.ActOnUnaryOp(S.getCurScope(), Loc, tok::star, TE);
13297-
}
13298-
if (Deref.isUsable() &&
13299-
Deref.get()->isModifiableLvalue(S.Context, &Loc) == Expr::MLV_Valid &&
13300-
!E->getType()->isObjCObjectPointerType()) {
13301-
S.Diag(E->getBeginLoc(),
13302-
diag::note_typecheck_add_deref_star_not_modifiable_lvalue)
13303-
<< E->getSourceRange()
13304-
<< FixItHint::CreateInsertion(E->getBeginLoc(), "*");
13305-
}
13306-
}
13307-
1330813291
/// Emit the "read-only variable not assignable" error and print notes to give
1330913292
/// more information about why the variable is not assignable, such as pointing
1331013293
/// to the declaration of a const variable, showing that a method is const, or
@@ -13399,7 +13382,6 @@ static void DiagnoseConstAssignment(Sema &S, const Expr *E,
1339913382
if (!DiagnosticEmitted) {
1340013383
S.Diag(Loc, diag::err_typecheck_assign_const)
1340113384
<< ExprRange << ConstVariable << VD << VD->getType();
13402-
MaybeSuggestDerefFixIt(S, E, Loc);
1340313385
DiagnosticEmitted = true;
1340413386
}
1340513387
S.Diag(VD->getLocation(), diag::note_typecheck_assign_const)
@@ -13620,12 +13602,10 @@ static bool CheckForModifiableLvalue(Expr *E, SourceLocation Loc, Sema &S) {
1362013602
SourceRange Assign;
1362113603
if (Loc != OrigLoc)
1362213604
Assign = SourceRange(OrigLoc, OrigLoc);
13623-
if (NeedType) {
13605+
if (NeedType)
1362413606
S.Diag(Loc, DiagID) << E->getType() << E->getSourceRange() << Assign;
13625-
} else {
13607+
else
1362613608
S.Diag(Loc, DiagID) << E->getSourceRange() << Assign;
13627-
MaybeSuggestDerefFixIt(S, E, Loc);
13628-
}
1362913609
return true;
1363013610
}
1363113611

clang/test/C/drs/dr1xx.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,6 @@ void dr126(void) {
296296
*/
297297
*object = 12; /* ok */
298298
++object; /* expected-error {{cannot assign to variable 'object' with const-qualified type 'const IP' (aka 'int *const')}} */
299-
/* expected-note@-1 {{add '*' to dereference it}} */
300299
}
301300

302301
/* WG14 DR128: yes

clang/test/Sema/debug-93066.cpp

Lines changed: 0 additions & 49 deletions
This file was deleted.

clang/test/Sema/exprs.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,8 @@ void test4(void) {
6565

6666
void test5(int *X, float *P) {
6767
(float*)X = P; // expected-error {{assignment to cast is illegal, lvalue casts are not supported}}
68-
// expected-note@-1 {{add '*' to dereference it}}
6968
#define FOO ((float*) X)
7069
FOO = P; // expected-error {{assignment to cast is illegal, lvalue casts are not supported}}
71-
// expected-note@-1 {{add '*' to dereference it}}
7270
}
7371

7472
void test6(void) {

clang/test/Sema/va_arg_x86_32.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,5 @@
22

33
int a(void) {
44
__builtin_va_arg((char*)0, int); // expected-error {{expression is not assignable}}
5-
// expected-note@-1 {{add '*' to dereference it}}
65
__builtin_va_arg((void*){0}, int); // expected-error {{first argument to 'va_arg' is of type 'void *'}}
76
}

clang/test/SemaObjCXX/sel-address.mm

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,7 @@ void h() {
99
SEL s = @selector(dealloc);
1010
SEL* ps = &s;
1111

12-
/*
13-
FIXME: https://github.com/llvm/llvm-project/pull/94159
14-
15-
TLDR; This is about inserting '*' to deref.
16-
17-
This would assign the value of s to the SEL object pointed to by
18-
@selector(dealloc). However, in Objective-C, selectors are not pointers,
19-
they are special compile-time constructs representing method names, and
20-
they are immutable, so you cannot assign values to them.
21-
22-
Therefore, this syntax is not valid for selectors in Objective-C.
23-
*/
2412
@selector(dealloc) = s; // expected-error {{expression is not assignable}}
25-
// expected-note@-1 {{add '*' to dereference it}}
2613

2714
SEL* ps2 = &@selector(dealloc);
2815

0 commit comments

Comments
 (0)