diff options
author | Ehsan Akhgari <ehsan.akhgari@gmail.com> | 2015-03-24 13:02:50 +0000 |
---|---|---|
committer | Ehsan Akhgari <ehsan.akhgari@gmail.com> | 2015-03-24 13:02:50 +0000 |
commit | 86638e59bff95e3a838ff2acb27a8debba4d03c5 (patch) | |
tree | e95b9243d44b2bb9e09ad871c852592f380ad4f2 /clang/lib | |
parent | 9a7adfcf3ac0be7fb1d3954226249a9269b94804 (diff) | |
download | bcm5719-llvm-86638e59bff95e3a838ff2acb27a8debba4d03c5.tar.gz bcm5719-llvm-86638e59bff95e3a838ff2acb27a8debba4d03c5.zip |
Diagnose ref-qualifiers occuring after virt-specifier-seq and generate fixit hints
Summary: Follow-up to the fix of PR22075.
Reviewers: rsmith
Subscribers: cfe-commits
Differential Revision: http://reviews.llvm.org/D7012
llvm-svn: 233070
Diffstat (limited to 'clang/lib')
-rw-r--r-- | clang/lib/Parse/ParseDecl.cpp | 25 | ||||
-rw-r--r-- | clang/lib/Parse/ParseDeclCXX.cpp | 20 |
2 files changed, 35 insertions, 10 deletions
diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp index c19759e596c..5726fb622c6 100644 --- a/clang/lib/Parse/ParseDecl.cpp +++ b/clang/lib/Parse/ParseDecl.cpp @@ -5342,15 +5342,8 @@ void Parser::ParseFunctionDeclarator(Declarator &D, } // Parse ref-qualifier[opt]. - if (Tok.is(tok::amp) || Tok.is(tok::ampamp)) { - Diag(Tok, getLangOpts().CPlusPlus11 ? - diag::warn_cxx98_compat_ref_qualifier : - diag::ext_ref_qualifier); - - RefQualifierIsLValueRef = Tok.is(tok::amp); - RefQualifierLoc = ConsumeToken(); + if (ParseRefQualifier(RefQualifierIsLValueRef, RefQualifierLoc)) EndLoc = RefQualifierLoc; - } // C++11 [expr.prim.general]p3: // If a declaration declares a member function or member function @@ -5446,6 +5439,22 @@ void Parser::ParseFunctionDeclarator(Declarator &D, FnAttrs, EndLoc); } +/// ParseRefQualifier - Parses a member function ref-qualifier. Returns +/// true if a ref-qualifier is found. +bool Parser::ParseRefQualifier(bool &RefQualifierIsLValueRef, + SourceLocation &RefQualifierLoc) { + if (Tok.is(tok::amp) || Tok.is(tok::ampamp)) { + Diag(Tok, getLangOpts().CPlusPlus11 ? + diag::warn_cxx98_compat_ref_qualifier : + diag::ext_ref_qualifier); + + RefQualifierIsLValueRef = Tok.is(tok::amp); + RefQualifierLoc = ConsumeToken(); + return true; + } + return false; +} + /// isFunctionDeclaratorIdentifierList - This parameter list may have an /// identifier list form for a K&R-style function: void foo(a,b,c) /// diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp index c92d5f30f95..89da9fbf3c9 100644 --- a/clang/lib/Parse/ParseDeclCXX.cpp +++ b/clang/lib/Parse/ParseDeclCXX.cpp @@ -2100,13 +2100,13 @@ void Parser::MaybeParseAndDiagnoseDeclSpecAfterCXX11VirtSpecifierSeq( ParseTypeQualifierListOpt(DS, AR_NoAttributesParsed, false); D.ExtendWithDeclSpec(DS); + auto &Function = D.getFunctionTypeInfo(); 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); @@ -2122,7 +2122,6 @@ void Parser::MaybeParseAndDiagnoseDeclSpecAfterCXX11VirtSpecifierSeq( << Insertion; } }; - auto &Function = D.getFunctionTypeInfo(); DeclSpecCheck(DeclSpec::TQ_const, "const", DS.getConstSpecLoc(), &Function.ConstQualifierLoc); DeclSpecCheck(DeclSpec::TQ_volatile, "volatile", DS.getVolatileSpecLoc(), @@ -2130,6 +2129,23 @@ void Parser::MaybeParseAndDiagnoseDeclSpecAfterCXX11VirtSpecifierSeq( DeclSpecCheck(DeclSpec::TQ_restrict, "restrict", DS.getRestrictSpecLoc(), &Function.RestrictQualifierLoc); } + + // Parse ref-qualifiers. + bool RefQualifierIsLValueRef = true; + SourceLocation RefQualifierLoc; + if (ParseRefQualifier(RefQualifierIsLValueRef, RefQualifierLoc)) { + const char *Name = (RefQualifierIsLValueRef ? "& " : "&& "); + FixItHint Insertion = FixItHint::CreateInsertion(VS.getFirstLocation(), Name); + Function.RefQualifierIsLValueRef = RefQualifierIsLValueRef; + Function.RefQualifierLoc = RefQualifierLoc.getRawEncoding(); + + Diag(RefQualifierLoc, diag::err_declspec_after_virtspec) + << (RefQualifierIsLValueRef ? "&" : "&&") + << VirtSpecifiers::getSpecifierName(VS.getLastSpecifier()) + << FixItHint::CreateRemoval(RefQualifierLoc) + << Insertion; + D.SetRangeEnd(RefQualifierLoc); + } } /// ParseCXXClassMemberDeclaration - Parse a C++ class member declaration. |