forked from OSchip/llvm-project
When emitting a dropped qualifier error, show which qualifiers are dropped.
llvm-svn: 237505
This commit is contained in:
parent
bb642e5456
commit
f956a49e6d
|
@ -1490,8 +1490,10 @@ def err_lvalue_reference_bind_to_unrelated : Error<
|
|||
"%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">;
|
||||
|
|
|
@ -6852,12 +6852,19 @@ bool InitializationSequence::Diagnose(Sema &S,
|
|||
<< 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)
|
||||
|
|
|
@ -123,7 +123,7 @@ namespace std_example_2 {
|
|||
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'}}
|
||||
|
|
|
@ -52,8 +52,8 @@ void bind_lvalue_to_lvalue(Base b, Derived d,
|
|||
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'}}
|
||||
|
@ -64,10 +64,10 @@ void bind_lvalue_quals(volatile Base b, volatile Derived d,
|
|||
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;
|
||||
|
@ -118,8 +118,8 @@ void bind_const_lvalue_to_rvalue() {
|
|||
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>();
|
||||
}
|
||||
|
|
|
@ -24,16 +24,16 @@ void test_capture(X x) {
|
|||
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}}
|
||||
}();
|
||||
}();
|
||||
}();
|
||||
|
|
|
@ -114,7 +114,7 @@ namespace reference_parameters {
|
|||
}
|
||||
|
||||
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;
|
||||
|
|
|
@ -1258,7 +1258,7 @@ using T = condition<(is_const())>;
|
|||
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 {
|
||||
|
|
|
@ -2,5 +2,5 @@
|
|||
|
||||
// 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}}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
// 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;
|
||||
}
|
|
@ -5,8 +5,8 @@ volatile int i;
|
|||
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) {
|
||||
|
|
|
@ -54,7 +54,7 @@ void test4() {
|
|||
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
|
||||
|
|
Loading…
Reference in New Issue