r237505 - When emitting a dropped qualifier error, show which qualifiers are dropped.

Richard Trieu rtrieu at google.com
Fri May 15 18:27:03 PDT 2015


Author: rtrieu
Date: Fri May 15 20:27:03 2015
New Revision: 237505

URL: http://llvm.org/viewvc/llvm-project?rev=237505&view=rev
Log:
When emitting a dropped qualifier error, show which qualifiers are dropped.

Added:
    cfe/trunk/test/SemaCXX/err_reference_bind_drops_quals.cpp
Modified:
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/trunk/lib/Sema/SemaInit.cpp
    cfe/trunk/test/CXX/dcl.decl/dcl.init/dcl.init.ref/p5-0x.cpp
    cfe/trunk/test/CXX/dcl.decl/dcl.init/dcl.init.ref/p5-var.cpp
    cfe/trunk/test/CXX/expr/expr.prim/expr.prim.lambda/p16.cpp
    cfe/trunk/test/CXX/temp/temp.arg/temp.arg.nontype/p5.cpp
    cfe/trunk/test/Misc/diag-template-diffing.cpp
    cfe/trunk/test/SemaCXX/builtins-arm.cpp
    cfe/trunk/test/SemaCXX/increment-decrement.cpp
    cfe/trunk/test/SemaCXX/references.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=237505&r1=237504&r2=237505&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Fri May 15 20:27:03 2015
@@ -1490,8 +1490,10 @@ def err_lvalue_reference_bind_to_unrelat
   "%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">;

Modified: cfe/trunk/lib/Sema/SemaInit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaInit.cpp?rev=237505&r1=237504&r2=237505&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaInit.cpp (original)
+++ cfe/trunk/lib/Sema/SemaInit.cpp Fri May 15 20:27:03 2015
@@ -6852,12 +6852,19 @@ bool InitializationSequence::Diagnose(Se
       << 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)

Modified: cfe/trunk/test/CXX/dcl.decl/dcl.init/dcl.init.ref/p5-0x.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/dcl.decl/dcl.init/dcl.init.ref/p5-0x.cpp?rev=237505&r1=237504&r2=237505&view=diff
==============================================================================
--- cfe/trunk/test/CXX/dcl.decl/dcl.init/dcl.init.ref/p5-0x.cpp (original)
+++ cfe/trunk/test/CXX/dcl.decl/dcl.init/dcl.init.ref/p5-0x.cpp Fri May 15 20:27:03 2015
@@ -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'}}

Modified: cfe/trunk/test/CXX/dcl.decl/dcl.init/dcl.init.ref/p5-var.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/dcl.decl/dcl.init/dcl.init.ref/p5-var.cpp?rev=237505&r1=237504&r2=237505&view=diff
==============================================================================
--- cfe/trunk/test/CXX/dcl.decl/dcl.init/dcl.init.ref/p5-var.cpp (original)
+++ cfe/trunk/test/CXX/dcl.decl/dcl.init/dcl.init.ref/p5-var.cpp Fri May 15 20:27:03 2015
@@ -52,8 +52,8 @@ void bind_lvalue_to_lvalue(Base b, Deriv
   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 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>();
 }

Modified: cfe/trunk/test/CXX/expr/expr.prim/expr.prim.lambda/p16.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/expr/expr.prim/expr.prim.lambda/p16.cpp?rev=237505&r1=237504&r2=237505&view=diff
==============================================================================
--- cfe/trunk/test/CXX/expr/expr.prim/expr.prim.lambda/p16.cpp (original)
+++ cfe/trunk/test/CXX/expr/expr.prim/expr.prim.lambda/p16.cpp Fri May 15 20:27:03 2015
@@ -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}}
       }();
     }(); 
   }(); 

Modified: cfe/trunk/test/CXX/temp/temp.arg/temp.arg.nontype/p5.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/temp/temp.arg/temp.arg.nontype/p5.cpp?rev=237505&r1=237504&r2=237505&view=diff
==============================================================================
--- cfe/trunk/test/CXX/temp/temp.arg/temp.arg.nontype/p5.cpp (original)
+++ cfe/trunk/test/CXX/temp/temp.arg/temp.arg.nontype/p5.cpp Fri May 15 20:27:03 2015
@@ -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;

Modified: cfe/trunk/test/Misc/diag-template-diffing.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Misc/diag-template-diffing.cpp?rev=237505&r1=237504&r2=237505&view=diff
==============================================================================
--- cfe/trunk/test/Misc/diag-template-diffing.cpp (original)
+++ cfe/trunk/test/Misc/diag-template-diffing.cpp Fri May 15 20:27:03 2015
@@ -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 {

Modified: cfe/trunk/test/SemaCXX/builtins-arm.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/builtins-arm.cpp?rev=237505&r1=237504&r2=237505&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/builtins-arm.cpp (original)
+++ cfe/trunk/test/SemaCXX/builtins-arm.cpp Fri May 15 20:27:03 2015
@@ -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}}
 }

Added: cfe/trunk/test/SemaCXX/err_reference_bind_drops_quals.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/err_reference_bind_drops_quals.cpp?rev=237505&view=auto
==============================================================================
--- cfe/trunk/test/SemaCXX/err_reference_bind_drops_quals.cpp (added)
+++ cfe/trunk/test/SemaCXX/err_reference_bind_drops_quals.cpp Fri May 15 20:27:03 2015
@@ -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;
+}

Modified: cfe/trunk/test/SemaCXX/increment-decrement.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/increment-decrement.cpp?rev=237505&r1=237504&r2=237505&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/increment-decrement.cpp (original)
+++ cfe/trunk/test/SemaCXX/increment-decrement.cpp Fri May 15 20:27:03 2015
@@ -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) {

Modified: cfe/trunk/test/SemaCXX/references.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/references.cpp?rev=237505&r1=237504&r2=237505&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/references.cpp (original)
+++ cfe/trunk/test/SemaCXX/references.cpp Fri May 15 20:27:03 2015
@@ -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





More information about the cfe-commits mailing list