[cfe-dev] Question regarding const-correctness

Jon Eyolfson jon at eyolfson.com
Mon Nov 4 10:46:30 PST 2013


A non-text attachment was scrubbed...
Name: example-const-correct.diff
Type: text/x-diff
Size: 1336 bytes
Desc: example-const-correct.diff
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20131104/5ac2720b/attachment.diff>
-------------- next part --------------

Hello Clang Developers,

In my brief time with the clang codebase I've noticed instances of const_cast
and mutable I don't believe are necessary. Are the uses of const_cast and
mutable just temporary to avoid some compile-time type errors?  Does const have
a different meaning for internal clang code? Is developer time prioritized
elsewhere and you're looking for contributors to help with const-correctness?

The attached example diff demonstrates what I believe is a const-correct version
of CFGBlock::getTerminatorCondition(). I don't understand the reasoning behind
including a non-const version of this member function that may unintentionally
allow bad client code.

After applying the diff, clang and the default plugins compile successfully as
expected. Granted I don't have any other client code, so I can't see their uses
(or misuses). I would argue that bad client code would now get a helpful error
message instead of possibly really breaking something in the future. Clients can
either fix their code or be explicit about breaking const and include the
const_cast themselves.

This is my first email to a mailing list, so I apologize in advance for
any misuse.

Jon


More information about the cfe-dev mailing list