]> granicus.if.org Git - clang/commitdiff
When emitting a dropped qualifier error, show which qualifiers are dropped.
authorRichard Trieu <rtrieu@google.com>
Sat, 16 May 2015 01:27:03 +0000 (01:27 +0000)
committerRichard Trieu <rtrieu@google.com>
Sat, 16 May 2015 01:27:03 +0000 (01:27 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@237505 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.prim/expr.prim.lambda/p16.cpp
test/CXX/temp/temp.arg/temp.arg.nontype/p5.cpp
test/Misc/diag-template-diffing.cpp
test/SemaCXX/builtins-arm.cpp
test/SemaCXX/err_reference_bind_drops_quals.cpp [new file with mode: 0644]
test/SemaCXX/increment-decrement.cpp
test/SemaCXX/references.cpp

index bc52d61d55c7d798a3c87cb1b545435ad6e7a877..052c93ebdd63837cff3c02ca4dbe71d03d261082 100644 (file)
@@ -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">;
index 32570c7175711f2ab875c3539d5b3188f561ac72..7dd93e8de5891fadf5d9effa4ceaedff224b5f46 100644 (file)
@@ -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)
index b872281b05a517b75b48e03651194e7ff3f5ac9b..a187713cb5a8c00821cd9a7e21640d92e36a46c2 100644 (file)
@@ -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'}}
index 36fcf904257606d2aed2946ce749b64cf461dbd3..9397bbd7a0649deb645607babe4202cbe0abe82e 100644 (file)
@@ -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>();
 }
index 0cbffe844e761038f971fd3f0da327a37a538af8..3f350bdbb87be8c20ea4c9f56ec4813afb095b56 100644 (file)
@@ -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}}
       }();
     }(); 
   }(); 
index e87153b9efe2e3c45b66106566f2f1998e648d5b..249563e7d9bf1383ac3d2d7baaf3397e63ee4adf 100644 (file)
@@ -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;
index 367de4b8a7416661d674c71b0128018a21e0624f..f345535ea1c5c2e7245b497a97af1abf8b3347c1 100644 (file)
@@ -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 {
index 683317dbbe65ad54217802092c44aeba2e5c27b6..81502794a948c97562fdbc94c18cd82139726134 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 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}}
 }
diff --git a/test/SemaCXX/err_reference_bind_drops_quals.cpp b/test/SemaCXX/err_reference_bind_drops_quals.cpp
new file mode 100644 (file)
index 0000000..afdd832
--- /dev/null
@@ -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;
+}
index 11b7d1e12f4e1845007c8ce389669e05fa39948a..4f131d76f04686469c45216257238b583c5d0b83 100644 (file)
@@ -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) {
index 64d87bd132b5f0e1895f937096d931f64e2e67a4..aae4930593a2e2345a1557fb94c5de2e4cfee482 100644 (file)
@@ -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