On Nov 29, 2011, at 6:44 PM, Ryosuke Niwa wrote:
> On Tue, Nov 29, 2011 at 6:42 PM, Ryosuke Niwa <[email protected]> wrote:
>> - Prevents misuse of variable in a later patch (by a different author)
>> through enforcement of const-ness.
>
> Prevents one specific type of misuse: Setting the variable to another value.
> And that may not be misuse despite the fact that the original author didn’t
> plan on changing it.
>
> Right, but it tells us the intent of the author, and appears to be useful
> even if the variable started with prefixes like "old", "original", and
> "previous".
>
> I'll add that I'd much prefer seeing a const in front of a local variable
> over seeing a comment like "This variable shouldn't be modified".
Thanks for the feedback everyone. In retrospect, I see that my original
question was too broad and too general.
What I (and Antti) really wanted to ask was whether it's okay to use const
pointers on a case-by-case basis without making it a project-wide rule.
And this is the specific case I'm talking about:
diff --git a/Source/WebCore/platform/KURL.cpp b/Source/WebCore/platform/KURL.cpp
index e752bb8..cb033bd 100644
--- a/Source/WebCore/platform/KURL.cpp
+++ b/Source/WebCore/platform/KURL.cpp
@@ -486,7 +486,7 @@ void KURL::init(const KURL& base, const String& relative,
const TextEncoding& en
parseBuffer.resize(bufferSize);
char* bufferPos = parseBuffer.data();
- char* bufferStart = bufferPos;
+ char* const bufferStart = bufferPos;
// first copy everything before the path from the base
unsigned baseLength = base.m_string.length();
But of course I couldn't stop there because there were other pointers that
could be const in this method, so I ended up with:
https://bugs.webkit.org/show_bug.cgi?id=73502
Dave
_______________________________________________
webkit-dev mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-dev