summaryrefslogtreecommitdiff
path: root/clang/test/SemaCXX
diff options
context:
space:
mode:
authorRichard Smith <richard-llvm@metafoo.co.uk>2018-07-11 00:19:19 +0000
committerRichard Smith <richard-llvm@metafoo.co.uk>2018-07-11 00:19:19 +0000
commit94b6962816b6a29006a598388580edab874a4d66 (patch)
treeed10dcfcf4dde9a639d9eb51834433cbe719a4ab /clang/test/SemaCXX
parent911674201ac3a174881c69ac803640f194b17f80 (diff)
DR330: look through array types when forming the cv-decomposition of a type.
This allows more qualification conversions, eg. conversion from 'int *(*)[]' -> 'const int *const (*)[]' is now permitted, along with all the consequences of that: more types are similar, more cases are permitted by const_cast, and conversely, fewer "casting away constness" cases are permitted by reinterpret_cast.
Diffstat (limited to 'clang/test/SemaCXX')
-rw-r--r--clang/test/SemaCXX/const-cast.cpp10
1 files changed, 8 insertions, 2 deletions
diff --git a/clang/test/SemaCXX/const-cast.cpp b/clang/test/SemaCXX/const-cast.cpp
index 87df61cbc7b..a9268660f1e 100644
--- a/clang/test/SemaCXX/const-cast.cpp
+++ b/clang/test/SemaCXX/const-cast.cpp
@@ -58,8 +58,14 @@ short *bad_const_cast_test(char const *volatile *const volatile *var)
// Non-pointer.
char v = const_cast<char>(**var2); // expected-error {{const_cast to 'char', which is not a reference, pointer-to-object, or pointer-to-data-member}}
const int *ar[100] = {0};
- // Not even lenient g++ accepts this.
- int *(*rar)[100] = const_cast<int *(*)[100]>(&ar); // expected-error {{const_cast from 'const int *(*)[100]' to 'int *(*)[100]' is not allowed}}
+ extern const int *aub[];
+ // const_cast looks through arrays as of DR330.
+ (void) const_cast<int *(*)[100]>(&ar); // ok
+ (void) const_cast<int *(*)[]>(&aub); // ok
+ // ... but the array bound must exactly match.
+ (void) const_cast<int *(*)[]>(&ar); // expected-error {{const_cast from 'const int *(*)[100]' to 'int *(*)[]' is not allowed}}
+ (void) const_cast<int *(*)[99]>(&ar); // expected-error {{const_cast from 'const int *(*)[100]' to 'int *(*)[99]' is not allowed}}
+ (void) const_cast<int *(*)[100]>(&aub); // expected-error {{const_cast from 'const int *(*)[]' to 'int *(*)[100]' is not allowed}}
f fp1 = 0;
// Function pointers.
f fp2 = const_cast<f>(fp1); // expected-error {{const_cast to 'f' (aka 'int (*)(int)'), which is not a reference, pointer-to-object, or pointer-to-data-member}}