ParseDeclCXX.cpp revision 9910df05e9b5f03043f4d8dc12ea1bbb722664df
18f08cb7d0b97786b17ef05e05caa55aad4d6bd39Chris Lattner//===--- ParseDeclCXX.cpp - C++ Declaration Parsing -----------------------===// 28f08cb7d0b97786b17ef05e05caa55aad4d6bd39Chris Lattner// 38f08cb7d0b97786b17ef05e05caa55aad4d6bd39Chris Lattner// The LLVM Compiler Infrastructure 48f08cb7d0b97786b17ef05e05caa55aad4d6bd39Chris Lattner// 50bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// This file is distributed under the University of Illinois Open Source 60bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// License. See LICENSE.TXT for details. 78f08cb7d0b97786b17ef05e05caa55aad4d6bd39Chris Lattner// 88f08cb7d0b97786b17ef05e05caa55aad4d6bd39Chris Lattner//===----------------------------------------------------------------------===// 98f08cb7d0b97786b17ef05e05caa55aad4d6bd39Chris Lattner// 108f08cb7d0b97786b17ef05e05caa55aad4d6bd39Chris Lattner// This file implements the C++ Declaration portions of the Parser interfaces. 118f08cb7d0b97786b17ef05e05caa55aad4d6bd39Chris Lattner// 128f08cb7d0b97786b17ef05e05caa55aad4d6bd39Chris Lattner//===----------------------------------------------------------------------===// 138f08cb7d0b97786b17ef05e05caa55aad4d6bd39Chris Lattner 140c6139d0c2497c4e8780340e0dc097de041f248eAnders Carlsson#include "clang/Basic/OperatorKinds.h" 151b7f89846f10681ce3cbe89ef5d60691d55bd918Douglas Gregor#include "clang/Parse/Parser.h" 16500d3297d2a21edeac4d46cbcbe21bc2352c2a28Chris Lattner#include "clang/Parse/ParseDiagnostic.h" 1719510856727e0e14a3696b2a72c35163bff2a71fJohn McCall#include "clang/Sema/DeclSpec.h" 1819510856727e0e14a3696b2a72c35163bff2a71fJohn McCall#include "clang/Sema/Scope.h" 1919510856727e0e14a3696b2a72c35163bff2a71fJohn McCall#include "clang/Sema/ParsedTemplate.h" 20f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall#include "clang/Sema/PrettyDeclStackTrace.h" 21d167ca0d26e43292b8b9e8d5300d92784ae0e27dChris Lattner#include "RAIIObjectsForParser.h" 228f08cb7d0b97786b17ef05e05caa55aad4d6bd39Chris Lattnerusing namespace clang; 238f08cb7d0b97786b17ef05e05caa55aad4d6bd39Chris Lattner 248f08cb7d0b97786b17ef05e05caa55aad4d6bd39Chris Lattner/// ParseNamespace - We know that the current token is a namespace keyword. This 25d078e641450bbc5a20df8d3b54f87b27e398acb3Sebastian Redl/// may either be a top level namespace or a block-level namespace alias. If 26d078e641450bbc5a20df8d3b54f87b27e398acb3Sebastian Redl/// there was an inline keyword, it has already been parsed. 278f08cb7d0b97786b17ef05e05caa55aad4d6bd39Chris Lattner/// 288f08cb7d0b97786b17ef05e05caa55aad4d6bd39Chris Lattner/// namespace-definition: [C++ 7.3: basic.namespace] 298f08cb7d0b97786b17ef05e05caa55aad4d6bd39Chris Lattner/// named-namespace-definition 308f08cb7d0b97786b17ef05e05caa55aad4d6bd39Chris Lattner/// unnamed-namespace-definition 318f08cb7d0b97786b17ef05e05caa55aad4d6bd39Chris Lattner/// 328f08cb7d0b97786b17ef05e05caa55aad4d6bd39Chris Lattner/// unnamed-namespace-definition: 33d078e641450bbc5a20df8d3b54f87b27e398acb3Sebastian Redl/// 'inline'[opt] 'namespace' attributes[opt] '{' namespace-body '}' 348f08cb7d0b97786b17ef05e05caa55aad4d6bd39Chris Lattner/// 358f08cb7d0b97786b17ef05e05caa55aad4d6bd39Chris Lattner/// named-namespace-definition: 368f08cb7d0b97786b17ef05e05caa55aad4d6bd39Chris Lattner/// original-namespace-definition 378f08cb7d0b97786b17ef05e05caa55aad4d6bd39Chris Lattner/// extension-namespace-definition 388f08cb7d0b97786b17ef05e05caa55aad4d6bd39Chris Lattner/// 398f08cb7d0b97786b17ef05e05caa55aad4d6bd39Chris Lattner/// original-namespace-definition: 40d078e641450bbc5a20df8d3b54f87b27e398acb3Sebastian Redl/// 'inline'[opt] 'namespace' identifier attributes[opt] 41d078e641450bbc5a20df8d3b54f87b27e398acb3Sebastian Redl/// '{' namespace-body '}' 428f08cb7d0b97786b17ef05e05caa55aad4d6bd39Chris Lattner/// 438f08cb7d0b97786b17ef05e05caa55aad4d6bd39Chris Lattner/// extension-namespace-definition: 44d078e641450bbc5a20df8d3b54f87b27e398acb3Sebastian Redl/// 'inline'[opt] 'namespace' original-namespace-name 45d078e641450bbc5a20df8d3b54f87b27e398acb3Sebastian Redl/// '{' namespace-body '}' 461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// 478f08cb7d0b97786b17ef05e05caa55aad4d6bd39Chris Lattner/// namespace-alias-definition: [C++ 7.3.2: namespace.alias] 488f08cb7d0b97786b17ef05e05caa55aad4d6bd39Chris Lattner/// 'namespace' identifier '=' qualified-namespace-specifier ';' 498f08cb7d0b97786b17ef05e05caa55aad4d6bd39Chris Lattner/// 50d226f65006733ed7f709c3174f22ce33391cb58fJohn McCallDecl *Parser::ParseNamespace(unsigned Context, 51d078e641450bbc5a20df8d3b54f87b27e398acb3Sebastian Redl SourceLocation &DeclEnd, 52d078e641450bbc5a20df8d3b54f87b27e398acb3Sebastian Redl SourceLocation InlineLoc) { 5304d6666eee19bbf25bdfcb8e79eb8b00ace03f0cChris Lattner assert(Tok.is(tok::kw_namespace) && "Not a namespace!"); 548f08cb7d0b97786b17ef05e05caa55aad4d6bd39Chris Lattner SourceLocation NamespaceLoc = ConsumeToken(); // eat the 'namespace'. 551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5649f40bd0c9c9de5e74727774fec429b47d36303aDouglas Gregor if (Tok.is(tok::code_completion)) { 5723c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteNamespaceDecl(getCurScope()); 58dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor ConsumeCodeCompletionToken(); 5949f40bd0c9c9de5e74727774fec429b47d36303aDouglas Gregor } 60193575455e00eca03fd7177f60e3f2e6263cb661Kovarththanan Rajaratnam 618f08cb7d0b97786b17ef05e05caa55aad4d6bd39Chris Lattner SourceLocation IdentLoc; 628f08cb7d0b97786b17ef05e05caa55aad4d6bd39Chris Lattner IdentifierInfo *Ident = 0; 63f858bd817e8d6eac58ae496fa96a2f508fbb286fRichard Trieu std::vector<SourceLocation> ExtraIdentLoc; 64f858bd817e8d6eac58ae496fa96a2f508fbb286fRichard Trieu std::vector<IdentifierInfo*> ExtraIdent; 65f858bd817e8d6eac58ae496fa96a2f508fbb286fRichard Trieu std::vector<SourceLocation> ExtraNamespaceLoc; 666a588dd230c14a364d222d6057bbcf11afbd9ffdDouglas Gregor 676a588dd230c14a364d222d6057bbcf11afbd9ffdDouglas Gregor Token attrTok; 681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6904d6666eee19bbf25bdfcb8e79eb8b00ace03f0cChris Lattner if (Tok.is(tok::identifier)) { 708f08cb7d0b97786b17ef05e05caa55aad4d6bd39Chris Lattner Ident = Tok.getIdentifierInfo(); 718f08cb7d0b97786b17ef05e05caa55aad4d6bd39Chris Lattner IdentLoc = ConsumeToken(); // eat the identifier. 72f858bd817e8d6eac58ae496fa96a2f508fbb286fRichard Trieu while (Tok.is(tok::coloncolon) && NextToken().is(tok::identifier)) { 73f858bd817e8d6eac58ae496fa96a2f508fbb286fRichard Trieu ExtraNamespaceLoc.push_back(ConsumeToken()); 74f858bd817e8d6eac58ae496fa96a2f508fbb286fRichard Trieu ExtraIdent.push_back(Tok.getIdentifierInfo()); 75f858bd817e8d6eac58ae496fa96a2f508fbb286fRichard Trieu ExtraIdentLoc.push_back(ConsumeToken()); 76f858bd817e8d6eac58ae496fa96a2f508fbb286fRichard Trieu } 778f08cb7d0b97786b17ef05e05caa55aad4d6bd39Chris Lattner } 781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 798f08cb7d0b97786b17ef05e05caa55aad4d6bd39Chris Lattner // Read label attributes, if present. 800b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall ParsedAttributes attrs(AttrFactory); 816a588dd230c14a364d222d6057bbcf11afbd9ffdDouglas Gregor if (Tok.is(tok::kw___attribute)) { 826a588dd230c14a364d222d6057bbcf11afbd9ffdDouglas Gregor attrTok = Tok; 837f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall ParseGNUAttributes(attrs); 846a588dd230c14a364d222d6057bbcf11afbd9ffdDouglas Gregor } 851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 866a588dd230c14a364d222d6057bbcf11afbd9ffdDouglas Gregor if (Tok.is(tok::equal)) { 877f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall if (!attrs.empty()) 886a588dd230c14a364d222d6057bbcf11afbd9ffdDouglas Gregor Diag(attrTok, diag::err_unexpected_namespace_attributes_alias); 89d078e641450bbc5a20df8d3b54f87b27e398acb3Sebastian Redl if (InlineLoc.isValid()) 90d078e641450bbc5a20df8d3b54f87b27e398acb3Sebastian Redl Diag(InlineLoc, diag::err_inline_namespace_alias) 91d078e641450bbc5a20df8d3b54f87b27e398acb3Sebastian Redl << FixItHint::CreateRemoval(InlineLoc); 926a588dd230c14a364d222d6057bbcf11afbd9ffdDouglas Gregor 9397144fc41a9419bf6d74fc9450e8ef3f6e11f7e0Chris Lattner return ParseNamespaceAlias(NamespaceLoc, IdentLoc, Ident, DeclEnd); 946a588dd230c14a364d222d6057bbcf11afbd9ffdDouglas Gregor } 951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 96f858bd817e8d6eac58ae496fa96a2f508fbb286fRichard Trieu 975144832ae62cf97543b274d4bb88d5f74d0f7a20Chris Lattner if (Tok.isNot(tok::l_brace)) { 98f858bd817e8d6eac58ae496fa96a2f508fbb286fRichard Trieu if (!ExtraIdent.empty()) { 99f858bd817e8d6eac58ae496fa96a2f508fbb286fRichard Trieu Diag(ExtraNamespaceLoc[0], diag::err_nested_namespaces_with_double_colon) 100f858bd817e8d6eac58ae496fa96a2f508fbb286fRichard Trieu << SourceRange(ExtraNamespaceLoc.front(), ExtraIdentLoc.back()); 101f858bd817e8d6eac58ae496fa96a2f508fbb286fRichard Trieu } 1021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Diag(Tok, Ident ? diag::err_expected_lbrace : 1035144832ae62cf97543b274d4bb88d5f74d0f7a20Chris Lattner diag::err_expected_ident_lbrace); 104d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 1055144832ae62cf97543b274d4bb88d5f74d0f7a20Chris Lattner } 1061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1075144832ae62cf97543b274d4bb88d5f74d0f7a20Chris Lattner SourceLocation LBrace = ConsumeBrace(); 1082d1c5d313cd0c229cc614e74baa4c5756a4b46f4Argyrios Kyrtzidis 10923c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor if (getCurScope()->isClassScope() || getCurScope()->isTemplateParamScope() || 11023c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor getCurScope()->isInObjcMethodScope() || getCurScope()->getBlockParent() || 11123c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor getCurScope()->getFnParent()) { 112f858bd817e8d6eac58ae496fa96a2f508fbb286fRichard Trieu if (!ExtraIdent.empty()) { 113f858bd817e8d6eac58ae496fa96a2f508fbb286fRichard Trieu Diag(ExtraNamespaceLoc[0], diag::err_nested_namespaces_with_double_colon) 114f858bd817e8d6eac58ae496fa96a2f508fbb286fRichard Trieu << SourceRange(ExtraNamespaceLoc.front(), ExtraIdentLoc.back()); 115f858bd817e8d6eac58ae496fa96a2f508fbb286fRichard Trieu } 11695f1b15ce1b281c8517d77792abe540753fbcc12Douglas Gregor Diag(LBrace, diag::err_namespace_nonnamespace_scope); 11795f1b15ce1b281c8517d77792abe540753fbcc12Douglas Gregor SkipUntil(tok::r_brace, false); 118d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 11995f1b15ce1b281c8517d77792abe540753fbcc12Douglas Gregor } 12095f1b15ce1b281c8517d77792abe540753fbcc12Douglas Gregor 121f858bd817e8d6eac58ae496fa96a2f508fbb286fRichard Trieu if (!ExtraIdent.empty()) { 122f858bd817e8d6eac58ae496fa96a2f508fbb286fRichard Trieu TentativeParsingAction TPA(*this); 123f858bd817e8d6eac58ae496fa96a2f508fbb286fRichard Trieu SkipUntil(tok::r_brace, /*StopAtSemi*/false, /*DontConsume*/true); 124f858bd817e8d6eac58ae496fa96a2f508fbb286fRichard Trieu Token rBraceToken = Tok; 125f858bd817e8d6eac58ae496fa96a2f508fbb286fRichard Trieu TPA.Revert(); 126f858bd817e8d6eac58ae496fa96a2f508fbb286fRichard Trieu 127f858bd817e8d6eac58ae496fa96a2f508fbb286fRichard Trieu if (!rBraceToken.is(tok::r_brace)) { 128f858bd817e8d6eac58ae496fa96a2f508fbb286fRichard Trieu Diag(ExtraNamespaceLoc[0], diag::err_nested_namespaces_with_double_colon) 129f858bd817e8d6eac58ae496fa96a2f508fbb286fRichard Trieu << SourceRange(ExtraNamespaceLoc.front(), ExtraIdentLoc.back()); 130f858bd817e8d6eac58ae496fa96a2f508fbb286fRichard Trieu } else { 1319910df05e9b5f03043f4d8dc12ea1bbb722664dfBenjamin Kramer std::string NamespaceFix; 132f858bd817e8d6eac58ae496fa96a2f508fbb286fRichard Trieu for (std::vector<IdentifierInfo*>::iterator I = ExtraIdent.begin(), 133f858bd817e8d6eac58ae496fa96a2f508fbb286fRichard Trieu E = ExtraIdent.end(); I != E; ++I) { 134f858bd817e8d6eac58ae496fa96a2f508fbb286fRichard Trieu NamespaceFix += " { namespace "; 135f858bd817e8d6eac58ae496fa96a2f508fbb286fRichard Trieu NamespaceFix += (*I)->getName(); 136f858bd817e8d6eac58ae496fa96a2f508fbb286fRichard Trieu } 1379910df05e9b5f03043f4d8dc12ea1bbb722664dfBenjamin Kramer 138f858bd817e8d6eac58ae496fa96a2f508fbb286fRichard Trieu std::string RBraces; 1399910df05e9b5f03043f4d8dc12ea1bbb722664dfBenjamin Kramer for (unsigned i = 0, e = ExtraIdent.size(); i != e; ++i) 140f858bd817e8d6eac58ae496fa96a2f508fbb286fRichard Trieu RBraces += "} "; 1419910df05e9b5f03043f4d8dc12ea1bbb722664dfBenjamin Kramer 142f858bd817e8d6eac58ae496fa96a2f508fbb286fRichard Trieu Diag(ExtraNamespaceLoc[0], diag::err_nested_namespaces_with_double_colon) 143f858bd817e8d6eac58ae496fa96a2f508fbb286fRichard Trieu << FixItHint::CreateReplacement(SourceRange(ExtraNamespaceLoc.front(), 144f858bd817e8d6eac58ae496fa96a2f508fbb286fRichard Trieu ExtraIdentLoc.back()), 145f858bd817e8d6eac58ae496fa96a2f508fbb286fRichard Trieu NamespaceFix) 146f858bd817e8d6eac58ae496fa96a2f508fbb286fRichard Trieu << FixItHint::CreateInsertion(rBraceToken.getLocation(), RBraces); 147f858bd817e8d6eac58ae496fa96a2f508fbb286fRichard Trieu } 148f858bd817e8d6eac58ae496fa96a2f508fbb286fRichard Trieu } 149f858bd817e8d6eac58ae496fa96a2f508fbb286fRichard Trieu 15088e64ca96d6c00c6f3bd43772cd325bede795d2aSebastian Redl // If we're still good, complain about inline namespaces in non-C++0x now. 15188e64ca96d6c00c6f3bd43772cd325bede795d2aSebastian Redl if (!getLang().CPlusPlus0x && InlineLoc.isValid()) 15288e64ca96d6c00c6f3bd43772cd325bede795d2aSebastian Redl Diag(InlineLoc, diag::ext_inline_namespace); 15388e64ca96d6c00c6f3bd43772cd325bede795d2aSebastian Redl 1545144832ae62cf97543b274d4bb88d5f74d0f7a20Chris Lattner // Enter a scope for the namespace. 1555144832ae62cf97543b274d4bb88d5f74d0f7a20Chris Lattner ParseScope NamespaceScope(this, Scope::DeclScope); 1562d1c5d313cd0c229cc614e74baa4c5756a4b46f4Argyrios Kyrtzidis 157d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *NamespcDecl = 158acba90f30876b4140b738f0d3dd0e50724053a96Abramo Bagnara Actions.ActOnStartNamespaceDef(getCurScope(), InlineLoc, NamespaceLoc, 159acba90f30876b4140b738f0d3dd0e50724053a96Abramo Bagnara IdentLoc, Ident, LBrace, attrs.getList()); 1602d1c5d313cd0c229cc614e74baa4c5756a4b46f4Argyrios Kyrtzidis 161f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall PrettyDeclStackTraceEntry CrashInfo(Actions, NamespcDecl, NamespaceLoc, 162f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall "parsing namespace"); 1631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 164f858bd817e8d6eac58ae496fa96a2f508fbb286fRichard Trieu SourceLocation RBraceLoc; 165f858bd817e8d6eac58ae496fa96a2f508fbb286fRichard Trieu // Parse the contents of the namespace. This includes parsing recovery on 166f858bd817e8d6eac58ae496fa96a2f508fbb286fRichard Trieu // any improperly nested namespaces. 167f858bd817e8d6eac58ae496fa96a2f508fbb286fRichard Trieu ParseInnerNamespace(ExtraIdentLoc, ExtraIdent, ExtraNamespaceLoc, 0, 168f858bd817e8d6eac58ae496fa96a2f508fbb286fRichard Trieu InlineLoc, LBrace, attrs, RBraceLoc); 1691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1705144832ae62cf97543b274d4bb88d5f74d0f7a20Chris Lattner // Leave the namespace scope. 1715144832ae62cf97543b274d4bb88d5f74d0f7a20Chris Lattner NamespaceScope.Exit(); 1728ba5d792032f475eb653ca6340eb51068df0fa90Argyrios Kyrtzidis 17397144fc41a9419bf6d74fc9450e8ef3f6e11f7e0Chris Lattner Actions.ActOnFinishNamespaceDef(NamespcDecl, RBraceLoc); 1742d1c5d313cd0c229cc614e74baa4c5756a4b46f4Argyrios Kyrtzidis 17597144fc41a9419bf6d74fc9450e8ef3f6e11f7e0Chris Lattner DeclEnd = RBraceLoc; 1765144832ae62cf97543b274d4bb88d5f74d0f7a20Chris Lattner return NamespcDecl; 1778f08cb7d0b97786b17ef05e05caa55aad4d6bd39Chris Lattner} 178c6fdc34ac0183bfa03d65f317c78b7bdac52897eChris Lattner 179f858bd817e8d6eac58ae496fa96a2f508fbb286fRichard Trieu/// ParseInnerNamespace - Parse the contents of a namespace. 180f858bd817e8d6eac58ae496fa96a2f508fbb286fRichard Trieuvoid Parser::ParseInnerNamespace(std::vector<SourceLocation>& IdentLoc, 181f858bd817e8d6eac58ae496fa96a2f508fbb286fRichard Trieu std::vector<IdentifierInfo*>& Ident, 182f858bd817e8d6eac58ae496fa96a2f508fbb286fRichard Trieu std::vector<SourceLocation>& NamespaceLoc, 183f858bd817e8d6eac58ae496fa96a2f508fbb286fRichard Trieu unsigned int index, SourceLocation& InlineLoc, 184f858bd817e8d6eac58ae496fa96a2f508fbb286fRichard Trieu SourceLocation& LBrace, 185f858bd817e8d6eac58ae496fa96a2f508fbb286fRichard Trieu ParsedAttributes& attrs, 186f858bd817e8d6eac58ae496fa96a2f508fbb286fRichard Trieu SourceLocation& RBraceLoc) { 187f858bd817e8d6eac58ae496fa96a2f508fbb286fRichard Trieu if (index == Ident.size()) { 188f858bd817e8d6eac58ae496fa96a2f508fbb286fRichard Trieu while (Tok.isNot(tok::r_brace) && Tok.isNot(tok::eof)) { 189f858bd817e8d6eac58ae496fa96a2f508fbb286fRichard Trieu ParsedAttributesWithRange attrs(AttrFactory); 190f858bd817e8d6eac58ae496fa96a2f508fbb286fRichard Trieu MaybeParseCXX0XAttributes(attrs); 191f858bd817e8d6eac58ae496fa96a2f508fbb286fRichard Trieu MaybeParseMicrosoftAttributes(attrs); 192f858bd817e8d6eac58ae496fa96a2f508fbb286fRichard Trieu ParseExternalDeclaration(attrs); 193f858bd817e8d6eac58ae496fa96a2f508fbb286fRichard Trieu } 194f858bd817e8d6eac58ae496fa96a2f508fbb286fRichard Trieu RBraceLoc = MatchRHSPunctuation(tok::r_brace, LBrace); 195f858bd817e8d6eac58ae496fa96a2f508fbb286fRichard Trieu 196f858bd817e8d6eac58ae496fa96a2f508fbb286fRichard Trieu return; 197f858bd817e8d6eac58ae496fa96a2f508fbb286fRichard Trieu } 198f858bd817e8d6eac58ae496fa96a2f508fbb286fRichard Trieu 199f858bd817e8d6eac58ae496fa96a2f508fbb286fRichard Trieu // Parse improperly nested namespaces. 200f858bd817e8d6eac58ae496fa96a2f508fbb286fRichard Trieu ParseScope NamespaceScope(this, Scope::DeclScope); 201f858bd817e8d6eac58ae496fa96a2f508fbb286fRichard Trieu Decl *NamespcDecl = 202f858bd817e8d6eac58ae496fa96a2f508fbb286fRichard Trieu Actions.ActOnStartNamespaceDef(getCurScope(), SourceLocation(), 203f858bd817e8d6eac58ae496fa96a2f508fbb286fRichard Trieu NamespaceLoc[index], IdentLoc[index], 204f858bd817e8d6eac58ae496fa96a2f508fbb286fRichard Trieu Ident[index], LBrace, attrs.getList()); 205f858bd817e8d6eac58ae496fa96a2f508fbb286fRichard Trieu 206f858bd817e8d6eac58ae496fa96a2f508fbb286fRichard Trieu ParseInnerNamespace(IdentLoc, Ident, NamespaceLoc, ++index, InlineLoc, 207f858bd817e8d6eac58ae496fa96a2f508fbb286fRichard Trieu LBrace, attrs, RBraceLoc); 208f858bd817e8d6eac58ae496fa96a2f508fbb286fRichard Trieu 209f858bd817e8d6eac58ae496fa96a2f508fbb286fRichard Trieu NamespaceScope.Exit(); 210f858bd817e8d6eac58ae496fa96a2f508fbb286fRichard Trieu 211f858bd817e8d6eac58ae496fa96a2f508fbb286fRichard Trieu Actions.ActOnFinishNamespaceDef(NamespcDecl, RBraceLoc); 212f858bd817e8d6eac58ae496fa96a2f508fbb286fRichard Trieu} 213f858bd817e8d6eac58ae496fa96a2f508fbb286fRichard Trieu 214f67606ae2febe3bb0718f05040c6c4bc2c2c3276Anders Carlsson/// ParseNamespaceAlias - Parse the part after the '=' in a namespace 215f67606ae2febe3bb0718f05040c6c4bc2c2c3276Anders Carlsson/// alias definition. 216f67606ae2febe3bb0718f05040c6c4bc2c2c3276Anders Carlsson/// 217d226f65006733ed7f709c3174f22ce33391cb58fJohn McCallDecl *Parser::ParseNamespaceAlias(SourceLocation NamespaceLoc, 2180b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall SourceLocation AliasLoc, 2190b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall IdentifierInfo *Alias, 2200b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall SourceLocation &DeclEnd) { 221f67606ae2febe3bb0718f05040c6c4bc2c2c3276Anders Carlsson assert(Tok.is(tok::equal) && "Not equal token"); 2221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 223f67606ae2febe3bb0718f05040c6c4bc2c2c3276Anders Carlsson ConsumeToken(); // eat the '='. 2241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 22549f40bd0c9c9de5e74727774fec429b47d36303aDouglas Gregor if (Tok.is(tok::code_completion)) { 22623c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteNamespaceAliasDecl(getCurScope()); 227dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor ConsumeCodeCompletionToken(); 22849f40bd0c9c9de5e74727774fec429b47d36303aDouglas Gregor } 229193575455e00eca03fd7177f60e3f2e6263cb661Kovarththanan Rajaratnam 230f67606ae2febe3bb0718f05040c6c4bc2c2c3276Anders Carlsson CXXScopeSpec SS; 231f67606ae2febe3bb0718f05040c6c4bc2c2c3276Anders Carlsson // Parse (optional) nested-name-specifier. 232b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParseOptionalCXXScopeSpecifier(SS, ParsedType(), false); 233f67606ae2febe3bb0718f05040c6c4bc2c2c3276Anders Carlsson 234f67606ae2febe3bb0718f05040c6c4bc2c2c3276Anders Carlsson if (SS.isInvalid() || Tok.isNot(tok::identifier)) { 235f67606ae2febe3bb0718f05040c6c4bc2c2c3276Anders Carlsson Diag(Tok, diag::err_expected_namespace_name); 236f67606ae2febe3bb0718f05040c6c4bc2c2c3276Anders Carlsson // Skip to end of the definition and eat the ';'. 237f67606ae2febe3bb0718f05040c6c4bc2c2c3276Anders Carlsson SkipUntil(tok::semi); 238d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 239f67606ae2febe3bb0718f05040c6c4bc2c2c3276Anders Carlsson } 240f67606ae2febe3bb0718f05040c6c4bc2c2c3276Anders Carlsson 241f67606ae2febe3bb0718f05040c6c4bc2c2c3276Anders Carlsson // Parse identifier. 24203bd5a1e9a54b62b10ae8aeb6eb5245e2031d98bAnders Carlsson IdentifierInfo *Ident = Tok.getIdentifierInfo(); 24303bd5a1e9a54b62b10ae8aeb6eb5245e2031d98bAnders Carlsson SourceLocation IdentLoc = ConsumeToken(); 2441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 245f67606ae2febe3bb0718f05040c6c4bc2c2c3276Anders Carlsson // Eat the ';'. 24697144fc41a9419bf6d74fc9450e8ef3f6e11f7e0Chris Lattner DeclEnd = Tok.getLocation(); 2476869d8ea1bb7d191b5b290f5a55ee74f2174829aChris Lattner ExpectAndConsume(tok::semi, diag::err_expected_semi_after_namespace_name, 2486869d8ea1bb7d191b5b290f5a55ee74f2174829aChris Lattner "", tok::semi); 2491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 25023c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor return Actions.ActOnNamespaceAliasDef(getCurScope(), NamespaceLoc, AliasLoc, Alias, 25103bd5a1e9a54b62b10ae8aeb6eb5245e2031d98bAnders Carlsson SS, IdentLoc, Ident); 252f67606ae2febe3bb0718f05040c6c4bc2c2c3276Anders Carlsson} 253f67606ae2febe3bb0718f05040c6c4bc2c2c3276Anders Carlsson 254c6fdc34ac0183bfa03d65f317c78b7bdac52897eChris Lattner/// ParseLinkage - We know that the current token is a string_literal 255c6fdc34ac0183bfa03d65f317c78b7bdac52897eChris Lattner/// and just before that, that extern was seen. 256c6fdc34ac0183bfa03d65f317c78b7bdac52897eChris Lattner/// 257c6fdc34ac0183bfa03d65f317c78b7bdac52897eChris Lattner/// linkage-specification: [C++ 7.5p2: dcl.link] 258c6fdc34ac0183bfa03d65f317c78b7bdac52897eChris Lattner/// 'extern' string-literal '{' declaration-seq[opt] '}' 259c6fdc34ac0183bfa03d65f317c78b7bdac52897eChris Lattner/// 'extern' string-literal declaration 260c6fdc34ac0183bfa03d65f317c78b7bdac52897eChris Lattner/// 2617d64271b162eaf5cae264ff64465b28af623dc17Chris LattnerDecl *Parser::ParseLinkage(ParsingDeclSpec &DS, unsigned Context) { 262c19923dda3d28f67aab4726cd40bb07032758383Douglas Gregor assert(Tok.is(tok::string_literal) && "Not a string literal!"); 263193575455e00eca03fd7177f60e3f2e6263cb661Kovarththanan Rajaratnam llvm::SmallString<8> LangBuffer; 264453091cc2082e207ea2c2dda645a9bc01b37fb0cDouglas Gregor bool Invalid = false; 265453091cc2082e207ea2c2dda645a9bc01b37fb0cDouglas Gregor llvm::StringRef Lang = PP.getSpelling(Tok, LangBuffer, &Invalid); 266453091cc2082e207ea2c2dda645a9bc01b37fb0cDouglas Gregor if (Invalid) 267d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 268c6fdc34ac0183bfa03d65f317c78b7bdac52897eChris Lattner 269c6fdc34ac0183bfa03d65f317c78b7bdac52897eChris Lattner SourceLocation Loc = ConsumeStringToken(); 270c6fdc34ac0183bfa03d65f317c78b7bdac52897eChris Lattner 271074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor ParseScope LinkageScope(this, Scope::DeclScope); 272d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *LinkageSpec 27323c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor = Actions.ActOnStartLinkageSpecification(getCurScope(), 274a2026c96d3935e7909e049ad9096762844544ed6Abramo Bagnara DS.getSourceRange().getBegin(), 275d56638180014e60538cd666cd11fde6d4698e051Benjamin Kramer Loc, Lang, 276a2026c96d3935e7909e049ad9096762844544ed6Abramo Bagnara Tok.is(tok::l_brace) ? Tok.getLocation() 277074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor : SourceLocation()); 278074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor 2790b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall ParsedAttributesWithRange attrs(AttrFactory); 2807f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall MaybeParseCXX0XAttributes(attrs); 2817f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall MaybeParseMicrosoftAttributes(attrs); 282193575455e00eca03fd7177f60e3f2e6263cb661Kovarththanan Rajaratnam 283074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor if (Tok.isNot(tok::l_brace)) { 284f41e33c29cd4b21065956129d5e923f3d73d97d3Abramo Bagnara // Reset the source range in DS, as the leading "extern" 285f41e33c29cd4b21065956129d5e923f3d73d97d3Abramo Bagnara // does not really belong to the inner declaration ... 286f41e33c29cd4b21065956129d5e923f3d73d97d3Abramo Bagnara DS.SetRangeStart(SourceLocation()); 287f41e33c29cd4b21065956129d5e923f3d73d97d3Abramo Bagnara DS.SetRangeEnd(SourceLocation()); 288f41e33c29cd4b21065956129d5e923f3d73d97d3Abramo Bagnara // ... but anyway remember that such an "extern" was seen. 28935f9a196ef897b9559de25aaecd957208f0b4f59Abramo Bagnara DS.setExternInLinkageSpec(true); 2907f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall ParseExternalDeclaration(attrs, &DS); 29123c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor return Actions.ActOnFinishLinkageSpecification(getCurScope(), LinkageSpec, 292074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor SourceLocation()); 2931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 294f44515a49b549171dc3ee9faa6281b72609da563Douglas Gregor 29563a011378d4b9483ce24400c163cb8d65ea096a5Douglas Gregor DS.abort(); 29663a011378d4b9483ce24400c163cb8d65ea096a5Douglas Gregor 2977f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall ProhibitAttributes(attrs); 298bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt 299f44515a49b549171dc3ee9faa6281b72609da563Douglas Gregor SourceLocation LBrace = ConsumeBrace(); 300f44515a49b549171dc3ee9faa6281b72609da563Douglas Gregor while (Tok.isNot(tok::r_brace) && Tok.isNot(tok::eof)) { 3010b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall ParsedAttributesWithRange attrs(AttrFactory); 3027f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall MaybeParseCXX0XAttributes(attrs); 3037f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall MaybeParseMicrosoftAttributes(attrs); 3047f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall ParseExternalDeclaration(attrs); 305f44515a49b549171dc3ee9faa6281b72609da563Douglas Gregor } 306c6fdc34ac0183bfa03d65f317c78b7bdac52897eChris Lattner 307f44515a49b549171dc3ee9faa6281b72609da563Douglas Gregor SourceLocation RBrace = MatchRHSPunctuation(tok::r_brace, LBrace); 3087d64271b162eaf5cae264ff64465b28af623dc17Chris Lattner return Actions.ActOnFinishLinkageSpecification(getCurScope(), LinkageSpec, 3097d64271b162eaf5cae264ff64465b28af623dc17Chris Lattner RBrace); 310c6fdc34ac0183bfa03d65f317c78b7bdac52897eChris Lattner} 311e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor 312f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor/// ParseUsingDirectiveOrDeclaration - Parse C++ using using-declaration or 313f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor/// using-directive. Assumes that current token is 'using'. 314d226f65006733ed7f709c3174f22ce33391cb58fJohn McCallDecl *Parser::ParseUsingDirectiveOrDeclaration(unsigned Context, 31578b810559d89e996e00684335407443936ce34a1John McCall const ParsedTemplateInfo &TemplateInfo, 31678b810559d89e996e00684335407443936ce34a1John McCall SourceLocation &DeclEnd, 3177f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall ParsedAttributesWithRange &attrs) { 318f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor assert(Tok.is(tok::kw_using) && "Not using token"); 319f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor 320f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor // Eat 'using'. 321f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor SourceLocation UsingLoc = ConsumeToken(); 322f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor 32349f40bd0c9c9de5e74727774fec429b47d36303aDouglas Gregor if (Tok.is(tok::code_completion)) { 32423c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteUsing(getCurScope()); 325dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor ConsumeCodeCompletionToken(); 32649f40bd0c9c9de5e74727774fec429b47d36303aDouglas Gregor } 327193575455e00eca03fd7177f60e3f2e6263cb661Kovarththanan Rajaratnam 32878b810559d89e996e00684335407443936ce34a1John McCall // 'using namespace' means this is a using-directive. 32978b810559d89e996e00684335407443936ce34a1John McCall if (Tok.is(tok::kw_namespace)) { 33078b810559d89e996e00684335407443936ce34a1John McCall // Template parameters are always an error here. 33178b810559d89e996e00684335407443936ce34a1John McCall if (TemplateInfo.Kind) { 33278b810559d89e996e00684335407443936ce34a1John McCall SourceRange R = TemplateInfo.getSourceRange(); 33378b810559d89e996e00684335407443936ce34a1John McCall Diag(UsingLoc, diag::err_templated_using_directive) 33478b810559d89e996e00684335407443936ce34a1John McCall << R << FixItHint::CreateRemoval(R); 33578b810559d89e996e00684335407443936ce34a1John McCall } 33678b810559d89e996e00684335407443936ce34a1John McCall 3377f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall return ParseUsingDirective(Context, UsingLoc, DeclEnd, attrs); 33878b810559d89e996e00684335407443936ce34a1John McCall } 339bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt 340162e1c1b487352434552147967c3dd296ebee2f7Richard Smith // Otherwise, it must be a using-declaration or an alias-declaration. 34178b810559d89e996e00684335407443936ce34a1John McCall 34278b810559d89e996e00684335407443936ce34a1John McCall // Using declarations can't have attributes. 3437f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall ProhibitAttributes(attrs); 3442f27477a29b6f5365ee545c1cac666cc8b95f518Chris Lattner 34578b810559d89e996e00684335407443936ce34a1John McCall return ParseUsingDeclaration(Context, TemplateInfo, UsingLoc, DeclEnd); 346f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor} 347f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor 348f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor/// ParseUsingDirective - Parse C++ using-directive, assumes 349f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor/// that current token is 'namespace' and 'using' was already parsed. 350f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor/// 351f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor/// using-directive: [C++ 7.3.p4: namespace.udir] 352f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor/// 'using' 'namespace' ::[opt] nested-name-specifier[opt] 353f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor/// namespace-name ; 354f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor/// [GNU] using-directive: 355f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor/// 'using' 'namespace' ::[opt] nested-name-specifier[opt] 356f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor/// namespace-name attributes[opt] ; 357f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor/// 358d226f65006733ed7f709c3174f22ce33391cb58fJohn McCallDecl *Parser::ParseUsingDirective(unsigned Context, 35978b810559d89e996e00684335407443936ce34a1John McCall SourceLocation UsingLoc, 36078b810559d89e996e00684335407443936ce34a1John McCall SourceLocation &DeclEnd, 3617f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall ParsedAttributes &attrs) { 362f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor assert(Tok.is(tok::kw_namespace) && "Not 'namespace' token"); 363f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor 364f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor // Eat 'namespace'. 365f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor SourceLocation NamespcLoc = ConsumeToken(); 366f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor 36749f40bd0c9c9de5e74727774fec429b47d36303aDouglas Gregor if (Tok.is(tok::code_completion)) { 36823c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteUsingDirective(getCurScope()); 369dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor ConsumeCodeCompletionToken(); 37049f40bd0c9c9de5e74727774fec429b47d36303aDouglas Gregor } 371193575455e00eca03fd7177f60e3f2e6263cb661Kovarththanan Rajaratnam 372f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor CXXScopeSpec SS; 373f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor // Parse (optional) nested-name-specifier. 374b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParseOptionalCXXScopeSpecifier(SS, ParsedType(), false); 375f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor 376f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor IdentifierInfo *NamespcName = 0; 377f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor SourceLocation IdentLoc = SourceLocation(); 378f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor 379f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor // Parse namespace-name. 380823c44e6d73141f642e207980b4021ddcf09897bChris Lattner if (SS.isInvalid() || Tok.isNot(tok::identifier)) { 381f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor Diag(Tok, diag::err_expected_namespace_name); 382f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor // If there was invalid namespace name, skip to end of decl, and eat ';'. 383f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor SkipUntil(tok::semi); 384f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor // FIXME: Are there cases, when we would like to call ActOnUsingDirective? 385d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 386f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor } 3871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 388823c44e6d73141f642e207980b4021ddcf09897bChris Lattner // Parse identifier. 389823c44e6d73141f642e207980b4021ddcf09897bChris Lattner NamespcName = Tok.getIdentifierInfo(); 390823c44e6d73141f642e207980b4021ddcf09897bChris Lattner IdentLoc = ConsumeToken(); 3911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 392823c44e6d73141f642e207980b4021ddcf09897bChris Lattner // Parse (optional) attributes (most likely GNU strong-using extension). 393bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt bool GNUAttr = false; 394bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt if (Tok.is(tok::kw___attribute)) { 395bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt GNUAttr = true; 3967f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall ParseGNUAttributes(attrs); 397bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt } 3981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 399823c44e6d73141f642e207980b4021ddcf09897bChris Lattner // Eat ';'. 40097144fc41a9419bf6d74fc9450e8ef3f6e11f7e0Chris Lattner DeclEnd = Tok.getLocation(); 4016869d8ea1bb7d191b5b290f5a55ee74f2174829aChris Lattner ExpectAndConsume(tok::semi, 4029ba23b4ceacd77cd264501690a7a9e94184ef71bDouglas Gregor GNUAttr ? diag::err_expected_semi_after_attribute_list 4039ba23b4ceacd77cd264501690a7a9e94184ef71bDouglas Gregor : diag::err_expected_semi_after_namespace_name, 4049ba23b4ceacd77cd264501690a7a9e94184ef71bDouglas Gregor "", tok::semi); 405f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor 40623c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor return Actions.ActOnUsingDirective(getCurScope(), UsingLoc, NamespcLoc, SS, 4077f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall IdentLoc, NamespcName, attrs.getList()); 408f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor} 409f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor 410162e1c1b487352434552147967c3dd296ebee2f7Richard Smith/// ParseUsingDeclaration - Parse C++ using-declaration or alias-declaration. 411162e1c1b487352434552147967c3dd296ebee2f7Richard Smith/// Assumes that 'using' was already seen. 412f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor/// 413f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor/// using-declaration: [C++ 7.3.p3: namespace.udecl] 414f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor/// 'using' 'typename'[opt] ::[opt] nested-name-specifier 4159cfbe48a7a20a217fdb2920b29b67ae7941cb116Douglas Gregor/// unqualified-id 4169cfbe48a7a20a217fdb2920b29b67ae7941cb116Douglas Gregor/// 'using' :: unqualified-id 417f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor/// 418162e1c1b487352434552147967c3dd296ebee2f7Richard Smith/// alias-declaration: C++0x [decl.typedef]p2 419162e1c1b487352434552147967c3dd296ebee2f7Richard Smith/// 'using' identifier = type-id ; 420162e1c1b487352434552147967c3dd296ebee2f7Richard Smith/// 421d226f65006733ed7f709c3174f22ce33391cb58fJohn McCallDecl *Parser::ParseUsingDeclaration(unsigned Context, 42278b810559d89e996e00684335407443936ce34a1John McCall const ParsedTemplateInfo &TemplateInfo, 42378b810559d89e996e00684335407443936ce34a1John McCall SourceLocation UsingLoc, 42478b810559d89e996e00684335407443936ce34a1John McCall SourceLocation &DeclEnd, 42578b810559d89e996e00684335407443936ce34a1John McCall AccessSpecifier AS) { 4269cfbe48a7a20a217fdb2920b29b67ae7941cb116Douglas Gregor CXXScopeSpec SS; 4277ba107a1863ddfa1664555854f0d7bdb3c491c92John McCall SourceLocation TypenameLoc; 4289cfbe48a7a20a217fdb2920b29b67ae7941cb116Douglas Gregor bool IsTypeName; 4299cfbe48a7a20a217fdb2920b29b67ae7941cb116Douglas Gregor 4309cfbe48a7a20a217fdb2920b29b67ae7941cb116Douglas Gregor // Ignore optional 'typename'. 43112c118a8ff9f61a4d63146fe1a5c0d60987f99bbDouglas Gregor // FIXME: This is wrong; we should parse this as a typename-specifier. 4329cfbe48a7a20a217fdb2920b29b67ae7941cb116Douglas Gregor if (Tok.is(tok::kw_typename)) { 4337ba107a1863ddfa1664555854f0d7bdb3c491c92John McCall TypenameLoc = Tok.getLocation(); 4349cfbe48a7a20a217fdb2920b29b67ae7941cb116Douglas Gregor ConsumeToken(); 4359cfbe48a7a20a217fdb2920b29b67ae7941cb116Douglas Gregor IsTypeName = true; 4369cfbe48a7a20a217fdb2920b29b67ae7941cb116Douglas Gregor } 4379cfbe48a7a20a217fdb2920b29b67ae7941cb116Douglas Gregor else 4389cfbe48a7a20a217fdb2920b29b67ae7941cb116Douglas Gregor IsTypeName = false; 4399cfbe48a7a20a217fdb2920b29b67ae7941cb116Douglas Gregor 4409cfbe48a7a20a217fdb2920b29b67ae7941cb116Douglas Gregor // Parse nested-name-specifier. 441b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParseOptionalCXXScopeSpecifier(SS, ParsedType(), false); 4429cfbe48a7a20a217fdb2920b29b67ae7941cb116Douglas Gregor 4439cfbe48a7a20a217fdb2920b29b67ae7941cb116Douglas Gregor // Check nested-name specifier. 4449cfbe48a7a20a217fdb2920b29b67ae7941cb116Douglas Gregor if (SS.isInvalid()) { 4459cfbe48a7a20a217fdb2920b29b67ae7941cb116Douglas Gregor SkipUntil(tok::semi); 446d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 4479cfbe48a7a20a217fdb2920b29b67ae7941cb116Douglas Gregor } 4481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 449193575455e00eca03fd7177f60e3f2e6263cb661Kovarththanan Rajaratnam // Parse the unqualified-id. We allow parsing of both constructor and 45012c118a8ff9f61a4d63146fe1a5c0d60987f99bbDouglas Gregor // destructor names and allow the action module to diagnose any semantic 45112c118a8ff9f61a4d63146fe1a5c0d60987f99bbDouglas Gregor // errors. 45212c118a8ff9f61a4d63146fe1a5c0d60987f99bbDouglas Gregor UnqualifiedId Name; 453193575455e00eca03fd7177f60e3f2e6263cb661Kovarththanan Rajaratnam if (ParseUnqualifiedId(SS, 45412c118a8ff9f61a4d63146fe1a5c0d60987f99bbDouglas Gregor /*EnteringContext=*/false, 45512c118a8ff9f61a4d63146fe1a5c0d60987f99bbDouglas Gregor /*AllowDestructorName=*/true, 456193575455e00eca03fd7177f60e3f2e6263cb661Kovarththanan Rajaratnam /*AllowConstructorName=*/true, 457b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType(), 45812c118a8ff9f61a4d63146fe1a5c0d60987f99bbDouglas Gregor Name)) { 4599cfbe48a7a20a217fdb2920b29b67ae7941cb116Douglas Gregor SkipUntil(tok::semi); 460d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 4619cfbe48a7a20a217fdb2920b29b67ae7941cb116Douglas Gregor } 462193575455e00eca03fd7177f60e3f2e6263cb661Kovarththanan Rajaratnam 4630b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall ParsedAttributes attrs(AttrFactory); 464162e1c1b487352434552147967c3dd296ebee2f7Richard Smith 465162e1c1b487352434552147967c3dd296ebee2f7Richard Smith // Maybe this is an alias-declaration. 466162e1c1b487352434552147967c3dd296ebee2f7Richard Smith bool IsAliasDecl = Tok.is(tok::equal); 467162e1c1b487352434552147967c3dd296ebee2f7Richard Smith TypeResult TypeAlias; 468162e1c1b487352434552147967c3dd296ebee2f7Richard Smith if (IsAliasDecl) { 4693e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith // TODO: Attribute support. C++0x attributes may appear before the equals. 4703e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith // Where can GNU attributes appear? 471162e1c1b487352434552147967c3dd296ebee2f7Richard Smith ConsumeToken(); 472162e1c1b487352434552147967c3dd296ebee2f7Richard Smith 473162e1c1b487352434552147967c3dd296ebee2f7Richard Smith if (!getLang().CPlusPlus0x) 474162e1c1b487352434552147967c3dd296ebee2f7Richard Smith Diag(Tok.getLocation(), diag::ext_alias_declaration); 475162e1c1b487352434552147967c3dd296ebee2f7Richard Smith 4763e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith // Type alias templates cannot be specialized. 4773e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith int SpecKind = -1; 478536e9c1f103f3e59ed47e35090819eb93596c35bRichard Smith if (TemplateInfo.Kind == ParsedTemplateInfo::Template && 479536e9c1f103f3e59ed47e35090819eb93596c35bRichard Smith Name.getKind() == UnqualifiedId::IK_TemplateId) 4803e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith SpecKind = 0; 4813e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith if (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitSpecialization) 4823e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith SpecKind = 1; 4833e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith if (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation) 4843e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith SpecKind = 2; 4853e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith if (SpecKind != -1) { 4863e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith SourceRange Range; 4873e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith if (SpecKind == 0) 4883e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith Range = SourceRange(Name.TemplateId->LAngleLoc, 4893e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith Name.TemplateId->RAngleLoc); 4903e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith else 4913e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith Range = TemplateInfo.getSourceRange(); 4923e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith Diag(Range.getBegin(), diag::err_alias_declaration_specialization) 4933e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith << SpecKind << Range; 4943e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith SkipUntil(tok::semi); 4953e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith return 0; 4963e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith } 4973e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith 498162e1c1b487352434552147967c3dd296ebee2f7Richard Smith // Name must be an identifier. 499162e1c1b487352434552147967c3dd296ebee2f7Richard Smith if (Name.getKind() != UnqualifiedId::IK_Identifier) { 500162e1c1b487352434552147967c3dd296ebee2f7Richard Smith Diag(Name.StartLocation, diag::err_alias_declaration_not_identifier); 501162e1c1b487352434552147967c3dd296ebee2f7Richard Smith // No removal fixit: can't recover from this. 502162e1c1b487352434552147967c3dd296ebee2f7Richard Smith SkipUntil(tok::semi); 503162e1c1b487352434552147967c3dd296ebee2f7Richard Smith return 0; 504162e1c1b487352434552147967c3dd296ebee2f7Richard Smith } else if (IsTypeName) 505162e1c1b487352434552147967c3dd296ebee2f7Richard Smith Diag(TypenameLoc, diag::err_alias_declaration_not_identifier) 506162e1c1b487352434552147967c3dd296ebee2f7Richard Smith << FixItHint::CreateRemoval(SourceRange(TypenameLoc, 507162e1c1b487352434552147967c3dd296ebee2f7Richard Smith SS.isNotEmpty() ? SS.getEndLoc() : TypenameLoc)); 508162e1c1b487352434552147967c3dd296ebee2f7Richard Smith else if (SS.isNotEmpty()) 509162e1c1b487352434552147967c3dd296ebee2f7Richard Smith Diag(SS.getBeginLoc(), diag::err_alias_declaration_not_identifier) 510162e1c1b487352434552147967c3dd296ebee2f7Richard Smith << FixItHint::CreateRemoval(SS.getRange()); 511162e1c1b487352434552147967c3dd296ebee2f7Richard Smith 5123e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith TypeAlias = ParseTypeName(0, TemplateInfo.Kind ? 5133e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith Declarator::AliasTemplateContext : 5143e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith Declarator::AliasDeclContext); 515162e1c1b487352434552147967c3dd296ebee2f7Richard Smith } else 516162e1c1b487352434552147967c3dd296ebee2f7Richard Smith // Parse (optional) attributes (most likely GNU strong-using extension). 517162e1c1b487352434552147967c3dd296ebee2f7Richard Smith MaybeParseGNUAttributes(attrs); 5181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5199cfbe48a7a20a217fdb2920b29b67ae7941cb116Douglas Gregor // Eat ';'. 5209cfbe48a7a20a217fdb2920b29b67ae7941cb116Douglas Gregor DeclEnd = Tok.getLocation(); 5219cfbe48a7a20a217fdb2920b29b67ae7941cb116Douglas Gregor ExpectAndConsume(tok::semi, diag::err_expected_semi_after, 522162e1c1b487352434552147967c3dd296ebee2f7Richard Smith !attrs.empty() ? "attributes list" : 523162e1c1b487352434552147967c3dd296ebee2f7Richard Smith IsAliasDecl ? "alias declaration" : "using declaration", 52412c118a8ff9f61a4d63146fe1a5c0d60987f99bbDouglas Gregor tok::semi); 5259cfbe48a7a20a217fdb2920b29b67ae7941cb116Douglas Gregor 52678b810559d89e996e00684335407443936ce34a1John McCall // Diagnose an attempt to declare a templated using-declaration. 5273e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith // In C++0x, alias-declarations can be templates: 528162e1c1b487352434552147967c3dd296ebee2f7Richard Smith // template <...> using id = type; 5293e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith if (TemplateInfo.Kind && !IsAliasDecl) { 53078b810559d89e996e00684335407443936ce34a1John McCall SourceRange R = TemplateInfo.getSourceRange(); 53178b810559d89e996e00684335407443936ce34a1John McCall Diag(UsingLoc, diag::err_templated_using_declaration) 53278b810559d89e996e00684335407443936ce34a1John McCall << R << FixItHint::CreateRemoval(R); 53378b810559d89e996e00684335407443936ce34a1John McCall 53478b810559d89e996e00684335407443936ce34a1John McCall // Unfortunately, we have to bail out instead of recovering by 53578b810559d89e996e00684335407443936ce34a1John McCall // ignoring the parameters, just in case the nested name specifier 53678b810559d89e996e00684335407443936ce34a1John McCall // depends on the parameters. 53778b810559d89e996e00684335407443936ce34a1John McCall return 0; 53878b810559d89e996e00684335407443936ce34a1John McCall } 53978b810559d89e996e00684335407443936ce34a1John McCall 5403e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith if (IsAliasDecl) { 5413e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith TemplateParameterLists *TemplateParams = TemplateInfo.TemplateParams; 5423e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith MultiTemplateParamsArg TemplateParamsArg(Actions, 5433e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith TemplateParams ? TemplateParams->data() : 0, 5443e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith TemplateParams ? TemplateParams->size() : 0); 5453e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith return Actions.ActOnAliasDeclaration(getCurScope(), AS, TemplateParamsArg, 5463e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith UsingLoc, Name, TypeAlias); 5473e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith } 548162e1c1b487352434552147967c3dd296ebee2f7Richard Smith 5498113ecfa4e41e2c888b1794389dfe3bce6386493Ted Kremenek return Actions.ActOnUsingDeclaration(getCurScope(), AS, true, UsingLoc, SS, 5507f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall Name, attrs.getList(), 5517f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall IsTypeName, TypenameLoc); 552f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor} 553f780abc21c39cd4731b9e38f2d2d9f7d1510bd7bDouglas Gregor 554c6eb44b321c543c5bcf28727228a0cceced57e2ePeter Collingbourne/// ParseStaticAssertDeclaration - Parse C++0x or C1X static_assert-declaration. 555511d7aba3b12853fdb88729a0313b80a60eab8adAnders Carlsson/// 556c6eb44b321c543c5bcf28727228a0cceced57e2ePeter Collingbourne/// [C++0x] static_assert-declaration: 557c6eb44b321c543c5bcf28727228a0cceced57e2ePeter Collingbourne/// static_assert ( constant-expression , string-literal ) ; 558c6eb44b321c543c5bcf28727228a0cceced57e2ePeter Collingbourne/// 559c6eb44b321c543c5bcf28727228a0cceced57e2ePeter Collingbourne/// [C1X] static_assert-declaration: 560c6eb44b321c543c5bcf28727228a0cceced57e2ePeter Collingbourne/// _Static_assert ( constant-expression , string-literal ) ; 561511d7aba3b12853fdb88729a0313b80a60eab8adAnders Carlsson/// 562d226f65006733ed7f709c3174f22ce33391cb58fJohn McCallDecl *Parser::ParseStaticAssertDeclaration(SourceLocation &DeclEnd){ 563c6eb44b321c543c5bcf28727228a0cceced57e2ePeter Collingbourne assert((Tok.is(tok::kw_static_assert) || Tok.is(tok::kw__Static_assert)) && 564c6eb44b321c543c5bcf28727228a0cceced57e2ePeter Collingbourne "Not a static_assert declaration"); 565c6eb44b321c543c5bcf28727228a0cceced57e2ePeter Collingbourne 566c6eb44b321c543c5bcf28727228a0cceced57e2ePeter Collingbourne if (Tok.is(tok::kw__Static_assert) && !getLang().C1X) 567c6eb44b321c543c5bcf28727228a0cceced57e2ePeter Collingbourne Diag(Tok, diag::ext_c1x_static_assert); 568c6eb44b321c543c5bcf28727228a0cceced57e2ePeter Collingbourne 569511d7aba3b12853fdb88729a0313b80a60eab8adAnders Carlsson SourceLocation StaticAssertLoc = ConsumeToken(); 5701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 571511d7aba3b12853fdb88729a0313b80a60eab8adAnders Carlsson if (Tok.isNot(tok::l_paren)) { 572511d7aba3b12853fdb88729a0313b80a60eab8adAnders Carlsson Diag(Tok, diag::err_expected_lparen); 573d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 574511d7aba3b12853fdb88729a0313b80a60eab8adAnders Carlsson } 5751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 576511d7aba3b12853fdb88729a0313b80a60eab8adAnders Carlsson SourceLocation LParenLoc = ConsumeParen(); 577e0762c92110dfdcdd207db461a4ea17afd168f1eDouglas Gregor 57860d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult AssertExpr(ParseConstantExpression()); 579511d7aba3b12853fdb88729a0313b80a60eab8adAnders Carlsson if (AssertExpr.isInvalid()) { 580511d7aba3b12853fdb88729a0313b80a60eab8adAnders Carlsson SkipUntil(tok::semi); 581d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 582511d7aba3b12853fdb88729a0313b80a60eab8adAnders Carlsson } 5831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 584ad5f960f9e42568a87bf5e03dce7ad878f9ba6daAnders Carlsson if (ExpectAndConsume(tok::comma, diag::err_expected_comma, "", tok::semi)) 585d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 586ad5f960f9e42568a87bf5e03dce7ad878f9ba6daAnders Carlsson 587511d7aba3b12853fdb88729a0313b80a60eab8adAnders Carlsson if (Tok.isNot(tok::string_literal)) { 588511d7aba3b12853fdb88729a0313b80a60eab8adAnders Carlsson Diag(Tok, diag::err_expected_string_literal); 589511d7aba3b12853fdb88729a0313b80a60eab8adAnders Carlsson SkipUntil(tok::semi); 590d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 591511d7aba3b12853fdb88729a0313b80a60eab8adAnders Carlsson } 5921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 59360d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult AssertMessage(ParseStringLiteralExpression()); 5941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump if (AssertMessage.isInvalid()) 595d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall return 0; 596511d7aba3b12853fdb88729a0313b80a60eab8adAnders Carlsson 597a2026c96d3935e7909e049ad9096762844544ed6Abramo Bagnara SourceLocation RParenLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc); 5981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 59997144fc41a9419bf6d74fc9450e8ef3f6e11f7e0Chris Lattner DeclEnd = Tok.getLocation(); 6009ba23b4ceacd77cd264501690a7a9e94184ef71bDouglas Gregor ExpectAndConsumeSemi(diag::err_expected_semi_after_static_assert); 601511d7aba3b12853fdb88729a0313b80a60eab8adAnders Carlsson 6029ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return Actions.ActOnStaticAssertDeclaration(StaticAssertLoc, 6039ae2f076ca5ab1feb3ba95629099ec2319833701John McCall AssertExpr.take(), 604a2026c96d3935e7909e049ad9096762844544ed6Abramo Bagnara AssertMessage.take(), 605a2026c96d3935e7909e049ad9096762844544ed6Abramo Bagnara RParenLoc); 606511d7aba3b12853fdb88729a0313b80a60eab8adAnders Carlsson} 607511d7aba3b12853fdb88729a0313b80a60eab8adAnders Carlsson 6086fd634f4ac59f5923cffadadb99d19f23c18707aAnders Carlsson/// ParseDecltypeSpecifier - Parse a C++0x decltype specifier. 6096fd634f4ac59f5923cffadadb99d19f23c18707aAnders Carlsson/// 6106fd634f4ac59f5923cffadadb99d19f23c18707aAnders Carlsson/// 'decltype' ( expression ) 6116fd634f4ac59f5923cffadadb99d19f23c18707aAnders Carlsson/// 6126fd634f4ac59f5923cffadadb99d19f23c18707aAnders Carlssonvoid Parser::ParseDecltypeSpecifier(DeclSpec &DS) { 6136fd634f4ac59f5923cffadadb99d19f23c18707aAnders Carlsson assert(Tok.is(tok::kw_decltype) && "Not a decltype specifier"); 6146fd634f4ac59f5923cffadadb99d19f23c18707aAnders Carlsson 6156fd634f4ac59f5923cffadadb99d19f23c18707aAnders Carlsson SourceLocation StartLoc = ConsumeToken(); 6166fd634f4ac59f5923cffadadb99d19f23c18707aAnders Carlsson SourceLocation LParenLoc = Tok.getLocation(); 6171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump if (ExpectAndConsume(tok::l_paren, diag::err_expected_lparen_after, 6196fd634f4ac59f5923cffadadb99d19f23c18707aAnders Carlsson "decltype")) { 6206fd634f4ac59f5923cffadadb99d19f23c18707aAnders Carlsson SkipUntil(tok::r_paren); 6216fd634f4ac59f5923cffadadb99d19f23c18707aAnders Carlsson return; 6226fd634f4ac59f5923cffadadb99d19f23c18707aAnders Carlsson } 6231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6246fd634f4ac59f5923cffadadb99d19f23c18707aAnders Carlsson // Parse the expression 6251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6266fd634f4ac59f5923cffadadb99d19f23c18707aAnders Carlsson // C++0x [dcl.type.simple]p4: 6276fd634f4ac59f5923cffadadb99d19f23c18707aAnders Carlsson // The operand of the decltype specifier is an unevaluated operand. 6286fd634f4ac59f5923cffadadb99d19f23c18707aAnders Carlsson EnterExpressionEvaluationContext Unevaluated(Actions, 629f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall Sema::Unevaluated); 63060d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Result = ParseExpression(); 6316fd634f4ac59f5923cffadadb99d19f23c18707aAnders Carlsson if (Result.isInvalid()) { 6326fd634f4ac59f5923cffadadb99d19f23c18707aAnders Carlsson SkipUntil(tok::r_paren); 6336fd634f4ac59f5923cffadadb99d19f23c18707aAnders Carlsson return; 6346fd634f4ac59f5923cffadadb99d19f23c18707aAnders Carlsson } 6351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6366fd634f4ac59f5923cffadadb99d19f23c18707aAnders Carlsson // Match the ')' 6376fd634f4ac59f5923cffadadb99d19f23c18707aAnders Carlsson SourceLocation RParenLoc; 6386fd634f4ac59f5923cffadadb99d19f23c18707aAnders Carlsson if (Tok.is(tok::r_paren)) 6396fd634f4ac59f5923cffadadb99d19f23c18707aAnders Carlsson RParenLoc = ConsumeParen(); 6406fd634f4ac59f5923cffadadb99d19f23c18707aAnders Carlsson else 6416fd634f4ac59f5923cffadadb99d19f23c18707aAnders Carlsson MatchRHSPunctuation(tok::r_paren, LParenLoc); 6421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6436fd634f4ac59f5923cffadadb99d19f23c18707aAnders Carlsson if (RParenLoc.isInvalid()) 6446fd634f4ac59f5923cffadadb99d19f23c18707aAnders Carlsson return; 6456fd634f4ac59f5923cffadadb99d19f23c18707aAnders Carlsson 6466fd634f4ac59f5923cffadadb99d19f23c18707aAnders Carlsson const char *PrevSpec = 0; 647fec54013fcd0eb72642741584ca04c1bc292bef8John McCall unsigned DiagID; 6486fd634f4ac59f5923cffadadb99d19f23c18707aAnders Carlsson // Check for duplicate type specifiers (e.g. "int decltype(a)"). 6491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump if (DS.SetTypeSpecType(DeclSpec::TST_decltype, StartLoc, PrevSpec, 650fec54013fcd0eb72642741584ca04c1bc292bef8John McCall DiagID, Result.release())) 651fec54013fcd0eb72642741584ca04c1bc292bef8John McCall Diag(StartLoc, DiagID) << PrevSpec; 6526fd634f4ac59f5923cffadadb99d19f23c18707aAnders Carlsson} 6536fd634f4ac59f5923cffadadb99d19f23c18707aAnders Carlsson 654db5d44b775c60166074acd184ca9f1981c10c2a7Sean Huntvoid Parser::ParseUnderlyingTypeSpecifier(DeclSpec &DS) { 655db5d44b775c60166074acd184ca9f1981c10c2a7Sean Hunt assert(Tok.is(tok::kw___underlying_type) && 656db5d44b775c60166074acd184ca9f1981c10c2a7Sean Hunt "Not an underlying type specifier"); 657db5d44b775c60166074acd184ca9f1981c10c2a7Sean Hunt 658db5d44b775c60166074acd184ca9f1981c10c2a7Sean Hunt SourceLocation StartLoc = ConsumeToken(); 659db5d44b775c60166074acd184ca9f1981c10c2a7Sean Hunt SourceLocation LParenLoc = Tok.getLocation(); 660db5d44b775c60166074acd184ca9f1981c10c2a7Sean Hunt 661db5d44b775c60166074acd184ca9f1981c10c2a7Sean Hunt if (ExpectAndConsume(tok::l_paren, diag::err_expected_lparen_after, 662db5d44b775c60166074acd184ca9f1981c10c2a7Sean Hunt "__underlying_type")) { 663db5d44b775c60166074acd184ca9f1981c10c2a7Sean Hunt SkipUntil(tok::r_paren); 664db5d44b775c60166074acd184ca9f1981c10c2a7Sean Hunt return; 665db5d44b775c60166074acd184ca9f1981c10c2a7Sean Hunt } 666db5d44b775c60166074acd184ca9f1981c10c2a7Sean Hunt 667db5d44b775c60166074acd184ca9f1981c10c2a7Sean Hunt TypeResult Result = ParseTypeName(); 668db5d44b775c60166074acd184ca9f1981c10c2a7Sean Hunt if (Result.isInvalid()) { 669db5d44b775c60166074acd184ca9f1981c10c2a7Sean Hunt SkipUntil(tok::r_paren); 670db5d44b775c60166074acd184ca9f1981c10c2a7Sean Hunt return; 671db5d44b775c60166074acd184ca9f1981c10c2a7Sean Hunt } 672db5d44b775c60166074acd184ca9f1981c10c2a7Sean Hunt 673db5d44b775c60166074acd184ca9f1981c10c2a7Sean Hunt // Match the ')' 674db5d44b775c60166074acd184ca9f1981c10c2a7Sean Hunt SourceLocation RParenLoc; 675db5d44b775c60166074acd184ca9f1981c10c2a7Sean Hunt if (Tok.is(tok::r_paren)) 676db5d44b775c60166074acd184ca9f1981c10c2a7Sean Hunt RParenLoc = ConsumeParen(); 677db5d44b775c60166074acd184ca9f1981c10c2a7Sean Hunt else 678db5d44b775c60166074acd184ca9f1981c10c2a7Sean Hunt MatchRHSPunctuation(tok::r_paren, LParenLoc); 679db5d44b775c60166074acd184ca9f1981c10c2a7Sean Hunt 680db5d44b775c60166074acd184ca9f1981c10c2a7Sean Hunt if (RParenLoc.isInvalid()) 681db5d44b775c60166074acd184ca9f1981c10c2a7Sean Hunt return; 682db5d44b775c60166074acd184ca9f1981c10c2a7Sean Hunt 683db5d44b775c60166074acd184ca9f1981c10c2a7Sean Hunt const char *PrevSpec = 0; 684db5d44b775c60166074acd184ca9f1981c10c2a7Sean Hunt unsigned DiagID; 685ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt if (DS.SetTypeSpecType(DeclSpec::TST_underlyingType, StartLoc, PrevSpec, 686db5d44b775c60166074acd184ca9f1981c10c2a7Sean Hunt DiagID, Result.release())) 687db5d44b775c60166074acd184ca9f1981c10c2a7Sean Hunt Diag(StartLoc, DiagID) << PrevSpec; 688db5d44b775c60166074acd184ca9f1981c10c2a7Sean Hunt} 689db5d44b775c60166074acd184ca9f1981c10c2a7Sean Hunt 69042a552f8200ba5948661aee0106fce0c04e39818Douglas Gregor/// ParseClassName - Parse a C++ class-name, which names a class. Note 69142a552f8200ba5948661aee0106fce0c04e39818Douglas Gregor/// that we only check that the result names a type; semantic analysis 69242a552f8200ba5948661aee0106fce0c04e39818Douglas Gregor/// will need to verify that the type names a class. The result is 6937f43d6764797ab21216421aeb00f4ec314d503d1Douglas Gregor/// either a type or NULL, depending on whether a type name was 69442a552f8200ba5948661aee0106fce0c04e39818Douglas Gregor/// found. 69542a552f8200ba5948661aee0106fce0c04e39818Douglas Gregor/// 69642a552f8200ba5948661aee0106fce0c04e39818Douglas Gregor/// class-name: [C++ 9.1] 69742a552f8200ba5948661aee0106fce0c04e39818Douglas Gregor/// identifier 6987f43d6764797ab21216421aeb00f4ec314d503d1Douglas Gregor/// simple-template-id 6991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// 70031a19b6989bbf326d2de5ae12e712e2a65ca9c34Douglas GregorParser::TypeResult Parser::ParseClassName(SourceLocation &EndLocation, 701059101f922de6eb765601459925f4c8914420b23Douglas Gregor CXXScopeSpec &SS) { 7027f43d6764797ab21216421aeb00f4ec314d503d1Douglas Gregor // Check whether we have a template-id that names a type. 7037f43d6764797ab21216421aeb00f4ec314d503d1Douglas Gregor if (Tok.is(tok::annot_template_id)) { 7041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump TemplateIdAnnotation *TemplateId 7057f43d6764797ab21216421aeb00f4ec314d503d1Douglas Gregor = static_cast<TemplateIdAnnotation *>(Tok.getAnnotationValue()); 706d9b600c1a589200be905c53e2e10fceb57efa18dDouglas Gregor if (TemplateId->Kind == TNK_Type_template || 707d9b600c1a589200be905c53e2e10fceb57efa18dDouglas Gregor TemplateId->Kind == TNK_Dependent_template_name) { 708059101f922de6eb765601459925f4c8914420b23Douglas Gregor AnnotateTemplateIdTokenAsType(); 7097f43d6764797ab21216421aeb00f4ec314d503d1Douglas Gregor 7107f43d6764797ab21216421aeb00f4ec314d503d1Douglas Gregor assert(Tok.is(tok::annot_typename) && "template-id -> type failed"); 711b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType Type = getTypeAnnotation(Tok); 7127f43d6764797ab21216421aeb00f4ec314d503d1Douglas Gregor EndLocation = Tok.getAnnotationEndLoc(); 7137f43d6764797ab21216421aeb00f4ec314d503d1Douglas Gregor ConsumeToken(); 71431a19b6989bbf326d2de5ae12e712e2a65ca9c34Douglas Gregor 71531a19b6989bbf326d2de5ae12e712e2a65ca9c34Douglas Gregor if (Type) 71631a19b6989bbf326d2de5ae12e712e2a65ca9c34Douglas Gregor return Type; 71731a19b6989bbf326d2de5ae12e712e2a65ca9c34Douglas Gregor return true; 7187f43d6764797ab21216421aeb00f4ec314d503d1Douglas Gregor } 7197f43d6764797ab21216421aeb00f4ec314d503d1Douglas Gregor 7207f43d6764797ab21216421aeb00f4ec314d503d1Douglas Gregor // Fall through to produce an error below. 7217f43d6764797ab21216421aeb00f4ec314d503d1Douglas Gregor } 7227f43d6764797ab21216421aeb00f4ec314d503d1Douglas Gregor 72342a552f8200ba5948661aee0106fce0c04e39818Douglas Gregor if (Tok.isNot(tok::identifier)) { 7241ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner Diag(Tok, diag::err_expected_class_name); 72531a19b6989bbf326d2de5ae12e712e2a65ca9c34Douglas Gregor return true; 72642a552f8200ba5948661aee0106fce0c04e39818Douglas Gregor } 72742a552f8200ba5948661aee0106fce0c04e39818Douglas Gregor 72884d0a19828599e8623223632d59447fd498999cfDouglas Gregor IdentifierInfo *Id = Tok.getIdentifierInfo(); 72984d0a19828599e8623223632d59447fd498999cfDouglas Gregor SourceLocation IdLoc = ConsumeToken(); 73084d0a19828599e8623223632d59447fd498999cfDouglas Gregor 73184d0a19828599e8623223632d59447fd498999cfDouglas Gregor if (Tok.is(tok::less)) { 73284d0a19828599e8623223632d59447fd498999cfDouglas Gregor // It looks the user intended to write a template-id here, but the 73384d0a19828599e8623223632d59447fd498999cfDouglas Gregor // template-name was wrong. Try to fix that. 73484d0a19828599e8623223632d59447fd498999cfDouglas Gregor TemplateNameKind TNK = TNK_Type_template; 73584d0a19828599e8623223632d59447fd498999cfDouglas Gregor TemplateTy Template; 73623c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor if (!Actions.DiagnoseUnknownTemplateName(*Id, IdLoc, getCurScope(), 737059101f922de6eb765601459925f4c8914420b23Douglas Gregor &SS, Template, TNK)) { 73884d0a19828599e8623223632d59447fd498999cfDouglas Gregor Diag(IdLoc, diag::err_unknown_template_name) 73984d0a19828599e8623223632d59447fd498999cfDouglas Gregor << Id; 74084d0a19828599e8623223632d59447fd498999cfDouglas Gregor } 741193575455e00eca03fd7177f60e3f2e6263cb661Kovarththanan Rajaratnam 74284d0a19828599e8623223632d59447fd498999cfDouglas Gregor if (!Template) 74384d0a19828599e8623223632d59447fd498999cfDouglas Gregor return true; 74484d0a19828599e8623223632d59447fd498999cfDouglas Gregor 745193575455e00eca03fd7177f60e3f2e6263cb661Kovarththanan Rajaratnam // Form the template name 74684d0a19828599e8623223632d59447fd498999cfDouglas Gregor UnqualifiedId TemplateName; 74784d0a19828599e8623223632d59447fd498999cfDouglas Gregor TemplateName.setIdentifier(Id, IdLoc); 748193575455e00eca03fd7177f60e3f2e6263cb661Kovarththanan Rajaratnam 74984d0a19828599e8623223632d59447fd498999cfDouglas Gregor // Parse the full template-id, then turn it into a type. 75084d0a19828599e8623223632d59447fd498999cfDouglas Gregor if (AnnotateTemplateIdToken(Template, TNK, SS, TemplateName, 75184d0a19828599e8623223632d59447fd498999cfDouglas Gregor SourceLocation(), true)) 75284d0a19828599e8623223632d59447fd498999cfDouglas Gregor return true; 75384d0a19828599e8623223632d59447fd498999cfDouglas Gregor if (TNK == TNK_Dependent_template_name) 754059101f922de6eb765601459925f4c8914420b23Douglas Gregor AnnotateTemplateIdTokenAsType(); 755193575455e00eca03fd7177f60e3f2e6263cb661Kovarththanan Rajaratnam 75684d0a19828599e8623223632d59447fd498999cfDouglas Gregor // If we didn't end up with a typename token, there's nothing more we 75784d0a19828599e8623223632d59447fd498999cfDouglas Gregor // can do. 75884d0a19828599e8623223632d59447fd498999cfDouglas Gregor if (Tok.isNot(tok::annot_typename)) 75984d0a19828599e8623223632d59447fd498999cfDouglas Gregor return true; 760193575455e00eca03fd7177f60e3f2e6263cb661Kovarththanan Rajaratnam 76184d0a19828599e8623223632d59447fd498999cfDouglas Gregor // Retrieve the type from the annotation token, consume that token, and 76284d0a19828599e8623223632d59447fd498999cfDouglas Gregor // return. 76384d0a19828599e8623223632d59447fd498999cfDouglas Gregor EndLocation = Tok.getAnnotationEndLoc(); 764b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType Type = getTypeAnnotation(Tok); 76584d0a19828599e8623223632d59447fd498999cfDouglas Gregor ConsumeToken(); 76684d0a19828599e8623223632d59447fd498999cfDouglas Gregor return Type; 76784d0a19828599e8623223632d59447fd498999cfDouglas Gregor } 76884d0a19828599e8623223632d59447fd498999cfDouglas Gregor 76942a552f8200ba5948661aee0106fce0c04e39818Douglas Gregor // We have an identifier; check whether it is actually a type. 770059101f922de6eb765601459925f4c8914420b23Douglas Gregor ParsedType Type = Actions.getTypeName(*Id, IdLoc, getCurScope(), &SS, true, 7719e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor false, ParsedType(), 7729e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor /*NonTrivialTypeSourceInfo=*/true); 773193575455e00eca03fd7177f60e3f2e6263cb661Kovarththanan Rajaratnam if (!Type) { 774124b878dba5007df0a268ea128a6ad8dc5dd2c5eDouglas Gregor Diag(IdLoc, diag::err_expected_class_name); 77531a19b6989bbf326d2de5ae12e712e2a65ca9c34Douglas Gregor return true; 77642a552f8200ba5948661aee0106fce0c04e39818Douglas Gregor } 77742a552f8200ba5948661aee0106fce0c04e39818Douglas Gregor 77842a552f8200ba5948661aee0106fce0c04e39818Douglas Gregor // Consume the identifier. 77984d0a19828599e8623223632d59447fd498999cfDouglas Gregor EndLocation = IdLoc; 7805606220447c7901ba8d80147ddab893bb7949dd5Nick Lewycky 7815606220447c7901ba8d80147ddab893bb7949dd5Nick Lewycky // Fake up a Declarator to use with ActOnTypeName. 7820b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall DeclSpec DS(AttrFactory); 7835606220447c7901ba8d80147ddab893bb7949dd5Nick Lewycky DS.SetRangeStart(IdLoc); 7845606220447c7901ba8d80147ddab893bb7949dd5Nick Lewycky DS.SetRangeEnd(EndLocation); 785059101f922de6eb765601459925f4c8914420b23Douglas Gregor DS.getTypeSpecScope() = SS; 7865606220447c7901ba8d80147ddab893bb7949dd5Nick Lewycky 7875606220447c7901ba8d80147ddab893bb7949dd5Nick Lewycky const char *PrevSpec = 0; 7885606220447c7901ba8d80147ddab893bb7949dd5Nick Lewycky unsigned DiagID; 7895606220447c7901ba8d80147ddab893bb7949dd5Nick Lewycky DS.SetTypeSpecType(TST_typename, IdLoc, PrevSpec, DiagID, Type); 7905606220447c7901ba8d80147ddab893bb7949dd5Nick Lewycky 7915606220447c7901ba8d80147ddab893bb7949dd5Nick Lewycky Declarator DeclaratorInfo(DS, Declarator::TypeNameContext); 7925606220447c7901ba8d80147ddab893bb7949dd5Nick Lewycky return Actions.ActOnTypeName(getCurScope(), DeclaratorInfo); 79342a552f8200ba5948661aee0106fce0c04e39818Douglas Gregor} 79442a552f8200ba5948661aee0106fce0c04e39818Douglas Gregor 795e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor/// ParseClassSpecifier - Parse a C++ class-specifier [C++ class] or 796e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor/// elaborated-type-specifier [C++ dcl.type.elab]; we can't tell which 797e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor/// until we reach the start of a definition or see a token that 798d9bafa76f8d6eb9e4f4974ed322217f8df6bb82eSebastian Redl/// cannot start a definition. If SuppressDeclarations is true, we do know. 799e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor/// 800e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor/// class-specifier: [C++ class] 801e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor/// class-head '{' member-specification[opt] '}' 802e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor/// class-head '{' member-specification[opt] '}' attributes[opt] 803e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor/// class-head: 804e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor/// class-key identifier[opt] base-clause[opt] 805e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor/// class-key nested-name-specifier identifier base-clause[opt] 806e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor/// class-key nested-name-specifier[opt] simple-template-id 807e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor/// base-clause[opt] 808e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor/// [GNU] class-key attributes[opt] identifier[opt] base-clause[opt] 8091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// [GNU] class-key attributes[opt] nested-name-specifier 810e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor/// identifier base-clause[opt] 8111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// [GNU] class-key attributes[opt] nested-name-specifier[opt] 812e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor/// simple-template-id base-clause[opt] 813e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor/// class-key: 814e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor/// 'class' 815e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor/// 'struct' 816e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor/// 'union' 817e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor/// 818e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor/// elaborated-type-specifier: [C++ dcl.type.elab] 8191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// class-key ::[opt] nested-name-specifier[opt] identifier 8201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// class-key ::[opt] nested-name-specifier[opt] 'template'[opt] 8211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// simple-template-id 822e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor/// 823e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor/// Note that the C++ class-specifier and elaborated-type-specifier, 824e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor/// together, subsume the C99 struct-or-union-specifier: 825e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor/// 826e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor/// struct-or-union-specifier: [C99 6.7.2.1] 827e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor/// struct-or-union identifier[opt] '{' struct-contents '}' 828e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor/// struct-or-union identifier 829e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor/// [GNU] struct-or-union attributes[opt] identifier[opt] '{' struct-contents 830e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor/// '}' attributes[opt] 831e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor/// [GNU] struct-or-union attributes[opt] identifier 832e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor/// struct-or-union: 833e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor/// 'struct' 834e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor/// 'union' 8354c97d762d8c5a84f6554e5bfb31d28c90df64158Chris Lattnervoid Parser::ParseClassSpecifier(tok::TokenKind TagTokKind, 8364c97d762d8c5a84f6554e5bfb31d28c90df64158Chris Lattner SourceLocation StartLoc, DeclSpec &DS, 8374d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor const ParsedTemplateInfo &TemplateInfo, 838d9bafa76f8d6eb9e4f4974ed322217f8df6bb82eSebastian Redl AccessSpecifier AS, bool SuppressDeclarations){ 8394c97d762d8c5a84f6554e5bfb31d28c90df64158Chris Lattner DeclSpec::TST TagType; 8404c97d762d8c5a84f6554e5bfb31d28c90df64158Chris Lattner if (TagTokKind == tok::kw_struct) 8414c97d762d8c5a84f6554e5bfb31d28c90df64158Chris Lattner TagType = DeclSpec::TST_struct; 8424c97d762d8c5a84f6554e5bfb31d28c90df64158Chris Lattner else if (TagTokKind == tok::kw_class) 8434c97d762d8c5a84f6554e5bfb31d28c90df64158Chris Lattner TagType = DeclSpec::TST_class; 8444c97d762d8c5a84f6554e5bfb31d28c90df64158Chris Lattner else { 8454c97d762d8c5a84f6554e5bfb31d28c90df64158Chris Lattner assert(TagTokKind == tok::kw_union && "Not a class specifier"); 8464c97d762d8c5a84f6554e5bfb31d28c90df64158Chris Lattner TagType = DeclSpec::TST_union; 8474c97d762d8c5a84f6554e5bfb31d28c90df64158Chris Lattner } 848e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor 849374929f7e88f6c7a96382b3eb4201b721c418372Douglas Gregor if (Tok.is(tok::code_completion)) { 850374929f7e88f6c7a96382b3eb4201b721c418372Douglas Gregor // Code completion for a struct, class, or union name. 85123c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.CodeCompleteTag(getCurScope(), TagType); 852dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor ConsumeCodeCompletionToken(); 853374929f7e88f6c7a96382b3eb4201b721c418372Douglas Gregor } 854193575455e00eca03fd7177f60e3f2e6263cb661Kovarththanan Rajaratnam 855926c4b486a08f698cd3a367fd6f1a3a07604358dChandler Carruth // C++03 [temp.explicit] 14.7.2/8: 856926c4b486a08f698cd3a367fd6f1a3a07604358dChandler Carruth // The usual access checking rules do not apply to names used to specify 857926c4b486a08f698cd3a367fd6f1a3a07604358dChandler Carruth // explicit instantiations. 858926c4b486a08f698cd3a367fd6f1a3a07604358dChandler Carruth // 859926c4b486a08f698cd3a367fd6f1a3a07604358dChandler Carruth // As an extension we do not perform access checking on the names used to 860926c4b486a08f698cd3a367fd6f1a3a07604358dChandler Carruth // specify explicit specializations either. This is important to allow 861926c4b486a08f698cd3a367fd6f1a3a07604358dChandler Carruth // specializing traits classes for private types. 862926c4b486a08f698cd3a367fd6f1a3a07604358dChandler Carruth bool SuppressingAccessChecks = false; 863926c4b486a08f698cd3a367fd6f1a3a07604358dChandler Carruth if (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation || 864926c4b486a08f698cd3a367fd6f1a3a07604358dChandler Carruth TemplateInfo.Kind == ParsedTemplateInfo::ExplicitSpecialization) { 865926c4b486a08f698cd3a367fd6f1a3a07604358dChandler Carruth Actions.ActOnStartSuppressingAccessChecks(); 866926c4b486a08f698cd3a367fd6f1a3a07604358dChandler Carruth SuppressingAccessChecks = true; 867926c4b486a08f698cd3a367fd6f1a3a07604358dChandler Carruth } 868926c4b486a08f698cd3a367fd6f1a3a07604358dChandler Carruth 8690b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall ParsedAttributes attrs(AttrFactory); 870e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor // If attributes exist after tag, parse them. 871e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor if (Tok.is(tok::kw___attribute)) 8727f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall ParseGNUAttributes(attrs); 873e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor 874f59e17ecf06ac60065e2d02058bd6f21f5d216ccSteve Naroff // If declspecs exist after tag, parse them. 875b1d397c23e1f8fd8b404d5731d531e7500f7140dJohn McCall while (Tok.is(tok::kw___declspec)) 8767f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall ParseMicrosoftDeclSpec(attrs); 877193575455e00eca03fd7177f60e3f2e6263cb661Kovarththanan Rajaratnam 878bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt // If C++0x attributes exist here, parse them. 879bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt // FIXME: Are we consistent with the ordering of parsing of different 880bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt // styles of attributes? 8817f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall MaybeParseCXX0XAttributes(attrs); 8821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 88320c0da7787c9a7d2529e42a4a91d777778595d74John Wiegley if (TagType == DeclSpec::TST_struct && 884b467cda8d97a1a18ee1aa62db3b7b21b2c294cebDouglas Gregor !Tok.is(tok::identifier) && 885b467cda8d97a1a18ee1aa62db3b7b21b2c294cebDouglas Gregor Tok.getIdentifierInfo() && 886b467cda8d97a1a18ee1aa62db3b7b21b2c294cebDouglas Gregor (Tok.is(tok::kw___is_arithmetic) || 887b467cda8d97a1a18ee1aa62db3b7b21b2c294cebDouglas Gregor Tok.is(tok::kw___is_convertible) || 88820c0da7787c9a7d2529e42a4a91d777778595d74John Wiegley Tok.is(tok::kw___is_empty) || 889b467cda8d97a1a18ee1aa62db3b7b21b2c294cebDouglas Gregor Tok.is(tok::kw___is_floating_point) || 890b467cda8d97a1a18ee1aa62db3b7b21b2c294cebDouglas Gregor Tok.is(tok::kw___is_function) || 89120c0da7787c9a7d2529e42a4a91d777778595d74John Wiegley Tok.is(tok::kw___is_fundamental) || 892b467cda8d97a1a18ee1aa62db3b7b21b2c294cebDouglas Gregor Tok.is(tok::kw___is_integral) || 893b467cda8d97a1a18ee1aa62db3b7b21b2c294cebDouglas Gregor Tok.is(tok::kw___is_member_function_pointer) || 894b467cda8d97a1a18ee1aa62db3b7b21b2c294cebDouglas Gregor Tok.is(tok::kw___is_member_pointer) || 895b467cda8d97a1a18ee1aa62db3b7b21b2c294cebDouglas Gregor Tok.is(tok::kw___is_pod) || 896b467cda8d97a1a18ee1aa62db3b7b21b2c294cebDouglas Gregor Tok.is(tok::kw___is_pointer) || 897b467cda8d97a1a18ee1aa62db3b7b21b2c294cebDouglas Gregor Tok.is(tok::kw___is_same) || 898877222e2491bbc40a5c74cc100c540983f306b70Douglas Gregor Tok.is(tok::kw___is_scalar) || 899b467cda8d97a1a18ee1aa62db3b7b21b2c294cebDouglas Gregor Tok.is(tok::kw___is_signed) || 900b467cda8d97a1a18ee1aa62db3b7b21b2c294cebDouglas Gregor Tok.is(tok::kw___is_unsigned) || 901b467cda8d97a1a18ee1aa62db3b7b21b2c294cebDouglas Gregor Tok.is(tok::kw___is_void))) { 902b467cda8d97a1a18ee1aa62db3b7b21b2c294cebDouglas Gregor // GNU libstdc++ 4.2 and libc++ uaw certain intrinsic names as the 903b467cda8d97a1a18ee1aa62db3b7b21b2c294cebDouglas Gregor // name of struct templates, but some are keywords in GCC >= 4.3 904b467cda8d97a1a18ee1aa62db3b7b21b2c294cebDouglas Gregor // and Clang. Therefore, when we see the token sequence "struct 905b467cda8d97a1a18ee1aa62db3b7b21b2c294cebDouglas Gregor // X", make X into a normal identifier rather than a keyword, to 906b467cda8d97a1a18ee1aa62db3b7b21b2c294cebDouglas Gregor // allow libstdc++ 4.2 and libc++ to work properly. 907646395bbcaa849c94bc2a3246c71d809ca719f01Argyrios Kyrtzidis Tok.getIdentifierInfo()->RevertTokenIDToIdentifier(); 908b117a60f7684261ddc8c8f14e8ef8a827e6af814Douglas Gregor Tok.setKind(tok::identifier); 909b117a60f7684261ddc8c8f14e8ef8a827e6af814Douglas Gregor } 9101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 911eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis // Parse the (optional) nested-name-specifier. 912aa87d33309f505b68c3bfc17486c93e4d224b24fJohn McCall CXXScopeSpec &SS = DS.getTypeSpecScope(); 91308d92ecf6e5b1fd23177a08c2312b58d63d863dbChris Lattner if (getLang().CPlusPlus) { 91408d92ecf6e5b1fd23177a08c2312b58d63d863dbChris Lattner // "FOO : BAR" is not a potential typo for "FOO::BAR". 91508d92ecf6e5b1fd23177a08c2312b58d63d863dbChris Lattner ColonProtectionRAIIObject X(*this); 916193575455e00eca03fd7177f60e3f2e6263cb661Kovarththanan Rajaratnam 917b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall if (ParseOptionalCXXScopeSpecifier(SS, ParsedType(), true)) 918207014eb2b372aa33721e86d90a8a586ba8dc8aeJohn McCall DS.SetTypeSpecError(); 9199ba6166f4a78722e7df8ffbd64eb788bfdf2764aJohn McCall if (SS.isSet()) 92008d92ecf6e5b1fd23177a08c2312b58d63d863dbChris Lattner if (Tok.isNot(tok::identifier) && Tok.isNot(tok::annot_template_id)) 92108d92ecf6e5b1fd23177a08c2312b58d63d863dbChris Lattner Diag(Tok, diag::err_expected_ident); 92208d92ecf6e5b1fd23177a08c2312b58d63d863dbChris Lattner } 923cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor 9242cc782f7932f1069d9fa8bb5c518165802aad68dDouglas Gregor TemplateParameterLists *TemplateParams = TemplateInfo.TemplateParams; 9252cc782f7932f1069d9fa8bb5c518165802aad68dDouglas Gregor 926cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor // Parse the (optional) class name or simple-template-id. 927e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor IdentifierInfo *Name = 0; 928e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor SourceLocation NameLoc; 92939a8de10c18365bde7062d8959b7ed525449c561Douglas Gregor TemplateIdAnnotation *TemplateId = 0; 930e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor if (Tok.is(tok::identifier)) { 931e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor Name = Tok.getIdentifierInfo(); 932e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor NameLoc = ConsumeToken(); 933193575455e00eca03fd7177f60e3f2e6263cb661Kovarththanan Rajaratnam 9345ee3734c0b5222a7c445591a1f14102c1b3a289bDouglas Gregor if (Tok.is(tok::less) && getLang().CPlusPlus) { 935193575455e00eca03fd7177f60e3f2e6263cb661Kovarththanan Rajaratnam // The name was supposed to refer to a template, but didn't. 9362cc782f7932f1069d9fa8bb5c518165802aad68dDouglas Gregor // Eat the template argument list and try to continue parsing this as 9372cc782f7932f1069d9fa8bb5c518165802aad68dDouglas Gregor // a class (or template thereof). 9382cc782f7932f1069d9fa8bb5c518165802aad68dDouglas Gregor TemplateArgList TemplateArgs; 9392cc782f7932f1069d9fa8bb5c518165802aad68dDouglas Gregor SourceLocation LAngleLoc, RAngleLoc; 940059101f922de6eb765601459925f4c8914420b23Douglas Gregor if (ParseTemplateIdAfterTemplateName(TemplateTy(), NameLoc, SS, 9412cc782f7932f1069d9fa8bb5c518165802aad68dDouglas Gregor true, LAngleLoc, 942314b97f8c564b465af605efaee23f91ec18a982bDouglas Gregor TemplateArgs, RAngleLoc)) { 9432cc782f7932f1069d9fa8bb5c518165802aad68dDouglas Gregor // We couldn't parse the template argument list at all, so don't 9442cc782f7932f1069d9fa8bb5c518165802aad68dDouglas Gregor // try to give any location information for the list. 9452cc782f7932f1069d9fa8bb5c518165802aad68dDouglas Gregor LAngleLoc = RAngleLoc = SourceLocation(); 9462cc782f7932f1069d9fa8bb5c518165802aad68dDouglas Gregor } 947193575455e00eca03fd7177f60e3f2e6263cb661Kovarththanan Rajaratnam 9482cc782f7932f1069d9fa8bb5c518165802aad68dDouglas Gregor Diag(NameLoc, diag::err_explicit_spec_non_template) 949c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor << (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation) 9502cc782f7932f1069d9fa8bb5c518165802aad68dDouglas Gregor << (TagType == DeclSpec::TST_class? 0 9512cc782f7932f1069d9fa8bb5c518165802aad68dDouglas Gregor : TagType == DeclSpec::TST_struct? 1 9522cc782f7932f1069d9fa8bb5c518165802aad68dDouglas Gregor : 2) 9532cc782f7932f1069d9fa8bb5c518165802aad68dDouglas Gregor << Name 9542cc782f7932f1069d9fa8bb5c518165802aad68dDouglas Gregor << SourceRange(LAngleLoc, RAngleLoc); 955193575455e00eca03fd7177f60e3f2e6263cb661Kovarththanan Rajaratnam 956193575455e00eca03fd7177f60e3f2e6263cb661Kovarththanan Rajaratnam // Strip off the last template parameter list if it was empty, since 957c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor // we've removed its template argument list. 958c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor if (TemplateParams && TemplateInfo.LastParameterListWasEmpty) { 959c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor if (TemplateParams && TemplateParams->size() > 1) { 960c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor TemplateParams->pop_back(); 961c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor } else { 962c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor TemplateParams = 0; 963193575455e00eca03fd7177f60e3f2e6263cb661Kovarththanan Rajaratnam const_cast<ParsedTemplateInfo&>(TemplateInfo).Kind 964c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor = ParsedTemplateInfo::NonTemplate; 965c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor } 966c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor } else if (TemplateInfo.Kind 967c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor == ParsedTemplateInfo::ExplicitInstantiation) { 968c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor // Pretend this is just a forward declaration. 9692cc782f7932f1069d9fa8bb5c518165802aad68dDouglas Gregor TemplateParams = 0; 970193575455e00eca03fd7177f60e3f2e6263cb661Kovarththanan Rajaratnam const_cast<ParsedTemplateInfo&>(TemplateInfo).Kind 9712cc782f7932f1069d9fa8bb5c518165802aad68dDouglas Gregor = ParsedTemplateInfo::NonTemplate; 972193575455e00eca03fd7177f60e3f2e6263cb661Kovarththanan Rajaratnam const_cast<ParsedTemplateInfo&>(TemplateInfo).TemplateLoc 973c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor = SourceLocation(); 974c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor const_cast<ParsedTemplateInfo&>(TemplateInfo).ExternLoc 975c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor = SourceLocation(); 9762cc782f7932f1069d9fa8bb5c518165802aad68dDouglas Gregor } 9772cc782f7932f1069d9fa8bb5c518165802aad68dDouglas Gregor } 97839a8de10c18365bde7062d8959b7ed525449c561Douglas Gregor } else if (Tok.is(tok::annot_template_id)) { 97939a8de10c18365bde7062d8959b7ed525449c561Douglas Gregor TemplateId = static_cast<TemplateIdAnnotation *>(Tok.getAnnotationValue()); 98039a8de10c18365bde7062d8959b7ed525449c561Douglas Gregor NameLoc = ConsumeToken(); 981cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor 982059101f922de6eb765601459925f4c8914420b23Douglas Gregor if (TemplateId->Kind != TNK_Type_template && 983059101f922de6eb765601459925f4c8914420b23Douglas Gregor TemplateId->Kind != TNK_Dependent_template_name) { 98439a8de10c18365bde7062d8959b7ed525449c561Douglas Gregor // The template-name in the simple-template-id refers to 98539a8de10c18365bde7062d8959b7ed525449c561Douglas Gregor // something other than a class template. Give an appropriate 98639a8de10c18365bde7062d8959b7ed525449c561Douglas Gregor // error message and skip to the ';'. 98739a8de10c18365bde7062d8959b7ed525449c561Douglas Gregor SourceRange Range(NameLoc); 98839a8de10c18365bde7062d8959b7ed525449c561Douglas Gregor if (SS.isNotEmpty()) 98939a8de10c18365bde7062d8959b7ed525449c561Douglas Gregor Range.setBegin(SS.getBeginLoc()); 99039a8de10c18365bde7062d8959b7ed525449c561Douglas Gregor 99139a8de10c18365bde7062d8959b7ed525449c561Douglas Gregor Diag(TemplateId->LAngleLoc, diag::err_template_spec_syntax_non_template) 99239a8de10c18365bde7062d8959b7ed525449c561Douglas Gregor << Name << static_cast<int>(TemplateId->Kind) << Range; 9931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 99439a8de10c18365bde7062d8959b7ed525449c561Douglas Gregor DS.SetTypeSpecError(); 99539a8de10c18365bde7062d8959b7ed525449c561Douglas Gregor SkipUntil(tok::semi, false, true); 99639a8de10c18365bde7062d8959b7ed525449c561Douglas Gregor TemplateId->Destroy(); 997926c4b486a08f698cd3a367fd6f1a3a07604358dChandler Carruth if (SuppressingAccessChecks) 998926c4b486a08f698cd3a367fd6f1a3a07604358dChandler Carruth Actions.ActOnStopSuppressingAccessChecks(); 999926c4b486a08f698cd3a367fd6f1a3a07604358dChandler Carruth 100039a8de10c18365bde7062d8959b7ed525449c561Douglas Gregor return; 1001cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor } 1002e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor } 1003e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor 1004926c4b486a08f698cd3a367fd6f1a3a07604358dChandler Carruth // As soon as we're finished parsing the class's template-id, turn access 1005926c4b486a08f698cd3a367fd6f1a3a07604358dChandler Carruth // checking back on. 1006926c4b486a08f698cd3a367fd6f1a3a07604358dChandler Carruth if (SuppressingAccessChecks) 1007926c4b486a08f698cd3a367fd6f1a3a07604358dChandler Carruth Actions.ActOnStopSuppressingAccessChecks(); 1008926c4b486a08f698cd3a367fd6f1a3a07604358dChandler Carruth 100967d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall // There are four options here. If we have 'struct foo;', then this 101067d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall // is either a forward declaration or a friend declaration, which 1011cc54d594d4f6509c0e3a8e349e481d9b5d899df6Anders Carlsson // have to be treated differently. If we have 'struct foo {...', 10121d20927fd0a08c26ef0e86e26f42073fd582ff77Anders Carlsson // 'struct foo :...' or 'struct foo final[opt]' then this is a 1013cc54d594d4f6509c0e3a8e349e481d9b5d899df6Anders Carlsson // definition. Otherwise we have something like 'struct foo xyz', a reference. 1014d9bafa76f8d6eb9e4f4974ed322217f8df6bb82eSebastian Redl // However, in some contexts, things look like declarations but are just 1015d9bafa76f8d6eb9e4f4974ed322217f8df6bb82eSebastian Redl // references, e.g. 1016d9bafa76f8d6eb9e4f4974ed322217f8df6bb82eSebastian Redl // new struct s; 1017d9bafa76f8d6eb9e4f4974ed322217f8df6bb82eSebastian Redl // or 1018d9bafa76f8d6eb9e4f4974ed322217f8df6bb82eSebastian Redl // &T::operator struct s; 1019d9bafa76f8d6eb9e4f4974ed322217f8df6bb82eSebastian Redl // For these, SuppressDeclarations is true. 1020f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall Sema::TagUseKind TUK; 1021d9bafa76f8d6eb9e4f4974ed322217f8df6bb82eSebastian Redl if (SuppressDeclarations) 1022f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall TUK = Sema::TUK_Reference; 1023cc54d594d4f6509c0e3a8e349e481d9b5d899df6Anders Carlsson else if (Tok.is(tok::l_brace) || 1024cc54d594d4f6509c0e3a8e349e481d9b5d899df6Anders Carlsson (getLang().CPlusPlus && Tok.is(tok::colon)) || 10258a29ba0d66bce99014651f1e3351aef6c3361d3fAnders Carlsson isCXX0XFinalKeyword()) { 1026d85bea2affdd59d83d1be7d24b97f436484c3625Douglas Gregor if (DS.isFriendSpecified()) { 1027d85bea2affdd59d83d1be7d24b97f436484c3625Douglas Gregor // C++ [class.friend]p2: 1028d85bea2affdd59d83d1be7d24b97f436484c3625Douglas Gregor // A class shall not be defined in a friend declaration. 1029d85bea2affdd59d83d1be7d24b97f436484c3625Douglas Gregor Diag(Tok.getLocation(), diag::err_friend_decl_defines_class) 1030d85bea2affdd59d83d1be7d24b97f436484c3625Douglas Gregor << SourceRange(DS.getFriendSpecLoc()); 1031d85bea2affdd59d83d1be7d24b97f436484c3625Douglas Gregor 1032d85bea2affdd59d83d1be7d24b97f436484c3625Douglas Gregor // Skip everything up to the semicolon, so that this looks like a proper 1033d85bea2affdd59d83d1be7d24b97f436484c3625Douglas Gregor // friend class (or template thereof) declaration. 1034d85bea2affdd59d83d1be7d24b97f436484c3625Douglas Gregor SkipUntil(tok::semi, true, true); 1035f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall TUK = Sema::TUK_Friend; 1036d85bea2affdd59d83d1be7d24b97f436484c3625Douglas Gregor } else { 1037d85bea2affdd59d83d1be7d24b97f436484c3625Douglas Gregor // Okay, this is a class definition. 1038f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall TUK = Sema::TUK_Definition; 1039d85bea2affdd59d83d1be7d24b97f436484c3625Douglas Gregor } 1040d85bea2affdd59d83d1be7d24b97f436484c3625Douglas Gregor } else if (Tok.is(tok::semi)) 1041f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall TUK = DS.isFriendSpecified() ? Sema::TUK_Friend : Sema::TUK_Declaration; 1042e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor else 1043f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall TUK = Sema::TUK_Reference; 1044e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor 1045207014eb2b372aa33721e86d90a8a586ba8dc8aeJohn McCall if (!Name && !TemplateId && (DS.getTypeSpecType() == DeclSpec::TST_error || 1046f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall TUK != Sema::TUK_Definition)) { 1047207014eb2b372aa33721e86d90a8a586ba8dc8aeJohn McCall if (DS.getTypeSpecType() != DeclSpec::TST_error) { 1048207014eb2b372aa33721e86d90a8a586ba8dc8aeJohn McCall // We have a declaration or reference to an anonymous class. 1049207014eb2b372aa33721e86d90a8a586ba8dc8aeJohn McCall Diag(StartLoc, diag::err_anon_type_definition) 1050207014eb2b372aa33721e86d90a8a586ba8dc8aeJohn McCall << DeclSpec::getSpecifierName(TagType); 1051207014eb2b372aa33721e86d90a8a586ba8dc8aeJohn McCall } 1052e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor 1053e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor SkipUntil(tok::comma, true); 105439a8de10c18365bde7062d8959b7ed525449c561Douglas Gregor 105539a8de10c18365bde7062d8959b7ed525449c561Douglas Gregor if (TemplateId) 105639a8de10c18365bde7062d8959b7ed525449c561Douglas Gregor TemplateId->Destroy(); 1057e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor return; 1058e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor } 1059e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor 1060ddc29e116db3c3f4144355e67a0137b38b6bb6d1Douglas Gregor // Create the tag portion of the class or class template. 1061d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall DeclResult TagOrTempResult = true; // invalid 1062d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall TypeResult TypeResult = true; // invalid 10634d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor 1064402abb55fc2e0cdda5fb1ac90009b1f5f6774906Douglas Gregor bool Owned = false; 1065f1bbbb49f06a7462476cd88166fccda5feb15cabJohn McCall if (TemplateId) { 10664d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor // Explicit specialization, class template partial specialization, 10674d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor // or explicit instantiation. 10681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ASTTemplateArgsPtr TemplateArgsPtr(Actions, 106939a8de10c18365bde7062d8959b7ed525449c561Douglas Gregor TemplateId->getTemplateArgs(), 107039a8de10c18365bde7062d8959b7ed525449c561Douglas Gregor TemplateId->NumArgs); 10714d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor if (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation && 1072f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall TUK == Sema::TUK_Declaration) { 10734d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor // This is an explicit instantiation of a class template. 10744d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor TagOrTempResult 107523c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor = Actions.ActOnExplicitInstantiation(getCurScope(), 107645f965581935791a018df829a14dff53c1dd8f47Douglas Gregor TemplateInfo.ExternLoc, 10771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump TemplateInfo.TemplateLoc, 10784d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor TagType, 10791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump StartLoc, 10804d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor SS, 10812b5289b6fd7e3d9899868410a498c081c9595662John McCall TemplateId->Template, 10821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump TemplateId->TemplateNameLoc, 10831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump TemplateId->LAngleLoc, 10844d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor TemplateArgsPtr, 10851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump TemplateId->RAngleLoc, 10867f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall attrs.getList()); 108774256f5ea6950c9fd34595aa124eb4740372f15cJohn McCall 108874256f5ea6950c9fd34595aa124eb4740372f15cJohn McCall // Friend template-ids are treated as references unless 108974256f5ea6950c9fd34595aa124eb4740372f15cJohn McCall // they have template headers, in which case they're ill-formed 109074256f5ea6950c9fd34595aa124eb4740372f15cJohn McCall // (FIXME: "template <class T> friend class A<T>::B<int>;"). 109174256f5ea6950c9fd34595aa124eb4740372f15cJohn McCall // We diagnose this error in ActOnClassTemplateSpecialization. 1092f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall } else if (TUK == Sema::TUK_Reference || 1093f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall (TUK == Sema::TUK_Friend && 109474256f5ea6950c9fd34595aa124eb4740372f15cJohn McCall TemplateInfo.Kind == ParsedTemplateInfo::NonTemplate)) { 1095059101f922de6eb765601459925f4c8914420b23Douglas Gregor TypeResult = Actions.ActOnTagTemplateIdType(TUK, TagType, 1096059101f922de6eb765601459925f4c8914420b23Douglas Gregor StartLoc, 1097059101f922de6eb765601459925f4c8914420b23Douglas Gregor TemplateId->SS, 1098059101f922de6eb765601459925f4c8914420b23Douglas Gregor TemplateId->Template, 1099059101f922de6eb765601459925f4c8914420b23Douglas Gregor TemplateId->TemplateNameLoc, 1100059101f922de6eb765601459925f4c8914420b23Douglas Gregor TemplateId->LAngleLoc, 1101059101f922de6eb765601459925f4c8914420b23Douglas Gregor TemplateArgsPtr, 1102059101f922de6eb765601459925f4c8914420b23Douglas Gregor TemplateId->RAngleLoc); 11034d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor } else { 11044d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor // This is an explicit specialization or a class template 11054d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor // partial specialization. 11064d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor TemplateParameterLists FakedParamLists; 11074d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor 11084d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor if (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation) { 11094d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor // This looks like an explicit instantiation, because we have 11104d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor // something like 11114d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor // 11124d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor // template class Foo<X> 11134d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor // 11143f5b61c394f4f205bcb4d316eb2a7a0a68b8af86Douglas Gregor // but it actually has a definition. Most likely, this was 11154d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor // meant to be an explicit specialization, but the user forgot 11164d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor // the '<>' after 'template'. 1117f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall assert(TUK == Sema::TUK_Definition && "Expected a definition here"); 11184d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor 11191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation LAngleLoc 11204d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor = PP.getLocForEndOfToken(TemplateInfo.TemplateLoc); 11211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Diag(TemplateId->TemplateNameLoc, 11224d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor diag::err_explicit_instantiation_with_definition) 11234d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor << SourceRange(TemplateInfo.TemplateLoc) 1124849b243d4065f56742a4677d6dc8277609a151f8Douglas Gregor << FixItHint::CreateInsertion(LAngleLoc, "<>"); 11254d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor 11264d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor // Create a fake template parameter list that contains only 11274d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor // "template<>", so that we treat this construct as a class 11284d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor // template specialization. 11294d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor FakedParamLists.push_back( 11301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Actions.ActOnTemplateParameterList(0, SourceLocation(), 11314d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor TemplateInfo.TemplateLoc, 11321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump LAngleLoc, 11331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 0, 0, 11344d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor LAngleLoc)); 11354d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor TemplateParams = &FakedParamLists; 11364d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor } 11374d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor 11384d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor // Build the class template specialization. 11394d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor TagOrTempResult 114023c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor = Actions.ActOnClassTemplateSpecialization(getCurScope(), TagType, TUK, 114139a8de10c18365bde7062d8959b7ed525449c561Douglas Gregor StartLoc, SS, 11422b5289b6fd7e3d9899868410a498c081c9595662John McCall TemplateId->Template, 11431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump TemplateId->TemplateNameLoc, 11441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump TemplateId->LAngleLoc, 114539a8de10c18365bde7062d8959b7ed525449c561Douglas Gregor TemplateArgsPtr, 11461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump TemplateId->RAngleLoc, 11477f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall attrs.getList(), 1148f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall MultiTemplateParamsArg(Actions, 1149cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor TemplateParams? &(*TemplateParams)[0] : 0, 1150cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor TemplateParams? TemplateParams->size() : 0)); 11514d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor } 115239a8de10c18365bde7062d8959b7ed525449c561Douglas Gregor TemplateId->Destroy(); 11533f5b61c394f4f205bcb4d316eb2a7a0a68b8af86Douglas Gregor } else if (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation && 1154f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall TUK == Sema::TUK_Declaration) { 11553f5b61c394f4f205bcb4d316eb2a7a0a68b8af86Douglas Gregor // Explicit instantiation of a member of a class template 11563f5b61c394f4f205bcb4d316eb2a7a0a68b8af86Douglas Gregor // specialization, e.g., 11573f5b61c394f4f205bcb4d316eb2a7a0a68b8af86Douglas Gregor // 11583f5b61c394f4f205bcb4d316eb2a7a0a68b8af86Douglas Gregor // template struct Outer<int>::Inner; 11593f5b61c394f4f205bcb4d316eb2a7a0a68b8af86Douglas Gregor // 11603f5b61c394f4f205bcb4d316eb2a7a0a68b8af86Douglas Gregor TagOrTempResult 116123c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor = Actions.ActOnExplicitInstantiation(getCurScope(), 116245f965581935791a018df829a14dff53c1dd8f47Douglas Gregor TemplateInfo.ExternLoc, 11631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump TemplateInfo.TemplateLoc, 11641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump TagType, StartLoc, SS, Name, 11657f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall NameLoc, attrs.getList()); 11669a34edb710917798aa30263374f624f13b594605John McCall } else if (TUK == Sema::TUK_Friend && 11679a34edb710917798aa30263374f624f13b594605John McCall TemplateInfo.Kind != ParsedTemplateInfo::NonTemplate) { 11689a34edb710917798aa30263374f624f13b594605John McCall TagOrTempResult = 11699a34edb710917798aa30263374f624f13b594605John McCall Actions.ActOnTemplatedFriendTag(getCurScope(), DS.getFriendSpecLoc(), 11709a34edb710917798aa30263374f624f13b594605John McCall TagType, StartLoc, SS, 11717f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall Name, NameLoc, attrs.getList(), 11729a34edb710917798aa30263374f624f13b594605John McCall MultiTemplateParamsArg(Actions, 11739a34edb710917798aa30263374f624f13b594605John McCall TemplateParams? &(*TemplateParams)[0] : 0, 11749a34edb710917798aa30263374f624f13b594605John McCall TemplateParams? TemplateParams->size() : 0)); 11753f5b61c394f4f205bcb4d316eb2a7a0a68b8af86Douglas Gregor } else { 11763f5b61c394f4f205bcb4d316eb2a7a0a68b8af86Douglas Gregor if (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation && 1177f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall TUK == Sema::TUK_Definition) { 11783f5b61c394f4f205bcb4d316eb2a7a0a68b8af86Douglas Gregor // FIXME: Diagnose this particular error. 11793f5b61c394f4f205bcb4d316eb2a7a0a68b8af86Douglas Gregor } 11803f5b61c394f4f205bcb4d316eb2a7a0a68b8af86Douglas Gregor 1181c4e7019d5c9034a2d84ee4695f8e98dc025ac131John McCall bool IsDependent = false; 1182c4e7019d5c9034a2d84ee4695f8e98dc025ac131John McCall 1183a25c4080a490ea2bab6f54094dd75b19eae83770John McCall // Don't pass down template parameter lists if this is just a tag 1184a25c4080a490ea2bab6f54094dd75b19eae83770John McCall // reference. For example, we don't need the template parameters here: 1185a25c4080a490ea2bab6f54094dd75b19eae83770John McCall // template <class T> class A *makeA(T t); 1186a25c4080a490ea2bab6f54094dd75b19eae83770John McCall MultiTemplateParamsArg TParams; 1187a25c4080a490ea2bab6f54094dd75b19eae83770John McCall if (TUK != Sema::TUK_Reference && TemplateParams) 1188a25c4080a490ea2bab6f54094dd75b19eae83770John McCall TParams = 1189a25c4080a490ea2bab6f54094dd75b19eae83770John McCall MultiTemplateParamsArg(&(*TemplateParams)[0], TemplateParams->size()); 1190a25c4080a490ea2bab6f54094dd75b19eae83770John McCall 11913f5b61c394f4f205bcb4d316eb2a7a0a68b8af86Douglas Gregor // Declaration or definition of a class type 11929a34edb710917798aa30263374f624f13b594605John McCall TagOrTempResult = Actions.ActOnTag(getCurScope(), TagType, TUK, StartLoc, 11937f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall SS, Name, NameLoc, attrs.getList(), AS, 1194a25c4080a490ea2bab6f54094dd75b19eae83770John McCall TParams, Owned, IsDependent, false, 1195a88cefd266c428be33cc06f7e8b00ff8fc97c1ffAbramo Bagnara false, clang::TypeResult()); 1196c4e7019d5c9034a2d84ee4695f8e98dc025ac131John McCall 1197c4e7019d5c9034a2d84ee4695f8e98dc025ac131John McCall // If ActOnTag said the type was dependent, try again with the 1198c4e7019d5c9034a2d84ee4695f8e98dc025ac131John McCall // less common call. 11999a34edb710917798aa30263374f624f13b594605John McCall if (IsDependent) { 12009a34edb710917798aa30263374f624f13b594605John McCall assert(TUK == Sema::TUK_Reference || TUK == Sema::TUK_Friend); 120123c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor TypeResult = Actions.ActOnDependentTag(getCurScope(), TagType, TUK, 1202193575455e00eca03fd7177f60e3f2e6263cb661Kovarththanan Rajaratnam SS, Name, StartLoc, NameLoc); 12039a34edb710917798aa30263374f624f13b594605John McCall } 12043f5b61c394f4f205bcb4d316eb2a7a0a68b8af86Douglas Gregor } 1205e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor 1206e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor // If there is a body, parse it and inform the actions module. 1207f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall if (TUK == Sema::TUK_Definition) { 1208bd0dfa5c37d422427080a0ae3af9b63e70e6e854John McCall assert(Tok.is(tok::l_brace) || 1209cc54d594d4f6509c0e3a8e349e481d9b5d899df6Anders Carlsson (getLang().CPlusPlus && Tok.is(tok::colon)) || 12108a29ba0d66bce99014651f1e3351aef6c3361d3fAnders Carlsson isCXX0XFinalKeyword()); 121107952324dda0e758c17f8bc3015793c65c51c48cArgyrios Kyrtzidis if (getLang().CPlusPlus) 1212212e81cc5151b3c42346e43cfd42499a53ffd39aDouglas Gregor ParseCXXMemberSpecification(StartLoc, TagType, TagOrTempResult.get()); 121307952324dda0e758c17f8bc3015793c65c51c48cArgyrios Kyrtzidis else 1214212e81cc5151b3c42346e43cfd42499a53ffd39aDouglas Gregor ParseStructUnionBody(StartLoc, TagType, TagOrTempResult.get()); 1215e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor } 1216e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor 1217b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall const char *PrevSpec = 0; 1218b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall unsigned DiagID; 1219b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall bool Result; 1220c4e7019d5c9034a2d84ee4695f8e98dc025ac131John McCall if (!TypeResult.isInvalid()) { 12210daaf32723ac78549c507c2a68a5300502703673Abramo Bagnara Result = DS.SetTypeSpecType(DeclSpec::TST_typename, StartLoc, 12220daaf32723ac78549c507c2a68a5300502703673Abramo Bagnara NameLoc.isValid() ? NameLoc : StartLoc, 1223b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall PrevSpec, DiagID, TypeResult.get()); 1224c4e7019d5c9034a2d84ee4695f8e98dc025ac131John McCall } else if (!TagOrTempResult.isInvalid()) { 12250daaf32723ac78549c507c2a68a5300502703673Abramo Bagnara Result = DS.SetTypeSpecType(TagType, StartLoc, 12260daaf32723ac78549c507c2a68a5300502703673Abramo Bagnara NameLoc.isValid() ? NameLoc : StartLoc, 12270daaf32723ac78549c507c2a68a5300502703673Abramo Bagnara PrevSpec, DiagID, TagOrTempResult.get(), Owned); 1228c4e7019d5c9034a2d84ee4695f8e98dc025ac131John McCall } else { 1229ddc29e116db3c3f4144355e67a0137b38b6bb6d1Douglas Gregor DS.SetTypeSpecError(); 123066e9977ddd6b197317d149213b76a9af0d3df4deAnders Carlsson return; 123166e9977ddd6b197317d149213b76a9af0d3df4deAnders Carlsson } 12321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1233b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall if (Result) 1234fec54013fcd0eb72642741584ca04c1bc292bef8John McCall Diag(StartLoc, DiagID) << PrevSpec; 1235193575455e00eca03fd7177f60e3f2e6263cb661Kovarththanan Rajaratnam 12364ed5d91db256f7dbe6bf716da0b801004c197254Chris Lattner // At this point, we've successfully parsed a class-specifier in 'definition' 12374ed5d91db256f7dbe6bf716da0b801004c197254Chris Lattner // form (e.g. "struct foo { int x; }". While we could just return here, we're 12384ed5d91db256f7dbe6bf716da0b801004c197254Chris Lattner // going to look at what comes after it to improve error recovery. If an 12394ed5d91db256f7dbe6bf716da0b801004c197254Chris Lattner // impossible token occurs next, we assume that the programmer forgot a ; at 12404ed5d91db256f7dbe6bf716da0b801004c197254Chris Lattner // the end of the declaration and recover that way. 12414ed5d91db256f7dbe6bf716da0b801004c197254Chris Lattner // 12424ed5d91db256f7dbe6bf716da0b801004c197254Chris Lattner // This switch enumerates the valid "follow" set for definition. 1243f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall if (TUK == Sema::TUK_Definition) { 1244b3a4e432c90be98c6d918087750397e86d030368Chris Lattner bool ExpectedSemi = true; 12454ed5d91db256f7dbe6bf716da0b801004c197254Chris Lattner switch (Tok.getKind()) { 1246b3a4e432c90be98c6d918087750397e86d030368Chris Lattner default: break; 12474ed5d91db256f7dbe6bf716da0b801004c197254Chris Lattner case tok::semi: // struct foo {...} ; 124899c952046600f6bfccf315aa7ad5b1be2d242cc3Chris Lattner case tok::star: // struct foo {...} * P; 124999c952046600f6bfccf315aa7ad5b1be2d242cc3Chris Lattner case tok::amp: // struct foo {...} & R = ... 125099c952046600f6bfccf315aa7ad5b1be2d242cc3Chris Lattner case tok::identifier: // struct foo {...} V ; 125199c952046600f6bfccf315aa7ad5b1be2d242cc3Chris Lattner case tok::r_paren: //(struct foo {...} ) {4} 125299c952046600f6bfccf315aa7ad5b1be2d242cc3Chris Lattner case tok::annot_cxxscope: // struct foo {...} a:: b; 125399c952046600f6bfccf315aa7ad5b1be2d242cc3Chris Lattner case tok::annot_typename: // struct foo {...} a ::b; 125499c952046600f6bfccf315aa7ad5b1be2d242cc3Chris Lattner case tok::annot_template_id: // struct foo {...} a<int> ::b; 1255c2e1c1af8ffe750b827284f207b9207112c7cc4eChris Lattner case tok::l_paren: // struct foo {...} ( x); 125616acfee729e00536af827935ccfcf69be721e462Chris Lattner case tok::comma: // __builtin_offsetof(struct foo{...} , 1257b3a4e432c90be98c6d918087750397e86d030368Chris Lattner ExpectedSemi = false; 1258b3a4e432c90be98c6d918087750397e86d030368Chris Lattner break; 1259b3a4e432c90be98c6d918087750397e86d030368Chris Lattner // Type qualifiers 1260b3a4e432c90be98c6d918087750397e86d030368Chris Lattner case tok::kw_const: // struct foo {...} const x; 1261b3a4e432c90be98c6d918087750397e86d030368Chris Lattner case tok::kw_volatile: // struct foo {...} volatile x; 1262b3a4e432c90be98c6d918087750397e86d030368Chris Lattner case tok::kw_restrict: // struct foo {...} restrict x; 1263b3a4e432c90be98c6d918087750397e86d030368Chris Lattner case tok::kw_inline: // struct foo {...} inline foo() {}; 126499c952046600f6bfccf315aa7ad5b1be2d242cc3Chris Lattner // Storage-class specifiers 126599c952046600f6bfccf315aa7ad5b1be2d242cc3Chris Lattner case tok::kw_static: // struct foo {...} static x; 126699c952046600f6bfccf315aa7ad5b1be2d242cc3Chris Lattner case tok::kw_extern: // struct foo {...} extern x; 126799c952046600f6bfccf315aa7ad5b1be2d242cc3Chris Lattner case tok::kw_typedef: // struct foo {...} typedef x; 126899c952046600f6bfccf315aa7ad5b1be2d242cc3Chris Lattner case tok::kw_register: // struct foo {...} register x; 126999c952046600f6bfccf315aa7ad5b1be2d242cc3Chris Lattner case tok::kw_auto: // struct foo {...} auto x; 127033f992425213f381fc503699b26ee8cf9b60494eDouglas Gregor case tok::kw_mutable: // struct foo {...} mutable x; 1271b3a4e432c90be98c6d918087750397e86d030368Chris Lattner // As shown above, type qualifiers and storage class specifiers absolutely 1272b3a4e432c90be98c6d918087750397e86d030368Chris Lattner // can occur after class specifiers according to the grammar. However, 1273fc8f0e14ad142ed811e90fbd9a30e419e301c717Chris Lattner // almost no one actually writes code like this. If we see one of these, 1274b3a4e432c90be98c6d918087750397e86d030368Chris Lattner // it is much more likely that someone missed a semi colon and the 1275b3a4e432c90be98c6d918087750397e86d030368Chris Lattner // type/storage class specifier we're seeing is part of the *next* 1276b3a4e432c90be98c6d918087750397e86d030368Chris Lattner // intended declaration, as in: 1277b3a4e432c90be98c6d918087750397e86d030368Chris Lattner // 1278b3a4e432c90be98c6d918087750397e86d030368Chris Lattner // struct foo { ... } 1279b3a4e432c90be98c6d918087750397e86d030368Chris Lattner // typedef int X; 1280b3a4e432c90be98c6d918087750397e86d030368Chris Lattner // 1281b3a4e432c90be98c6d918087750397e86d030368Chris Lattner // We'd really like to emit a missing semicolon error instead of emitting 1282b3a4e432c90be98c6d918087750397e86d030368Chris Lattner // an error on the 'int' saying that you can't have two type specifiers in 1283b3a4e432c90be98c6d918087750397e86d030368Chris Lattner // the same declaration of X. Because of this, we look ahead past this 1284b3a4e432c90be98c6d918087750397e86d030368Chris Lattner // token to see if it's a type specifier. If so, we know the code is 1285b3a4e432c90be98c6d918087750397e86d030368Chris Lattner // otherwise invalid, so we can produce the expected semi error. 1286b3a4e432c90be98c6d918087750397e86d030368Chris Lattner if (!isKnownToBeTypeSpecifier(NextToken())) 1287b3a4e432c90be98c6d918087750397e86d030368Chris Lattner ExpectedSemi = false; 12884ed5d91db256f7dbe6bf716da0b801004c197254Chris Lattner break; 1289193575455e00eca03fd7177f60e3f2e6263cb661Kovarththanan Rajaratnam 1290193575455e00eca03fd7177f60e3f2e6263cb661Kovarththanan Rajaratnam case tok::r_brace: // struct bar { struct foo {...} } 12914ed5d91db256f7dbe6bf716da0b801004c197254Chris Lattner // Missing ';' at end of struct is accepted as an extension in C mode. 1292b3a4e432c90be98c6d918087750397e86d030368Chris Lattner if (!getLang().CPlusPlus) 1293b3a4e432c90be98c6d918087750397e86d030368Chris Lattner ExpectedSemi = false; 1294b3a4e432c90be98c6d918087750397e86d030368Chris Lattner break; 1295b3a4e432c90be98c6d918087750397e86d030368Chris Lattner } 1296193575455e00eca03fd7177f60e3f2e6263cb661Kovarththanan Rajaratnam 1297b3a4e432c90be98c6d918087750397e86d030368Chris Lattner if (ExpectedSemi) { 12984ed5d91db256f7dbe6bf716da0b801004c197254Chris Lattner ExpectAndConsume(tok::semi, diag::err_expected_semi_after_tagdecl, 12994ed5d91db256f7dbe6bf716da0b801004c197254Chris Lattner TagType == DeclSpec::TST_class ? "class" 13004ed5d91db256f7dbe6bf716da0b801004c197254Chris Lattner : TagType == DeclSpec::TST_struct? "struct" : "union"); 13014ed5d91db256f7dbe6bf716da0b801004c197254Chris Lattner // Push this token back into the preprocessor and change our current token 13024ed5d91db256f7dbe6bf716da0b801004c197254Chris Lattner // to ';' so that the rest of the code recovers as though there were an 13034ed5d91db256f7dbe6bf716da0b801004c197254Chris Lattner // ';' after the definition. 13044ed5d91db256f7dbe6bf716da0b801004c197254Chris Lattner PP.EnterToken(Tok); 1305193575455e00eca03fd7177f60e3f2e6263cb661Kovarththanan Rajaratnam Tok.setKind(tok::semi); 13064ed5d91db256f7dbe6bf716da0b801004c197254Chris Lattner } 13074ed5d91db256f7dbe6bf716da0b801004c197254Chris Lattner } 1308e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor} 1309e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor 13101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// ParseBaseClause - Parse the base-clause of a C++ class [C++ class.derived]. 1311e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor/// 1312e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor/// base-clause : [C++ class.derived] 1313e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor/// ':' base-specifier-list 1314e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor/// base-specifier-list: 1315e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor/// base-specifier '...'[opt] 1316e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor/// base-specifier-list ',' base-specifier '...'[opt] 1317d226f65006733ed7f709c3174f22ce33391cb58fJohn McCallvoid Parser::ParseBaseClause(Decl *ClassDecl) { 1318e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor assert(Tok.is(tok::colon) && "Not a base clause"); 1319e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor ConsumeToken(); 1320e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor 1321f8268ae3196002bbab6adb830302e79b0f368f13Douglas Gregor // Build up an array of parsed base specifiers. 1322ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall llvm::SmallVector<CXXBaseSpecifier *, 8> BaseInfo; 1323f8268ae3196002bbab6adb830302e79b0f368f13Douglas Gregor 1324e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor while (true) { 1325e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor // Parse a base-specifier. 1326f8268ae3196002bbab6adb830302e79b0f368f13Douglas Gregor BaseResult Result = ParseBaseSpecifier(ClassDecl); 13275ac8aff3d7431dc7e4d64d960574a10c9f7e0078Douglas Gregor if (Result.isInvalid()) { 1328e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor // Skip the rest of this base specifier, up until the comma or 1329e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor // opening brace. 1330f8268ae3196002bbab6adb830302e79b0f368f13Douglas Gregor SkipUntil(tok::comma, tok::l_brace, true, true); 1331f8268ae3196002bbab6adb830302e79b0f368f13Douglas Gregor } else { 1332f8268ae3196002bbab6adb830302e79b0f368f13Douglas Gregor // Add this to our array of base specifiers. 13335ac8aff3d7431dc7e4d64d960574a10c9f7e0078Douglas Gregor BaseInfo.push_back(Result.get()); 1334e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor } 1335e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor 1336e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor // If the next token is a comma, consume it and keep reading 1337e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor // base-specifiers. 1338e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor if (Tok.isNot(tok::comma)) break; 13391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1340e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor // Consume the comma. 1341e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor ConsumeToken(); 1342e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor } 1343f8268ae3196002bbab6adb830302e79b0f368f13Douglas Gregor 1344f8268ae3196002bbab6adb830302e79b0f368f13Douglas Gregor // Attach the base specifiers 1345beaaccd8e2a8748f77b66e2b330fb9136937e14cJay Foad Actions.ActOnBaseSpecifiers(ClassDecl, BaseInfo.data(), BaseInfo.size()); 1346e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor} 1347e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor 1348e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor/// ParseBaseSpecifier - Parse a C++ base-specifier. A base-specifier is 1349e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor/// one entry in the base class list of a class specifier, for example: 1350e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor/// class foo : public bar, virtual private baz { 1351e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor/// 'public bar' and 'virtual private baz' are each base-specifiers. 1352e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor/// 1353e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor/// base-specifier: [C++ class.derived] 1354e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor/// ::[opt] nested-name-specifier[opt] class-name 1355e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor/// 'virtual' access-specifier[opt] ::[opt] nested-name-specifier[opt] 1356e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor/// class-name 1357e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor/// access-specifier 'virtual'[opt] ::[opt] nested-name-specifier[opt] 1358e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor/// class-name 1359d226f65006733ed7f709c3174f22ce33391cb58fJohn McCallParser::BaseResult Parser::ParseBaseSpecifier(Decl *ClassDecl) { 1360e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor bool IsVirtual = false; 1361e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor SourceLocation StartLoc = Tok.getLocation(); 1362e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor 1363e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor // Parse the 'virtual' keyword. 1364e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor if (Tok.is(tok::kw_virtual)) { 1365e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor ConsumeToken(); 1366e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor IsVirtual = true; 1367e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor } 1368e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor 1369e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor // Parse an (optional) access specifier. 1370e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor AccessSpecifier Access = getAccessSpecifierIfPresent(); 137192f883177b162928a8e632e4e3b93fafd2b26072John McCall if (Access != AS_none) 1372e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor ConsumeToken(); 13731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1374e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor // Parse the 'virtual' keyword (again!), in case it came after the 1375e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor // access specifier. 1376e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor if (Tok.is(tok::kw_virtual)) { 1377e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor SourceLocation VirtualLoc = ConsumeToken(); 1378e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor if (IsVirtual) { 1379e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor // Complain about duplicate 'virtual' 13801ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner Diag(VirtualLoc, diag::err_dup_virtual) 1381849b243d4065f56742a4677d6dc8277609a151f8Douglas Gregor << FixItHint::CreateRemoval(VirtualLoc); 1382e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor } 1383e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor 1384e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor IsVirtual = true; 1385e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor } 1386e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor 1387eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis // Parse optional '::' and optional nested-name-specifier. 1388eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis CXXScopeSpec SS; 1389b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParseOptionalCXXScopeSpecifier(SS, ParsedType(), /*EnteringContext=*/false); 1390e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor 1391e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor // The location of the base class itself. 1392e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor SourceLocation BaseLoc = Tok.getLocation(); 139342a552f8200ba5948661aee0106fce0c04e39818Douglas Gregor 139442a552f8200ba5948661aee0106fce0c04e39818Douglas Gregor // Parse the class-name. 13957f43d6764797ab21216421aeb00f4ec314d503d1Douglas Gregor SourceLocation EndLocation; 1396059101f922de6eb765601459925f4c8914420b23Douglas Gregor TypeResult BaseType = ParseClassName(EndLocation, SS); 139731a19b6989bbf326d2de5ae12e712e2a65ca9c34Douglas Gregor if (BaseType.isInvalid()) 139842a552f8200ba5948661aee0106fce0c04e39818Douglas Gregor return true; 13991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1400f90b27ad077c3339b62befc892382845339f9490Douglas Gregor // Parse the optional ellipsis (for a pack expansion). The ellipsis is 1401f90b27ad077c3339b62befc892382845339f9490Douglas Gregor // actually part of the base-specifier-list grammar productions, but we 1402f90b27ad077c3339b62befc892382845339f9490Douglas Gregor // parse it here for convenience. 1403f90b27ad077c3339b62befc892382845339f9490Douglas Gregor SourceLocation EllipsisLoc; 1404f90b27ad077c3339b62befc892382845339f9490Douglas Gregor if (Tok.is(tok::ellipsis)) 1405f90b27ad077c3339b62befc892382845339f9490Douglas Gregor EllipsisLoc = ConsumeToken(); 1406f90b27ad077c3339b62befc892382845339f9490Douglas Gregor 14071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // Find the complete source range for the base-specifier. 14087f43d6764797ab21216421aeb00f4ec314d503d1Douglas Gregor SourceRange Range(StartLoc, EndLocation); 14091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1410e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor // Notify semantic analysis that we have parsed a complete 1411e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor // base-specifier. 1412a55e52c0802cae3b7c366a05c461d3d15074c1a3Sebastian Redl return Actions.ActOnBaseSpecifier(ClassDecl, Range, IsVirtual, Access, 1413f90b27ad077c3339b62befc892382845339f9490Douglas Gregor BaseType.get(), BaseLoc, EllipsisLoc); 1414e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor} 1415e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor 1416e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor/// getAccessSpecifierIfPresent - Determine whether the next token is 1417e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor/// a C++ access-specifier. 1418e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor/// 1419e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor/// access-specifier: [C++ class.derived] 1420e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor/// 'private' 1421e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor/// 'protected' 1422e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor/// 'public' 14231eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpAccessSpecifier Parser::getAccessSpecifierIfPresent() const { 1424e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor switch (Tok.getKind()) { 1425e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor default: return AS_none; 1426e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor case tok::kw_private: return AS_private; 1427e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor case tok::kw_protected: return AS_protected; 1428e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor case tok::kw_public: return AS_public; 1429e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor } 1430e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor} 14314cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis 1432d33133cdc1af466f9c276249b2621be03867888bEli Friedmanvoid Parser::HandleMemberFunctionDefaultArgs(Declarator& DeclaratorInfo, 1433d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ThisDecl) { 1434d33133cdc1af466f9c276249b2621be03867888bEli Friedman // We just declared a member function. If this member function 1435d33133cdc1af466f9c276249b2621be03867888bEli Friedman // has any default arguments, we'll need to parse them later. 1436d33133cdc1af466f9c276249b2621be03867888bEli Friedman LateParsedMethodDeclaration *LateMethod = 0; 14371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump DeclaratorChunk::FunctionTypeInfo &FTI 1438075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara = DeclaratorInfo.getFunctionTypeInfo(); 1439d33133cdc1af466f9c276249b2621be03867888bEli Friedman for (unsigned ParamIdx = 0; ParamIdx < FTI.NumArgs; ++ParamIdx) { 1440d33133cdc1af466f9c276249b2621be03867888bEli Friedman if (LateMethod || FTI.ArgInfo[ParamIdx].DefaultArgTokens) { 1441d33133cdc1af466f9c276249b2621be03867888bEli Friedman if (!LateMethod) { 1442d33133cdc1af466f9c276249b2621be03867888bEli Friedman // Push this method onto the stack of late-parsed method 1443d33133cdc1af466f9c276249b2621be03867888bEli Friedman // declarations. 1444d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor LateMethod = new LateParsedMethodDeclaration(this, ThisDecl); 1445d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor getCurrentClass().LateParsedDeclarations.push_back(LateMethod); 144623c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor LateMethod->TemplateScope = getCurScope()->isTemplateParamScope(); 1447d33133cdc1af466f9c276249b2621be03867888bEli Friedman 1448d33133cdc1af466f9c276249b2621be03867888bEli Friedman // Add all of the parameters prior to this one (they don't 1449d33133cdc1af466f9c276249b2621be03867888bEli Friedman // have default arguments). 1450d33133cdc1af466f9c276249b2621be03867888bEli Friedman LateMethod->DefaultArgs.reserve(FTI.NumArgs); 1451d33133cdc1af466f9c276249b2621be03867888bEli Friedman for (unsigned I = 0; I < ParamIdx; ++I) 1452d33133cdc1af466f9c276249b2621be03867888bEli Friedman LateMethod->DefaultArgs.push_back( 14538f8210c47797f013e0fb24a26f9c4751b10783feDouglas Gregor LateParsedDefaultArgument(FTI.ArgInfo[I].Param)); 1454d33133cdc1af466f9c276249b2621be03867888bEli Friedman } 1455d33133cdc1af466f9c276249b2621be03867888bEli Friedman 1456d33133cdc1af466f9c276249b2621be03867888bEli Friedman // Add this parameter to the list of parameters (it or may 1457d33133cdc1af466f9c276249b2621be03867888bEli Friedman // not have a default argument). 1458d33133cdc1af466f9c276249b2621be03867888bEli Friedman LateMethod->DefaultArgs.push_back( 1459d33133cdc1af466f9c276249b2621be03867888bEli Friedman LateParsedDefaultArgument(FTI.ArgInfo[ParamIdx].Param, 1460d33133cdc1af466f9c276249b2621be03867888bEli Friedman FTI.ArgInfo[ParamIdx].DefaultArgTokens)); 1461d33133cdc1af466f9c276249b2621be03867888bEli Friedman } 1462d33133cdc1af466f9c276249b2621be03867888bEli Friedman } 1463d33133cdc1af466f9c276249b2621be03867888bEli Friedman} 1464d33133cdc1af466f9c276249b2621be03867888bEli Friedman 14651f3b6fdabbb10779a473d6315154d7325ce20aeaAnders Carlsson/// isCXX0XVirtSpecifier - Determine whether the next token is a C++0x 14661f3b6fdabbb10779a473d6315154d7325ce20aeaAnders Carlsson/// virt-specifier. 14671f3b6fdabbb10779a473d6315154d7325ce20aeaAnders Carlsson/// 14681f3b6fdabbb10779a473d6315154d7325ce20aeaAnders Carlsson/// virt-specifier: 14691f3b6fdabbb10779a473d6315154d7325ce20aeaAnders Carlsson/// override 14701f3b6fdabbb10779a473d6315154d7325ce20aeaAnders Carlsson/// final 1471cc54d594d4f6509c0e3a8e349e481d9b5d899df6Anders CarlssonVirtSpecifiers::Specifier Parser::isCXX0XVirtSpecifier() const { 1472ce93a7cee6c0ea979c12b278771a79c4d6a37fc0Anders Carlsson if (!getLang().CPlusPlus) 1473cc54d594d4f6509c0e3a8e349e481d9b5d899df6Anders Carlsson return VirtSpecifiers::VS_None; 1474cc54d594d4f6509c0e3a8e349e481d9b5d899df6Anders Carlsson 1475b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson if (Tok.is(tok::identifier)) { 1476b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson IdentifierInfo *II = Tok.getIdentifierInfo(); 14771f3b6fdabbb10779a473d6315154d7325ce20aeaAnders Carlsson 14787eeb4ec11043d4860361348f2b19299d957d47a9Anders Carlsson // Initialize the contextual keywords. 14797eeb4ec11043d4860361348f2b19299d957d47a9Anders Carlsson if (!Ident_final) { 14807eeb4ec11043d4860361348f2b19299d957d47a9Anders Carlsson Ident_final = &PP.getIdentifierTable().get("final"); 14817eeb4ec11043d4860361348f2b19299d957d47a9Anders Carlsson Ident_override = &PP.getIdentifierTable().get("override"); 14827eeb4ec11043d4860361348f2b19299d957d47a9Anders Carlsson } 14837eeb4ec11043d4860361348f2b19299d957d47a9Anders Carlsson 1484b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson if (II == Ident_override) 1485b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson return VirtSpecifiers::VS_Override; 14861f3b6fdabbb10779a473d6315154d7325ce20aeaAnders Carlsson 1487b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson if (II == Ident_final) 1488b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson return VirtSpecifiers::VS_Final; 1489b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson } 1490b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson 1491b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson return VirtSpecifiers::VS_None; 14921f3b6fdabbb10779a473d6315154d7325ce20aeaAnders Carlsson} 14931f3b6fdabbb10779a473d6315154d7325ce20aeaAnders Carlsson 14941f3b6fdabbb10779a473d6315154d7325ce20aeaAnders Carlsson/// ParseOptionalCXX0XVirtSpecifierSeq - Parse a virt-specifier-seq. 14951f3b6fdabbb10779a473d6315154d7325ce20aeaAnders Carlsson/// 14961f3b6fdabbb10779a473d6315154d7325ce20aeaAnders Carlsson/// virt-specifier-seq: 14971f3b6fdabbb10779a473d6315154d7325ce20aeaAnders Carlsson/// virt-specifier 14981f3b6fdabbb10779a473d6315154d7325ce20aeaAnders Carlsson/// virt-specifier-seq virt-specifier 1499b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlssonvoid Parser::ParseOptionalCXX0XVirtSpecifierSeq(VirtSpecifiers &VS) { 1500b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson while (true) { 1501cc54d594d4f6509c0e3a8e349e481d9b5d899df6Anders Carlsson VirtSpecifiers::Specifier Specifier = isCXX0XVirtSpecifier(); 1502b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson if (Specifier == VirtSpecifiers::VS_None) 1503b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson return; 1504b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson 1505b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson // C++ [class.mem]p8: 1506b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson // A virt-specifier-seq shall contain at most one of each virt-specifier. 1507cc54d594d4f6509c0e3a8e349e481d9b5d899df6Anders Carlsson const char *PrevSpec = 0; 150846127a96b6dd6b93aa18d5f7a55bc2db8b52a2c9Anders Carlsson if (VS.SetSpecifier(Specifier, Tok.getLocation(), PrevSpec)) 1509b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson Diag(Tok.getLocation(), diag::err_duplicate_virt_specifier) 1510b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson << PrevSpec 1511b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson << FixItHint::CreateRemoval(Tok.getLocation()); 1512b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson 1513ce93a7cee6c0ea979c12b278771a79c4d6a37fc0Anders Carlsson if (!getLang().CPlusPlus0x) 1514ce93a7cee6c0ea979c12b278771a79c4d6a37fc0Anders Carlsson Diag(Tok.getLocation(), diag::ext_override_control_keyword) 1515ce93a7cee6c0ea979c12b278771a79c4d6a37fc0Anders Carlsson << VirtSpecifiers::getSpecifierName(Specifier); 1516b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson ConsumeToken(); 1517b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson } 15181f3b6fdabbb10779a473d6315154d7325ce20aeaAnders Carlsson} 15191f3b6fdabbb10779a473d6315154d7325ce20aeaAnders Carlsson 15208a29ba0d66bce99014651f1e3351aef6c3361d3fAnders Carlsson/// isCXX0XFinalKeyword - Determine whether the next token is a C++0x 15218a29ba0d66bce99014651f1e3351aef6c3361d3fAnders Carlsson/// contextual 'final' keyword. 15228a29ba0d66bce99014651f1e3351aef6c3361d3fAnders Carlssonbool Parser::isCXX0XFinalKeyword() const { 1523ce93a7cee6c0ea979c12b278771a79c4d6a37fc0Anders Carlsson if (!getLang().CPlusPlus) 15248a29ba0d66bce99014651f1e3351aef6c3361d3fAnders Carlsson return false; 1525cc54d594d4f6509c0e3a8e349e481d9b5d899df6Anders Carlsson 15268a29ba0d66bce99014651f1e3351aef6c3361d3fAnders Carlsson if (!Tok.is(tok::identifier)) 15278a29ba0d66bce99014651f1e3351aef6c3361d3fAnders Carlsson return false; 1528cc54d594d4f6509c0e3a8e349e481d9b5d899df6Anders Carlsson 15298a29ba0d66bce99014651f1e3351aef6c3361d3fAnders Carlsson // Initialize the contextual keywords. 15308a29ba0d66bce99014651f1e3351aef6c3361d3fAnders Carlsson if (!Ident_final) { 15318a29ba0d66bce99014651f1e3351aef6c3361d3fAnders Carlsson Ident_final = &PP.getIdentifierTable().get("final"); 15328a29ba0d66bce99014651f1e3351aef6c3361d3fAnders Carlsson Ident_override = &PP.getIdentifierTable().get("override"); 1533cc54d594d4f6509c0e3a8e349e481d9b5d899df6Anders Carlsson } 15348a29ba0d66bce99014651f1e3351aef6c3361d3fAnders Carlsson 15358a29ba0d66bce99014651f1e3351aef6c3361d3fAnders Carlsson return Tok.getIdentifierInfo() == Ident_final; 1536cc54d594d4f6509c0e3a8e349e481d9b5d899df6Anders Carlsson} 1537cc54d594d4f6509c0e3a8e349e481d9b5d899df6Anders Carlsson 15384cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis/// ParseCXXClassMemberDeclaration - Parse a C++ class member declaration. 15394cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis/// 15404cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis/// member-declaration: 15414cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis/// decl-specifier-seq[opt] member-declarator-list[opt] ';' 15424cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis/// function-definition ';'[opt] 15434cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis/// ::[opt] nested-name-specifier template[opt] unqualified-id ';'[TODO] 15444cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis/// using-declaration [TODO] 1545511d7aba3b12853fdb88729a0313b80a60eab8adAnders Carlsson/// [C++0x] static_assert-declaration 15465aeccdbb4bdc94e48c04cacc59fa812af32109b2Anders Carlsson/// template-declaration 1547bc8d56496a6ecdba14769df03d75c001184f8c54Chris Lattner/// [GNU] '__extension__' member-declaration 15484cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis/// 15494cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis/// member-declarator-list: 15504cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis/// member-declarator 15514cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis/// member-declarator-list ',' member-declarator 15524cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis/// 15534cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis/// member-declarator: 15541f3b6fdabbb10779a473d6315154d7325ce20aeaAnders Carlsson/// declarator virt-specifier-seq[opt] pure-specifier[opt] 15554cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis/// declarator constant-initializer[opt] 15564cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis/// identifier[opt] ':' constant-expression 15574cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis/// 15581f3b6fdabbb10779a473d6315154d7325ce20aeaAnders Carlsson/// virt-specifier-seq: 15591f3b6fdabbb10779a473d6315154d7325ce20aeaAnders Carlsson/// virt-specifier 15601f3b6fdabbb10779a473d6315154d7325ce20aeaAnders Carlsson/// virt-specifier-seq virt-specifier 15611f3b6fdabbb10779a473d6315154d7325ce20aeaAnders Carlsson/// 15621f3b6fdabbb10779a473d6315154d7325ce20aeaAnders Carlsson/// virt-specifier: 15631f3b6fdabbb10779a473d6315154d7325ce20aeaAnders Carlsson/// override 15641f3b6fdabbb10779a473d6315154d7325ce20aeaAnders Carlsson/// final 15651f3b6fdabbb10779a473d6315154d7325ce20aeaAnders Carlsson/// new 15661f3b6fdabbb10779a473d6315154d7325ce20aeaAnders Carlsson/// 1567e2b6833d445c7a4ce64f1816c05f176ba1740acaSebastian Redl/// pure-specifier: 15684cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis/// '= 0' 15694cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis/// 15704cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis/// constant-initializer: 15714cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis/// '=' constant-expression 15724cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis/// 157337b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregorvoid Parser::ParseCXXClassMemberDeclaration(AccessSpecifier AS, 1574c9068d7dd94d439cec66c421115d15303e481025John McCall const ParsedTemplateInfo &TemplateInfo, 1575c9068d7dd94d439cec66c421115d15303e481025John McCall ParsingDeclRAIIObject *TemplateDiags) { 15768a9013d24864272cf5b18c908a267bd7a2bda4c4Douglas Gregor if (Tok.is(tok::at)) { 15778a9013d24864272cf5b18c908a267bd7a2bda4c4Douglas Gregor if (getLang().ObjC1 && NextToken().isObjCAtKeyword(tok::objc_defs)) 15788a9013d24864272cf5b18c908a267bd7a2bda4c4Douglas Gregor Diag(Tok, diag::err_at_defs_cxx); 15798a9013d24864272cf5b18c908a267bd7a2bda4c4Douglas Gregor else 15808a9013d24864272cf5b18c908a267bd7a2bda4c4Douglas Gregor Diag(Tok, diag::err_at_in_class); 15818a9013d24864272cf5b18c908a267bd7a2bda4c4Douglas Gregor 15828a9013d24864272cf5b18c908a267bd7a2bda4c4Douglas Gregor ConsumeToken(); 15838a9013d24864272cf5b18c908a267bd7a2bda4c4Douglas Gregor SkipUntil(tok::r_brace); 15848a9013d24864272cf5b18c908a267bd7a2bda4c4Douglas Gregor return; 15858a9013d24864272cf5b18c908a267bd7a2bda4c4Douglas Gregor } 15868a9013d24864272cf5b18c908a267bd7a2bda4c4Douglas Gregor 158760fa3cfd7aa63c29f9fc2d593bac56a3646337ccJohn McCall // Access declarations. 158860fa3cfd7aa63c29f9fc2d593bac56a3646337ccJohn McCall if (!TemplateInfo.Kind && 158960fa3cfd7aa63c29f9fc2d593bac56a3646337ccJohn McCall (Tok.is(tok::identifier) || Tok.is(tok::coloncolon)) && 15909ba6166f4a78722e7df8ffbd64eb788bfdf2764aJohn McCall !TryAnnotateCXXScopeToken() && 159160fa3cfd7aa63c29f9fc2d593bac56a3646337ccJohn McCall Tok.is(tok::annot_cxxscope)) { 159260fa3cfd7aa63c29f9fc2d593bac56a3646337ccJohn McCall bool isAccessDecl = false; 159360fa3cfd7aa63c29f9fc2d593bac56a3646337ccJohn McCall if (NextToken().is(tok::identifier)) 159460fa3cfd7aa63c29f9fc2d593bac56a3646337ccJohn McCall isAccessDecl = GetLookAheadToken(2).is(tok::semi); 159560fa3cfd7aa63c29f9fc2d593bac56a3646337ccJohn McCall else 159660fa3cfd7aa63c29f9fc2d593bac56a3646337ccJohn McCall isAccessDecl = NextToken().is(tok::kw_operator); 159760fa3cfd7aa63c29f9fc2d593bac56a3646337ccJohn McCall 159860fa3cfd7aa63c29f9fc2d593bac56a3646337ccJohn McCall if (isAccessDecl) { 159960fa3cfd7aa63c29f9fc2d593bac56a3646337ccJohn McCall // Collect the scope specifier token we annotated earlier. 160060fa3cfd7aa63c29f9fc2d593bac56a3646337ccJohn McCall CXXScopeSpec SS; 1601b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParseOptionalCXXScopeSpecifier(SS, ParsedType(), false); 160260fa3cfd7aa63c29f9fc2d593bac56a3646337ccJohn McCall 160360fa3cfd7aa63c29f9fc2d593bac56a3646337ccJohn McCall // Try to parse an unqualified-id. 160460fa3cfd7aa63c29f9fc2d593bac56a3646337ccJohn McCall UnqualifiedId Name; 1605b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall if (ParseUnqualifiedId(SS, false, true, true, ParsedType(), Name)) { 160660fa3cfd7aa63c29f9fc2d593bac56a3646337ccJohn McCall SkipUntil(tok::semi); 160760fa3cfd7aa63c29f9fc2d593bac56a3646337ccJohn McCall return; 160860fa3cfd7aa63c29f9fc2d593bac56a3646337ccJohn McCall } 160960fa3cfd7aa63c29f9fc2d593bac56a3646337ccJohn McCall 161060fa3cfd7aa63c29f9fc2d593bac56a3646337ccJohn McCall // TODO: recover from mistakenly-qualified operator declarations. 161160fa3cfd7aa63c29f9fc2d593bac56a3646337ccJohn McCall if (ExpectAndConsume(tok::semi, 161260fa3cfd7aa63c29f9fc2d593bac56a3646337ccJohn McCall diag::err_expected_semi_after, 161360fa3cfd7aa63c29f9fc2d593bac56a3646337ccJohn McCall "access declaration", 161460fa3cfd7aa63c29f9fc2d593bac56a3646337ccJohn McCall tok::semi)) 161560fa3cfd7aa63c29f9fc2d593bac56a3646337ccJohn McCall return; 161660fa3cfd7aa63c29f9fc2d593bac56a3646337ccJohn McCall 161723c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.ActOnUsingDeclaration(getCurScope(), AS, 161860fa3cfd7aa63c29f9fc2d593bac56a3646337ccJohn McCall false, SourceLocation(), 161960fa3cfd7aa63c29f9fc2d593bac56a3646337ccJohn McCall SS, Name, 162060fa3cfd7aa63c29f9fc2d593bac56a3646337ccJohn McCall /* AttrList */ 0, 162160fa3cfd7aa63c29f9fc2d593bac56a3646337ccJohn McCall /* IsTypeName */ false, 162260fa3cfd7aa63c29f9fc2d593bac56a3646337ccJohn McCall SourceLocation()); 162360fa3cfd7aa63c29f9fc2d593bac56a3646337ccJohn McCall return; 162460fa3cfd7aa63c29f9fc2d593bac56a3646337ccJohn McCall } 162560fa3cfd7aa63c29f9fc2d593bac56a3646337ccJohn McCall } 162660fa3cfd7aa63c29f9fc2d593bac56a3646337ccJohn McCall 1627511d7aba3b12853fdb88729a0313b80a60eab8adAnders Carlsson // static_assert-declaration 1628c6eb44b321c543c5bcf28727228a0cceced57e2ePeter Collingbourne if (Tok.is(tok::kw_static_assert) || Tok.is(tok::kw__Static_assert)) { 162937b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregor // FIXME: Check for templates 163097144fc41a9419bf6d74fc9450e8ef3f6e11f7e0Chris Lattner SourceLocation DeclEnd; 163197144fc41a9419bf6d74fc9450e8ef3f6e11f7e0Chris Lattner ParseStaticAssertDeclaration(DeclEnd); 1632682bf92db408a6cbc3d37b5496a99b6ef85041ecChris Lattner return; 1633682bf92db408a6cbc3d37b5496a99b6ef85041ecChris Lattner } 16341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1635682bf92db408a6cbc3d37b5496a99b6ef85041ecChris Lattner if (Tok.is(tok::kw_template)) { 16361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump assert(!TemplateInfo.TemplateParams && 163737b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregor "Nested template improperly parsed?"); 163897144fc41a9419bf6d74fc9450e8ef3f6e11f7e0Chris Lattner SourceLocation DeclEnd; 16391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ParseDeclarationStartingWithTemplate(Declarator::MemberContext, DeclEnd, 16404d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor AS); 1641682bf92db408a6cbc3d37b5496a99b6ef85041ecChris Lattner return; 1642682bf92db408a6cbc3d37b5496a99b6ef85041ecChris Lattner } 16435aeccdbb4bdc94e48c04cacc59fa812af32109b2Anders Carlsson 1644bc8d56496a6ecdba14769df03d75c001184f8c54Chris Lattner // Handle: member-declaration ::= '__extension__' member-declaration 1645bc8d56496a6ecdba14769df03d75c001184f8c54Chris Lattner if (Tok.is(tok::kw___extension__)) { 1646bc8d56496a6ecdba14769df03d75c001184f8c54Chris Lattner // __extension__ silences extension warnings in the subexpression. 1647bc8d56496a6ecdba14769df03d75c001184f8c54Chris Lattner ExtensionRAIIObject O(Diags); // Use RAII to do this. 1648bc8d56496a6ecdba14769df03d75c001184f8c54Chris Lattner ConsumeToken(); 1649c9068d7dd94d439cec66c421115d15303e481025John McCall return ParseCXXClassMemberDeclaration(AS, TemplateInfo, TemplateDiags); 1650bc8d56496a6ecdba14769df03d75c001184f8c54Chris Lattner } 16519cfbe48a7a20a217fdb2920b29b67ae7941cb116Douglas Gregor 16524ed5d91db256f7dbe6bf716da0b801004c197254Chris Lattner // Don't parse FOO:BAR as if it were a typo for FOO::BAR, in this context it 16534ed5d91db256f7dbe6bf716da0b801004c197254Chris Lattner // is a bitfield. 1654a1efc8c8c6460d860d6509b05b341e77ed9bfe87Chris Lattner ColonProtectionRAIIObject X(*this); 1655193575455e00eca03fd7177f60e3f2e6263cb661Kovarththanan Rajaratnam 16560b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall ParsedAttributesWithRange attrs(AttrFactory); 1657bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt // Optional C++0x attribute-specifier 16587f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall MaybeParseCXX0XAttributes(attrs); 16597f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall MaybeParseMicrosoftAttributes(attrs); 1660bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt 16619cfbe48a7a20a217fdb2920b29b67ae7941cb116Douglas Gregor if (Tok.is(tok::kw_using)) { 16627f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall ProhibitAttributes(attrs); 16631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 16649cfbe48a7a20a217fdb2920b29b67ae7941cb116Douglas Gregor // Eat 'using'. 16659cfbe48a7a20a217fdb2920b29b67ae7941cb116Douglas Gregor SourceLocation UsingLoc = ConsumeToken(); 16669cfbe48a7a20a217fdb2920b29b67ae7941cb116Douglas Gregor 16679cfbe48a7a20a217fdb2920b29b67ae7941cb116Douglas Gregor if (Tok.is(tok::kw_namespace)) { 16689cfbe48a7a20a217fdb2920b29b67ae7941cb116Douglas Gregor Diag(UsingLoc, diag::err_using_namespace_in_class); 16699cfbe48a7a20a217fdb2920b29b67ae7941cb116Douglas Gregor SkipUntil(tok::semi, true, true); 1670ae50d501f463d7032320ec31840f60ae68df3a55Chris Lattner } else { 16719cfbe48a7a20a217fdb2920b29b67ae7941cb116Douglas Gregor SourceLocation DeclEnd; 16723e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith // Otherwise, it must be a using-declaration or an alias-declaration. 167378b810559d89e996e00684335407443936ce34a1John McCall ParseUsingDeclaration(Declarator::MemberContext, TemplateInfo, 167478b810559d89e996e00684335407443936ce34a1John McCall UsingLoc, DeclEnd, AS); 16759cfbe48a7a20a217fdb2920b29b67ae7941cb116Douglas Gregor } 16769cfbe48a7a20a217fdb2920b29b67ae7941cb116Douglas Gregor return; 16779cfbe48a7a20a217fdb2920b29b67ae7941cb116Douglas Gregor } 16789cfbe48a7a20a217fdb2920b29b67ae7941cb116Douglas Gregor 16794cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis // decl-specifier-seq: 16804cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis // Parse the common declaration-specifiers piece. 1681c9068d7dd94d439cec66c421115d15303e481025John McCall ParsingDeclSpec DS(*this, TemplateDiags); 16827f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall DS.takeAttributesFrom(attrs); 168337b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregor ParseDeclarationSpecifiers(DS, TemplateInfo, AS, DSC_class); 16844cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis 1685f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall MultiTemplateParamsArg TemplateParams(Actions, 1686dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall TemplateInfo.TemplateParams? TemplateInfo.TemplateParams->data() : 0, 1687dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall TemplateInfo.TemplateParams? TemplateInfo.TemplateParams->size() : 0); 1688dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall 16894cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis if (Tok.is(tok::semi)) { 16904cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis ConsumeToken(); 1691d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *TheDecl = 16920f4be74ff0273e505d383f89174ef539828424edChandler Carruth Actions.ParsedFreeStandingDeclSpec(getCurScope(), AS, DS, TemplateParams); 1693c9068d7dd94d439cec66c421115d15303e481025John McCall DS.complete(TheDecl); 169467d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall return; 16954cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis } 169607952324dda0e758c17f8bc3015793c65c51c48cArgyrios Kyrtzidis 169754abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall ParsingDeclarator DeclaratorInfo(*this, DS, Declarator::MemberContext); 16984867347e82648d3baf09524b98b09c297a5a198fNico Weber VirtSpecifiers VS; 16996a24747beed797b2f1184c66ca45beb4db20eb08Francois Pichet ExprResult Init; 17004cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis 17013a9fdb4742b21c0a3c27f18c5e4e94bab6f9e64cArgyrios Kyrtzidis if (Tok.isNot(tok::colon)) { 1702a1efc8c8c6460d860d6509b05b341e77ed9bfe87Chris Lattner // Don't parse FOO:BAR as if it were a typo for FOO::BAR. 1703a1efc8c8c6460d860d6509b05b341e77ed9bfe87Chris Lattner ColonProtectionRAIIObject X(*this); 1704a1efc8c8c6460d860d6509b05b341e77ed9bfe87Chris Lattner 17053a9fdb4742b21c0a3c27f18c5e4e94bab6f9e64cArgyrios Kyrtzidis // Parse the first declarator. 17063a9fdb4742b21c0a3c27f18c5e4e94bab6f9e64cArgyrios Kyrtzidis ParseDeclarator(DeclaratorInfo); 17073a9fdb4742b21c0a3c27f18c5e4e94bab6f9e64cArgyrios Kyrtzidis // Error parsing the declarator? 170810bd36882406cdf4805e35add1ce2f11ab9ae152Douglas Gregor if (!DeclaratorInfo.hasName()) { 17093a9fdb4742b21c0a3c27f18c5e4e94bab6f9e64cArgyrios Kyrtzidis // If so, skip until the semi-colon or a }. 1710d941fa4ff0d0d64b5a541dbd4f99693bff7f6e8dSebastian Redl SkipUntil(tok::r_brace, true, true); 17113a9fdb4742b21c0a3c27f18c5e4e94bab6f9e64cArgyrios Kyrtzidis if (Tok.is(tok::semi)) 17123a9fdb4742b21c0a3c27f18c5e4e94bab6f9e64cArgyrios Kyrtzidis ConsumeToken(); 1713682bf92db408a6cbc3d37b5496a99b6ef85041ecChris Lattner return; 17144cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis } 17154cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis 17164867347e82648d3baf09524b98b09c297a5a198fNico Weber ParseOptionalCXX0XVirtSpecifierSeq(VS); 17174867347e82648d3baf09524b98b09c297a5a198fNico Weber 17181b2fc0f3e181d99fb34f60e711066fb11628ecd0John Thompson // If attributes exist after the declarator, but before an '{', parse them. 17197f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall MaybeParseGNUAttributes(DeclaratorInfo); 17201b2fc0f3e181d99fb34f60e711066fb11628ecd0John Thompson 17216a24747beed797b2f1184c66ca45beb4db20eb08Francois Pichet // MSVC permits pure specifier on inline functions declared at class scope. 17226a24747beed797b2f1184c66ca45beb4db20eb08Francois Pichet // Hence check for =0 before checking for function definition. 17236a24747beed797b2f1184c66ca45beb4db20eb08Francois Pichet if (getLang().Microsoft && Tok.is(tok::equal) && 17246a24747beed797b2f1184c66ca45beb4db20eb08Francois Pichet DeclaratorInfo.isFunctionDeclarator() && 17256a24747beed797b2f1184c66ca45beb4db20eb08Francois Pichet NextToken().is(tok::numeric_constant)) { 17266a24747beed797b2f1184c66ca45beb4db20eb08Francois Pichet ConsumeToken(); 17276a24747beed797b2f1184c66ca45beb4db20eb08Francois Pichet Init = ParseInitializer(); 17286a24747beed797b2f1184c66ca45beb4db20eb08Francois Pichet if (Init.isInvalid()) 17296a24747beed797b2f1184c66ca45beb4db20eb08Francois Pichet SkipUntil(tok::comma, true, true); 17306a24747beed797b2f1184c66ca45beb4db20eb08Francois Pichet } 17316a24747beed797b2f1184c66ca45beb4db20eb08Francois Pichet 1732e4246a633b13197634225971b25df0cbdcec0c5dSean Hunt bool IsDefinition = false; 17333a9fdb4742b21c0a3c27f18c5e4e94bab6f9e64cArgyrios Kyrtzidis // function-definition: 1734e4246a633b13197634225971b25df0cbdcec0c5dSean Hunt if (Tok.is(tok::l_brace)) { 1735e4246a633b13197634225971b25df0cbdcec0c5dSean Hunt IsDefinition = true; 1736e4246a633b13197634225971b25df0cbdcec0c5dSean Hunt } else if (DeclaratorInfo.isFunctionDeclarator()) { 1737e4246a633b13197634225971b25df0cbdcec0c5dSean Hunt if (Tok.is(tok::colon) || Tok.is(tok::kw_try)) { 1738e4246a633b13197634225971b25df0cbdcec0c5dSean Hunt IsDefinition = true; 1739e4246a633b13197634225971b25df0cbdcec0c5dSean Hunt } else if (Tok.is(tok::equal)) { 1740e4246a633b13197634225971b25df0cbdcec0c5dSean Hunt const Token &KW = NextToken(); 1741e4246a633b13197634225971b25df0cbdcec0c5dSean Hunt if (KW.is(tok::kw_default) || KW.is(tok::kw_delete)) 1742e4246a633b13197634225971b25df0cbdcec0c5dSean Hunt IsDefinition = true; 1743e4246a633b13197634225971b25df0cbdcec0c5dSean Hunt } 1744e4246a633b13197634225971b25df0cbdcec0c5dSean Hunt } 1745e4246a633b13197634225971b25df0cbdcec0c5dSean Hunt 1746e4246a633b13197634225971b25df0cbdcec0c5dSean Hunt if (IsDefinition) { 17473a9fdb4742b21c0a3c27f18c5e4e94bab6f9e64cArgyrios Kyrtzidis if (!DeclaratorInfo.isFunctionDeclarator()) { 17483a9fdb4742b21c0a3c27f18c5e4e94bab6f9e64cArgyrios Kyrtzidis Diag(Tok, diag::err_func_def_no_params); 17493a9fdb4742b21c0a3c27f18c5e4e94bab6f9e64cArgyrios Kyrtzidis ConsumeBrace(); 17503a9fdb4742b21c0a3c27f18c5e4e94bab6f9e64cArgyrios Kyrtzidis SkipUntil(tok::r_brace, true); 17519ea416e598fa3cb09d67d514c4519c99abb81321Douglas Gregor 17529ea416e598fa3cb09d67d514c4519c99abb81321Douglas Gregor // Consume the optional ';' 17539ea416e598fa3cb09d67d514c4519c99abb81321Douglas Gregor if (Tok.is(tok::semi)) 17549ea416e598fa3cb09d67d514c4519c99abb81321Douglas Gregor ConsumeToken(); 1755682bf92db408a6cbc3d37b5496a99b6ef85041ecChris Lattner return; 17563a9fdb4742b21c0a3c27f18c5e4e94bab6f9e64cArgyrios Kyrtzidis } 17573a9fdb4742b21c0a3c27f18c5e4e94bab6f9e64cArgyrios Kyrtzidis 17583a9fdb4742b21c0a3c27f18c5e4e94bab6f9e64cArgyrios Kyrtzidis if (DS.getStorageClassSpec() == DeclSpec::SCS_typedef) { 17593a9fdb4742b21c0a3c27f18c5e4e94bab6f9e64cArgyrios Kyrtzidis Diag(Tok, diag::err_function_declared_typedef); 17603a9fdb4742b21c0a3c27f18c5e4e94bab6f9e64cArgyrios Kyrtzidis // This recovery skips the entire function body. It would be nice 17613a9fdb4742b21c0a3c27f18c5e4e94bab6f9e64cArgyrios Kyrtzidis // to simply call ParseCXXInlineMethodDef() below, however Sema 17623a9fdb4742b21c0a3c27f18c5e4e94bab6f9e64cArgyrios Kyrtzidis // assumes the declarator represents a function, not a typedef. 17633a9fdb4742b21c0a3c27f18c5e4e94bab6f9e64cArgyrios Kyrtzidis ConsumeBrace(); 17643a9fdb4742b21c0a3c27f18c5e4e94bab6f9e64cArgyrios Kyrtzidis SkipUntil(tok::r_brace, true); 17659ea416e598fa3cb09d67d514c4519c99abb81321Douglas Gregor 17669ea416e598fa3cb09d67d514c4519c99abb81321Douglas Gregor // Consume the optional ';' 17679ea416e598fa3cb09d67d514c4519c99abb81321Douglas Gregor if (Tok.is(tok::semi)) 17689ea416e598fa3cb09d67d514c4519c99abb81321Douglas Gregor ConsumeToken(); 1769682bf92db408a6cbc3d37b5496a99b6ef85041ecChris Lattner return; 17703a9fdb4742b21c0a3c27f18c5e4e94bab6f9e64cArgyrios Kyrtzidis } 17714cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis 17726a24747beed797b2f1184c66ca45beb4db20eb08Francois Pichet ParseCXXInlineMethodDef(AS, DeclaratorInfo, TemplateInfo, VS, Init); 1773e4246a633b13197634225971b25df0cbdcec0c5dSean Hunt 1774e4246a633b13197634225971b25df0cbdcec0c5dSean Hunt // Consume the ';' - it's optional unless we have a delete or default 1775e4246a633b13197634225971b25df0cbdcec0c5dSean Hunt if (Tok.is(tok::semi)) { 17769ea416e598fa3cb09d67d514c4519c99abb81321Douglas Gregor ConsumeToken(); 1777e4246a633b13197634225971b25df0cbdcec0c5dSean Hunt } 17789ea416e598fa3cb09d67d514c4519c99abb81321Douglas Gregor 1779682bf92db408a6cbc3d37b5496a99b6ef85041ecChris Lattner return; 17803a9fdb4742b21c0a3c27f18c5e4e94bab6f9e64cArgyrios Kyrtzidis } 17814cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis } 17824cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis 17834cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis // member-declarator-list: 17844cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis // member-declarator 17854cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis // member-declarator-list ',' member-declarator 17864cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis 1787d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall llvm::SmallVector<Decl *, 8> DeclsInGroup; 178860d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult BitfieldSize; 17894cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis 17904cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis while (1) { 17914cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis // member-declarator: 17924cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis // declarator pure-specifier[opt] 17934cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis // declarator constant-initializer[opt] 17944cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis // identifier[opt] ':' constant-expression 17954cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis if (Tok.is(tok::colon)) { 17964cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis ConsumeToken(); 17970e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl BitfieldSize = ParseConstantExpression(); 17980e9eabca263e8922bec0e2b38c8670eba9a39a1fSebastian Redl if (BitfieldSize.isInvalid()) 17994cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis SkipUntil(tok::comma, true, true); 18004cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis } 18011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1802b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson ParseOptionalCXX0XVirtSpecifierSeq(VS); 18031f3b6fdabbb10779a473d6315154d7325ce20aeaAnders Carlsson 18044cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis // pure-specifier: 18054cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis // '= 0' 18064cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis // 18074cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis // constant-initializer: 18084cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis // '=' constant-expression 1809e2b6833d445c7a4ce64f1816c05f176ba1740acaSebastian Redl // 1810e2b6833d445c7a4ce64f1816c05f176ba1740acaSebastian Redl // defaulted/deleted function-definition: 1811e2b6833d445c7a4ce64f1816c05f176ba1740acaSebastian Redl // '=' 'default' [TODO] 1812e2b6833d445c7a4ce64f1816c05f176ba1740acaSebastian Redl // '=' 'delete' 18134cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis if (Tok.is(tok::equal)) { 18144cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis ConsumeToken(); 181537bf9d2bb74944c9d9a52522412bc077629977f1Anders Carlsson if (Tok.is(tok::kw_delete)) { 1816e4246a633b13197634225971b25df0cbdcec0c5dSean Hunt if (DeclaratorInfo.isFunctionDeclarator()) 1817e4246a633b13197634225971b25df0cbdcec0c5dSean Hunt Diag(ConsumeToken(), diag::err_default_delete_in_multiple_declaration) 1818e4246a633b13197634225971b25df0cbdcec0c5dSean Hunt << 1 /* delete */; 1819e4246a633b13197634225971b25df0cbdcec0c5dSean Hunt else 1820e4246a633b13197634225971b25df0cbdcec0c5dSean Hunt Diag(ConsumeToken(), diag::err_deleted_non_function); 1821fe2695eec167b28578825576863228f86b392f24Sean Hunt } else if (Tok.is(tok::kw_default)) { 1822e4246a633b13197634225971b25df0cbdcec0c5dSean Hunt if (DeclaratorInfo.isFunctionDeclarator()) 1823e4246a633b13197634225971b25df0cbdcec0c5dSean Hunt Diag(Tok, diag::err_default_delete_in_multiple_declaration) 1824e4246a633b13197634225971b25df0cbdcec0c5dSean Hunt << 1 /* delete */; 1825e4246a633b13197634225971b25df0cbdcec0c5dSean Hunt else 1826e4246a633b13197634225971b25df0cbdcec0c5dSean Hunt Diag(ConsumeToken(), diag::err_default_special_members); 1827e2b6833d445c7a4ce64f1816c05f176ba1740acaSebastian Redl } else { 1828e2b6833d445c7a4ce64f1816c05f176ba1740acaSebastian Redl Init = ParseInitializer(); 1829e2b6833d445c7a4ce64f1816c05f176ba1740acaSebastian Redl if (Init.isInvalid()) 1830e2b6833d445c7a4ce64f1816c05f176ba1740acaSebastian Redl SkipUntil(tok::comma, true, true); 1831e2b6833d445c7a4ce64f1816c05f176ba1740acaSebastian Redl } 18324cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis } 18334cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis 1834e6563256a4b3b9fee70ce3335d28406607c1faafChris Lattner // If a simple-asm-expr is present, parse it. 1835e6563256a4b3b9fee70ce3335d28406607c1faafChris Lattner if (Tok.is(tok::kw_asm)) { 1836e6563256a4b3b9fee70ce3335d28406607c1faafChris Lattner SourceLocation Loc; 183760d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult AsmLabel(ParseSimpleAsm(&Loc)); 1838e6563256a4b3b9fee70ce3335d28406607c1faafChris Lattner if (AsmLabel.isInvalid()) 1839e6563256a4b3b9fee70ce3335d28406607c1faafChris Lattner SkipUntil(tok::comma, true, true); 1840e6563256a4b3b9fee70ce3335d28406607c1faafChris Lattner 1841e6563256a4b3b9fee70ce3335d28406607c1faafChris Lattner DeclaratorInfo.setAsmLabel(AsmLabel.release()); 1842e6563256a4b3b9fee70ce3335d28406607c1faafChris Lattner DeclaratorInfo.SetRangeEnd(Loc); 1843e6563256a4b3b9fee70ce3335d28406607c1faafChris Lattner } 1844e6563256a4b3b9fee70ce3335d28406607c1faafChris Lattner 18454cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis // If attributes exist after the declarator, parse them. 18467f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall MaybeParseGNUAttributes(DeclaratorInfo); 18474cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis 184807952324dda0e758c17f8bc3015793c65c51c48cArgyrios Kyrtzidis // NOTE: If Sema is the Action module and declarator is an instance field, 1849682bf92db408a6cbc3d37b5496a99b6ef85041ecChris Lattner // this call will *not* return the created decl; It will return null. 185007952324dda0e758c17f8bc3015793c65c51c48cArgyrios Kyrtzidis // See Sema::ActOnCXXMemberDeclarator for details. 185167d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall 1852d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ThisDecl = 0; 185367d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall if (DS.isFriendSpecified()) { 1854bbbcdd9cc06b6078939129330ecc9bda3310984dJohn McCall // TODO: handle initializers, bitfields, 'delete' 185523c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor ThisDecl = Actions.ActOnFriendFunctionDecl(getCurScope(), DeclaratorInfo, 1856bbbcdd9cc06b6078939129330ecc9bda3310984dJohn McCall /*IsDefinition*/ false, 1857bbbcdd9cc06b6078939129330ecc9bda3310984dJohn McCall move(TemplateParams)); 185837b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregor } else { 185923c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor ThisDecl = Actions.ActOnCXXMemberDeclarator(getCurScope(), AS, 186067d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall DeclaratorInfo, 186137b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregor move(TemplateParams), 186267d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall BitfieldSize.release(), 1863e4246a633b13197634225971b25df0cbdcec0c5dSean Hunt VS, Init.release(), false); 186437b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregor } 1865682bf92db408a6cbc3d37b5496a99b6ef85041ecChris Lattner if (ThisDecl) 1866682bf92db408a6cbc3d37b5496a99b6ef85041ecChris Lattner DeclsInGroup.push_back(ThisDecl); 18674cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis 186872b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor if (DeclaratorInfo.isFunctionDeclarator() && 18691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump DeclaratorInfo.getDeclSpec().getStorageClassSpec() 187072b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor != DeclSpec::SCS_typedef) { 1871d33133cdc1af466f9c276249b2621be03867888bEli Friedman HandleMemberFunctionDefaultArgs(DeclaratorInfo, ThisDecl); 187272b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor } 187372b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor 187454abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall DeclaratorInfo.complete(ThisDecl); 187554abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 18764cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis // If we don't have a comma, it is either the end of the list (a ';') 18774cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis // or an error, bail out. 18784cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis if (Tok.isNot(tok::comma)) 18794cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis break; 18801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 18814cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis // Consume the comma. 18824cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis ConsumeToken(); 18831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 18844cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis // Parse the next declarator. 18854cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis DeclaratorInfo.clear(); 18864867347e82648d3baf09524b98b09c297a5a198fNico Weber VS.clear(); 188715faa7fdfb496489dec9470aa5eb699b29ecdaccSebastian Redl BitfieldSize = 0; 188815faa7fdfb496489dec9470aa5eb699b29ecdaccSebastian Redl Init = 0; 18891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 18904cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis // Attributes are only allowed on the second declarator. 18917f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall MaybeParseGNUAttributes(DeclaratorInfo); 18924cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis 18933a9fdb4742b21c0a3c27f18c5e4e94bab6f9e64cArgyrios Kyrtzidis if (Tok.isNot(tok::colon)) 18943a9fdb4742b21c0a3c27f18c5e4e94bab6f9e64cArgyrios Kyrtzidis ParseDeclarator(DeclaratorInfo); 18954cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis } 18964cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis 1897ae50d501f463d7032320ec31840f60ae68df3a55Chris Lattner if (ExpectAndConsume(tok::semi, diag::err_expected_semi_decl_list)) { 1898ae50d501f463d7032320ec31840f60ae68df3a55Chris Lattner // Skip to end of block or statement. 1899ae50d501f463d7032320ec31840f60ae68df3a55Chris Lattner SkipUntil(tok::r_brace, true, true); 1900ae50d501f463d7032320ec31840f60ae68df3a55Chris Lattner // If we stopped at a ';', eat it. 1901ae50d501f463d7032320ec31840f60ae68df3a55Chris Lattner if (Tok.is(tok::semi)) ConsumeToken(); 1902682bf92db408a6cbc3d37b5496a99b6ef85041ecChris Lattner return; 19034cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis } 19044cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis 190523c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.FinalizeDeclaratorGroup(getCurScope(), DS, DeclsInGroup.data(), 1906ae50d501f463d7032320ec31840f60ae68df3a55Chris Lattner DeclsInGroup.size()); 19074cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis} 19084cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis 19094cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis/// ParseCXXMemberSpecification - Parse the class definition. 19104cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis/// 19114cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis/// member-specification: 19124cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis/// member-declaration member-specification[opt] 19134cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis/// access-specifier ':' member-specification[opt] 19144cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis/// 19154cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidisvoid Parser::ParseCXXMemberSpecification(SourceLocation RecordLoc, 1916d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall unsigned TagType, Decl *TagDecl) { 191731fc07df7f0fc89ebf83ca05a20b29de45a7598dSanjiv Gupta assert((TagType == DeclSpec::TST_struct || 19184cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis TagType == DeclSpec::TST_union || 191931fc07df7f0fc89ebf83ca05a20b29de45a7598dSanjiv Gupta TagType == DeclSpec::TST_class) && "Invalid TagType!"); 19204cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis 1921f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall PrettyDeclStackTraceEntry CrashInfo(Actions, TagDecl, RecordLoc, 1922f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall "parsing struct/union/class body"); 19231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 192426997fd58c9560584edd154618f2f2c15ee68af4Douglas Gregor // Determine whether this is a non-nested class. Note that local 192526997fd58c9560584edd154618f2f2c15ee68af4Douglas Gregor // classes are *not* considered to be nested classes. 192626997fd58c9560584edd154618f2f2c15ee68af4Douglas Gregor bool NonNestedClass = true; 192726997fd58c9560584edd154618f2f2c15ee68af4Douglas Gregor if (!ClassStack.empty()) { 192823c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor for (const Scope *S = getCurScope(); S; S = S->getParent()) { 192926997fd58c9560584edd154618f2f2c15ee68af4Douglas Gregor if (S->isClassScope()) { 193026997fd58c9560584edd154618f2f2c15ee68af4Douglas Gregor // We're inside a class scope, so this is a nested class. 193126997fd58c9560584edd154618f2f2c15ee68af4Douglas Gregor NonNestedClass = false; 193226997fd58c9560584edd154618f2f2c15ee68af4Douglas Gregor break; 193326997fd58c9560584edd154618f2f2c15ee68af4Douglas Gregor } 193426997fd58c9560584edd154618f2f2c15ee68af4Douglas Gregor 193526997fd58c9560584edd154618f2f2c15ee68af4Douglas Gregor if ((S->getFlags() & Scope::FnScope)) { 193626997fd58c9560584edd154618f2f2c15ee68af4Douglas Gregor // If we're in a function or function template declared in the 193726997fd58c9560584edd154618f2f2c15ee68af4Douglas Gregor // body of a class, then this is a local class rather than a 193826997fd58c9560584edd154618f2f2c15ee68af4Douglas Gregor // nested class. 193926997fd58c9560584edd154618f2f2c15ee68af4Douglas Gregor const Scope *Parent = S->getParent(); 194026997fd58c9560584edd154618f2f2c15ee68af4Douglas Gregor if (Parent->isTemplateParamScope()) 194126997fd58c9560584edd154618f2f2c15ee68af4Douglas Gregor Parent = Parent->getParent(); 194226997fd58c9560584edd154618f2f2c15ee68af4Douglas Gregor if (Parent->isClassScope()) 194326997fd58c9560584edd154618f2f2c15ee68af4Douglas Gregor break; 194426997fd58c9560584edd154618f2f2c15ee68af4Douglas Gregor } 194526997fd58c9560584edd154618f2f2c15ee68af4Douglas Gregor } 194626997fd58c9560584edd154618f2f2c15ee68af4Douglas Gregor } 19474cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis 19484cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis // Enter a scope for the class. 19493218c4bb3b5d7250f12420de6db7ef3e3f805a75Douglas Gregor ParseScope ClassScope(this, Scope::ClassScope|Scope::DeclScope); 19504cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis 19516569d68745c8213709740337d2be52b031384f58Douglas Gregor // Note that we are parsing a new (potentially-nested) class definition. 195226997fd58c9560584edd154618f2f2c15ee68af4Douglas Gregor ParsingClassDefinition ParsingDef(*this, TagDecl, NonNestedClass); 19536569d68745c8213709740337d2be52b031384f58Douglas Gregor 1954ddc29e116db3c3f4144355e67a0137b38b6bb6d1Douglas Gregor if (TagDecl) 195523c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.ActOnTagStartDefinition(getCurScope(), TagDecl); 1956bd0dfa5c37d422427080a0ae3af9b63e70e6e854John McCall 1957b184a18a0a52e4bec33ef70f13bfcc29aafa14f2Anders Carlsson SourceLocation FinalLoc; 1958b184a18a0a52e4bec33ef70f13bfcc29aafa14f2Anders Carlsson 1959b184a18a0a52e4bec33ef70f13bfcc29aafa14f2Anders Carlsson // Parse the optional 'final' keyword. 1960b184a18a0a52e4bec33ef70f13bfcc29aafa14f2Anders Carlsson if (getLang().CPlusPlus && Tok.is(tok::identifier)) { 1961b184a18a0a52e4bec33ef70f13bfcc29aafa14f2Anders Carlsson IdentifierInfo *II = Tok.getIdentifierInfo(); 1962b184a18a0a52e4bec33ef70f13bfcc29aafa14f2Anders Carlsson 1963b184a18a0a52e4bec33ef70f13bfcc29aafa14f2Anders Carlsson // Initialize the contextual keywords. 1964b184a18a0a52e4bec33ef70f13bfcc29aafa14f2Anders Carlsson if (!Ident_final) { 1965b184a18a0a52e4bec33ef70f13bfcc29aafa14f2Anders Carlsson Ident_final = &PP.getIdentifierTable().get("final"); 1966b184a18a0a52e4bec33ef70f13bfcc29aafa14f2Anders Carlsson Ident_override = &PP.getIdentifierTable().get("override"); 1967b184a18a0a52e4bec33ef70f13bfcc29aafa14f2Anders Carlsson } 1968b184a18a0a52e4bec33ef70f13bfcc29aafa14f2Anders Carlsson 1969b184a18a0a52e4bec33ef70f13bfcc29aafa14f2Anders Carlsson if (II == Ident_final) 1970b184a18a0a52e4bec33ef70f13bfcc29aafa14f2Anders Carlsson FinalLoc = ConsumeToken(); 1971b184a18a0a52e4bec33ef70f13bfcc29aafa14f2Anders Carlsson 1972b184a18a0a52e4bec33ef70f13bfcc29aafa14f2Anders Carlsson if (!getLang().CPlusPlus0x) 1973b184a18a0a52e4bec33ef70f13bfcc29aafa14f2Anders Carlsson Diag(FinalLoc, diag::ext_override_control_keyword) << "final"; 1974b184a18a0a52e4bec33ef70f13bfcc29aafa14f2Anders Carlsson } 1975cc54d594d4f6509c0e3a8e349e481d9b5d899df6Anders Carlsson 1976bd0dfa5c37d422427080a0ae3af9b63e70e6e854John McCall if (Tok.is(tok::colon)) { 1977bd0dfa5c37d422427080a0ae3af9b63e70e6e854John McCall ParseBaseClause(TagDecl); 1978bd0dfa5c37d422427080a0ae3af9b63e70e6e854John McCall 1979bd0dfa5c37d422427080a0ae3af9b63e70e6e854John McCall if (!Tok.is(tok::l_brace)) { 1980bd0dfa5c37d422427080a0ae3af9b63e70e6e854John McCall Diag(Tok, diag::err_expected_lbrace_after_base_specifiers); 1981db7bb4a4e7d9744cbc994c90932e6f056228e1ffJohn McCall 1982db7bb4a4e7d9744cbc994c90932e6f056228e1ffJohn McCall if (TagDecl) 198323c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.ActOnTagDefinitionError(getCurScope(), TagDecl); 1984bd0dfa5c37d422427080a0ae3af9b63e70e6e854John McCall return; 1985bd0dfa5c37d422427080a0ae3af9b63e70e6e854John McCall } 1986bd0dfa5c37d422427080a0ae3af9b63e70e6e854John McCall } 1987bd0dfa5c37d422427080a0ae3af9b63e70e6e854John McCall 1988bd0dfa5c37d422427080a0ae3af9b63e70e6e854John McCall assert(Tok.is(tok::l_brace)); 1989bd0dfa5c37d422427080a0ae3af9b63e70e6e854John McCall 1990bd0dfa5c37d422427080a0ae3af9b63e70e6e854John McCall SourceLocation LBraceLoc = ConsumeBrace(); 1991bd0dfa5c37d422427080a0ae3af9b63e70e6e854John McCall 199242a4f66ffeb26e69b2f0ec873a5d41b0e39e634cJohn McCall if (TagDecl) 19932c3ee54e51d835a35bbf781c69e17f39e2ba0480Anders Carlsson Actions.ActOnStartCXXMemberDeclarations(getCurScope(), TagDecl, FinalLoc, 1994dfc2f1035d23e294b298766a3cf51dfe249d53a2Anders Carlsson LBraceLoc); 1995f9368159334ff86ea5fa367225c1a580977f3b03John McCall 19964cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis // C++ 11p3: Members of a class defined with the keyword class are private 19974cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis // by default. Members of a class defined with the keywords struct or union 19984cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis // are public by default. 19994cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis AccessSpecifier CurAS; 20004cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis if (TagType == DeclSpec::TST_class) 20014cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis CurAS = AS_private; 20024cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis else 20034cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis CurAS = AS_public; 20044cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis 200507976d25eda0fed2734518be022ee84fab898cc6Douglas Gregor SourceLocation RBraceLoc; 200607976d25eda0fed2734518be022ee84fab898cc6Douglas Gregor if (TagDecl) { 200707976d25eda0fed2734518be022ee84fab898cc6Douglas Gregor // While we still have something to read, read the member-declarations. 200807976d25eda0fed2734518be022ee84fab898cc6Douglas Gregor while (Tok.isNot(tok::r_brace) && Tok.isNot(tok::eof)) { 200907976d25eda0fed2734518be022ee84fab898cc6Douglas Gregor // Each iteration of this loop reads one member-declaration. 201007976d25eda0fed2734518be022ee84fab898cc6Douglas Gregor 2011563a645de82231a55e221fe655b7188bf8369662Francois Pichet if (getLang().Microsoft && (Tok.is(tok::kw___if_exists) || 2012563a645de82231a55e221fe655b7188bf8369662Francois Pichet Tok.is(tok::kw___if_not_exists))) { 2013563a645de82231a55e221fe655b7188bf8369662Francois Pichet ParseMicrosoftIfExistsClassDeclaration((DeclSpec::TST)TagType, CurAS); 2014563a645de82231a55e221fe655b7188bf8369662Francois Pichet continue; 2015563a645de82231a55e221fe655b7188bf8369662Francois Pichet } 2016563a645de82231a55e221fe655b7188bf8369662Francois Pichet 201707976d25eda0fed2734518be022ee84fab898cc6Douglas Gregor // Check for extraneous top-level semicolon. 201807976d25eda0fed2734518be022ee84fab898cc6Douglas Gregor if (Tok.is(tok::semi)) { 201907976d25eda0fed2734518be022ee84fab898cc6Douglas Gregor Diag(Tok, diag::ext_extra_struct_semi) 202007976d25eda0fed2734518be022ee84fab898cc6Douglas Gregor << DeclSpec::getSpecifierName((DeclSpec::TST)TagType) 202107976d25eda0fed2734518be022ee84fab898cc6Douglas Gregor << FixItHint::CreateRemoval(Tok.getLocation()); 202207976d25eda0fed2734518be022ee84fab898cc6Douglas Gregor ConsumeToken(); 202307976d25eda0fed2734518be022ee84fab898cc6Douglas Gregor continue; 202407976d25eda0fed2734518be022ee84fab898cc6Douglas Gregor } 20251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 202607976d25eda0fed2734518be022ee84fab898cc6Douglas Gregor AccessSpecifier AS = getAccessSpecifierIfPresent(); 202707976d25eda0fed2734518be022ee84fab898cc6Douglas Gregor if (AS != AS_none) { 202807976d25eda0fed2734518be022ee84fab898cc6Douglas Gregor // Current token is a C++ access specifier. 202907976d25eda0fed2734518be022ee84fab898cc6Douglas Gregor CurAS = AS; 203007976d25eda0fed2734518be022ee84fab898cc6Douglas Gregor SourceLocation ASLoc = Tok.getLocation(); 203107976d25eda0fed2734518be022ee84fab898cc6Douglas Gregor ConsumeToken(); 203207976d25eda0fed2734518be022ee84fab898cc6Douglas Gregor if (Tok.is(tok::colon)) 203307976d25eda0fed2734518be022ee84fab898cc6Douglas Gregor Actions.ActOnAccessSpecifier(AS, ASLoc, Tok.getLocation()); 203407976d25eda0fed2734518be022ee84fab898cc6Douglas Gregor else 203507976d25eda0fed2734518be022ee84fab898cc6Douglas Gregor Diag(Tok, diag::err_expected_colon); 203607976d25eda0fed2734518be022ee84fab898cc6Douglas Gregor ConsumeToken(); 203707976d25eda0fed2734518be022ee84fab898cc6Douglas Gregor continue; 203807976d25eda0fed2734518be022ee84fab898cc6Douglas Gregor } 20394cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis 204007976d25eda0fed2734518be022ee84fab898cc6Douglas Gregor // FIXME: Make sure we don't have a template here. 20414cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis 204207976d25eda0fed2734518be022ee84fab898cc6Douglas Gregor // Parse all the comma separated declarators. 204307976d25eda0fed2734518be022ee84fab898cc6Douglas Gregor ParseCXXClassMemberDeclaration(CurAS); 204407976d25eda0fed2734518be022ee84fab898cc6Douglas Gregor } 20451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 204607976d25eda0fed2734518be022ee84fab898cc6Douglas Gregor RBraceLoc = MatchRHSPunctuation(tok::r_brace, LBraceLoc); 204707976d25eda0fed2734518be022ee84fab898cc6Douglas Gregor } else { 204807976d25eda0fed2734518be022ee84fab898cc6Douglas Gregor SkipUntil(tok::r_brace, false, false); 20494cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis } 20501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 20514cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis // If attributes exist after class contents, parse them. 20520b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall ParsedAttributes attrs(AttrFactory); 20537f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall MaybeParseGNUAttributes(attrs); 20544cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis 205542a4f66ffeb26e69b2f0ec873a5d41b0e39e634cJohn McCall if (TagDecl) 205623c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.ActOnFinishCXXMemberSpecification(getCurScope(), RecordLoc, TagDecl, 205742a4f66ffeb26e69b2f0ec873a5d41b0e39e634cJohn McCall LBraceLoc, RBraceLoc, 20587f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall attrs.getList()); 20594cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis 20604cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis // C++ 9.2p2: Within the class member-specification, the class is regarded as 20614cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis // complete within function bodies, default arguments, 20624cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis // exception-specifications, and constructor ctor-initializers (including 20634cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis // such things in nested classes). 20644cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis // 206572b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor // FIXME: Only function bodies and constructor ctor-initializers are 206672b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor // parsed correctly, fix the rest. 206707976d25eda0fed2734518be022ee84fab898cc6Douglas Gregor if (TagDecl && NonNestedClass) { 20684cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis // We are not inside a nested class. This class and its nested classes 206972b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor // are complete and we can parse the delayed portions of method 207072b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor // declarations and the lexed inline method definitions. 2071e0cc047b1984fc301bbe6e98b6d197bed39ad562Douglas Gregor SourceLocation SavedPrevTokLocation = PrevTokLocation; 20726569d68745c8213709740337d2be52b031384f58Douglas Gregor ParseLexedMethodDeclarations(getCurrentClass()); 20736569d68745c8213709740337d2be52b031384f58Douglas Gregor ParseLexedMethodDefs(getCurrentClass()); 2074e0cc047b1984fc301bbe6e98b6d197bed39ad562Douglas Gregor PrevTokLocation = SavedPrevTokLocation; 20754cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis } 20764cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis 207742a4f66ffeb26e69b2f0ec873a5d41b0e39e634cJohn McCall if (TagDecl) 207823c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Actions.ActOnTagFinishDefinition(getCurScope(), TagDecl, RBraceLoc); 2079db7bb4a4e7d9744cbc994c90932e6f056228e1ffJohn McCall 20804cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis // Leave the class scope. 20816569d68745c8213709740337d2be52b031384f58Douglas Gregor ParsingDef.Pop(); 20828935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor ClassScope.Exit(); 20834cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis} 20847ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor 20857ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor/// ParseConstructorInitializer - Parse a C++ constructor initializer, 20867ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor/// which explicitly initializes the members or base classes of a 20877ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor/// class (C++ [class.base.init]). For example, the three initializers 20887ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor/// after the ':' in the Derived constructor below: 20897ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor/// 20907ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor/// @code 20917ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor/// class Base { }; 20927ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor/// class Derived : Base { 20937ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor/// int x; 20947ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor/// float f; 20957ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor/// public: 20967ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor/// Derived(float f) : Base(), x(17), f(f) { } 20977ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor/// }; 20987ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor/// @endcode 20997ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor/// 21001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// [C++] ctor-initializer: 21011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// ':' mem-initializer-list 21027ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor/// 21031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// [C++] mem-initializer-list: 21043fb9e4b89f72823f162096086f0f964e6dcf66d6Douglas Gregor/// mem-initializer ...[opt] 21053fb9e4b89f72823f162096086f0f964e6dcf66d6Douglas Gregor/// mem-initializer ...[opt] , mem-initializer-list 2106d226f65006733ed7f709c3174f22ce33391cb58fJohn McCallvoid Parser::ParseConstructorInitializer(Decl *ConstructorDecl) { 21077ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor assert(Tok.is(tok::colon) && "Constructor initializer always starts with ':'"); 21087ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor 210928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley // Poison the SEH identifiers so they are flagged as illegal in constructor initializers 211028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley PoisonSEHIdentifiersRAIIObject PoisonSEHIdentifiers(*this, true); 21117ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor SourceLocation ColonLoc = ConsumeToken(); 21121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2113cbb67480094b3bcb5b715acd827cbad55e2a204cSean Hunt llvm::SmallVector<CXXCtorInitializer*, 4> MemInitializers; 21149db7dbb918ca49f4ee6c181e4917e7b6ec547353Douglas Gregor bool AnyErrors = false; 2115193575455e00eca03fd7177f60e3f2e6263cb661Kovarththanan Rajaratnam 21167ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor do { 21170133f525a23e18dd444880f7554f25fbcbd834e5Douglas Gregor if (Tok.is(tok::code_completion)) { 21180133f525a23e18dd444880f7554f25fbcbd834e5Douglas Gregor Actions.CodeCompleteConstructorInitializer(ConstructorDecl, 21190133f525a23e18dd444880f7554f25fbcbd834e5Douglas Gregor MemInitializers.data(), 21200133f525a23e18dd444880f7554f25fbcbd834e5Douglas Gregor MemInitializers.size()); 21210133f525a23e18dd444880f7554f25fbcbd834e5Douglas Gregor ConsumeCodeCompletionToken(); 21220133f525a23e18dd444880f7554f25fbcbd834e5Douglas Gregor } else { 21230133f525a23e18dd444880f7554f25fbcbd834e5Douglas Gregor MemInitResult MemInit = ParseMemInitializer(ConstructorDecl); 21240133f525a23e18dd444880f7554f25fbcbd834e5Douglas Gregor if (!MemInit.isInvalid()) 21250133f525a23e18dd444880f7554f25fbcbd834e5Douglas Gregor MemInitializers.push_back(MemInit.get()); 21260133f525a23e18dd444880f7554f25fbcbd834e5Douglas Gregor else 21270133f525a23e18dd444880f7554f25fbcbd834e5Douglas Gregor AnyErrors = true; 21280133f525a23e18dd444880f7554f25fbcbd834e5Douglas Gregor } 21290133f525a23e18dd444880f7554f25fbcbd834e5Douglas Gregor 21307ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor if (Tok.is(tok::comma)) 21317ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor ConsumeToken(); 21327ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor else if (Tok.is(tok::l_brace)) 21337ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor break; 2134b1f6fa48960eae269a3931d1fc545ed468d9a4d2Douglas Gregor // If the next token looks like a base or member initializer, assume that 2135b1f6fa48960eae269a3931d1fc545ed468d9a4d2Douglas Gregor // we're just missing a comma. 2136751f6922376dfe9432795b65a3649179e4ef5cf5Douglas Gregor else if (Tok.is(tok::identifier) || Tok.is(tok::coloncolon)) { 2137751f6922376dfe9432795b65a3649179e4ef5cf5Douglas Gregor SourceLocation Loc = PP.getLocForEndOfToken(PrevTokLocation); 2138751f6922376dfe9432795b65a3649179e4ef5cf5Douglas Gregor Diag(Loc, diag::err_ctor_init_missing_comma) 2139751f6922376dfe9432795b65a3649179e4ef5cf5Douglas Gregor << FixItHint::CreateInsertion(Loc, ", "); 2140751f6922376dfe9432795b65a3649179e4ef5cf5Douglas Gregor } else { 21417ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor // Skip over garbage, until we get to '{'. Don't eat the '{'. 2142d3a413d3b8eb39bcee5944bc545d9997c1abe492Sebastian Redl Diag(Tok.getLocation(), diag::err_expected_lbrace_or_comma); 21437ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor SkipUntil(tok::l_brace, true, true); 21447ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor break; 21457ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor } 21467ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor } while (true); 21477ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor 21481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Actions.ActOnMemInitializers(ConstructorDecl, ColonLoc, 21499db7dbb918ca49f4ee6c181e4917e7b6ec547353Douglas Gregor MemInitializers.data(), MemInitializers.size(), 21509db7dbb918ca49f4ee6c181e4917e7b6ec547353Douglas Gregor AnyErrors); 21517ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor} 21527ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor 21537ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor/// ParseMemInitializer - Parse a C++ member initializer, which is 21547ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor/// part of a constructor initializer that explicitly initializes one 21557ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor/// member or base class (C++ [class.base.init]). See 21567ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor/// ParseConstructorInitializer for an example. 21577ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor/// 21587ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor/// [C++] mem-initializer: 21597ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor/// mem-initializer-id '(' expression-list[opt] ')' 21601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// 21617ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor/// [C++] mem-initializer-id: 21627ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor/// '::'[opt] nested-name-specifier[opt] class-name 21637ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor/// identifier 2164d226f65006733ed7f709c3174f22ce33391cb58fJohn McCallParser::MemInitResult Parser::ParseMemInitializer(Decl *ConstructorDecl) { 2165bcfad54a43e5570e09daddd976bd4545933e75b1Fariborz Jahanian // parse '::'[opt] nested-name-specifier[opt] 2166bcfad54a43e5570e09daddd976bd4545933e75b1Fariborz Jahanian CXXScopeSpec SS; 2167b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParseOptionalCXXScopeSpecifier(SS, ParsedType(), false); 2168b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType TemplateTypeTy; 2169961743326fd18776f897bf4461345dba680ef637Fariborz Jahanian if (Tok.is(tok::annot_template_id)) { 2170961743326fd18776f897bf4461345dba680ef637Fariborz Jahanian TemplateIdAnnotation *TemplateId 2171961743326fd18776f897bf4461345dba680ef637Fariborz Jahanian = static_cast<TemplateIdAnnotation *>(Tok.getAnnotationValue()); 2172d9b600c1a589200be905c53e2e10fceb57efa18dDouglas Gregor if (TemplateId->Kind == TNK_Type_template || 2173d9b600c1a589200be905c53e2e10fceb57efa18dDouglas Gregor TemplateId->Kind == TNK_Dependent_template_name) { 2174059101f922de6eb765601459925f4c8914420b23Douglas Gregor AnnotateTemplateIdTokenAsType(); 2175961743326fd18776f897bf4461345dba680ef637Fariborz Jahanian assert(Tok.is(tok::annot_typename) && "template-id -> type failed"); 2176b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall TemplateTypeTy = getTypeAnnotation(Tok); 2177961743326fd18776f897bf4461345dba680ef637Fariborz Jahanian } 2178961743326fd18776f897bf4461345dba680ef637Fariborz Jahanian } 2179961743326fd18776f897bf4461345dba680ef637Fariborz Jahanian if (!TemplateTypeTy && Tok.isNot(tok::identifier)) { 21801ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner Diag(Tok, diag::err_expected_member_or_base_name); 21817ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor return true; 21827ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor } 21831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 21847ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor // Get the identifier. This may be a member name or a class name, 21857ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor // but we'll let the semantic analysis determine which it is. 2186961743326fd18776f897bf4461345dba680ef637Fariborz Jahanian IdentifierInfo *II = Tok.is(tok::identifier) ? Tok.getIdentifierInfo() : 0; 21877ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor SourceLocation IdLoc = ConsumeToken(); 21887ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor 21897ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor // Parse the '('. 21907ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor if (Tok.isNot(tok::l_paren)) { 21911ab3b96de160e4fbffec2a776e284a48a3bb543dChris Lattner Diag(Tok, diag::err_expected_lparen); 21927ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor return true; 21937ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor } 21947ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor SourceLocation LParenLoc = ConsumeParen(); 21957ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor 21967ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor // Parse the optional expression-list. 2197a55e52c0802cae3b7c366a05c461d3d15074c1a3Sebastian Redl ExprVector ArgExprs(Actions); 21987ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor CommaLocsTy CommaLocs; 21997ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor if (Tok.isNot(tok::r_paren) && ParseExpressionList(ArgExprs, CommaLocs)) { 22007ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor SkipUntil(tok::r_paren); 22017ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor return true; 22027ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor } 22037ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor 22047ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor SourceLocation RParenLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc); 22057ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor 22063fb9e4b89f72823f162096086f0f964e6dcf66d6Douglas Gregor SourceLocation EllipsisLoc; 22073fb9e4b89f72823f162096086f0f964e6dcf66d6Douglas Gregor if (Tok.is(tok::ellipsis)) 22083fb9e4b89f72823f162096086f0f964e6dcf66d6Douglas Gregor EllipsisLoc = ConsumeToken(); 22093fb9e4b89f72823f162096086f0f964e6dcf66d6Douglas Gregor 221023c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor return Actions.ActOnMemInitializer(ConstructorDecl, getCurScope(), SS, II, 2211961743326fd18776f897bf4461345dba680ef637Fariborz Jahanian TemplateTypeTy, IdLoc, 2212a55e52c0802cae3b7c366a05c461d3d15074c1a3Sebastian Redl LParenLoc, ArgExprs.take(), 22133fb9e4b89f72823f162096086f0f964e6dcf66d6Douglas Gregor ArgExprs.size(), RParenLoc, 22143fb9e4b89f72823f162096086f0f964e6dcf66d6Douglas Gregor EllipsisLoc); 22157ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor} 22160fe7bea6fca9737c6c145aaa4a2ad3abe595782aDouglas Gregor 22177acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl/// \brief Parse a C++ exception-specification if present (C++0x [except.spec]). 22180fe7bea6fca9737c6c145aaa4a2ad3abe595782aDouglas Gregor/// 2219a4745616ebe36ba7699f18618382e764aa8183a1Douglas Gregor/// exception-specification: 22207acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl/// dynamic-exception-specification 22217acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl/// noexcept-specification 22227acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl/// 22237acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl/// noexcept-specification: 22247acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl/// 'noexcept' 22257acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl/// 'noexcept' '(' constant-expression ')' 22267acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian RedlExceptionSpecificationType 22277acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian RedlParser::MaybeParseExceptionSpecification(SourceRange &SpecificationRange, 22287acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl llvm::SmallVectorImpl<ParsedType> &DynamicExceptions, 22297acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl llvm::SmallVectorImpl<SourceRange> &DynamicExceptionRanges, 22307acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl ExprResult &NoexceptExpr) { 22317acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl ExceptionSpecificationType Result = EST_None; 22327acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl 22337acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl // See if there's a dynamic specification. 22347acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl if (Tok.is(tok::kw_throw)) { 22357acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl Result = ParseDynamicExceptionSpecification(SpecificationRange, 22367acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl DynamicExceptions, 22377acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl DynamicExceptionRanges); 22387acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl assert(DynamicExceptions.size() == DynamicExceptionRanges.size() && 22397acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl "Produced different number of exception types and ranges."); 22407acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl } 22417acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl 22427acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl // If there's no noexcept specification, we're done. 22437acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl if (Tok.isNot(tok::kw_noexcept)) 22447acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl return Result; 22457acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl 22467acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl // If we already had a dynamic specification, parse the noexcept for, 22477acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl // recovery, but emit a diagnostic and don't store the results. 22487acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl SourceRange NoexceptRange; 22497acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl ExceptionSpecificationType NoexceptType = EST_None; 22507acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl 22517acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl SourceLocation KeywordLoc = ConsumeToken(); 22527acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl if (Tok.is(tok::l_paren)) { 22537acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl // There is an argument. 22547acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl SourceLocation LParenLoc = ConsumeParen(); 22557acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl NoexceptType = EST_ComputedNoexcept; 22567acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl NoexceptExpr = ParseConstantExpression(); 225760618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl // The argument must be contextually convertible to bool. We use 225860618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl // ActOnBooleanCondition for this purpose. 225960618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl if (!NoexceptExpr.isInvalid()) 226060618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl NoexceptExpr = Actions.ActOnBooleanCondition(getCurScope(), KeywordLoc, 226160618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl NoexceptExpr.get()); 22627acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl SourceLocation RParenLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc); 22637acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl NoexceptRange = SourceRange(KeywordLoc, RParenLoc); 22647acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl } else { 22657acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl // There is no argument. 22667acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl NoexceptType = EST_BasicNoexcept; 22677acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl NoexceptRange = SourceRange(KeywordLoc, KeywordLoc); 22687acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl } 22697acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl 22707acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl if (Result == EST_None) { 22717acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl SpecificationRange = NoexceptRange; 22727acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl Result = NoexceptType; 22737acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl 22747acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl // If there's a dynamic specification after a noexcept specification, 22757acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl // parse that and ignore the results. 22767acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl if (Tok.is(tok::kw_throw)) { 22777acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl Diag(Tok.getLocation(), diag::err_dynamic_and_noexcept_specification); 22787acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl ParseDynamicExceptionSpecification(NoexceptRange, DynamicExceptions, 22797acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl DynamicExceptionRanges); 22807acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl } 22817acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl } else { 22827acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl Diag(Tok.getLocation(), diag::err_dynamic_and_noexcept_specification); 22837acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl } 22847acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl 22857acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl return Result; 22867acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl} 22877acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl 22887acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl/// ParseDynamicExceptionSpecification - Parse a C++ 22897acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl/// dynamic-exception-specification (C++ [except.spec]). 22907acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl/// 22917acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl/// dynamic-exception-specification: 2292a4745616ebe36ba7699f18618382e764aa8183a1Douglas Gregor/// 'throw' '(' type-id-list [opt] ')' 2293a4745616ebe36ba7699f18618382e764aa8183a1Douglas Gregor/// [MS] 'throw' '(' '...' ')' 22941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// 2295a4745616ebe36ba7699f18618382e764aa8183a1Douglas Gregor/// type-id-list: 2296a04426c5416f22df1078f6b31c1619de73c40b59Douglas Gregor/// type-id ... [opt] 2297a04426c5416f22df1078f6b31c1619de73c40b59Douglas Gregor/// type-id-list ',' type-id ... [opt] 22980fe7bea6fca9737c6c145aaa4a2ad3abe595782aDouglas Gregor/// 22997acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian RedlExceptionSpecificationType Parser::ParseDynamicExceptionSpecification( 23007acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl SourceRange &SpecificationRange, 23017acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl llvm::SmallVectorImpl<ParsedType> &Exceptions, 23027acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl llvm::SmallVectorImpl<SourceRange> &Ranges) { 23030fe7bea6fca9737c6c145aaa4a2ad3abe595782aDouglas Gregor assert(Tok.is(tok::kw_throw) && "expected throw"); 23041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 23057acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl SpecificationRange.setBegin(ConsumeToken()); 23061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 23070fe7bea6fca9737c6c145aaa4a2ad3abe595782aDouglas Gregor if (!Tok.is(tok::l_paren)) { 23087acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl Diag(Tok, diag::err_expected_lparen_after) << "throw"; 23097acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl SpecificationRange.setEnd(SpecificationRange.getBegin()); 231060618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl return EST_DynamicNone; 23110fe7bea6fca9737c6c145aaa4a2ad3abe595782aDouglas Gregor } 23120fe7bea6fca9737c6c145aaa4a2ad3abe595782aDouglas Gregor SourceLocation LParenLoc = ConsumeParen(); 23130fe7bea6fca9737c6c145aaa4a2ad3abe595782aDouglas Gregor 2314a4745616ebe36ba7699f18618382e764aa8183a1Douglas Gregor // Parse throw(...), a Microsoft extension that means "this function 2315a4745616ebe36ba7699f18618382e764aa8183a1Douglas Gregor // can throw anything". 2316a4745616ebe36ba7699f18618382e764aa8183a1Douglas Gregor if (Tok.is(tok::ellipsis)) { 2317a4745616ebe36ba7699f18618382e764aa8183a1Douglas Gregor SourceLocation EllipsisLoc = ConsumeToken(); 2318a4745616ebe36ba7699f18618382e764aa8183a1Douglas Gregor if (!getLang().Microsoft) 2319a4745616ebe36ba7699f18618382e764aa8183a1Douglas Gregor Diag(EllipsisLoc, diag::ext_ellipsis_exception_spec); 23207acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl SourceLocation RParenLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc); 23217acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl SpecificationRange.setEnd(RParenLoc); 232260618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl return EST_MSAny; 2323a4745616ebe36ba7699f18618382e764aa8183a1Douglas Gregor } 2324a4745616ebe36ba7699f18618382e764aa8183a1Douglas Gregor 23250fe7bea6fca9737c6c145aaa4a2ad3abe595782aDouglas Gregor // Parse the sequence of type-ids. 2326ef65f06e8e440aec541442cfd73a8a836e9bc842Sebastian Redl SourceRange Range; 23270fe7bea6fca9737c6c145aaa4a2ad3abe595782aDouglas Gregor while (Tok.isNot(tok::r_paren)) { 2328ef65f06e8e440aec541442cfd73a8a836e9bc842Sebastian Redl TypeResult Res(ParseTypeName(&Range)); 23297acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl 2330a04426c5416f22df1078f6b31c1619de73c40b59Douglas Gregor if (Tok.is(tok::ellipsis)) { 2331a04426c5416f22df1078f6b31c1619de73c40b59Douglas Gregor // C++0x [temp.variadic]p5: 2332a04426c5416f22df1078f6b31c1619de73c40b59Douglas Gregor // - In a dynamic-exception-specification (15.4); the pattern is a 2333a04426c5416f22df1078f6b31c1619de73c40b59Douglas Gregor // type-id. 2334a04426c5416f22df1078f6b31c1619de73c40b59Douglas Gregor SourceLocation Ellipsis = ConsumeToken(); 23357acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl Range.setEnd(Ellipsis); 2336a04426c5416f22df1078f6b31c1619de73c40b59Douglas Gregor if (!Res.isInvalid()) 2337a04426c5416f22df1078f6b31c1619de73c40b59Douglas Gregor Res = Actions.ActOnPackExpansion(Res.get(), Ellipsis); 2338a04426c5416f22df1078f6b31c1619de73c40b59Douglas Gregor } 23397acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl 2340ef65f06e8e440aec541442cfd73a8a836e9bc842Sebastian Redl if (!Res.isInvalid()) { 23417dc813462dd9fd3f6f4296f896a12de14264fef8Sebastian Redl Exceptions.push_back(Res.get()); 2342ef65f06e8e440aec541442cfd73a8a836e9bc842Sebastian Redl Ranges.push_back(Range); 2343ef65f06e8e440aec541442cfd73a8a836e9bc842Sebastian Redl } 2344a04426c5416f22df1078f6b31c1619de73c40b59Douglas Gregor 23450fe7bea6fca9737c6c145aaa4a2ad3abe595782aDouglas Gregor if (Tok.is(tok::comma)) 23460fe7bea6fca9737c6c145aaa4a2ad3abe595782aDouglas Gregor ConsumeToken(); 23477dc813462dd9fd3f6f4296f896a12de14264fef8Sebastian Redl else 23480fe7bea6fca9737c6c145aaa4a2ad3abe595782aDouglas Gregor break; 23490fe7bea6fca9737c6c145aaa4a2ad3abe595782aDouglas Gregor } 23500fe7bea6fca9737c6c145aaa4a2ad3abe595782aDouglas Gregor 23517acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl SpecificationRange.setEnd(MatchRHSPunctuation(tok::r_paren, LParenLoc)); 235260618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl return Exceptions.empty() ? EST_DynamicNone : EST_Dynamic; 23530fe7bea6fca9737c6c145aaa4a2ad3abe595782aDouglas Gregor} 23546569d68745c8213709740337d2be52b031384f58Douglas Gregor 2355dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor/// ParseTrailingReturnType - Parse a trailing return type on a new-style 2356dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor/// function declaration. 2357dab60ad68a3a98d687305941a3852e793705f945Douglas GregorTypeResult Parser::ParseTrailingReturnType() { 2358dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor assert(Tok.is(tok::arrow) && "expected arrow"); 2359dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor 2360dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor ConsumeToken(); 2361dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor 2362dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor // FIXME: Need to suppress declarations when parsing this typename. 2363dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor // Otherwise in this function definition: 2364dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor // 2365dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor // auto f() -> struct X {} 2366dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor // 2367dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor // struct X is parsed as class definition because of the trailing 2368dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor // brace. 2369dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor 2370dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor SourceRange Range; 2371dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor return ParseTypeName(&Range); 2372dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor} 2373dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor 23746569d68745c8213709740337d2be52b031384f58Douglas Gregor/// \brief We have just started parsing the definition of a new class, 23756569d68745c8213709740337d2be52b031384f58Douglas Gregor/// so push that class onto our stack of classes that is currently 23766569d68745c8213709740337d2be52b031384f58Douglas Gregor/// being parsed. 2377eee1d5434ebfa955ffc3c493aecd68bb7b3f4838John McCallSema::ParsingClassState 2378eee1d5434ebfa955ffc3c493aecd68bb7b3f4838John McCallParser::PushParsingClass(Decl *ClassDecl, bool NonNestedClass) { 237926997fd58c9560584edd154618f2f2c15ee68af4Douglas Gregor assert((NonNestedClass || !ClassStack.empty()) && 23806569d68745c8213709740337d2be52b031384f58Douglas Gregor "Nested class without outer class"); 238126997fd58c9560584edd154618f2f2c15ee68af4Douglas Gregor ClassStack.push(new ParsingClass(ClassDecl, NonNestedClass)); 2382eee1d5434ebfa955ffc3c493aecd68bb7b3f4838John McCall return Actions.PushParsingClass(); 23836569d68745c8213709740337d2be52b031384f58Douglas Gregor} 23846569d68745c8213709740337d2be52b031384f58Douglas Gregor 23856569d68745c8213709740337d2be52b031384f58Douglas Gregor/// \brief Deallocate the given parsed class and all of its nested 23866569d68745c8213709740337d2be52b031384f58Douglas Gregor/// classes. 23876569d68745c8213709740337d2be52b031384f58Douglas Gregorvoid Parser::DeallocateParsedClasses(Parser::ParsingClass *Class) { 2388d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor for (unsigned I = 0, N = Class->LateParsedDeclarations.size(); I != N; ++I) 2389d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor delete Class->LateParsedDeclarations[I]; 23906569d68745c8213709740337d2be52b031384f58Douglas Gregor delete Class; 23916569d68745c8213709740337d2be52b031384f58Douglas Gregor} 23926569d68745c8213709740337d2be52b031384f58Douglas Gregor 23936569d68745c8213709740337d2be52b031384f58Douglas Gregor/// \brief Pop the top class of the stack of classes that are 23946569d68745c8213709740337d2be52b031384f58Douglas Gregor/// currently being parsed. 23956569d68745c8213709740337d2be52b031384f58Douglas Gregor/// 23966569d68745c8213709740337d2be52b031384f58Douglas Gregor/// This routine should be called when we have finished parsing the 23976569d68745c8213709740337d2be52b031384f58Douglas Gregor/// definition of a class, but have not yet popped the Scope 23986569d68745c8213709740337d2be52b031384f58Douglas Gregor/// associated with the class's definition. 23996569d68745c8213709740337d2be52b031384f58Douglas Gregor/// 24006569d68745c8213709740337d2be52b031384f58Douglas Gregor/// \returns true if the class we've popped is a top-level class, 24016569d68745c8213709740337d2be52b031384f58Douglas Gregor/// false otherwise. 2402eee1d5434ebfa955ffc3c493aecd68bb7b3f4838John McCallvoid Parser::PopParsingClass(Sema::ParsingClassState state) { 24036569d68745c8213709740337d2be52b031384f58Douglas Gregor assert(!ClassStack.empty() && "Mismatched push/pop for class parsing"); 24041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2405eee1d5434ebfa955ffc3c493aecd68bb7b3f4838John McCall Actions.PopParsingClass(state); 2406eee1d5434ebfa955ffc3c493aecd68bb7b3f4838John McCall 24076569d68745c8213709740337d2be52b031384f58Douglas Gregor ParsingClass *Victim = ClassStack.top(); 24086569d68745c8213709740337d2be52b031384f58Douglas Gregor ClassStack.pop(); 24096569d68745c8213709740337d2be52b031384f58Douglas Gregor if (Victim->TopLevelClass) { 24106569d68745c8213709740337d2be52b031384f58Douglas Gregor // Deallocate all of the nested classes of this class, 24116569d68745c8213709740337d2be52b031384f58Douglas Gregor // recursively: we don't need to keep any of this information. 24126569d68745c8213709740337d2be52b031384f58Douglas Gregor DeallocateParsedClasses(Victim); 24136569d68745c8213709740337d2be52b031384f58Douglas Gregor return; 24141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 24156569d68745c8213709740337d2be52b031384f58Douglas Gregor assert(!ClassStack.empty() && "Missing top-level class?"); 24166569d68745c8213709740337d2be52b031384f58Douglas Gregor 2417d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor if (Victim->LateParsedDeclarations.empty()) { 24186569d68745c8213709740337d2be52b031384f58Douglas Gregor // The victim is a nested class, but we will not need to perform 24196569d68745c8213709740337d2be52b031384f58Douglas Gregor // any processing after the definition of this class since it has 24206569d68745c8213709740337d2be52b031384f58Douglas Gregor // no members whose handling was delayed. Therefore, we can just 24216569d68745c8213709740337d2be52b031384f58Douglas Gregor // remove this nested class. 2422d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor DeallocateParsedClasses(Victim); 24236569d68745c8213709740337d2be52b031384f58Douglas Gregor return; 24246569d68745c8213709740337d2be52b031384f58Douglas Gregor } 24256569d68745c8213709740337d2be52b031384f58Douglas Gregor 24266569d68745c8213709740337d2be52b031384f58Douglas Gregor // This nested class has some members that will need to be processed 24276569d68745c8213709740337d2be52b031384f58Douglas Gregor // after the top-level class is completely defined. Therefore, add 24286569d68745c8213709740337d2be52b031384f58Douglas Gregor // it to the list of nested classes within its parent. 242923c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor assert(getCurScope()->isClassScope() && "Nested class outside of class scope?"); 2430d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor ClassStack.top()->LateParsedDeclarations.push_back(new LateParsedClass(this, Victim)); 243123c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Victim->TemplateScope = getCurScope()->getParent()->isTemplateParamScope(); 24326569d68745c8213709740337d2be52b031384f58Douglas Gregor} 2433bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt 2434bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt/// ParseCXX0XAttributes - Parse a C++0x attribute-specifier. Currently only 2435bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt/// parses standard attributes. 2436bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt/// 2437bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt/// [C++0x] attribute-specifier: 2438bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt/// '[' '[' attribute-list ']' ']' 2439bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt/// 2440bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt/// [C++0x] attribute-list: 2441bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt/// attribute[opt] 2442bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt/// attribute-list ',' attribute[opt] 2443bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt/// 2444bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt/// [C++0x] attribute: 2445bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt/// attribute-token attribute-argument-clause[opt] 2446bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt/// 2447bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt/// [C++0x] attribute-token: 2448bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt/// identifier 2449bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt/// attribute-scoped-token 2450bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt/// 2451bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt/// [C++0x] attribute-scoped-token: 2452bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt/// attribute-namespace '::' identifier 2453bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt/// 2454bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt/// [C++0x] attribute-namespace: 2455bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt/// identifier 2456bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt/// 2457bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt/// [C++0x] attribute-argument-clause: 2458bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt/// '(' balanced-token-seq ')' 2459bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt/// 2460bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt/// [C++0x] balanced-token-seq: 2461bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt/// balanced-token 2462bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt/// balanced-token-seq balanced-token 2463bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt/// 2464bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt/// [C++0x] balanced-token: 2465bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt/// '(' balanced-token-seq ')' 2466bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt/// '[' balanced-token-seq ']' 2467bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt/// '{' balanced-token-seq '}' 2468bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt/// any token but '(', ')', '[', ']', '{', or '}' 24697f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCallvoid Parser::ParseCXX0XAttributes(ParsedAttributesWithRange &attrs, 24707f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall SourceLocation *endLoc) { 2471bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt assert(Tok.is(tok::l_square) && NextToken().is(tok::l_square) 2472bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt && "Not a C++0x attribute list"); 2473bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt 2474bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt SourceLocation StartLoc = Tok.getLocation(), Loc; 2475bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt 2476bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt ConsumeBracket(); 2477bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt ConsumeBracket(); 2478193575455e00eca03fd7177f60e3f2e6263cb661Kovarththanan Rajaratnam 2479bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt if (Tok.is(tok::comma)) { 2480bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt Diag(Tok.getLocation(), diag::err_expected_ident); 2481bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt ConsumeToken(); 2482bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt } 2483bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt 2484bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt while (Tok.is(tok::identifier) || Tok.is(tok::comma)) { 2485bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt // attribute not present 2486bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt if (Tok.is(tok::comma)) { 2487bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt ConsumeToken(); 2488bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt continue; 2489bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt } 2490bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt 2491bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt IdentifierInfo *ScopeName = 0, *AttrName = Tok.getIdentifierInfo(); 2492bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt SourceLocation ScopeLoc, AttrLoc = ConsumeToken(); 2493193575455e00eca03fd7177f60e3f2e6263cb661Kovarththanan Rajaratnam 2494bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt // scoped attribute 2495bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt if (Tok.is(tok::coloncolon)) { 2496bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt ConsumeToken(); 2497bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt 2498bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt if (!Tok.is(tok::identifier)) { 2499bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt Diag(Tok.getLocation(), diag::err_expected_ident); 2500bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt SkipUntil(tok::r_square, tok::comma, true, true); 2501bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt continue; 2502bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt } 2503193575455e00eca03fd7177f60e3f2e6263cb661Kovarththanan Rajaratnam 2504bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt ScopeName = AttrName; 2505bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt ScopeLoc = AttrLoc; 2506bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt 2507bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt AttrName = Tok.getIdentifierInfo(); 2508bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt AttrLoc = ConsumeToken(); 2509bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt } 2510bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt 2511bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt bool AttrParsed = false; 2512bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt // No scoped names are supported; ideally we could put all non-standard 2513bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt // attributes into namespaces. 2514bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt if (!ScopeName) { 2515bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt switch(AttributeList::getKind(AttrName)) 2516bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt { 2517bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt // No arguments 25187725e67639fa2fe74f8775b7ed884a076ffdbffcSean Hunt case AttributeList::AT_carries_dependency: 251915e14a289583616e582a23b320933e846a742626Anders Carlsson case AttributeList::AT_noreturn: { 2520bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt if (Tok.is(tok::l_paren)) { 2521bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt Diag(Tok.getLocation(), diag::err_cxx0x_attribute_forbids_arguments) 2522bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt << AttrName->getName(); 2523bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt break; 2524bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt } 2525bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt 25260b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall attrs.addNew(AttrName, AttrLoc, 0, AttrLoc, 0, 25270b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall SourceLocation(), 0, 0, false, true); 2528bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt AttrParsed = true; 2529bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt break; 2530bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt } 2531bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt 2532bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt // One argument; must be a type-id or assignment-expression 2533bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt case AttributeList::AT_aligned: { 2534bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt if (Tok.isNot(tok::l_paren)) { 2535bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt Diag(Tok.getLocation(), diag::err_cxx0x_attribute_requires_arguments) 2536bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt << AttrName->getName(); 2537bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt break; 2538bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt } 2539bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt SourceLocation ParamLoc = ConsumeParen(); 2540bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt 254160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ArgExpr = ParseCXX0XAlignArgument(ParamLoc); 2542bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt 2543bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt MatchRHSPunctuation(tok::r_paren, ParamLoc); 2544bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt 2545bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt ExprVector ArgExprs(Actions); 2546bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt ArgExprs.push_back(ArgExpr.release()); 25470b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall attrs.addNew(AttrName, AttrLoc, 0, AttrLoc, 25480b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall 0, ParamLoc, ArgExprs.take(), 1, 25490b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall false, true); 2550bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt 2551bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt AttrParsed = true; 2552bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt break; 2553bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt } 2554bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt 2555bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt // Silence warnings 2556bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt default: break; 2557bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt } 2558bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt } 2559bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt 2560bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt // Skip the entire parameter clause, if any 2561bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt if (!AttrParsed && Tok.is(tok::l_paren)) { 2562bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt ConsumeParen(); 2563bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt // SkipUntil maintains the balancedness of tokens. 2564bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt SkipUntil(tok::r_paren, false); 2565bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt } 2566bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt } 2567bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt 2568bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt if (ExpectAndConsume(tok::r_square, diag::err_expected_rsquare)) 2569bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt SkipUntil(tok::r_square, false); 2570bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt Loc = Tok.getLocation(); 2571bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt if (ExpectAndConsume(tok::r_square, diag::err_expected_rsquare)) 2572bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt SkipUntil(tok::r_square, false); 2573bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt 25747f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall attrs.Range = SourceRange(StartLoc, Loc); 2575bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt} 2576bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt 2577bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt/// ParseCXX0XAlignArgument - Parse the argument to C++0x's [[align]] 2578bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt/// attribute. 2579bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt/// 2580bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt/// FIXME: Simply returns an alignof() expression if the argument is a 2581bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt/// type. Ideally, the type should be propagated directly into Sema. 2582bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt/// 2583bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt/// [C++0x] 'align' '(' type-id ')' 2584bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt/// [C++0x] 'align' '(' assignment-expression ')' 258560d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult Parser::ParseCXX0XAlignArgument(SourceLocation Start) { 2586bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt if (isTypeIdInParens()) { 2587f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall EnterExpressionEvaluationContext Unevaluated(Actions, Sema::Unevaluated); 2588bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt SourceLocation TypeLoc = Tok.getLocation(); 2589b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType Ty = ParseTypeName().get(); 2590bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt SourceRange TypeRange(Start, Tok.getLocation()); 2591f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne return Actions.ActOnUnaryExprOrTypeTraitExpr(TypeLoc, UETT_AlignOf, true, 2592f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne Ty.getAsOpaquePtr(), TypeRange); 2593bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt } else 2594bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt return ParseConstantExpression(); 2595bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt} 2596334d47e92e9f241576fdeb7477b69a03136ba854Francois Pichet 2597334d47e92e9f241576fdeb7477b69a03136ba854Francois Pichet/// ParseMicrosoftAttributes - Parse a Microsoft attribute [Attr] 2598334d47e92e9f241576fdeb7477b69a03136ba854Francois Pichet/// 2599334d47e92e9f241576fdeb7477b69a03136ba854Francois Pichet/// [MS] ms-attribute: 2600334d47e92e9f241576fdeb7477b69a03136ba854Francois Pichet/// '[' token-seq ']' 2601334d47e92e9f241576fdeb7477b69a03136ba854Francois Pichet/// 2602334d47e92e9f241576fdeb7477b69a03136ba854Francois Pichet/// [MS] ms-attribute-seq: 2603334d47e92e9f241576fdeb7477b69a03136ba854Francois Pichet/// ms-attribute[opt] 2604334d47e92e9f241576fdeb7477b69a03136ba854Francois Pichet/// ms-attribute ms-attribute-seq 26057f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCallvoid Parser::ParseMicrosoftAttributes(ParsedAttributes &attrs, 26067f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall SourceLocation *endLoc) { 2607334d47e92e9f241576fdeb7477b69a03136ba854Francois Pichet assert(Tok.is(tok::l_square) && "Not a Microsoft attribute list"); 2608334d47e92e9f241576fdeb7477b69a03136ba854Francois Pichet 2609334d47e92e9f241576fdeb7477b69a03136ba854Francois Pichet while (Tok.is(tok::l_square)) { 2610334d47e92e9f241576fdeb7477b69a03136ba854Francois Pichet ConsumeBracket(); 2611334d47e92e9f241576fdeb7477b69a03136ba854Francois Pichet SkipUntil(tok::r_square, true, true); 26127f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall if (endLoc) *endLoc = Tok.getLocation(); 2613334d47e92e9f241576fdeb7477b69a03136ba854Francois Pichet ExpectAndConsume(tok::r_square, diag::err_expected_rsquare); 2614334d47e92e9f241576fdeb7477b69a03136ba854Francois Pichet } 2615334d47e92e9f241576fdeb7477b69a03136ba854Francois Pichet} 2616563a645de82231a55e221fe655b7188bf8369662Francois Pichet 2617563a645de82231a55e221fe655b7188bf8369662Francois Pichetvoid Parser::ParseMicrosoftIfExistsClassDeclaration(DeclSpec::TST TagType, 2618563a645de82231a55e221fe655b7188bf8369662Francois Pichet AccessSpecifier& CurAS) { 2619563a645de82231a55e221fe655b7188bf8369662Francois Pichet bool Result; 2620563a645de82231a55e221fe655b7188bf8369662Francois Pichet if (ParseMicrosoftIfExistsCondition(Result)) 2621563a645de82231a55e221fe655b7188bf8369662Francois Pichet return; 2622563a645de82231a55e221fe655b7188bf8369662Francois Pichet 2623563a645de82231a55e221fe655b7188bf8369662Francois Pichet if (Tok.isNot(tok::l_brace)) { 2624563a645de82231a55e221fe655b7188bf8369662Francois Pichet Diag(Tok, diag::err_expected_lbrace); 2625563a645de82231a55e221fe655b7188bf8369662Francois Pichet return; 2626563a645de82231a55e221fe655b7188bf8369662Francois Pichet } 2627563a645de82231a55e221fe655b7188bf8369662Francois Pichet ConsumeBrace(); 2628563a645de82231a55e221fe655b7188bf8369662Francois Pichet 2629563a645de82231a55e221fe655b7188bf8369662Francois Pichet // Condition is false skip all inside the {}. 2630563a645de82231a55e221fe655b7188bf8369662Francois Pichet if (!Result) { 2631563a645de82231a55e221fe655b7188bf8369662Francois Pichet SkipUntil(tok::r_brace, false); 2632563a645de82231a55e221fe655b7188bf8369662Francois Pichet return; 2633563a645de82231a55e221fe655b7188bf8369662Francois Pichet } 2634563a645de82231a55e221fe655b7188bf8369662Francois Pichet 2635563a645de82231a55e221fe655b7188bf8369662Francois Pichet // Condition is true, parse the declaration. 2636563a645de82231a55e221fe655b7188bf8369662Francois Pichet while (Tok.isNot(tok::r_brace)) { 2637563a645de82231a55e221fe655b7188bf8369662Francois Pichet 2638563a645de82231a55e221fe655b7188bf8369662Francois Pichet // __if_exists, __if_not_exists can nest. 2639563a645de82231a55e221fe655b7188bf8369662Francois Pichet if ((Tok.is(tok::kw___if_exists) || Tok.is(tok::kw___if_not_exists))) { 2640563a645de82231a55e221fe655b7188bf8369662Francois Pichet ParseMicrosoftIfExistsClassDeclaration((DeclSpec::TST)TagType, CurAS); 2641563a645de82231a55e221fe655b7188bf8369662Francois Pichet continue; 2642563a645de82231a55e221fe655b7188bf8369662Francois Pichet } 2643563a645de82231a55e221fe655b7188bf8369662Francois Pichet 2644563a645de82231a55e221fe655b7188bf8369662Francois Pichet // Check for extraneous top-level semicolon. 2645563a645de82231a55e221fe655b7188bf8369662Francois Pichet if (Tok.is(tok::semi)) { 2646563a645de82231a55e221fe655b7188bf8369662Francois Pichet Diag(Tok, diag::ext_extra_struct_semi) 2647563a645de82231a55e221fe655b7188bf8369662Francois Pichet << DeclSpec::getSpecifierName((DeclSpec::TST)TagType) 2648563a645de82231a55e221fe655b7188bf8369662Francois Pichet << FixItHint::CreateRemoval(Tok.getLocation()); 2649563a645de82231a55e221fe655b7188bf8369662Francois Pichet ConsumeToken(); 2650563a645de82231a55e221fe655b7188bf8369662Francois Pichet continue; 2651563a645de82231a55e221fe655b7188bf8369662Francois Pichet } 2652563a645de82231a55e221fe655b7188bf8369662Francois Pichet 2653563a645de82231a55e221fe655b7188bf8369662Francois Pichet AccessSpecifier AS = getAccessSpecifierIfPresent(); 2654563a645de82231a55e221fe655b7188bf8369662Francois Pichet if (AS != AS_none) { 2655563a645de82231a55e221fe655b7188bf8369662Francois Pichet // Current token is a C++ access specifier. 2656563a645de82231a55e221fe655b7188bf8369662Francois Pichet CurAS = AS; 2657563a645de82231a55e221fe655b7188bf8369662Francois Pichet SourceLocation ASLoc = Tok.getLocation(); 2658563a645de82231a55e221fe655b7188bf8369662Francois Pichet ConsumeToken(); 2659563a645de82231a55e221fe655b7188bf8369662Francois Pichet if (Tok.is(tok::colon)) 2660563a645de82231a55e221fe655b7188bf8369662Francois Pichet Actions.ActOnAccessSpecifier(AS, ASLoc, Tok.getLocation()); 2661563a645de82231a55e221fe655b7188bf8369662Francois Pichet else 2662563a645de82231a55e221fe655b7188bf8369662Francois Pichet Diag(Tok, diag::err_expected_colon); 2663563a645de82231a55e221fe655b7188bf8369662Francois Pichet ConsumeToken(); 2664563a645de82231a55e221fe655b7188bf8369662Francois Pichet continue; 2665563a645de82231a55e221fe655b7188bf8369662Francois Pichet } 2666563a645de82231a55e221fe655b7188bf8369662Francois Pichet 2667563a645de82231a55e221fe655b7188bf8369662Francois Pichet // Parse all the comma separated declarators. 2668563a645de82231a55e221fe655b7188bf8369662Francois Pichet ParseCXXClassMemberDeclaration(CurAS); 2669563a645de82231a55e221fe655b7188bf8369662Francois Pichet } 2670563a645de82231a55e221fe655b7188bf8369662Francois Pichet 2671563a645de82231a55e221fe655b7188bf8369662Francois Pichet if (Tok.isNot(tok::r_brace)) { 2672563a645de82231a55e221fe655b7188bf8369662Francois Pichet Diag(Tok, diag::err_expected_rbrace); 2673563a645de82231a55e221fe655b7188bf8369662Francois Pichet return; 2674563a645de82231a55e221fe655b7188bf8369662Francois Pichet } 2675563a645de82231a55e221fe655b7188bf8369662Francois Pichet ConsumeBrace(); 2676563a645de82231a55e221fe655b7188bf8369662Francois Pichet} 2677