[cfe-commits] r154136 - in /cfe/trunk: lib/Sema/SemaType.cpp test/Sema/c89.c

Eli Friedman eli.friedman at gmail.com
Thu Apr 5 15:47:34 PDT 2012


Author: efriedma
Date: Thu Apr  5 17:47:34 2012
New Revision: 154136

URL: http://llvm.org/viewvc/llvm-project?rev=154136&view=rev
Log:
Implement C90 pedantic warning for duplicate declaration specifiers which are duplicated via a typedef.  Patch by Tim Northover.


Modified:
    cfe/trunk/lib/Sema/SemaType.cpp
    cfe/trunk/test/Sema/c89.c

Modified: cfe/trunk/lib/Sema/SemaType.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=154136&r1=154135&r2=154136&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaType.cpp (original)
+++ cfe/trunk/lib/Sema/SemaType.cpp Thu Apr  5 17:47:34 2012
@@ -26,6 +26,7 @@
 #include "clang/Basic/PartialDiagnostic.h"
 #include "clang/Basic/TargetInfo.h"
 #include "clang/Lex/Preprocessor.h"
+#include "clang/Parse/ParseDiagnostic.h"
 #include "clang/Sema/DeclSpec.h"
 #include "clang/Sema/DelayedDiagnostic.h"
 #include "clang/Sema/Lookup.h"
@@ -979,6 +980,25 @@
       TypeQuals &= ~DeclSpec::TQ_volatile;
     }
 
+    // C90 6.5.3 constraints: "The same type qualifier shall not appear more
+    // than once in the same specifier-list or qualifier-list, either directly
+    // or via one or more typedefs."
+    if (!S.getLangOpts().C99 && !S.getLangOpts().CPlusPlus 
+        && TypeQuals & Result.getCVRQualifiers()) {
+      if (TypeQuals & DeclSpec::TQ_const && Result.isConstQualified()) {
+        S.Diag(DS.getConstSpecLoc(), diag::ext_duplicate_declspec) 
+          << "const";
+      }
+
+      if (TypeQuals & DeclSpec::TQ_volatile && Result.isVolatileQualified()) {
+        S.Diag(DS.getVolatileSpecLoc(), diag::ext_duplicate_declspec) 
+          << "volatile";
+      }
+
+      // C90 doesn't have restrict, so it doesn't force us to produce a warning
+      // in this case.
+    }
+
     Qualifiers Quals = Qualifiers::fromCVRMask(TypeQuals);
     Result = Context.getQualifiedType(Result, Quals);
   }

Modified: cfe/trunk/test/Sema/c89.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/c89.c?rev=154136&r1=154135&r2=154136&view=diff
==============================================================================
--- cfe/trunk/test/Sema/c89.c (original)
+++ cfe/trunk/test/Sema/c89.c Thu Apr  5 17:47:34 2012
@@ -92,4 +92,21 @@
 
 struct x { int x,y[]; }; /* expected-warning {{Flexible array members are a C99-specific feature}} */
 
+/* Duplicated type-qualifiers aren't allowed by C90 */
+const const int c_i; /* expected-warning {{duplicate 'const' declaration specifier}} */
+typedef volatile int vol_int;
+volatile vol_int volvol_i; /* expected-warning {{duplicate 'volatile' declaration specifier}} */
+typedef volatile vol_int volvol_int; /* expected-warning {{duplicate 'volatile' declaration specifier}} */
+const int * const c;
+
+typedef const int CI;
+
+const CI mine1[5][5]; /* expected-warning {{duplicate 'const' declaration specifier}} */
+
+typedef CI array_of_CI[5];
+const array_of_CI mine2; /* expected-warning {{duplicate 'const' declaration specifier}} */
+
+typedef CI *array_of_pointer_to_CI[5];
+const array_of_pointer_to_CI mine3;
+
 void main() {} /* expected-error {{'main' must return 'int'}} */





More information about the cfe-commits mailing list