In code such as "char* volatile const j()", Clang warns that "volatile
const" will be ignored, but the error currently points to the location
of "const". The attached patch makes the error point to the location
of the first ignored qualifier, and tries to simplify the code a bit.

I posted this to the wrong list before [1] and didn't receive any
response. I would be grateful for any feedback.

Thanks,
Hans


[1]: http://lists.cs.uiuc.edu/pipermail/cfe-dev/2011-April/014809.html
Index: test/SemaCXX/return.cpp
===================================================================
--- test/SemaCXX/return.cpp	(revision 132394)
+++ test/SemaCXX/return.cpp	(working copy)
@@ -39,6 +39,11 @@
 char* const h(); // expected-warning{{'const' type qualifier on return type has no effect}}
 char* volatile i(); // expected-warning{{'volatile' type qualifier on return type has no effect}}
 
+char*
+volatile // expected-warning{{'const volatile' type qualifiers on return type have no effect}}
+const
+j();
+
 const volatile int scalar_cv(); // expected-warning{{'const volatile' type qualifiers on return type have no effect}}
 }
 
Index: lib/Sema/SemaType.cpp
===================================================================
--- lib/Sema/SemaType.cpp	(revision 132394)
+++ lib/Sema/SemaType.cpp	(working copy)
@@ -1484,36 +1484,30 @@
   // the order in which they textually appear.
   if (Quals & Qualifiers::Const) {
     ConstFixIt = FixItHint::CreateRemoval(ConstQualLoc);
-    Loc = ConstQualLoc;
-    ++NumQuals;
     QualStr = "const";
+    ++NumQuals;
+    if (!Loc.isValid() || ConstQualLoc < Loc)
+      Loc = ConstQualLoc;
   }
   if (Quals & Qualifiers::Volatile) {
     VolatileFixIt = FixItHint::CreateRemoval(VolatileQualLoc);
-    if (NumQuals == 0) {
-      Loc = VolatileQualLoc;
-      QualStr = "volatile";
-    } else {
-      QualStr += " volatile";
-    }
+    QualStr += (NumQuals == 0 ? "volatile" : " volatile");
     ++NumQuals;
+    if (!Loc.isValid() || VolatileQualLoc < Loc)
+      Loc = VolatileQualLoc;
   }
   if (Quals & Qualifiers::Restrict) {
     RestrictFixIt = FixItHint::CreateRemoval(RestrictQualLoc);
-    if (NumQuals == 0) {
-      Loc = RestrictQualLoc;
-      QualStr = "restrict";
-    } else {
-      QualStr += " restrict";
-    }
+    QualStr += (NumQuals == 0 ? "restrict" : " restrict");
     ++NumQuals;
+    if (!Loc.isValid() || RestrictQualLoc < Loc)
+      Loc = RestrictQualLoc;
   }
 
   assert(NumQuals > 0 && "No known qualifiers?");
 
   S.Diag(Loc, diag::warn_qual_return_type)
-    << QualStr << NumQuals
-    << ConstFixIt << VolatileFixIt << RestrictFixIt;
+    << QualStr << NumQuals << ConstFixIt << VolatileFixIt << RestrictFixIt;
 }
 
 /// GetTypeForDeclarator - Convert the type for the specified
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to