From b82932c19ba1d0b929ce444f65b6655902ea78a0 Mon Sep 17 00:00:00 2001 From: Ehsan Akhgari Date: Tue, 24 Mar 2015 13:25:26 +0000 Subject: [PATCH] Revert "Diagnose declspecs occuring after virt-specifier-seq and generate fixit hints" This reverts commit 2131e63e2fdff7c831ab3bfe31facf2e3ebab03d. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@233074 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Basic/DiagnosticParseKinds.td | 2 - include/clang/Parse/Parser.h | 2 - include/clang/Sema/DeclSpec.h | 6 +-- lib/Parse/ParseDecl.cpp | 2 +- lib/Parse/ParseDeclCXX.cpp | 50 +-------------------- lib/Sema/DeclSpec.cpp | 3 -- test/FixIt/fixit-cxx0x.cpp | 11 ----- 7 files changed, 3 insertions(+), 73 deletions(-) diff --git a/include/clang/Basic/DiagnosticParseKinds.td b/include/clang/Basic/DiagnosticParseKinds.td index d96fbac50d..56a984baf4 100644 --- a/include/clang/Basic/DiagnosticParseKinds.td +++ b/include/clang/Basic/DiagnosticParseKinds.td @@ -183,8 +183,6 @@ def warn_attribute_no_decl : Warning< "attribute %0 ignored, because it is not attached to a declaration">, InGroup; def err_expected_method_body : Error<"expected method body">; -def err_declspec_after_virtspec : Error< - "'%0' qualifier may not appear after the virtual specifier '%1'">; def err_invalid_token_after_toplevel_declarator : Error< "expected ';' after top level declarator">; def err_invalid_token_after_declarator_suggest_equal : Error< diff --git a/include/clang/Parse/Parser.h b/include/clang/Parse/Parser.h index ba3fd133cc..498af7c5b7 100644 --- a/include/clang/Parse/Parser.h +++ b/include/clang/Parse/Parser.h @@ -2293,8 +2293,6 @@ private: VirtSpecifiers &VS, ExprResult &BitfieldSize, LateParsedAttrList &LateAttrs); - void MaybeParseAndDiagnoseDeclSpecAfterCXX11VirtSpecifierSeq(Declarator &D, - VirtSpecifiers &VS); void ParseCXXClassMemberDeclaration(AccessSpecifier AS, AttributeList *Attr, const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(), ParsingDeclRAIIObject *DiagsFromTParams = nullptr); diff --git a/include/clang/Sema/DeclSpec.h b/include/clang/Sema/DeclSpec.h index 03c3427d68..76ccb1d23a 100644 --- a/include/clang/Sema/DeclSpec.h +++ b/include/clang/Sema/DeclSpec.h @@ -2180,7 +2180,7 @@ public: VS_Sealed = 4 }; - VirtSpecifiers() : Specifiers(0), LastSpecifier(VS_None) { } + VirtSpecifiers() : Specifiers(0) { } bool SetSpecifier(Specifier VS, SourceLocation Loc, const char *&PrevSpec); @@ -2198,16 +2198,12 @@ public: static const char *getSpecifierName(Specifier VS); - SourceLocation getFirstLocation() const { return FirstLocation; } SourceLocation getLastLocation() const { return LastLocation; } - Specifier getLastSpecifier() const { return LastSpecifier; } private: unsigned Specifiers; - Specifier LastSpecifier; SourceLocation VS_overrideLoc, VS_finalLoc; - SourceLocation FirstLocation; SourceLocation LastLocation; }; diff --git a/lib/Parse/ParseDecl.cpp b/lib/Parse/ParseDecl.cpp index c19759e596..b4a7664298 100644 --- a/lib/Parse/ParseDecl.cpp +++ b/lib/Parse/ParseDecl.cpp @@ -5329,7 +5329,7 @@ void Parser::ParseFunctionDeclarator(Declarator &D, if (getLangOpts().CPlusPlus) { // FIXME: Accept these components in any order, and produce fixits to // correct the order if the user gets it wrong. Ideally we should deal - // with the pure-specifier in the same way. + // with the virt-specifier-seq and pure-specifier in the same way. // Parse cv-qualifier-seq[opt]. ParseTypeQualifierListOpt(DS, AR_NoAttributesParsed, diff --git a/lib/Parse/ParseDeclCXX.cpp b/lib/Parse/ParseDeclCXX.cpp index c92d5f30f9..3403cdea7a 100644 --- a/lib/Parse/ParseDeclCXX.cpp +++ b/lib/Parse/ParseDeclCXX.cpp @@ -2037,13 +2037,10 @@ bool Parser::ParseCXXMemberDeclaratorBeforeInitializer( BitfieldSize = ParseConstantExpression(); if (BitfieldSize.isInvalid()) SkipUntil(tok::comma, StopAtSemi | StopBeforeMatch); - } else { + } else ParseOptionalCXX11VirtSpecifierSeq( VS, getCurrentClass().IsInterface, DeclaratorInfo.getDeclSpec().getFriendSpecLoc()); - if (!VS.isUnset()) - MaybeParseAndDiagnoseDeclSpecAfterCXX11VirtSpecifierSeq(DeclaratorInfo, VS); - } // If a simple-asm-expr is present, parse it. if (Tok.is(tok::kw_asm)) { @@ -2074,7 +2071,6 @@ bool Parser::ParseCXXMemberDeclaratorBeforeInitializer( Diag(Attr->getLoc(), diag::warn_gcc_attribute_location); Attr = Attr->getNext(); } - MaybeParseAndDiagnoseDeclSpecAfterCXX11VirtSpecifierSeq(DeclaratorInfo, VS); } } @@ -2088,50 +2084,6 @@ bool Parser::ParseCXXMemberDeclaratorBeforeInitializer( return false; } -/// \brief Look for declaration specifiers possibly occurring after C++11 -/// virt-specifier-seq and diagnose them. -void Parser::MaybeParseAndDiagnoseDeclSpecAfterCXX11VirtSpecifierSeq( - Declarator &D, - VirtSpecifiers &VS) { - DeclSpec DS(AttrFactory); - - // GNU-style and C++11 attributes are not allowed here, but they will be - // handled by the caller. Diagnose everything else. - ParseTypeQualifierListOpt(DS, AR_NoAttributesParsed, false); - D.ExtendWithDeclSpec(DS); - - if (DS.getTypeQualifiers() != DeclSpec::TQ_unspecified) { - auto DeclSpecCheck = [&] (DeclSpec::TQ TypeQual, - const char *FixItName, - SourceLocation SpecLoc, - unsigned* QualifierLoc) { - FixItHint Insertion; - auto &Function = D.getFunctionTypeInfo(); - if (DS.getTypeQualifiers() & TypeQual) { - if (!(Function.TypeQuals & TypeQual)) { - std::string Name(FixItName); - Name += " "; - Insertion = FixItHint::CreateInsertion(VS.getFirstLocation(), Name.c_str()); - Function.TypeQuals |= TypeQual; - *QualifierLoc = SpecLoc.getRawEncoding(); - } - Diag(SpecLoc, diag::err_declspec_after_virtspec) - << FixItName - << VirtSpecifiers::getSpecifierName(VS.getLastSpecifier()) - << FixItHint::CreateRemoval(SpecLoc) - << Insertion; - } - }; - auto &Function = D.getFunctionTypeInfo(); - DeclSpecCheck(DeclSpec::TQ_const, "const", DS.getConstSpecLoc(), - &Function.ConstQualifierLoc); - DeclSpecCheck(DeclSpec::TQ_volatile, "volatile", DS.getVolatileSpecLoc(), - &Function.VolatileQualifierLoc); - DeclSpecCheck(DeclSpec::TQ_restrict, "restrict", DS.getRestrictSpecLoc(), - &Function.RestrictQualifierLoc); - } -} - /// ParseCXXClassMemberDeclaration - Parse a C++ class member declaration. /// /// member-declaration: diff --git a/lib/Sema/DeclSpec.cpp b/lib/Sema/DeclSpec.cpp index f6689a96bd..5e349bc2ad 100644 --- a/lib/Sema/DeclSpec.cpp +++ b/lib/Sema/DeclSpec.cpp @@ -1220,10 +1220,7 @@ void UnqualifiedId::setOperatorFunctionId(SourceLocation OperatorLoc, bool VirtSpecifiers::SetSpecifier(Specifier VS, SourceLocation Loc, const char *&PrevSpec) { - if (!FirstLocation.isValid()) - FirstLocation = Loc; LastLocation = Loc; - LastSpecifier = VS; if (Specifiers & VS) { PrevSpec = getSpecifierName(VS); diff --git a/test/FixIt/fixit-cxx0x.cpp b/test/FixIt/fixit-cxx0x.cpp index 6e096e5e78..49a05ff8d1 100644 --- a/test/FixIt/fixit-cxx0x.cpp +++ b/test/FixIt/fixit-cxx0x.cpp @@ -158,14 +158,3 @@ namespace MisplacedParameterPack { template // expected-error {{'...' must immediately precede declared identifier}} void redundantEllipsisInNonTypeTemplateParameter(); } - -namespace MisplacedDeclSpecAfterVirtSpec { - struct B { - virtual void f(); - virtual void f() volatile const; - }; - struct D : B { - virtual void f() override; - virtual void f() override final const volatile; // expected-error {{'const' qualifier may not appear after the virtual specifier 'final'}} expected-error {{'volatile' qualifier may not appear after the virtual specifier 'final'}} - }; -} -- 2.40.0