]> granicus.if.org Git - clang/commitdiff
[Sema] Improved diagnostic for qualifiers in reference binding
authorAnastasia Stulova <anastasia.stulova@arm.com>
Fri, 21 Jun 2019 10:50:02 +0000 (10:50 +0000)
committerAnastasia Stulova <anastasia.stulova@arm.com>
Fri, 21 Jun 2019 10:50:02 +0000 (10:50 +0000)
Improved wording and also simplified by using printing
method from qualifiers.

Differential Revision: https://reviews.llvm.org/D62914

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@364023 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/DiagnosticSemaKinds.td
lib/Sema/SemaInit.cpp
test/CXX/dcl.decl/dcl.init/dcl.init.ref/p5-0x.cpp
test/CXX/dcl.decl/dcl.init/dcl.init.ref/p5-var.cpp
test/CXX/expr/expr.post/expr.static.cast/p3-p4-0x.cpp
test/CXX/expr/expr.prim/expr.prim.lambda/p16.cpp
test/Misc/diag-template-diffing.cpp
test/SemaCXX/builtins-arm.cpp
test/SemaCXX/err_reference_bind_drops_quals.cpp
test/SemaCXX/references.cpp

index dff40055bbc4796729a1f60c28543de623f4a7d8..c8674d781c9b417382c344676ff4a48879c316a6 100644 (file)
@@ -1851,10 +1851,8 @@ 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 to 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">;
+  "binding reference %diff{of type $ to value of type $|to value}0,1 "
+  "drops %2 qualifier%plural{1:|2:|4:|:s}3">;
 def err_reference_bind_failed : Error<
   "reference %diff{to %select{type|incomplete type}1 $ could not bind to an "
   "%select{rvalue|lvalue}2 of type $|could not bind to %select{rvalue|lvalue}2 of "
index 16c396890a90ca8f9481de38b298185883539764..128809175e247dcb22f647382db10509119f6ce3 100644 (file)
@@ -8522,8 +8522,9 @@ bool InitializationSequence::Diagnose(Sema &S,
         SourceType.getQualifiers() - NonRefType.getQualifiers();
 
     S.Diag(Kind.getLocation(), diag::err_reference_bind_drops_quals)
-      << SourceType
       << NonRefType
+      << SourceType
+      << Qualifiers::fromCVRMask(DroppedQualifiers.getCVRQualifiers())
       << DroppedQualifiers.getCVRQualifiers()
       << Args[0]->getSourceRange();
     break;
index a4d7d63754b9b854c8deff1c4ad7798ec6999962..8bfb0047bdab207bd1d289690885078fde3341a2 100644 (file)
@@ -122,8 +122,8 @@ 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 to type 'const int' drops 'volatile' qualifier}}
+  const volatile int cvi = 1;
+  const int& r2 = cvi; // expected-error{{binding reference of type 'const int' to value of type 'const volatile int' drops 'volatile' qualifier}}
 
   double d;
   double&& rrd2 = d; // expected-error{{rvalue reference to type 'double' cannot bind to lvalue of type 'double'}}
index 382212269772ea89dcb43f95b5a1c44a8649f9ca..c2f138a42b965e9e3d5cc146ad6b78bd9a2736c7 100644 (file)
@@ -69,10 +69,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 to type 'volatile Base' drops 'const' qualifier}}
-  volatile Base &bvr4 = dvc; // expected-error{{binding value of type 'const volatile Derived' to reference to type 'volatile Base' drops 'const' qualifier}}
-  
-  volatile int &ir = ivc; // expected-error{{binding value of type 'const volatile int' to reference to type 'volatile int' drops 'const' qualifier}}
+  volatile Base &bvr3 = bvc; // expected-error{{binding reference of type 'volatile Base' to value of type 'const volatile Base' drops 'const' qualifier}}
+  volatile Base &bvr4 = dvc; // expected-error{{binding reference of type 'volatile Base' to value of type 'const volatile Derived' drops 'const' qualifier}}
+
+  volatile int &ir = ivc; // expected-error{{binding reference of type 'volatile int' to value of type 'const volatile int' drops 'const' qualifier}}
 
   const volatile Base &bcvr1 = b;
   const volatile Base &bcvr2 = d;
@@ -123,8 +123,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 to type 'const Base' drops 'volatile' qualifier}}
-  const Base &br6 = create<const volatile Derived>(); // expected-error{{binding value of type 'const volatile Derived' to reference to type 'const Base' drops 'volatile' qualifier}}
+  const Base &br5 = create<const volatile Base>();    // expected-error{{binding reference of type 'const Base' to value of type 'const volatile Base' drops 'volatile' qualifier}}
+  const Base &br6 = create<const volatile Derived>(); // expected-error{{binding reference of type 'const Base' to value of type 'const volatile Derived' drops 'volatile' qualifier}}
 
   const int &ir = create<int>();
 }
