]> granicus.if.org Git - clang/commitdiff
DR1528: C++11 doesn't allow repeated cv-qualifiers in declarators after all.
authorRichard Smith <richard-llvm@metafoo.co.uk>
Wed, 17 Oct 2012 23:31:46 +0000 (23:31 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Wed, 17 Oct 2012 23:31:46 +0000 (23:31 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@166152 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 6a4a9ce4e65f66c2c6f8d0548199b2b4f8b10f0c..0728e87376387d497bc387948e430d3e01e263f0 100644 (file)
@@ -600,8 +600,7 @@ public:
   }
 
   bool SetTypeQual(TQ T, SourceLocation Loc, const char *&PrevSpec,
-                   unsigned &DiagID, const LangOptions &Lang,
-                   bool IsTypeSpec);
+                   unsigned &DiagID, const LangOptions &Lang);
 
   bool SetFunctionSpecInline(SourceLocation Loc, const char *&PrevSpec,
                              unsigned &DiagID);
index 3e4d92abe8fe4c988864748f8c9fac3bd2c53fd4..26175a50f53fe543d730c33713d13382456f3c53 100644 (file)
@@ -2741,15 +2741,15 @@ void Parser::ParseDeclarationSpecifiers(DeclSpec &DS,
     // cv-qualifier:
     case tok::kw_const:
       isInvalid = DS.SetTypeQual(DeclSpec::TQ_const, Loc, PrevSpec, DiagID,
-                                 getLangOpts(), /*IsTypeSpec*/true);
+                                 getLangOpts());
       break;
     case tok::kw_volatile:
       isInvalid = DS.SetTypeQual(DeclSpec::TQ_volatile, Loc, PrevSpec, DiagID,
-                                 getLangOpts(), /*IsTypeSpec*/true);
+                                 getLangOpts());
       break;
     case tok::kw_restrict:
       isInvalid = DS.SetTypeQual(DeclSpec::TQ_restrict, Loc, PrevSpec, DiagID,
-                                 getLangOpts(), /*IsTypeSpec*/true);
+                                 getLangOpts());
       break;
 
     // C++ typename-specifier:
@@ -3948,15 +3948,15 @@ void Parser::ParseTypeQualifierListOpt(DeclSpec &DS,
 
     case tok::kw_const:
       isInvalid = DS.SetTypeQual(DeclSpec::TQ_const   , Loc, PrevSpec, DiagID,
-                                 getLangOpts(), /*IsTypeSpec*/false);
+                                 getLangOpts());
       break;
     case tok::kw_volatile:
       isInvalid = DS.SetTypeQual(DeclSpec::TQ_volatile, Loc, PrevSpec, DiagID,
-                                 getLangOpts(), /*IsTypeSpec*/false);
+                                 getLangOpts());
       break;
     case tok::kw_restrict:
       isInvalid = DS.SetTypeQual(DeclSpec::TQ_restrict, Loc, PrevSpec, DiagID,
-                                 getLangOpts(), /*IsTypeSpec*/false);
+                                 getLangOpts());
       break;
 
     // OpenCL qualifiers:
index 971fc721c1c78b63c6770266497070add58e2070..b3066eb0801342ee848d54ac91e2158ce4202802 100644 (file)
@@ -680,15 +680,13 @@ bool DeclSpec::SetTypeSpecError() {
 }
 
 bool DeclSpec::SetTypeQual(TQ T, SourceLocation Loc, const char *&PrevSpec,
-                           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.  However, since this is likely 
-  // not what the user intended, we will always warn.  We do not need to set the
-  // qualifier's location since we already have it.
+                           unsigned &DiagID, const LangOptions &Lang) {
+  // Duplicates are permitted in C99, but are not permitted in C++. However,
+  // since this is likely not what the user intended, we will always warn.  We
+  // do not need to set the qualifier's location since we already have it.
   if (TypeQualifiers & T) {
     bool IsExtension = true;
-    if (Lang.C99 || (Lang.CPlusPlus0x && !IsTypeSpec))
+    if (Lang.C99)
       IsExtension = false;
     return BadSpecifier(T, T, PrevSpec, DiagID, IsExtension);
   }
index 13c7fbf0b01371f332cfb2639f8e0e07eb28dd54..3af73f95c78fcff5831fc7bcd0d9afcd0f2d684a 100644 (file)
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -verify -fsyntax-only -std=c++11 -pedantic %s
+// RUN: %clang_cc1 -verify -fsyntax-only -std=c++11 -pedantic-errors %s
 
 // Make sure we know these are legitimate commas and not typos for ';'.
 namespace Commas {
@@ -23,12 +23,14 @@ class ExtraSemiAfterMemFn {
   void f() = delete // expected-error {{expected ';' after delete}}
   void g() = delete; // ok
   void h() = delete;; // ok
-  void i() = delete;;; // expected-warning {{extra ';' after member function definition}}
+  void i() = delete;;; // expected-error {{extra ';' after member function definition}}
 };
 
-// This is technically okay, but not likely what the user expects, so we will
-// pedantically warn on it
-int *const const p = 0; // expected-warning {{duplicate 'const' declaration specifier}}
-const const int *q = 0; // expected-warning {{duplicate 'const' declaration specifier}}
+int *const const p = 0; // expected-error {{duplicate 'const' declaration specifier}}
+const const int *q = 0; // expected-error {{duplicate 'const' declaration specifier}}
+
+struct MultiCV {
+  void f() const const; // expected-error {{duplicate 'const' declaration specifier}}
+};
 
 static_assert(something, ""); // expected-error {{undeclared identifier}}