summaryrefslogtreecommitdiffstats
path: root/clang/test/CXX
diff options
context:
space:
mode:
authorRichard Smith <richard@metafoo.co.uk>2020-01-09 15:31:56 -0800
committerRichard Smith <richard@metafoo.co.uk>2020-01-09 18:24:06 -0800
commitf041e9ad706aee7987c5299427c33424fcabbd0d (patch)
treed156216fbbbc28d09f997c4cfea552a5cfee2939 /clang/test/CXX
parent3727ca313783e23696caeae53c688409555ab0fc (diff)
downloadbcm5719-llvm-f041e9ad706aee7987c5299427c33424fcabbd0d.tar.gz
bcm5719-llvm-f041e9ad706aee7987c5299427c33424fcabbd0d.zip
CWG2352: Allow qualification conversions during reference binding.
The language wording change forgot to update overload resolution to rank implicit conversion sequences based on qualification conversions in reference bindings. The anticipated resolution for that oversight is implemented here -- we order candidates based on qualification conversion, not only on top-level cv-qualifiers, including ranking reference bindings against non-reference bindings if they differ in non-top-level qualification conversions. For OpenCL/C++, this allows reference binding between pointers with differing (nested) address spaces. This makes the behavior of reference binding consistent with that of implicit pointer conversions, as is the purpose of this change, but that pre-existing behavior for pointer conversions is itself probably not correct. In any case, it's now consistently the same behavior and implemented in only one place. This reinstates commit de21704ba96fa80d3e9402f12c6505917a3885f4, reverted in commit d8018233d1ea4234de68d5b4593abd773db79484, with workarounds for some overload resolution ordering problems introduced by CWG2352.
Diffstat (limited to 'clang/test/CXX')
-rw-r--r--clang/test/CXX/drs/dr23xx.cpp35
-rw-r--r--clang/test/CXX/drs/dr4xx.cpp11
2 files changed, 41 insertions, 5 deletions
diff --git a/clang/test/CXX/drs/dr23xx.cpp b/clang/test/CXX/drs/dr23xx.cpp
index 763abd5368e..85f59207460 100644
--- a/clang/test/CXX/drs/dr23xx.cpp
+++ b/clang/test/CXX/drs/dr23xx.cpp
@@ -1,12 +1,41 @@
-// RUN: %clang_cc1 -std=c++98 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors 2>&1 | FileCheck %s
+// RUN: %clang_cc1 -std=c++98 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors 2>&1
// RUN: %clang_cc1 -std=c++11 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors 2>&1 | FileCheck %s
// RUN: %clang_cc1 -std=c++14 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors 2>&1 | FileCheck %s
// RUN: %clang_cc1 -std=c++17 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors 2>&1 | FileCheck %s
// RUN: %clang_cc1 -std=c++2a %s -verify -fexceptions -fcxx-exceptions -pedantic-errors 2>&1 | FileCheck %s
-#if __cplusplus <= 201103L
-// expected-no-diagnostics
+namespace dr2352 { // dr2352: 10
+ int **p;
+ const int *const *const &f1() { return p; }
+ int *const *const &f2() { return p; }
+ int **const &f3() { return p; }
+
+ const int **const &f4() { return p; } // expected-error {{reference to type 'const int **const' could not bind to an lvalue of type 'int **'}}
+ const int *const *&f5() { return p; } // expected-error {{binding reference of type 'const int *const *' to value of type 'int **' not permitted due to incompatible qualifiers}}
+
+ // FIXME: We permit this as a speculative defect resolution, allowing
+ // qualification conversions when forming a glvalue conditional expression.
+ const int * const * const q = 0;
+ __typeof(&(true ? p : q)) x = &(true ? p : q);
+
+ // FIXME: Should we compute the composite pointer type here and produce an
+ // lvalue of type 'const int *const * const'?
+ const int * const * r;
+ void *y = &(true ? p : r); // expected-error {{rvalue of type 'const int *const *'}}
+
+ // FIXME: We order these as a speculative defect resolution.
+ void f(const int * const * const &r);
+#if __cplusplus >= 201103L
+ constexpr
#endif
+ int *const *const &f(int * const * const &r) { return r; }
+
+ // No temporary is created here.
+ int *const *const &check_f = f(p);
+#if __cplusplus >= 201103L
+ static_assert(&p == &check_f, "");
+#endif
+}
namespace dr2353 { // dr2353: 9
struct X {
diff --git a/clang/test/CXX/drs/dr4xx.cpp b/clang/test/CXX/drs/dr4xx.cpp
index 8eeb7715cad..d37ece6cb88 100644
--- a/clang/test/CXX/drs/dr4xx.cpp
+++ b/clang/test/CXX/drs/dr4xx.cpp
@@ -486,14 +486,21 @@ namespace dr433 { // dr433: yes
S<int> s;
}
-namespace dr434 { // dr434: yes
+namespace dr434 { // dr434: sup 2352
void f() {
const int ci = 0;
int *pi = 0;
- const int *&rpci = pi; // expected-error {{cannot bind}}
+ const int *&rpci = pi; // expected-error {{incompatible qualifiers}}
+ const int * const &rcpci = pi; // OK
rpci = &ci;
*pi = 1;
}
+
+#if __cplusplus >= 201103L
+ int *pi = 0;
+ const int * const &rcpci = pi;
+ static_assert(&rcpci == &pi, "");
+#endif
}
// dr435: na
OpenPOWER on IntegriCloud