index 8701a00d5cf0148024d098a049e94d3a2addfd32..a368a6484081f05240646012c29f4c70b7f2d640 100644 (file)
@@ -28,8 +28,8 @@ void test(A &a, B &b) {
   A &&ar6 = static_cast<A&&>(xvalue<D>());
   A &&ar7 = static_cast<A&&>(prvalue<D>());
 
-  A &&ar8 = static_cast<A&&>(prvalue<const A>()); // expected-error {{binding value of type 'const A' to reference to type 'A' drops 'const' qualifier}}
-  A &&ar9 = static_cast<A&&>(lvalue<const A>()); // expected-error {{cannot cast from lvalue of type 'const A'}}
+  A &&ar8 = static_cast<A&&>(prvalue<const A>()); // expected-error {{binding reference of type 'A' to value of type 'const A' drops 'const' qualifier}}
+  A &&ar9 = static_cast<A&&>(lvalue<const A>());  // expected-error {{cannot cast from lvalue of type 'const A'}}
   A &&ar10 = static_cast<A&&>(xvalue<const A>()); // expected-error {{cannot cast from rvalue of type 'const A'}}
 
   const A &&ar11 = static_cast<const A&&>(prvalue<A>());
@@ -39,5 +39,5 @@ void test(A &a, B &b) {
   const A &&ar15 = static_cast<const A&&>(prvalue<C>());
   const A &&ar16 = static_cast<const A&&>(lvalue<D>());
 
-  const A &&ar17 = static_cast<const A&&>(prvalue<A const volatile>()); // expected-error {{binding value of type 'const volatile A' to reference to type 'const A' drops 'volatile' qualifier}}
+  const A &&ar17 = static_cast<const A&&>(prvalue<A const volatile>()); // expected-error {{binding reference of type 'const A' to value of type 'const volatile A' drops 'volatile' qualifier}}
 }
index 905192ff830b8e976df7b9ebaad85940362694b5..d8ba372608f12b92dcbd9deb81ecdc3a5fc264c8 100644 (file)
@@ -21,20 +21,20 @@ void test_capture(X x) {
     }();
   }();
 
-  int a; 
-  [=]
-    [&] { 
-      int &x = a;  // expected-error{{binding value of type 'const int' to reference to type 'int' drops 'const' qualifier}}
-      int &x2 = a;  // expected-error{{binding value of type 'const int' to reference to type 'int' drops 'const' qualifier}}
-    }(); 
-  }(); 
+  int a;
+  [=] {
+    [&] {
+      int &x = a;  // expected-error{{binding reference of type 'int' to value of type 'const int' drops 'const' qualifier}}
+      int &x2 = a; // expected-error{{binding reference of type 'int' to value of type 'const int' drops 'const' qualifier}}
+    }();
+  }();
 
-  [=]
-    [&a] { 
-      [&] { 
-        int &x = a;  // expected-error{{binding value of type 'const int' to reference to type 'int' drops 'const' qualifier}}
-        int &x2 = a;  // expected-error{{binding value of type 'const int' to reference to type 'int' drops 'const' qualifier}}
+  [=] {
+    [&a] {
+      [&] {
+        int &x = a;  // expected-error{{binding reference of type 'int' to value of type 'const int' drops 'const' qualifier}}
+        int &x2 = a; // expected-error{{binding reference of type 'int' to value of type 'const int' drops 'const' qualifier}}
       }();
-    }(); 
-  }(); 
+    }();
+  }();
 }
index 7d3e21533fcf3107d131678b5c8e49dc2b55905b..cc1cc9ca70679ed8479bc813feadc7fc73e16433 100644 (file)
@@ -1252,7 +1252,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 to type 'condition<...>' drops 'const' qualifier
+// CHECK-ELIDE-NOTREE: binding reference of type 'condition<...>' to value of type 'const condition<...>' drops 'const' qualifier
 }
 
 namespace BoolArgumentBitExtended {
index bd70b812b971b4124a123835731cd9bcfa6f0f32..e68e99df856c6ae6d677c89982884aabf99786c3 100644 (file)
@@ -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 to type '__builtin_va_list' drops 'const' qualifier}}
+  return __builtin_va_arg(ap, int); // expected-error {{binding reference of type '__builtin_va_list' to value of type 'const __builtin_va_list' drops 'const' qualifier}}
 }
index afdd8327f9368c6ad4d6bb53b56e2264b079be17..42d7e247a96c3e45a9ffdc8204661ec97870ee7a 100644 (file)
@@ -6,31 +6,31 @@ 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}}
+  ptr& p2 = cp;   // expected-error {{drops 'const' qualifier}}
+  ptr& p3 = rp;   // expected-error {{drops '__restrict' qualifier}}
+  ptr& p4 = crp;  // expected-error {{drops 'const __restrict' qualifiers}}
+  ptr& p5 = vp;   // expected-error {{drops 'volatile' qualifier}}
+  ptr& p6 = cvp;  // expected-error {{drops 'const volatile' qualifiers}}
+  ptr& p7 = rvp;  // expected-error {{drops 'volatile __restrict' qualifiers}}
+  ptr& p8 = crvp; // expected-error {{drops 'const volatile __restrict' 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 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 'volatile __restrict' qualifiers}}
+  const ptr& cp8 = crvp; // expected-error {{drops 'volatile __restrict' 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& 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 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;
index e32f4a8b0b08554f49a9224e26e7ef3435b3808c..f30e16d990ebeaae32a7327a080c24434564099f 100644 (file)
@@ -55,13 +55,13 @@ 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 to type 'const int' drops 'volatile' qualifier}}
+  const int& r = cvi; // expected-error{{binding reference of type 'const int' to value of type 'const volatile int' drops 'volatile' qualifier}}
 
 #if __cplusplus >= 201103L
-  const int& r2{cvi}; // expected-error{{binding value of type 'const volatile int' to reference to type 'const int' drops 'volatile' qualifier}}
+  const int& r2{cvi}; // expected-error{{binding reference of type 'const int' to value of type 'const volatile int' drops 'volatile' qualifier}}
 
   const int a = 2;
-  int& r3{a}; // expected-error{{binding value of type 'const int' to reference to type 'int' drops 'const'}}
+  int& r3{a}; // expected-error{{binding reference of type 'int' to value of type 'const int' drops 'const' qualifier}}
 
   const int&& r4{a}; // expected-error{{rvalue reference to type 'const int' cannot bind to lvalue of type 'const int'}}