diff options
author | Eli Friedman <eli.friedman@gmail.com> | 2012-04-05 22:47:34 +0000 |
---|---|---|
committer | Eli Friedman <eli.friedman@gmail.com> | 2012-04-05 22:47:34 +0000 |
commit | bc1029b4a47282cb4ce27c7014acb864b10a4043 (patch) | |
tree | 96423d4ed9298dafc20ded4a5057c612b038c588 /lib/Sema | |
parent | ae916a14cf727b4ce3ac316f4fd780d1c83c5baf (diff) |
Implement C90 pedantic warning for duplicate declaration specifiers which are duplicated via a typedef. Patch by Tim Northover.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@154136 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema')
-rw-r--r-- | lib/Sema/SemaType.cpp | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/lib/Sema/SemaType.cpp b/lib/Sema/SemaType.cpp index 711ff08ce1..c41df82a48 100644 --- a/lib/Sema/SemaType.cpp +++ b/lib/Sema/SemaType.cpp @@ -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 @@ static QualType ConvertDeclSpecToType(TypeProcessingState &state) { 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); } |