[PATCH] Add more information when displaying a "read-only variable is not assignable" error
Richard Trieu
rtrieu at google.com
Fri Jul 11 18:57:45 PDT 2014
http://llvm.org/bugs/show_bug.cgi?id=19139
When a "read-only variable is not assignable" is emitted, give additional notes to show where the const is location.
$ cat test.cc
const int k = 1;
void f() { k = 0; }
class X {
int i;
const int j = 1;
void f() const { i = 0; }
void g() { j = 0; }
};
$ old_clang test.cc -std=c++11
test.cc:2:14: error: read-only variable is not assignable
void f() { k = 0; }
~ ^
test.cc:6:22: error: read-only variable is not assignable
void f() const { i = 0; }
~ ^
test.cc:7:16: error: read-only variable is not assignable
void g() { j = 0; }
~ ^
3 errors generated.
$ new_clang test.cc -std=c++11
test.cc:2:14: error: read-only variable is not assignable
void f() { k = 0; }
~ ^
test.cc:1:11: note: variable 'k' is declared here with type 'const int' which is const
const int k = 1;
~~~~~~~~~~^~~~~
test.cc:6:22: error: read-only variable is not assignable
void f() const { i = 0; }
~ ^
test.cc:6:8: note: method 'f' is declared const here
void f() const { i = 0; }
~~~~~^~~~~~~~~
test.cc:7:16: error: read-only variable is not assignable
void g() { j = 0; }
~ ^
test.cc:5:13: note: field 'j' is declared here with type 'const int' which is const
const int j = 1;
~~~~~~~~~~^~~~~
3 errors generated.
http://reviews.llvm.org/D4479
Files:
include/clang/Basic/DiagnosticSemaKinds.td
lib/Sema/SemaExpr.cpp
test/CXX/temp/temp.decls/temp.mem/p5.cpp
test/Sema/block-misc.c
test/SemaCXX/anonymous-union.cpp
test/SemaCXX/captured-statements.cpp
test/SemaCXX/cxx0x-constexpr-const.cpp
test/SemaCXX/err_typecheck_assign_const.cpp
test/SemaCXX/function-type-qual.cpp
test/SemaObjC/arc.m
test/SemaTemplate/dependent-type-identity.cpp
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D4479.11334.patch
Type: text/x-patch
Size: 10471 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140712/c5462979/attachment.bin>
More information about the cfe-commits
mailing list