"%diff{to type $ cannot bind to a value of unrelated type $|"
"cannot bind to a value of unrelated type}1,2">;
def err_reference_bind_drops_quals : Error<
- "binding value %diff{of type $ to reference of type $ drops qualifiers|"
- "to reference drops qualifiers}0,1">;
+ "binding value %diff{of type $ to reference of type $|to reference}0,1 "
+ "drops %select{<<ERROR>>|'const'|'restrict'|'const' and 'restrict'|"
+ "'volatile'|'const' and 'volatile'|'restrict' and 'volatile'|"
+ "'const', 'restrict', and 'volatile'}2 qualifier%plural{1:|2:|4:|:s}2">;
def err_reference_bind_failed : Error<
"reference %diff{to type $ could not bind to an %select{rvalue|lvalue}1 of "
"type $|could not bind to %select{rvalue|lvalue}1 of incompatible type}0,2">;
<< Args[0]->getSourceRange();
break;
- case FK_ReferenceInitDropsQualifiers:
+ case FK_ReferenceInitDropsQualifiers: {
+ QualType SourceType = Args[0]->getType();
+ QualType NonRefType = DestType.getNonReferenceType();
+ Qualifiers DroppedQualifiers =
+ SourceType.getQualifiers() - NonRefType.getQualifiers();
+
S.Diag(Kind.getLocation(), diag::err_reference_bind_drops_quals)
- << Args[0]->getType()
- << DestType.getNonReferenceType()
+ << SourceType
+ << NonRefType
+ << DroppedQualifiers.getCVRQualifiers()
<< Args[0]->getSourceRange();
break;
+ }
case FK_ReferenceInitFailed:
S.Diag(Kind.getLocation(), diag::err_reference_bind_failed)
const double& rcd2 = 2;
double&& rrd = 2;
const volatile int cvi = 1;
- const int& r2 = cvi; // expected-error{{binding value of type 'const volatile int' to reference of type 'const int' drops qualifiers}}
+ const int& r2 = cvi; // expected-error{{binding value of type 'const volatile int' to reference of type 'const int' drops 'volatile' qualifier}}
double d;
double&& rrd2 = d; // expected-error{{rvalue reference to type 'double' cannot bind to lvalue of type 'double'}}
Base &br2 = d;
Derived &dr1 = d;
Derived &dr2 = b; // expected-error{{non-const lvalue reference to type 'Derived' cannot bind to a value of unrelated type 'Base'}}
- Base &br3 = bc; // expected-error{{drops qualifiers}}
- Base &br4 = dc; // expected-error{{drops qualifiers}}
+ Base &br3 = bc; // expected-error{{drops 'const' qualifier}}
+ Base &br4 = dc; // expected-error{{drops 'const' qualifier}}
Base &br5 = diamond; // expected-error{{ambiguous conversion from derived class 'Diamond' to base class 'Base':}}
int &ir = i;
long &lr = i; // expected-error{{non-const lvalue reference to type 'long' cannot bind to a value of unrelated type 'int'}}
volatile const int ivc) {
volatile Base &bvr1 = b;
volatile Base &bvr2 = d;
- volatile Base &bvr3 = bvc; // expected-error{{binding value of type 'const volatile Base' to reference of type 'volatile Base' drops qualifiers}}
- volatile Base &bvr4 = dvc; // expected-error{{binding value of type 'const volatile Derived' to reference of type 'volatile Base' drops qualifiers}}
+ volatile Base &bvr3 = bvc; // expected-error{{binding value of type 'const volatile Base' to reference of type 'volatile Base' drops 'const' qualifier}}
+ volatile Base &bvr4 = dvc; // expected-error{{binding value of type 'const volatile Derived' to reference of type 'volatile Base' drops 'const' qualifier}}
- volatile int &ir = ivc; // expected-error{{binding value of type 'const volatile int' to reference of type 'volatile int' drops qualifiers}}
+ volatile int &ir = ivc; // expected-error{{binding value of type 'const volatile int' to reference of type 'volatile int' drops 'const' qualifier}}
const volatile Base &bcvr1 = b;
const volatile Base &bcvr2 = d;
const Base &br3 = create<const Base>();
const Base &br4 = create<const Derived>();
- const Base &br5 = create<const volatile Base>(); // expected-error{{binding value of type 'const volatile Base' to reference of type 'const Base' drops qualifiers}}
- const Base &br6 = create<const volatile Derived>(); // expected-error{{binding value of type 'const volatile Derived' to reference of type 'const Base' drops qualifiers}}
+ const Base &br5 = create<const volatile Base>(); // expected-error{{binding value of type 'const volatile Base' to reference of type 'const Base' drops 'volatile' qualifier}}
+ const Base &br6 = create<const volatile Derived>(); // expected-error{{binding value of type 'const volatile Derived' to reference of type 'const Base' drops 'volatile' qualifier}}
const int &ir = create<int>();
}
int a;
[=]{
[&] {
- int &x = a; // expected-error{{binding value of type 'const int' to reference of type 'int' drops qualifiers}}
- int &x2 = a; // expected-error{{binding value of type 'const int' to reference of type 'int' drops qualifiers}}
+ int &x = a; // expected-error{{binding value of type 'const int' to reference of type 'int' drops 'const' qualifier}}
+ int &x2 = a; // expected-error{{binding value of type 'const int' to reference of type 'int' drops 'const' qualifier}}
}();
}();
[=]{
[&a] {
[&] {
- int &x = a; // expected-error{{binding value of type 'const int' to reference of type 'int' drops qualifiers}}
- int &x2 = a; // expected-error{{binding value of type 'const int' to reference of type 'int' drops qualifiers}}
+ int &x = a; // expected-error{{binding value of type 'const int' to reference of type 'int' drops 'const' qualifier}}
+ int &x2 = a; // expected-error{{binding value of type 'const int' to reference of type 'int' drops 'const' qualifier}}
}();
}();
}();
}
template<typename T, const T &ref> void bind() {
- T &ref2 = ref; // expected-error{{drops qualifiers}}
+ T &ref2 = ref; // expected-error{{drops 'const' qualifier}}
}
int counter;
void foo(const T &t) {
T &t2 = t;
}
-// CHECK-ELIDE-NOTREE: binding value of type 'const condition<[...]>' to reference of type 'condition<[...]>' drops qualifiers
+// CHECK-ELIDE-NOTREE: binding value of type 'const condition<[...]>' to reference of type 'condition<[...]>' drops 'const' qualifier
}
namespace BoolArgumentBitExtended {
// va_list on ARM AAPCS is struct { void* __ap }.
int test1(const __builtin_va_list &ap) {
- return __builtin_va_arg(ap, int); // expected-error {{binding value of type 'const __builtin_va_list' to reference of type '__builtin_va_list' drops qualifiers}}
+ return __builtin_va_arg(ap, int); // expected-error {{binding value of type 'const __builtin_va_list' to reference of type '__builtin_va_list' drops 'const' qualifier}}
}
--- /dev/null
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+#define restrict __restrict__
+typedef int* ptr;
+void test1(ptr p, const ptr cp, restrict ptr rp, const restrict ptr crp,
+ volatile ptr vp, const volatile ptr cvp, restrict volatile ptr rvp,
+ const restrict volatile ptr crvp) {
+ ptr& p1 = p;
+ ptr& p2 = cp; // expected-error {{drops 'const' qualifier}}
+ ptr& p3 = rp; // expected-error {{drops 'restrict' qualifier}}
+ ptr& p4 = crp; // expected-error {{drops 'const' and 'restrict' qualifiers}}
+ ptr& p5 = vp; // expected-error {{drops 'volatile' qualifier}}
+ ptr& p6 = cvp; // expected-error {{drops 'const' and 'volatile' qualifiers}}
+ ptr& p7 = rvp; // expected-error {{drops 'restrict' and 'volatile' qualifiers}}
+ ptr& p8 = crvp; // expected-error {{drops 'const', 'restrict', and 'volatile' qualifiers}}
+
+ const ptr& cp1 = p;
+ const ptr& cp2 = cp;
+ const ptr& cp3 = rp; // expected-error {{drops 'restrict' qualifier}}
+ const ptr& cp4 = crp; // expected-error {{drops 'restrict' qualifier}}
+ const ptr& cp5 = vp; // expected-error {{drops 'volatile' qualifier}}
+ const ptr& cp6 = cvp; // expected-error {{drops 'volatile' qualifier}}
+ const ptr& cp7 = rvp; // expected-error {{drops 'restrict' and 'volatile' qualifiers}}
+ const ptr& cp8 = crvp; // expected-error {{drops 'restrict' and 'volatile' qualifiers}}
+
+ const volatile ptr& cvp1 = p;
+ const volatile ptr& cvp2 = cp;
+ const volatile ptr& cvp3 = rp; // expected-error {{drops 'restrict' qualifier}}
+ const volatile ptr& cvp4 = crp; // expected-error {{drops 'restrict' qualifier}}
+ const volatile ptr& cvp5 = vp;
+ const volatile ptr& cvp6 = cvp;
+ const volatile ptr& cvp7 = rvp; // expected-error {{drops 'restrict' qualifier}}
+ const volatile ptr& cvp8 = crvp; // expected-error {{drops 'restrict' qualifier}}
+
+ const restrict volatile ptr& crvp1 = p;
+ const restrict volatile ptr& crvp2 = cp;
+ const restrict volatile ptr& crvp3 = rp;
+ const restrict volatile ptr& crvp4 = crp;
+ const restrict volatile ptr& crvp5 = vp;
+ const restrict volatile ptr& crvp6 = cvp;
+ const restrict volatile ptr& crvp7 = rvp;
+ const restrict volatile ptr& crvp8 = crvp;
+}
const int &inc = i++;
const int &dec = i--;
-const int &incfail = ++i; // expected-error {{drops qualifiers}}
-const int &decfail = --i; // expected-error {{drops qualifiers}}
+const int &incfail = ++i; // expected-error {{drops 'volatile' qualifier}}
+const int &decfail = --i; // expected-error {{drops 'volatile' qualifier}}
// PR7794
void f0(int e) {
void test5() {
// const double& rcd2 = 2; // rcd2 refers to temporary with value 2.0
const volatile int cvi = 1;
- const int& r = cvi; // expected-error{{binding value of type 'const volatile int' to reference of type 'const int' drops qualifiers}}
+ const int& r = cvi; // expected-error{{binding value of type 'const volatile int' to reference of type 'const int' drops 'volatile' qualifier}}
}
// C++ [dcl.init.ref]p3