[cfe-commits] [PATCH] Warn on duplicate const specifier

Chandler Carruth chandlerc at google.com
Tue Aug 28 13:19:49 PDT 2012


Index: lib/Sema/DeclSpec.cpp
===================================================================
--- lib/Sema/DeclSpec.cpp (revision 162690)
+++ lib/Sema/DeclSpec.cpp (working copy)
@@ -325,10 +325,17 @@

 template <class T> static bool BadSpecifier(T TNew, T TPrev,
                                             const char *&PrevSpec,
-                                            unsigned &DiagID) {
+                                            unsigned &DiagID,
+                                            bool Pedantic = true) {

How about "IsExtension"?

   PrevSpec = DeclSpec::getSpecifierName(TPrev);
-  DiagID = (TNew == TPrev ? diag::ext_duplicate_declspec
-            : diag::err_invalid_decl_spec_combination);
+  if (TNew == TPrev) {
+    if (Pedantic)
+      DiagID = diag::ext_duplicate_declspec;
+    else
+      DiagID = diag::warn_duplicate_declspec;
+  } else {
+    DiagID = diag::err_invalid_decl_spec_combination;
+  }

Would early exit make this cleaner?


On Tue, Aug 28, 2012 at 12:56 PM, Aaron Ballman <aaron at aaronballman.com>wrote:

> On Tue, Aug 28, 2012 at 3:06 PM, Chandler Carruth <chandlerc at google.com>
> wrote:
> > I'm a bit uncomfortable making this an ExtWarn in all cases, as it
> doesn't
> > seem like it should be controlled by -pedantic when it is pedantically
> well
> > formed code.
> >
> > We should probably have two (yea, I know) diagnostics, one for when we
> > accept this an an extension, and one for when it is valid but likely
> > confusing / inadvisable. I'm happy for them to both be under the same
> > diagnostic group though.
>
> Thank you for the feedback (and clarifications).  Here's a revised
> patch which splits this into two warnings.  One is an ExtWarn for when
> we pedantically allow the behavior.  The other is a vanilla Warning
> for when we don't pedantically allow the behavior.  Both are
> implemented under the same group.
>
> Thanks!
>
> ~Aaron
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20120828/9a668150/attachment.html>


More information about the cfe-commits mailing list