]> granicus.if.org Git - clang/commitdiff
Pedantic -pedantic correction. Duplicate cv-qualifiers are permitted in C++11
authorRichard Smith <richard-llvm@metafoo.co.uk>
Tue, 24 Jul 2012 20:24:58 +0000 (20:24 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Tue, 24 Jul 2012 20:24:58 +0000 (20:24 +0000)
unless they appear in a decl-specifier-seq.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@160688 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Sema/DeclSpec.h
lib/Parse/ParseDecl.cpp
lib/Sema/DeclSpec.cpp
test/Parser/cxx0x-decl.cpp

index 0f323bd9292d73953ad65b27a960b93ceaa28cd4..7999748b0f9a1045b3489e0f3a88ccf5b1bd1cc0 100644 (file)
@@ -598,7 +598,8 @@ public:
   }
 
   bool SetTypeQual(TQ T, SourceLocation Loc, const char *&PrevSpec,
-                   unsigned &DiagID, const LangOptions &Lang);
+                   unsigned &DiagID, const LangOptions &Lang,
+                   bool IsTypeSpec);
 
   bool SetFunctionSpecInline(SourceLocation Loc, const char *&PrevSpec,
                              unsigned &DiagID);
index c6a7d05c8f7627d21fa1215d5a5a4b22325d8129..b2a6b4bb41ffa86e45e5aee905d98bbe7bd395e3 100644 (file)
@@ -2666,15 +2666,15 @@ void Parser::ParseDeclarationSpecifiers(DeclSpec &DS,
     // cv-qualifier:
     case tok::kw_const:
       isInvalid = DS.SetTypeQual(DeclSpec::TQ_const, Loc, PrevSpec, DiagID,
-                                 getLangOpts());
+                                 getLangOpts(), /*IsTypeSpec*/true);
       break;
     case tok::kw_volatile:
       isInvalid = DS.SetTypeQual(DeclSpec::TQ_volatile, Loc, PrevSpec, DiagID,
-                                 getLangOpts());
+                                 getLangOpts(), /*IsTypeSpec*/true);
       break;
     case tok::kw_restrict:
       isInvalid = DS.SetTypeQual(DeclSpec::TQ_restrict, Loc, PrevSpec, DiagID,
-                                 getLangOpts());
+                                 getLangOpts(), /*IsTypeSpec*/true);
       break;
 
     // C++ typename-specifier:
@@ -3869,15 +3869,15 @@ void Parser::ParseTypeQualifierListOpt(DeclSpec &DS,
 
     case tok::kw_const:
       isInvalid = DS.SetTypeQual(DeclSpec::TQ_const   , Loc, PrevSpec, DiagID,
-                                 getLangOpts());
+                                 getLangOpts(), /*IsTypeSpec*/false);
       break;
     case tok::kw_volatile:
       isInvalid = DS.SetTypeQual(DeclSpec::TQ_volatile, Loc, PrevSpec, DiagID,
-                                 getLangOpts());
+                                 getLangOpts(), /*IsTypeSpec*/false);
       break;
     case tok::kw_restrict:
       isInvalid = DS.SetTypeQual(DeclSpec::TQ_restrict, Loc, PrevSpec, DiagID,
-                                 getLangOpts());
+                                 getLangOpts(), /*IsTypeSpec*/false);
       break;
 
     // OpenCL qualifiers:
index 3cce8cb44493f6b6e4237ca28c830c0ead819723..f3ec5656ea33953dc0b7d56f0806eb0bb13987d9 100644 (file)
@@ -668,9 +668,11 @@ bool DeclSpec::SetTypeSpecError() {
 }
 
 bool DeclSpec::SetTypeQual(TQ T, SourceLocation Loc, const char *&PrevSpec,
-                           unsigned &DiagID, const LangOptions &Lang) {
-  // Duplicates turn into warnings pre-C99.
-  if ((TypeQualifiers & T) && !Lang.C99)
+                           unsigned &DiagID, const LangOptions &Lang,
+                           bool IsTypeSpec) {
+  // Duplicates are permitted in C99, and are permitted in C++11 unless the
+  // cv-qualifier appears as a type-specifier.
+  if ((TypeQualifiers & T) && !Lang.C99 && (!Lang.CPlusPlus0x || IsTypeSpec))
     return BadSpecifier(T, T, PrevSpec, DiagID);
   TypeQualifiers |= T;
 
index 9a220caa5ad5d6f932e38934a8dfbb3223501191..a6fc49cb9e9d7bf777032f2afec4a0fdf660b730 100644 (file)
@@ -25,3 +25,6 @@ class ExtraSemiAfterMemFn {
   void h() = delete;; // ok
   void i() = delete;;; // expected-warning {{extra ';' after member function definition}}
 };
+
+int *const const p = 0; // ok
+const const int *q = 0; // expected-warning {{duplicate 'const' declaration specifier}}