]> granicus.if.org Git - clang/commit
Implement appropriate semantics for C++ casting and conversion when
authorDouglas Gregor <dgregor@apple.com>
Fri, 15 Apr 2011 17:59:54 +0000 (17:59 +0000)
committerDouglas Gregor <dgregor@apple.com>
Fri, 15 Apr 2011 17:59:54 +0000 (17:59 +0000)
commitd4c5f84bbed2ecb5ddd0f0e8316c553b2084772a
treee88448f1b2f7fe6ec848dfef941b773c60ffa6cc
parent562627d782393c0d8045625a53a97f4fbad091bc
Implement appropriate semantics for C++ casting and conversion when
dealing with address-space- and GC-qualified pointers. Previously,
these qualifiers were being treated just like cvr-qualifiers (in some
cases) or were completely ignored, leading to uneven behavior. For
example, const_cast would allow conversion between pointers to
different address spaces.

The new semantics are fairly simple: reinterpret_cast can be used to
explicitly cast between pointers to different address spaces
(including adding/removing addresss spaces), while
static_cast/dynamic_cast/const_cast do not tolerate any changes in the
address space. C-style casts can add/remove/change address spaces
through the reinterpret_cast mechanism. Other non-CVR qualifiers
(e.g., Objective-C GC qualifiers) work similarly.

As part of this change, I tweaked the "casts away constness"
diagnostic to use the term "casts away qualifiers". The term
"constness" actually comes from the C++ standard, despite the fact
that removing "volatile" also falls under that category. In Clang, we
also have restrict, address spaces, ObjC GC attributes, etc., so the
more general "qualifiers" is clearer.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@129583 91177308-0d34-0410-b5e6-96231b3b80d8
include/clang/Basic/DiagnosticSemaKinds.td
lib/Sema/SemaCXXCast.cpp
test/SemaCXX/address-space-conversion.cpp [new file with mode: 0644]
test/SemaCXX/reinterpret-cast.cpp
test/SemaCXX/static-cast.cpp
test/SemaTemplate/instantiate-cast.cpp