llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.25k stars 11.66k forks source link

A new warning: unneeded 'const_cast' #15515

Open gribozavr opened 11 years ago

gribozavr commented 11 years ago
Bugzilla Link 15143
Version trunk
OS Linux

Extended Description

I've been removing quite a few const_casts in clang codebase. All of those follow the pattern:

void f(const Z *);

...

const Z *cz = ...;
f(const_cast<Z*>(cz));
gribozavr commented 11 years ago

And there's also this gem:

Z z = ...; const_cast<Z>(z);

gribozavr commented 11 years ago

A different pattern:

class Z { void f() const; };

...

const Z cz = ...; const_cast<Z>(cz)->f();

philnik777 commented 1 month ago

This seems more like a candidate for a clang-tidy check to me, since it requires some more complex checks.

llvmbot commented 1 month ago

@llvm/issue-subscribers-clang-tidy

Author: Dmitri Gribenko (gribozavr)

| | | | --- | --- | | Bugzilla Link | [15143](https://llvm.org/bz15143) | | Version | trunk | | OS | Linux | ## Extended Description I've been removing quite a few const_casts in clang codebase. All of those follow the pattern: ```c void f(const Z *); ... const Z *cz = ...; f(const_cast<Z*>(cz)); ```