Chris Lattner | a523517 | 2007-08-25 06:57:03 +0000 | [diff] [blame] | 1 | //===--- ParseDeclCXX.cpp - C++ Declaration Parsing -----------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 5b12ab8 | 2007-12-29 19:59:25 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Chris Lattner | a523517 | 2007-08-25 06:57:03 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file implements the C++ Declaration portions of the Parser interfaces. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Douglas Gregor | 423984d | 2008-04-14 00:13:42 +0000 | [diff] [blame] | 14 | #include "clang/Parse/Parser.h" |
Chandler Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 15 | #include "RAIIObjectsForParser.h" |
Chandler Carruth | 5553d0d | 2014-01-07 11:51:46 +0000 | [diff] [blame] | 16 | #include "clang/AST/DeclTemplate.h" |
Erik Verbruggen | 888d52a | 2014-01-15 09:15:43 +0000 | [diff] [blame] | 17 | #include "clang/AST/ASTContext.h" |
Jordan Rose | a7d0384 | 2013-02-08 22:30:41 +0000 | [diff] [blame] | 18 | #include "clang/Basic/CharInfo.h" |
Chandler Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 19 | #include "clang/Basic/OperatorKinds.h" |
Chris Lattner | 60f3622 | 2009-01-29 05:15:15 +0000 | [diff] [blame] | 20 | #include "clang/Parse/ParseDiagnostic.h" |
John McCall | 8b0666c | 2010-08-20 18:27:03 +0000 | [diff] [blame] | 21 | #include "clang/Sema/DeclSpec.h" |
John McCall | 8b0666c | 2010-08-20 18:27:03 +0000 | [diff] [blame] | 22 | #include "clang/Sema/ParsedTemplate.h" |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 23 | #include "clang/Sema/PrettyDeclStackTrace.h" |
Chandler Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 24 | #include "clang/Sema/Scope.h" |
John McCall | db632ac | 2012-09-25 07:32:39 +0000 | [diff] [blame] | 25 | #include "clang/Sema/SemaDiagnostic.h" |
Benjamin Kramer | 4903802 | 2012-02-04 13:45:25 +0000 | [diff] [blame] | 26 | #include "llvm/ADT/SmallString.h" |
Chris Lattner | a523517 | 2007-08-25 06:57:03 +0000 | [diff] [blame] | 27 | using namespace clang; |
| 28 | |
| 29 | /// ParseNamespace - We know that the current token is a namespace keyword. This |
Sebastian Redl | 6766794 | 2010-08-27 23:12:46 +0000 | [diff] [blame] | 30 | /// may either be a top level namespace or a block-level namespace alias. If |
| 31 | /// there was an inline keyword, it has already been parsed. |
Chris Lattner | a523517 | 2007-08-25 06:57:03 +0000 | [diff] [blame] | 32 | /// |
| 33 | /// namespace-definition: [C++ 7.3: basic.namespace] |
| 34 | /// named-namespace-definition |
| 35 | /// unnamed-namespace-definition |
| 36 | /// |
| 37 | /// unnamed-namespace-definition: |
Sebastian Redl | 6766794 | 2010-08-27 23:12:46 +0000 | [diff] [blame] | 38 | /// 'inline'[opt] 'namespace' attributes[opt] '{' namespace-body '}' |
Chris Lattner | a523517 | 2007-08-25 06:57:03 +0000 | [diff] [blame] | 39 | /// |
| 40 | /// named-namespace-definition: |
| 41 | /// original-namespace-definition |
| 42 | /// extension-namespace-definition |
| 43 | /// |
| 44 | /// original-namespace-definition: |
Sebastian Redl | 6766794 | 2010-08-27 23:12:46 +0000 | [diff] [blame] | 45 | /// 'inline'[opt] 'namespace' identifier attributes[opt] |
| 46 | /// '{' namespace-body '}' |
Chris Lattner | a523517 | 2007-08-25 06:57:03 +0000 | [diff] [blame] | 47 | /// |
| 48 | /// extension-namespace-definition: |
Sebastian Redl | 6766794 | 2010-08-27 23:12:46 +0000 | [diff] [blame] | 49 | /// 'inline'[opt] 'namespace' original-namespace-name |
| 50 | /// '{' namespace-body '}' |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 51 | /// |
Chris Lattner | a523517 | 2007-08-25 06:57:03 +0000 | [diff] [blame] | 52 | /// namespace-alias-definition: [C++ 7.3.2: namespace.alias] |
| 53 | /// 'namespace' identifier '=' qualified-namespace-specifier ';' |
| 54 | /// |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 55 | Decl *Parser::ParseNamespace(unsigned Context, |
Sebastian Redl | 6766794 | 2010-08-27 23:12:46 +0000 | [diff] [blame] | 56 | SourceLocation &DeclEnd, |
| 57 | SourceLocation InlineLoc) { |
Chris Lattner | 76c7228 | 2007-10-09 17:33:22 +0000 | [diff] [blame] | 58 | assert(Tok.is(tok::kw_namespace) && "Not a namespace!"); |
Chris Lattner | a523517 | 2007-08-25 06:57:03 +0000 | [diff] [blame] | 59 | SourceLocation NamespaceLoc = ConsumeToken(); // eat the 'namespace'. |
Fariborz Jahanian | 4bf8262 | 2011-08-22 17:59:19 +0000 | [diff] [blame] | 60 | ObjCDeclContextSwitch ObjCDC(*this); |
Fariborz Jahanian | 8d382dc | 2011-08-22 15:54:49 +0000 | [diff] [blame] | 61 | |
Douglas Gregor | 7e90c6d | 2009-09-18 19:03:04 +0000 | [diff] [blame] | 62 | if (Tok.is(tok::code_completion)) { |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 63 | Actions.CodeCompleteNamespaceDecl(getCurScope()); |
Argyrios Kyrtzidis | 5cec2ae | 2011-09-04 03:32:15 +0000 | [diff] [blame] | 64 | cutOffParsing(); |
| 65 | return 0; |
Douglas Gregor | 7e90c6d | 2009-09-18 19:03:04 +0000 | [diff] [blame] | 66 | } |
Kovarththanan Rajaratnam | ba2c652 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 67 | |
Chris Lattner | a523517 | 2007-08-25 06:57:03 +0000 | [diff] [blame] | 68 | SourceLocation IdentLoc; |
| 69 | IdentifierInfo *Ident = 0; |
Richard Trieu | 61384cb | 2011-05-26 20:11:09 +0000 | [diff] [blame] | 70 | std::vector<SourceLocation> ExtraIdentLoc; |
| 71 | std::vector<IdentifierInfo*> ExtraIdent; |
| 72 | std::vector<SourceLocation> ExtraNamespaceLoc; |
Douglas Gregor | 6b6bba4 | 2009-06-17 19:49:00 +0000 | [diff] [blame] | 73 | |
| 74 | Token attrTok; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 75 | |
Chris Lattner | 76c7228 | 2007-10-09 17:33:22 +0000 | [diff] [blame] | 76 | if (Tok.is(tok::identifier)) { |
Chris Lattner | a523517 | 2007-08-25 06:57:03 +0000 | [diff] [blame] | 77 | Ident = Tok.getIdentifierInfo(); |
| 78 | IdentLoc = ConsumeToken(); // eat the identifier. |
Richard Trieu | 61384cb | 2011-05-26 20:11:09 +0000 | [diff] [blame] | 79 | while (Tok.is(tok::coloncolon) && NextToken().is(tok::identifier)) { |
| 80 | ExtraNamespaceLoc.push_back(ConsumeToken()); |
| 81 | ExtraIdent.push_back(Tok.getIdentifierInfo()); |
| 82 | ExtraIdentLoc.push_back(ConsumeToken()); |
| 83 | } |
Chris Lattner | a523517 | 2007-08-25 06:57:03 +0000 | [diff] [blame] | 84 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 85 | |
Chris Lattner | a523517 | 2007-08-25 06:57:03 +0000 | [diff] [blame] | 86 | // Read label attributes, if present. |
John McCall | 084e83d | 2011-03-24 11:26:52 +0000 | [diff] [blame] | 87 | ParsedAttributes attrs(AttrFactory); |
Douglas Gregor | 6b6bba4 | 2009-06-17 19:49:00 +0000 | [diff] [blame] | 88 | if (Tok.is(tok::kw___attribute)) { |
| 89 | attrTok = Tok; |
John McCall | 53fa714 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 90 | ParseGNUAttributes(attrs); |
Douglas Gregor | 6b6bba4 | 2009-06-17 19:49:00 +0000 | [diff] [blame] | 91 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 92 | |
Douglas Gregor | 6b6bba4 | 2009-06-17 19:49:00 +0000 | [diff] [blame] | 93 | if (Tok.is(tok::equal)) { |
Nico Weber | 729f1e2 | 2012-10-27 23:44:27 +0000 | [diff] [blame] | 94 | if (Ident == 0) { |
Alp Toker | ec54327 | 2013-12-24 09:48:30 +0000 | [diff] [blame] | 95 | Diag(Tok, diag::err_expected) << tok::identifier; |
Nico Weber | 729f1e2 | 2012-10-27 23:44:27 +0000 | [diff] [blame] | 96 | // Skip to end of the definition and eat the ';'. |
| 97 | SkipUntil(tok::semi); |
| 98 | return 0; |
| 99 | } |
John McCall | 53fa714 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 100 | if (!attrs.empty()) |
Douglas Gregor | 6b6bba4 | 2009-06-17 19:49:00 +0000 | [diff] [blame] | 101 | Diag(attrTok, diag::err_unexpected_namespace_attributes_alias); |
Sebastian Redl | 6766794 | 2010-08-27 23:12:46 +0000 | [diff] [blame] | 102 | if (InlineLoc.isValid()) |
| 103 | Diag(InlineLoc, diag::err_inline_namespace_alias) |
| 104 | << FixItHint::CreateRemoval(InlineLoc); |
Fariborz Jahanian | 4bf8262 | 2011-08-22 17:59:19 +0000 | [diff] [blame] | 105 | return ParseNamespaceAlias(NamespaceLoc, IdentLoc, Ident, DeclEnd); |
Douglas Gregor | 6b6bba4 | 2009-06-17 19:49:00 +0000 | [diff] [blame] | 106 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 107 | |
Richard Trieu | 61384cb | 2011-05-26 20:11:09 +0000 | [diff] [blame] | 108 | |
Douglas Gregor | e7a8e3b | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 109 | BalancedDelimiterTracker T(*this, tok::l_brace); |
| 110 | if (T.consumeOpen()) { |
Richard Trieu | 61384cb | 2011-05-26 20:11:09 +0000 | [diff] [blame] | 111 | if (!ExtraIdent.empty()) { |
| 112 | Diag(ExtraNamespaceLoc[0], diag::err_nested_namespaces_with_double_colon) |
| 113 | << SourceRange(ExtraNamespaceLoc.front(), ExtraIdentLoc.back()); |
| 114 | } |
Alp Toker | ec54327 | 2013-12-24 09:48:30 +0000 | [diff] [blame] | 115 | |
| 116 | if (Ident) |
| 117 | Diag(Tok, diag::err_expected) << tok::l_brace; |
| 118 | else |
| 119 | Diag(Tok, diag::err_expected_either) << tok::identifier << tok::l_brace; |
| 120 | |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 121 | return 0; |
Chris Lattner | a523517 | 2007-08-25 06:57:03 +0000 | [diff] [blame] | 122 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 123 | |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 124 | if (getCurScope()->isClassScope() || getCurScope()->isTemplateParamScope() || |
| 125 | getCurScope()->isInObjcMethodScope() || getCurScope()->getBlockParent() || |
| 126 | getCurScope()->getFnParent()) { |
Richard Trieu | 61384cb | 2011-05-26 20:11:09 +0000 | [diff] [blame] | 127 | if (!ExtraIdent.empty()) { |
| 128 | Diag(ExtraNamespaceLoc[0], diag::err_nested_namespaces_with_double_colon) |
| 129 | << SourceRange(ExtraNamespaceLoc.front(), ExtraIdentLoc.back()); |
| 130 | } |
Douglas Gregor | e7a8e3b | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 131 | Diag(T.getOpenLocation(), diag::err_namespace_nonnamespace_scope); |
Alexey Bataev | ee6507d | 2013-11-18 08:17:37 +0000 | [diff] [blame] | 132 | SkipUntil(tok::r_brace); |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 133 | return 0; |
Douglas Gregor | 05cfc29 | 2010-05-14 05:08:22 +0000 | [diff] [blame] | 134 | } |
| 135 | |
Richard Trieu | 61384cb | 2011-05-26 20:11:09 +0000 | [diff] [blame] | 136 | if (!ExtraIdent.empty()) { |
| 137 | TentativeParsingAction TPA(*this); |
Alexey Bataev | ee6507d | 2013-11-18 08:17:37 +0000 | [diff] [blame] | 138 | SkipUntil(tok::r_brace, StopBeforeMatch); |
Richard Trieu | 61384cb | 2011-05-26 20:11:09 +0000 | [diff] [blame] | 139 | Token rBraceToken = Tok; |
| 140 | TPA.Revert(); |
| 141 | |
| 142 | if (!rBraceToken.is(tok::r_brace)) { |
| 143 | Diag(ExtraNamespaceLoc[0], diag::err_nested_namespaces_with_double_colon) |
| 144 | << SourceRange(ExtraNamespaceLoc.front(), ExtraIdentLoc.back()); |
| 145 | } else { |
Benjamin Kramer | f546f41 | 2011-05-26 21:32:30 +0000 | [diff] [blame] | 146 | std::string NamespaceFix; |
Richard Trieu | 61384cb | 2011-05-26 20:11:09 +0000 | [diff] [blame] | 147 | for (std::vector<IdentifierInfo*>::iterator I = ExtraIdent.begin(), |
| 148 | E = ExtraIdent.end(); I != E; ++I) { |
| 149 | NamespaceFix += " { namespace "; |
| 150 | NamespaceFix += (*I)->getName(); |
| 151 | } |
Benjamin Kramer | f546f41 | 2011-05-26 21:32:30 +0000 | [diff] [blame] | 152 | |
Richard Trieu | 61384cb | 2011-05-26 20:11:09 +0000 | [diff] [blame] | 153 | std::string RBraces; |
Benjamin Kramer | f546f41 | 2011-05-26 21:32:30 +0000 | [diff] [blame] | 154 | for (unsigned i = 0, e = ExtraIdent.size(); i != e; ++i) |
Richard Trieu | 61384cb | 2011-05-26 20:11:09 +0000 | [diff] [blame] | 155 | RBraces += "} "; |
Benjamin Kramer | f546f41 | 2011-05-26 21:32:30 +0000 | [diff] [blame] | 156 | |
Richard Trieu | 61384cb | 2011-05-26 20:11:09 +0000 | [diff] [blame] | 157 | Diag(ExtraNamespaceLoc[0], diag::err_nested_namespaces_with_double_colon) |
| 158 | << FixItHint::CreateReplacement(SourceRange(ExtraNamespaceLoc.front(), |
| 159 | ExtraIdentLoc.back()), |
| 160 | NamespaceFix) |
| 161 | << FixItHint::CreateInsertion(rBraceToken.getLocation(), RBraces); |
| 162 | } |
| 163 | } |
| 164 | |
Sebastian Redl | 5a5f2c7 | 2010-08-31 00:36:45 +0000 | [diff] [blame] | 165 | // If we're still good, complain about inline namespaces in non-C++0x now. |
Richard Smith | 5d164bc | 2011-10-15 05:09:34 +0000 | [diff] [blame] | 166 | if (InlineLoc.isValid()) |
Richard Smith | 2bf7fdb | 2013-01-02 11:42:31 +0000 | [diff] [blame] | 167 | Diag(InlineLoc, getLangOpts().CPlusPlus11 ? |
Richard Smith | 5d164bc | 2011-10-15 05:09:34 +0000 | [diff] [blame] | 168 | diag::warn_cxx98_compat_inline_namespace : diag::ext_inline_namespace); |
Sebastian Redl | 5a5f2c7 | 2010-08-31 00:36:45 +0000 | [diff] [blame] | 169 | |
Chris Lattner | 4de55aa | 2009-03-29 14:02:43 +0000 | [diff] [blame] | 170 | // Enter a scope for the namespace. |
| 171 | ParseScope NamespaceScope(this, Scope::DeclScope); |
| 172 | |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 173 | Decl *NamespcDecl = |
Abramo Bagnara | b5545be | 2011-03-08 12:38:20 +0000 | [diff] [blame] | 174 | Actions.ActOnStartNamespaceDef(getCurScope(), InlineLoc, NamespaceLoc, |
Douglas Gregor | e7a8e3b | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 175 | IdentLoc, Ident, T.getOpenLocation(), |
| 176 | attrs.getList()); |
Chris Lattner | 4de55aa | 2009-03-29 14:02:43 +0000 | [diff] [blame] | 177 | |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 178 | PrettyDeclStackTraceEntry CrashInfo(Actions, NamespcDecl, NamespaceLoc, |
| 179 | "parsing namespace"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 180 | |
Richard Trieu | 61384cb | 2011-05-26 20:11:09 +0000 | [diff] [blame] | 181 | // Parse the contents of the namespace. This includes parsing recovery on |
| 182 | // any improperly nested namespaces. |
| 183 | ParseInnerNamespace(ExtraIdentLoc, ExtraIdent, ExtraNamespaceLoc, 0, |
Douglas Gregor | e7a8e3b | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 184 | InlineLoc, attrs, T); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 185 | |
Chris Lattner | 4de55aa | 2009-03-29 14:02:43 +0000 | [diff] [blame] | 186 | // Leave the namespace scope. |
| 187 | NamespaceScope.Exit(); |
| 188 | |
Douglas Gregor | e7a8e3b | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 189 | DeclEnd = T.getCloseLocation(); |
| 190 | Actions.ActOnFinishNamespaceDef(NamespcDecl, DeclEnd); |
Chris Lattner | 4de55aa | 2009-03-29 14:02:43 +0000 | [diff] [blame] | 191 | |
| 192 | return NamespcDecl; |
Chris Lattner | a523517 | 2007-08-25 06:57:03 +0000 | [diff] [blame] | 193 | } |
Chris Lattner | 38376f1 | 2008-01-12 07:05:38 +0000 | [diff] [blame] | 194 | |
Richard Trieu | 61384cb | 2011-05-26 20:11:09 +0000 | [diff] [blame] | 195 | /// ParseInnerNamespace - Parse the contents of a namespace. |
| 196 | void Parser::ParseInnerNamespace(std::vector<SourceLocation>& IdentLoc, |
| 197 | std::vector<IdentifierInfo*>& Ident, |
| 198 | std::vector<SourceLocation>& NamespaceLoc, |
| 199 | unsigned int index, SourceLocation& InlineLoc, |
Richard Trieu | 61384cb | 2011-05-26 20:11:09 +0000 | [diff] [blame] | 200 | ParsedAttributes& attrs, |
Douglas Gregor | e7a8e3b | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 201 | BalancedDelimiterTracker &Tracker) { |
Richard Trieu | 61384cb | 2011-05-26 20:11:09 +0000 | [diff] [blame] | 202 | if (index == Ident.size()) { |
Richard Smith | 34f3051 | 2013-11-23 04:06:09 +0000 | [diff] [blame] | 203 | while (Tok.isNot(tok::r_brace) && !isEofOrEom()) { |
Richard Trieu | 61384cb | 2011-05-26 20:11:09 +0000 | [diff] [blame] | 204 | ParsedAttributesWithRange attrs(AttrFactory); |
Richard Smith | 89645bc | 2013-01-02 12:01:23 +0000 | [diff] [blame] | 205 | MaybeParseCXX11Attributes(attrs); |
Richard Trieu | 61384cb | 2011-05-26 20:11:09 +0000 | [diff] [blame] | 206 | MaybeParseMicrosoftAttributes(attrs); |
| 207 | ParseExternalDeclaration(attrs); |
| 208 | } |
Douglas Gregor | e7a8e3b | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 209 | |
| 210 | // The caller is what called check -- we are simply calling |
| 211 | // the close for it. |
| 212 | Tracker.consumeClose(); |
Richard Trieu | 61384cb | 2011-05-26 20:11:09 +0000 | [diff] [blame] | 213 | |
| 214 | return; |
| 215 | } |
| 216 | |
| 217 | // Parse improperly nested namespaces. |
| 218 | ParseScope NamespaceScope(this, Scope::DeclScope); |
| 219 | Decl *NamespcDecl = |
| 220 | Actions.ActOnStartNamespaceDef(getCurScope(), SourceLocation(), |
| 221 | NamespaceLoc[index], IdentLoc[index], |
Douglas Gregor | e7a8e3b | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 222 | Ident[index], Tracker.getOpenLocation(), |
| 223 | attrs.getList()); |
Richard Trieu | 61384cb | 2011-05-26 20:11:09 +0000 | [diff] [blame] | 224 | |
| 225 | ParseInnerNamespace(IdentLoc, Ident, NamespaceLoc, ++index, InlineLoc, |
Douglas Gregor | e7a8e3b | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 226 | attrs, Tracker); |
Richard Trieu | 61384cb | 2011-05-26 20:11:09 +0000 | [diff] [blame] | 227 | |
| 228 | NamespaceScope.Exit(); |
| 229 | |
Douglas Gregor | e7a8e3b | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 230 | Actions.ActOnFinishNamespaceDef(NamespcDecl, Tracker.getCloseLocation()); |
Richard Trieu | 61384cb | 2011-05-26 20:11:09 +0000 | [diff] [blame] | 231 | } |
| 232 | |
Anders Carlsson | 1894f0d4 | 2009-03-28 04:07:16 +0000 | [diff] [blame] | 233 | /// ParseNamespaceAlias - Parse the part after the '=' in a namespace |
| 234 | /// alias definition. |
| 235 | /// |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 236 | Decl *Parser::ParseNamespaceAlias(SourceLocation NamespaceLoc, |
John McCall | 084e83d | 2011-03-24 11:26:52 +0000 | [diff] [blame] | 237 | SourceLocation AliasLoc, |
| 238 | IdentifierInfo *Alias, |
| 239 | SourceLocation &DeclEnd) { |
Anders Carlsson | 1894f0d4 | 2009-03-28 04:07:16 +0000 | [diff] [blame] | 240 | assert(Tok.is(tok::equal) && "Not equal token"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 241 | |
Anders Carlsson | 1894f0d4 | 2009-03-28 04:07:16 +0000 | [diff] [blame] | 242 | ConsumeToken(); // eat the '='. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 243 | |
Douglas Gregor | 7e90c6d | 2009-09-18 19:03:04 +0000 | [diff] [blame] | 244 | if (Tok.is(tok::code_completion)) { |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 245 | Actions.CodeCompleteNamespaceAliasDecl(getCurScope()); |
Argyrios Kyrtzidis | 5cec2ae | 2011-09-04 03:32:15 +0000 | [diff] [blame] | 246 | cutOffParsing(); |
| 247 | return 0; |
Douglas Gregor | 7e90c6d | 2009-09-18 19:03:04 +0000 | [diff] [blame] | 248 | } |
Kovarththanan Rajaratnam | ba2c652 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 249 | |
Anders Carlsson | 1894f0d4 | 2009-03-28 04:07:16 +0000 | [diff] [blame] | 250 | CXXScopeSpec SS; |
| 251 | // Parse (optional) nested-name-specifier. |
Douglas Gregor | df593fb | 2011-11-07 17:33:42 +0000 | [diff] [blame] | 252 | ParseOptionalCXXScopeSpecifier(SS, ParsedType(), /*EnteringContext=*/false); |
Anders Carlsson | 1894f0d4 | 2009-03-28 04:07:16 +0000 | [diff] [blame] | 253 | |
| 254 | if (SS.isInvalid() || Tok.isNot(tok::identifier)) { |
| 255 | Diag(Tok, diag::err_expected_namespace_name); |
| 256 | // Skip to end of the definition and eat the ';'. |
| 257 | SkipUntil(tok::semi); |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 258 | return 0; |
Anders Carlsson | 1894f0d4 | 2009-03-28 04:07:16 +0000 | [diff] [blame] | 259 | } |
| 260 | |
| 261 | // Parse identifier. |
Anders Carlsson | 47952ae | 2009-03-28 22:53:22 +0000 | [diff] [blame] | 262 | IdentifierInfo *Ident = Tok.getIdentifierInfo(); |
| 263 | SourceLocation IdentLoc = ConsumeToken(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 264 | |
Anders Carlsson | 1894f0d4 | 2009-03-28 04:07:16 +0000 | [diff] [blame] | 265 | // Eat the ';'. |
Chris Lattner | 49836b4 | 2009-04-02 04:16:50 +0000 | [diff] [blame] | 266 | DeclEnd = Tok.getLocation(); |
Alp Toker | 383d2c4 | 2014-01-01 03:08:43 +0000 | [diff] [blame] | 267 | if (ExpectAndConsume(tok::semi, diag::err_expected_semi_after_namespace_name)) |
| 268 | SkipUntil(tok::semi); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 269 | |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 270 | return Actions.ActOnNamespaceAliasDef(getCurScope(), NamespaceLoc, AliasLoc, Alias, |
Anders Carlsson | 47952ae | 2009-03-28 22:53:22 +0000 | [diff] [blame] | 271 | SS, IdentLoc, Ident); |
Anders Carlsson | 1894f0d4 | 2009-03-28 04:07:16 +0000 | [diff] [blame] | 272 | } |
| 273 | |
Chris Lattner | 38376f1 | 2008-01-12 07:05:38 +0000 | [diff] [blame] | 274 | /// ParseLinkage - We know that the current token is a string_literal |
| 275 | /// and just before that, that extern was seen. |
| 276 | /// |
| 277 | /// linkage-specification: [C++ 7.5p2: dcl.link] |
| 278 | /// 'extern' string-literal '{' declaration-seq[opt] '}' |
| 279 | /// 'extern' string-literal declaration |
| 280 | /// |
Chris Lattner | 8ea6442 | 2010-11-09 20:15:55 +0000 | [diff] [blame] | 281 | Decl *Parser::ParseLinkage(ParsingDeclSpec &DS, unsigned Context) { |
Richard Smith | 4ee696d | 2014-02-17 23:25:27 +0000 | [diff] [blame^] | 282 | assert(isTokenStringLiteral() && "Not a string literal!"); |
| 283 | ExprResult Lang = ParseStringLiteralExpression(false); |
Chris Lattner | 38376f1 | 2008-01-12 07:05:38 +0000 | [diff] [blame] | 284 | |
Douglas Gregor | 07665a6 | 2009-01-05 19:45:36 +0000 | [diff] [blame] | 285 | ParseScope LinkageScope(this, Scope::DeclScope); |
Richard Smith | 4ee696d | 2014-02-17 23:25:27 +0000 | [diff] [blame^] | 286 | Decl *LinkageSpec = |
| 287 | Lang.isInvalid() |
| 288 | ? 0 |
| 289 | : Actions.ActOnStartLinkageSpecification( |
| 290 | getCurScope(), DS.getSourceRange().getBegin(), Lang.take(), |
| 291 | Tok.is(tok::l_brace) ? Tok.getLocation() : SourceLocation()); |
Douglas Gregor | 07665a6 | 2009-01-05 19:45:36 +0000 | [diff] [blame] | 292 | |
John McCall | 084e83d | 2011-03-24 11:26:52 +0000 | [diff] [blame] | 293 | ParsedAttributesWithRange attrs(AttrFactory); |
Richard Smith | 89645bc | 2013-01-02 12:01:23 +0000 | [diff] [blame] | 294 | MaybeParseCXX11Attributes(attrs); |
John McCall | 53fa714 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 295 | MaybeParseMicrosoftAttributes(attrs); |
Kovarththanan Rajaratnam | ba2c652 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 296 | |
Douglas Gregor | 07665a6 | 2009-01-05 19:45:36 +0000 | [diff] [blame] | 297 | if (Tok.isNot(tok::l_brace)) { |
Abramo Bagnara | 4d42399 | 2011-05-01 16:25:54 +0000 | [diff] [blame] | 298 | // Reset the source range in DS, as the leading "extern" |
| 299 | // does not really belong to the inner declaration ... |
| 300 | DS.SetRangeStart(SourceLocation()); |
| 301 | DS.SetRangeEnd(SourceLocation()); |
| 302 | // ... but anyway remember that such an "extern" was seen. |
Abramo Bagnara | ed5b689 | 2010-07-30 16:47:02 +0000 | [diff] [blame] | 303 | DS.setExternInLinkageSpec(true); |
John McCall | 53fa714 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 304 | ParseExternalDeclaration(attrs, &DS); |
Richard Smith | 4ee696d | 2014-02-17 23:25:27 +0000 | [diff] [blame^] | 305 | return LinkageSpec ? Actions.ActOnFinishLinkageSpecification( |
| 306 | getCurScope(), LinkageSpec, SourceLocation()) |
| 307 | : 0; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 308 | } |
Douglas Gregor | 29ff7d0 | 2008-12-16 22:23:02 +0000 | [diff] [blame] | 309 | |
Douglas Gregor | b65a913 | 2010-02-07 08:38:28 +0000 | [diff] [blame] | 310 | DS.abort(); |
| 311 | |
John McCall | 53fa714 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 312 | ProhibitAttributes(attrs); |
Alexis Hunt | 96d5c76 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 313 | |
Douglas Gregor | e7a8e3b | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 314 | BalancedDelimiterTracker T(*this, tok::l_brace); |
| 315 | T.consumeOpen(); |
Richard Smith | 34f3051 | 2013-11-23 04:06:09 +0000 | [diff] [blame] | 316 | while (Tok.isNot(tok::r_brace) && !isEofOrEom()) { |
John McCall | 084e83d | 2011-03-24 11:26:52 +0000 | [diff] [blame] | 317 | ParsedAttributesWithRange attrs(AttrFactory); |
Richard Smith | 89645bc | 2013-01-02 12:01:23 +0000 | [diff] [blame] | 318 | MaybeParseCXX11Attributes(attrs); |
John McCall | 53fa714 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 319 | MaybeParseMicrosoftAttributes(attrs); |
| 320 | ParseExternalDeclaration(attrs); |
Chris Lattner | 38376f1 | 2008-01-12 07:05:38 +0000 | [diff] [blame] | 321 | } |
| 322 | |
Douglas Gregor | e7a8e3b | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 323 | T.consumeClose(); |
Richard Smith | 4ee696d | 2014-02-17 23:25:27 +0000 | [diff] [blame^] | 324 | return LinkageSpec ? Actions.ActOnFinishLinkageSpecification( |
| 325 | getCurScope(), LinkageSpec, T.getCloseLocation()) |
| 326 | : 0; |
Chris Lattner | 38376f1 | 2008-01-12 07:05:38 +0000 | [diff] [blame] | 327 | } |
Douglas Gregor | 556877c | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 328 | |
Douglas Gregor | d7c4d98 | 2008-12-30 03:27:21 +0000 | [diff] [blame] | 329 | /// ParseUsingDirectiveOrDeclaration - Parse C++ using using-declaration or |
| 330 | /// using-directive. Assumes that current token is 'using'. |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 331 | Decl *Parser::ParseUsingDirectiveOrDeclaration(unsigned Context, |
John McCall | 9b72f89 | 2010-11-10 02:40:36 +0000 | [diff] [blame] | 332 | const ParsedTemplateInfo &TemplateInfo, |
| 333 | SourceLocation &DeclEnd, |
Richard Smith | cd1c055 | 2011-07-01 19:46:12 +0000 | [diff] [blame] | 334 | ParsedAttributesWithRange &attrs, |
| 335 | Decl **OwnedType) { |
Douglas Gregor | d7c4d98 | 2008-12-30 03:27:21 +0000 | [diff] [blame] | 336 | assert(Tok.is(tok::kw_using) && "Not using token"); |
Fariborz Jahanian | 4bf8262 | 2011-08-22 17:59:19 +0000 | [diff] [blame] | 337 | ObjCDeclContextSwitch ObjCDC(*this); |
| 338 | |
Douglas Gregor | d7c4d98 | 2008-12-30 03:27:21 +0000 | [diff] [blame] | 339 | // Eat 'using'. |
| 340 | SourceLocation UsingLoc = ConsumeToken(); |
| 341 | |
Douglas Gregor | 7e90c6d | 2009-09-18 19:03:04 +0000 | [diff] [blame] | 342 | if (Tok.is(tok::code_completion)) { |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 343 | Actions.CodeCompleteUsing(getCurScope()); |
Argyrios Kyrtzidis | 5cec2ae | 2011-09-04 03:32:15 +0000 | [diff] [blame] | 344 | cutOffParsing(); |
| 345 | return 0; |
Douglas Gregor | 7e90c6d | 2009-09-18 19:03:04 +0000 | [diff] [blame] | 346 | } |
Kovarththanan Rajaratnam | ba2c652 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 347 | |
John McCall | 9b72f89 | 2010-11-10 02:40:36 +0000 | [diff] [blame] | 348 | // 'using namespace' means this is a using-directive. |
| 349 | if (Tok.is(tok::kw_namespace)) { |
| 350 | // Template parameters are always an error here. |
| 351 | if (TemplateInfo.Kind) { |
| 352 | SourceRange R = TemplateInfo.getSourceRange(); |
| 353 | Diag(UsingLoc, diag::err_templated_using_directive) |
| 354 | << R << FixItHint::CreateRemoval(R); |
| 355 | } |
Alexis Hunt | 96d5c76 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 356 | |
Fariborz Jahanian | 4bf8262 | 2011-08-22 17:59:19 +0000 | [diff] [blame] | 357 | return ParseUsingDirective(Context, UsingLoc, DeclEnd, attrs); |
John McCall | 9b72f89 | 2010-11-10 02:40:36 +0000 | [diff] [blame] | 358 | } |
| 359 | |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 360 | // Otherwise, it must be a using-declaration or an alias-declaration. |
John McCall | 9b72f89 | 2010-11-10 02:40:36 +0000 | [diff] [blame] | 361 | |
| 362 | // Using declarations can't have attributes. |
John McCall | 53fa714 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 363 | ProhibitAttributes(attrs); |
Chris Lattner | 9b01ca1 | 2009-01-06 06:55:51 +0000 | [diff] [blame] | 364 | |
Fariborz Jahanian | 4bf8262 | 2011-08-22 17:59:19 +0000 | [diff] [blame] | 365 | return ParseUsingDeclaration(Context, TemplateInfo, UsingLoc, DeclEnd, |
Fariborz Jahanian | 8d382dc | 2011-08-22 15:54:49 +0000 | [diff] [blame] | 366 | AS_none, OwnedType); |
Douglas Gregor | d7c4d98 | 2008-12-30 03:27:21 +0000 | [diff] [blame] | 367 | } |
| 368 | |
| 369 | /// ParseUsingDirective - Parse C++ using-directive, assumes |
| 370 | /// that current token is 'namespace' and 'using' was already parsed. |
| 371 | /// |
| 372 | /// using-directive: [C++ 7.3.p4: namespace.udir] |
| 373 | /// 'using' 'namespace' ::[opt] nested-name-specifier[opt] |
| 374 | /// namespace-name ; |
| 375 | /// [GNU] using-directive: |
| 376 | /// 'using' 'namespace' ::[opt] nested-name-specifier[opt] |
| 377 | /// namespace-name attributes[opt] ; |
| 378 | /// |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 379 | Decl *Parser::ParseUsingDirective(unsigned Context, |
John McCall | 9b72f89 | 2010-11-10 02:40:36 +0000 | [diff] [blame] | 380 | SourceLocation UsingLoc, |
| 381 | SourceLocation &DeclEnd, |
John McCall | 53fa714 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 382 | ParsedAttributes &attrs) { |
Douglas Gregor | d7c4d98 | 2008-12-30 03:27:21 +0000 | [diff] [blame] | 383 | assert(Tok.is(tok::kw_namespace) && "Not 'namespace' token"); |
| 384 | |
| 385 | // Eat 'namespace'. |
| 386 | SourceLocation NamespcLoc = ConsumeToken(); |
| 387 | |
Douglas Gregor | 7e90c6d | 2009-09-18 19:03:04 +0000 | [diff] [blame] | 388 | if (Tok.is(tok::code_completion)) { |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 389 | Actions.CodeCompleteUsingDirective(getCurScope()); |
Argyrios Kyrtzidis | 5cec2ae | 2011-09-04 03:32:15 +0000 | [diff] [blame] | 390 | cutOffParsing(); |
| 391 | return 0; |
Douglas Gregor | 7e90c6d | 2009-09-18 19:03:04 +0000 | [diff] [blame] | 392 | } |
Kovarththanan Rajaratnam | ba2c652 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 393 | |
Douglas Gregor | d7c4d98 | 2008-12-30 03:27:21 +0000 | [diff] [blame] | 394 | CXXScopeSpec SS; |
| 395 | // Parse (optional) nested-name-specifier. |
Douglas Gregor | df593fb | 2011-11-07 17:33:42 +0000 | [diff] [blame] | 396 | ParseOptionalCXXScopeSpecifier(SS, ParsedType(), /*EnteringContext=*/false); |
Douglas Gregor | d7c4d98 | 2008-12-30 03:27:21 +0000 | [diff] [blame] | 397 | |
Douglas Gregor | d7c4d98 | 2008-12-30 03:27:21 +0000 | [diff] [blame] | 398 | IdentifierInfo *NamespcName = 0; |
| 399 | SourceLocation IdentLoc = SourceLocation(); |
| 400 | |
| 401 | // Parse namespace-name. |
Chris Lattner | ce1da2c | 2009-01-06 07:27:21 +0000 | [diff] [blame] | 402 | if (SS.isInvalid() || Tok.isNot(tok::identifier)) { |
Douglas Gregor | d7c4d98 | 2008-12-30 03:27:21 +0000 | [diff] [blame] | 403 | Diag(Tok, diag::err_expected_namespace_name); |
| 404 | // If there was invalid namespace name, skip to end of decl, and eat ';'. |
| 405 | SkipUntil(tok::semi); |
| 406 | // FIXME: Are there cases, when we would like to call ActOnUsingDirective? |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 407 | return 0; |
Douglas Gregor | d7c4d98 | 2008-12-30 03:27:21 +0000 | [diff] [blame] | 408 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 409 | |
Chris Lattner | ce1da2c | 2009-01-06 07:27:21 +0000 | [diff] [blame] | 410 | // Parse identifier. |
| 411 | NamespcName = Tok.getIdentifierInfo(); |
| 412 | IdentLoc = ConsumeToken(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 413 | |
Chris Lattner | ce1da2c | 2009-01-06 07:27:21 +0000 | [diff] [blame] | 414 | // Parse (optional) attributes (most likely GNU strong-using extension). |
Alexis Hunt | 96d5c76 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 415 | bool GNUAttr = false; |
| 416 | if (Tok.is(tok::kw___attribute)) { |
| 417 | GNUAttr = true; |
John McCall | 53fa714 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 418 | ParseGNUAttributes(attrs); |
Alexis Hunt | 96d5c76 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 419 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 420 | |
Chris Lattner | ce1da2c | 2009-01-06 07:27:21 +0000 | [diff] [blame] | 421 | // Eat ';'. |
Chris Lattner | 49836b4 | 2009-04-02 04:16:50 +0000 | [diff] [blame] | 422 | DeclEnd = Tok.getLocation(); |
Alp Toker | 383d2c4 | 2014-01-01 03:08:43 +0000 | [diff] [blame] | 423 | if (ExpectAndConsume(tok::semi, |
| 424 | GNUAttr ? diag::err_expected_semi_after_attribute_list |
| 425 | : diag::err_expected_semi_after_namespace_name)) |
| 426 | SkipUntil(tok::semi); |
Douglas Gregor | d7c4d98 | 2008-12-30 03:27:21 +0000 | [diff] [blame] | 427 | |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 428 | return Actions.ActOnUsingDirective(getCurScope(), UsingLoc, NamespcLoc, SS, |
John McCall | 53fa714 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 429 | IdentLoc, NamespcName, attrs.getList()); |
Douglas Gregor | d7c4d98 | 2008-12-30 03:27:21 +0000 | [diff] [blame] | 430 | } |
| 431 | |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 432 | /// ParseUsingDeclaration - Parse C++ using-declaration or alias-declaration. |
| 433 | /// Assumes that 'using' was already seen. |
Douglas Gregor | d7c4d98 | 2008-12-30 03:27:21 +0000 | [diff] [blame] | 434 | /// |
| 435 | /// using-declaration: [C++ 7.3.p3: namespace.udecl] |
| 436 | /// 'using' 'typename'[opt] ::[opt] nested-name-specifier |
Douglas Gregor | fec5263 | 2009-06-20 00:51:54 +0000 | [diff] [blame] | 437 | /// unqualified-id |
| 438 | /// 'using' :: unqualified-id |
Douglas Gregor | d7c4d98 | 2008-12-30 03:27:21 +0000 | [diff] [blame] | 439 | /// |
Richard Smith | 810ad3e | 2013-01-29 10:02:16 +0000 | [diff] [blame] | 440 | /// alias-declaration: C++11 [dcl.dcl]p1 |
| 441 | /// 'using' identifier attribute-specifier-seq[opt] = type-id ; |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 442 | /// |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 443 | Decl *Parser::ParseUsingDeclaration(unsigned Context, |
John McCall | 9b72f89 | 2010-11-10 02:40:36 +0000 | [diff] [blame] | 444 | const ParsedTemplateInfo &TemplateInfo, |
| 445 | SourceLocation UsingLoc, |
| 446 | SourceLocation &DeclEnd, |
Richard Smith | cd1c055 | 2011-07-01 19:46:12 +0000 | [diff] [blame] | 447 | AccessSpecifier AS, |
| 448 | Decl **OwnedType) { |
Douglas Gregor | fec5263 | 2009-06-20 00:51:54 +0000 | [diff] [blame] | 449 | CXXScopeSpec SS; |
John McCall | e61f2ba | 2009-11-18 02:36:19 +0000 | [diff] [blame] | 450 | SourceLocation TypenameLoc; |
Enea Zaffanella | e05a3cf | 2013-07-22 10:54:09 +0000 | [diff] [blame] | 451 | bool HasTypenameKeyword = false; |
Alexis Hunt | 6aa9bee | 2012-06-23 05:07:58 +0000 | [diff] [blame] | 452 | |
Richard Smith | c2c8bb8 | 2013-10-15 01:34:54 +0000 | [diff] [blame] | 453 | // Check for misplaced attributes before the identifier in an |
| 454 | // alias-declaration. |
| 455 | ParsedAttributesWithRange MisplacedAttrs(AttrFactory); |
| 456 | MaybeParseCXX11Attributes(MisplacedAttrs); |
Douglas Gregor | fec5263 | 2009-06-20 00:51:54 +0000 | [diff] [blame] | 457 | |
| 458 | // Ignore optional 'typename'. |
Douglas Gregor | 220f427 | 2009-11-04 16:30:06 +0000 | [diff] [blame] | 459 | // FIXME: This is wrong; we should parse this as a typename-specifier. |
Alp Toker | 9765056 | 2014-01-10 11:19:30 +0000 | [diff] [blame] | 460 | if (TryConsumeToken(tok::kw_typename, TypenameLoc)) |
Enea Zaffanella | e05a3cf | 2013-07-22 10:54:09 +0000 | [diff] [blame] | 461 | HasTypenameKeyword = true; |
Douglas Gregor | fec5263 | 2009-06-20 00:51:54 +0000 | [diff] [blame] | 462 | |
| 463 | // Parse nested-name-specifier. |
Richard Smith | 7447af4 | 2013-03-26 01:15:19 +0000 | [diff] [blame] | 464 | IdentifierInfo *LastII = 0; |
| 465 | ParseOptionalCXXScopeSpecifier(SS, ParsedType(), /*EnteringContext=*/false, |
| 466 | /*MayBePseudoDtor=*/0, /*IsTypename=*/false, |
| 467 | /*LastII=*/&LastII); |
Douglas Gregor | fec5263 | 2009-06-20 00:51:54 +0000 | [diff] [blame] | 468 | |
Douglas Gregor | fec5263 | 2009-06-20 00:51:54 +0000 | [diff] [blame] | 469 | // Check nested-name specifier. |
| 470 | if (SS.isInvalid()) { |
| 471 | SkipUntil(tok::semi); |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 472 | return 0; |
Douglas Gregor | fec5263 | 2009-06-20 00:51:54 +0000 | [diff] [blame] | 473 | } |
Douglas Gregor | 220f427 | 2009-11-04 16:30:06 +0000 | [diff] [blame] | 474 | |
Richard Smith | 7447af4 | 2013-03-26 01:15:19 +0000 | [diff] [blame] | 475 | SourceLocation TemplateKWLoc; |
| 476 | UnqualifiedId Name; |
| 477 | |
Kovarththanan Rajaratnam | ba2c652 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 478 | // Parse the unqualified-id. We allow parsing of both constructor and |
Douglas Gregor | 220f427 | 2009-11-04 16:30:06 +0000 | [diff] [blame] | 479 | // destructor names and allow the action module to diagnose any semantic |
| 480 | // errors. |
Richard Smith | 7447af4 | 2013-03-26 01:15:19 +0000 | [diff] [blame] | 481 | // |
| 482 | // C++11 [class.qual]p2: |
| 483 | // [...] in a using-declaration that is a member-declaration, if the name |
| 484 | // specified after the nested-name-specifier is the same as the identifier |
| 485 | // or the simple-template-id's template-name in the last component of the |
| 486 | // nested-name-specifier, the name is [...] considered to name the |
| 487 | // constructor. |
| 488 | if (getLangOpts().CPlusPlus11 && Context == Declarator::MemberContext && |
| 489 | Tok.is(tok::identifier) && NextToken().is(tok::semi) && |
| 490 | SS.isNotEmpty() && LastII == Tok.getIdentifierInfo() && |
| 491 | !SS.getScopeRep()->getAsNamespace() && |
| 492 | !SS.getScopeRep()->getAsNamespaceAlias()) { |
| 493 | SourceLocation IdLoc = ConsumeToken(); |
| 494 | ParsedType Type = Actions.getInheritingConstructorName(SS, IdLoc, *LastII); |
| 495 | Name.setConstructorName(Type, IdLoc, IdLoc); |
| 496 | } else if (ParseUnqualifiedId(SS, /*EnteringContext=*/ false, |
| 497 | /*AllowDestructorName=*/ true, |
| 498 | /*AllowConstructorName=*/ true, ParsedType(), |
| 499 | TemplateKWLoc, Name)) { |
Douglas Gregor | fec5263 | 2009-06-20 00:51:54 +0000 | [diff] [blame] | 500 | SkipUntil(tok::semi); |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 501 | return 0; |
Douglas Gregor | fec5263 | 2009-06-20 00:51:54 +0000 | [diff] [blame] | 502 | } |
Kovarththanan Rajaratnam | ba2c652 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 503 | |
Richard Smith | c2c8bb8 | 2013-10-15 01:34:54 +0000 | [diff] [blame] | 504 | ParsedAttributesWithRange Attrs(AttrFactory); |
Richard Smith | 37a45dd | 2013-10-24 01:21:09 +0000 | [diff] [blame] | 505 | MaybeParseGNUAttributes(Attrs); |
Richard Smith | 54ecd98 | 2013-02-20 19:22:51 +0000 | [diff] [blame] | 506 | MaybeParseCXX11Attributes(Attrs); |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 507 | |
| 508 | // Maybe this is an alias-declaration. |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 509 | TypeResult TypeAlias; |
Richard Smith | c2c8bb8 | 2013-10-15 01:34:54 +0000 | [diff] [blame] | 510 | bool IsAliasDecl = Tok.is(tok::equal); |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 511 | if (IsAliasDecl) { |
Richard Smith | c2c8bb8 | 2013-10-15 01:34:54 +0000 | [diff] [blame] | 512 | // If we had any misplaced attributes from earlier, this is where they |
| 513 | // should have been written. |
| 514 | if (MisplacedAttrs.Range.isValid()) { |
| 515 | Diag(MisplacedAttrs.Range.getBegin(), diag::err_attributes_not_allowed) |
| 516 | << FixItHint::CreateInsertionFromRange( |
| 517 | Tok.getLocation(), |
| 518 | CharSourceRange::getTokenRange(MisplacedAttrs.Range)) |
| 519 | << FixItHint::CreateRemoval(MisplacedAttrs.Range); |
| 520 | Attrs.takeAllFrom(MisplacedAttrs); |
| 521 | } |
| 522 | |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 523 | ConsumeToken(); |
| 524 | |
Richard Smith | 2bf7fdb | 2013-01-02 11:42:31 +0000 | [diff] [blame] | 525 | Diag(Tok.getLocation(), getLangOpts().CPlusPlus11 ? |
Richard Smith | 5d164bc | 2011-10-15 05:09:34 +0000 | [diff] [blame] | 526 | diag::warn_cxx98_compat_alias_declaration : |
| 527 | diag::ext_alias_declaration); |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 528 | |
Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 529 | // Type alias templates cannot be specialized. |
| 530 | int SpecKind = -1; |
Richard Smith | 1403402 | 2011-05-05 22:36:10 +0000 | [diff] [blame] | 531 | if (TemplateInfo.Kind == ParsedTemplateInfo::Template && |
| 532 | Name.getKind() == UnqualifiedId::IK_TemplateId) |
Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 533 | SpecKind = 0; |
| 534 | if (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitSpecialization) |
| 535 | SpecKind = 1; |
| 536 | if (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation) |
| 537 | SpecKind = 2; |
| 538 | if (SpecKind != -1) { |
| 539 | SourceRange Range; |
| 540 | if (SpecKind == 0) |
| 541 | Range = SourceRange(Name.TemplateId->LAngleLoc, |
| 542 | Name.TemplateId->RAngleLoc); |
| 543 | else |
| 544 | Range = TemplateInfo.getSourceRange(); |
| 545 | Diag(Range.getBegin(), diag::err_alias_declaration_specialization) |
| 546 | << SpecKind << Range; |
| 547 | SkipUntil(tok::semi); |
| 548 | return 0; |
| 549 | } |
| 550 | |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 551 | // Name must be an identifier. |
| 552 | if (Name.getKind() != UnqualifiedId::IK_Identifier) { |
| 553 | Diag(Name.StartLocation, diag::err_alias_declaration_not_identifier); |
| 554 | // No removal fixit: can't recover from this. |
| 555 | SkipUntil(tok::semi); |
| 556 | return 0; |
Enea Zaffanella | e05a3cf | 2013-07-22 10:54:09 +0000 | [diff] [blame] | 557 | } else if (HasTypenameKeyword) |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 558 | Diag(TypenameLoc, diag::err_alias_declaration_not_identifier) |
| 559 | << FixItHint::CreateRemoval(SourceRange(TypenameLoc, |
| 560 | SS.isNotEmpty() ? SS.getEndLoc() : TypenameLoc)); |
| 561 | else if (SS.isNotEmpty()) |
| 562 | Diag(SS.getBeginLoc(), diag::err_alias_declaration_not_identifier) |
| 563 | << FixItHint::CreateRemoval(SS.getRange()); |
| 564 | |
Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 565 | TypeAlias = ParseTypeName(0, TemplateInfo.Kind ? |
| 566 | Declarator::AliasTemplateContext : |
Richard Smith | 54ecd98 | 2013-02-20 19:22:51 +0000 | [diff] [blame] | 567 | Declarator::AliasDeclContext, AS, OwnedType, |
| 568 | &Attrs); |
Alexis Hunt | 6aa9bee | 2012-06-23 05:07:58 +0000 | [diff] [blame] | 569 | } else { |
| 570 | // C++11 attributes are not allowed on a using-declaration, but GNU ones |
| 571 | // are. |
Richard Smith | c2c8bb8 | 2013-10-15 01:34:54 +0000 | [diff] [blame] | 572 | ProhibitAttributes(MisplacedAttrs); |
Richard Smith | 54ecd98 | 2013-02-20 19:22:51 +0000 | [diff] [blame] | 573 | ProhibitAttributes(Attrs); |
Alexis Hunt | 6aa9bee | 2012-06-23 05:07:58 +0000 | [diff] [blame] | 574 | |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 575 | // Parse (optional) attributes (most likely GNU strong-using extension). |
Richard Smith | 54ecd98 | 2013-02-20 19:22:51 +0000 | [diff] [blame] | 576 | MaybeParseGNUAttributes(Attrs); |
Alexis Hunt | 6aa9bee | 2012-06-23 05:07:58 +0000 | [diff] [blame] | 577 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 578 | |
Douglas Gregor | fec5263 | 2009-06-20 00:51:54 +0000 | [diff] [blame] | 579 | // Eat ';'. |
| 580 | DeclEnd = Tok.getLocation(); |
Alp Toker | 383d2c4 | 2014-01-01 03:08:43 +0000 | [diff] [blame] | 581 | if (ExpectAndConsume(tok::semi, diag::err_expected_after, |
| 582 | !Attrs.empty() ? "attributes list" |
| 583 | : IsAliasDecl ? "alias declaration" |
| 584 | : "using declaration")) |
| 585 | SkipUntil(tok::semi); |
Douglas Gregor | fec5263 | 2009-06-20 00:51:54 +0000 | [diff] [blame] | 586 | |
John McCall | 9b72f89 | 2010-11-10 02:40:36 +0000 | [diff] [blame] | 587 | // Diagnose an attempt to declare a templated using-declaration. |
Richard Smith | 810ad3e | 2013-01-29 10:02:16 +0000 | [diff] [blame] | 588 | // In C++11, alias-declarations can be templates: |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 589 | // template <...> using id = type; |
Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 590 | if (TemplateInfo.Kind && !IsAliasDecl) { |
John McCall | 9b72f89 | 2010-11-10 02:40:36 +0000 | [diff] [blame] | 591 | SourceRange R = TemplateInfo.getSourceRange(); |
| 592 | Diag(UsingLoc, diag::err_templated_using_declaration) |
| 593 | << R << FixItHint::CreateRemoval(R); |
| 594 | |
| 595 | // Unfortunately, we have to bail out instead of recovering by |
| 596 | // ignoring the parameters, just in case the nested name specifier |
| 597 | // depends on the parameters. |
| 598 | return 0; |
| 599 | } |
| 600 | |
Douglas Gregor | 882a61a | 2011-09-26 14:30:28 +0000 | [diff] [blame] | 601 | // "typename" keyword is allowed for identifiers only, |
| 602 | // because it may be a type definition. |
Enea Zaffanella | e05a3cf | 2013-07-22 10:54:09 +0000 | [diff] [blame] | 603 | if (HasTypenameKeyword && Name.getKind() != UnqualifiedId::IK_Identifier) { |
Douglas Gregor | 882a61a | 2011-09-26 14:30:28 +0000 | [diff] [blame] | 604 | Diag(Name.getSourceRange().getBegin(), diag::err_typename_identifiers_only) |
| 605 | << FixItHint::CreateRemoval(SourceRange(TypenameLoc)); |
Enea Zaffanella | e05a3cf | 2013-07-22 10:54:09 +0000 | [diff] [blame] | 606 | // Proceed parsing, but reset the HasTypenameKeyword flag. |
| 607 | HasTypenameKeyword = false; |
Douglas Gregor | 882a61a | 2011-09-26 14:30:28 +0000 | [diff] [blame] | 608 | } |
| 609 | |
Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 610 | if (IsAliasDecl) { |
| 611 | TemplateParameterLists *TemplateParams = TemplateInfo.TemplateParams; |
Benjamin Kramer | cc4c49d | 2012-08-23 23:38:35 +0000 | [diff] [blame] | 612 | MultiTemplateParamsArg TemplateParamsArg( |
Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 613 | TemplateParams ? TemplateParams->data() : 0, |
| 614 | TemplateParams ? TemplateParams->size() : 0); |
| 615 | return Actions.ActOnAliasDeclaration(getCurScope(), AS, TemplateParamsArg, |
Richard Smith | 54ecd98 | 2013-02-20 19:22:51 +0000 | [diff] [blame] | 616 | UsingLoc, Name, Attrs.getList(), |
| 617 | TypeAlias); |
Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 618 | } |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 619 | |
Enea Zaffanella | e05a3cf | 2013-07-22 10:54:09 +0000 | [diff] [blame] | 620 | return Actions.ActOnUsingDeclaration(getCurScope(), AS, |
| 621 | /* HasUsingKeyword */ true, UsingLoc, |
| 622 | SS, Name, Attrs.getList(), |
| 623 | HasTypenameKeyword, TypenameLoc); |
Douglas Gregor | d7c4d98 | 2008-12-30 03:27:21 +0000 | [diff] [blame] | 624 | } |
| 625 | |
Benjamin Kramer | e56f393 | 2011-12-23 17:00:35 +0000 | [diff] [blame] | 626 | /// ParseStaticAssertDeclaration - Parse C++0x or C11 static_assert-declaration. |
Anders Carlsson | f24fcff6 | 2009-03-11 16:27:10 +0000 | [diff] [blame] | 627 | /// |
Peter Collingbourne | 3d9cbdc | 2011-04-15 00:35:57 +0000 | [diff] [blame] | 628 | /// [C++0x] static_assert-declaration: |
| 629 | /// static_assert ( constant-expression , string-literal ) ; |
| 630 | /// |
Benjamin Kramer | e56f393 | 2011-12-23 17:00:35 +0000 | [diff] [blame] | 631 | /// [C11] static_assert-declaration: |
Peter Collingbourne | 3d9cbdc | 2011-04-15 00:35:57 +0000 | [diff] [blame] | 632 | /// _Static_assert ( constant-expression , string-literal ) ; |
Anders Carlsson | f24fcff6 | 2009-03-11 16:27:10 +0000 | [diff] [blame] | 633 | /// |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 634 | Decl *Parser::ParseStaticAssertDeclaration(SourceLocation &DeclEnd){ |
Peter Collingbourne | 3d9cbdc | 2011-04-15 00:35:57 +0000 | [diff] [blame] | 635 | assert((Tok.is(tok::kw_static_assert) || Tok.is(tok::kw__Static_assert)) && |
| 636 | "Not a static_assert declaration"); |
| 637 | |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 638 | if (Tok.is(tok::kw__Static_assert) && !getLangOpts().C11) |
Benjamin Kramer | e56f393 | 2011-12-23 17:00:35 +0000 | [diff] [blame] | 639 | Diag(Tok, diag::ext_c11_static_assert); |
Richard Smith | b15c11c | 2011-10-17 23:06:20 +0000 | [diff] [blame] | 640 | if (Tok.is(tok::kw_static_assert)) |
| 641 | Diag(Tok, diag::warn_cxx98_compat_static_assert); |
Peter Collingbourne | 3d9cbdc | 2011-04-15 00:35:57 +0000 | [diff] [blame] | 642 | |
Anders Carlsson | f24fcff6 | 2009-03-11 16:27:10 +0000 | [diff] [blame] | 643 | SourceLocation StaticAssertLoc = ConsumeToken(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 644 | |
Douglas Gregor | e7a8e3b | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 645 | BalancedDelimiterTracker T(*this, tok::l_paren); |
| 646 | if (T.consumeOpen()) { |
Alp Toker | ec54327 | 2013-12-24 09:48:30 +0000 | [diff] [blame] | 647 | Diag(Tok, diag::err_expected) << tok::l_paren; |
Richard Smith | 7696571 | 2012-09-13 19:12:50 +0000 | [diff] [blame] | 648 | SkipMalformedDecl(); |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 649 | return 0; |
Anders Carlsson | f24fcff6 | 2009-03-11 16:27:10 +0000 | [diff] [blame] | 650 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 651 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 652 | ExprResult AssertExpr(ParseConstantExpression()); |
Anders Carlsson | f24fcff6 | 2009-03-11 16:27:10 +0000 | [diff] [blame] | 653 | if (AssertExpr.isInvalid()) { |
Richard Smith | 7696571 | 2012-09-13 19:12:50 +0000 | [diff] [blame] | 654 | SkipMalformedDecl(); |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 655 | return 0; |
Anders Carlsson | f24fcff6 | 2009-03-11 16:27:10 +0000 | [diff] [blame] | 656 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 657 | |
Alp Toker | 383d2c4 | 2014-01-01 03:08:43 +0000 | [diff] [blame] | 658 | if (ExpectAndConsume(tok::comma)) { |
| 659 | SkipUntil(tok::semi); |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 660 | return 0; |
Alp Toker | 383d2c4 | 2014-01-01 03:08:43 +0000 | [diff] [blame] | 661 | } |
Anders Carlsson | b4cf3ad | 2009-03-13 23:29:20 +0000 | [diff] [blame] | 662 | |
Richard Smith | f506eaf | 2012-03-05 23:20:05 +0000 | [diff] [blame] | 663 | if (!isTokenStringLiteral()) { |
Andy Gibbs | a8df57a | 2012-11-17 19:16:52 +0000 | [diff] [blame] | 664 | Diag(Tok, diag::err_expected_string_literal) |
| 665 | << /*Source='static_assert'*/1; |
Richard Smith | 7696571 | 2012-09-13 19:12:50 +0000 | [diff] [blame] | 666 | SkipMalformedDecl(); |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 667 | return 0; |
Anders Carlsson | f24fcff6 | 2009-03-11 16:27:10 +0000 | [diff] [blame] | 668 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 669 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 670 | ExprResult AssertMessage(ParseStringLiteralExpression()); |
Richard Smith | d67aea2 | 2012-03-06 03:21:47 +0000 | [diff] [blame] | 671 | if (AssertMessage.isInvalid()) { |
Richard Smith | 7696571 | 2012-09-13 19:12:50 +0000 | [diff] [blame] | 672 | SkipMalformedDecl(); |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 673 | return 0; |
Richard Smith | d67aea2 | 2012-03-06 03:21:47 +0000 | [diff] [blame] | 674 | } |
Anders Carlsson | f24fcff6 | 2009-03-11 16:27:10 +0000 | [diff] [blame] | 675 | |
Douglas Gregor | e7a8e3b | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 676 | T.consumeClose(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 677 | |
Chris Lattner | 49836b4 | 2009-04-02 04:16:50 +0000 | [diff] [blame] | 678 | DeclEnd = Tok.getLocation(); |
Douglas Gregor | 45d6bdf | 2010-09-07 15:23:11 +0000 | [diff] [blame] | 679 | ExpectAndConsumeSemi(diag::err_expected_semi_after_static_assert); |
Anders Carlsson | f24fcff6 | 2009-03-11 16:27:10 +0000 | [diff] [blame] | 680 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 681 | return Actions.ActOnStaticAssertDeclaration(StaticAssertLoc, |
| 682 | AssertExpr.take(), |
Abramo Bagnara | ea94788 | 2011-03-08 16:41:52 +0000 | [diff] [blame] | 683 | AssertMessage.take(), |
Douglas Gregor | e7a8e3b | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 684 | T.getCloseLocation()); |
Anders Carlsson | f24fcff6 | 2009-03-11 16:27:10 +0000 | [diff] [blame] | 685 | } |
| 686 | |
Richard Smith | 74aeef5 | 2013-04-26 16:15:35 +0000 | [diff] [blame] | 687 | /// ParseDecltypeSpecifier - Parse a C++11 decltype specifier. |
Anders Carlsson | 74948d0 | 2009-06-24 17:47:40 +0000 | [diff] [blame] | 688 | /// |
| 689 | /// 'decltype' ( expression ) |
Richard Smith | 74aeef5 | 2013-04-26 16:15:35 +0000 | [diff] [blame] | 690 | /// 'decltype' ( 'auto' ) [C++1y] |
Anders Carlsson | 74948d0 | 2009-06-24 17:47:40 +0000 | [diff] [blame] | 691 | /// |
David Blaikie | 15a430a | 2011-12-04 05:04:18 +0000 | [diff] [blame] | 692 | SourceLocation Parser::ParseDecltypeSpecifier(DeclSpec &DS) { |
| 693 | assert((Tok.is(tok::kw_decltype) || Tok.is(tok::annot_decltype)) |
| 694 | && "Not a decltype specifier"); |
| 695 | |
David Blaikie | 15a430a | 2011-12-04 05:04:18 +0000 | [diff] [blame] | 696 | ExprResult Result; |
| 697 | SourceLocation StartLoc = Tok.getLocation(); |
| 698 | SourceLocation EndLoc; |
| 699 | |
| 700 | if (Tok.is(tok::annot_decltype)) { |
| 701 | Result = getExprAnnotation(Tok); |
| 702 | EndLoc = Tok.getAnnotationEndLoc(); |
| 703 | ConsumeToken(); |
| 704 | if (Result.isInvalid()) { |
| 705 | DS.SetTypeSpecError(); |
| 706 | return EndLoc; |
| 707 | } |
| 708 | } else { |
Richard Smith | 324df55 | 2012-02-24 22:30:04 +0000 | [diff] [blame] | 709 | if (Tok.getIdentifierInfo()->isStr("decltype")) |
| 710 | Diag(Tok, diag::warn_cxx98_compat_decltype); |
Richard Smith | fd3da93 | 2012-02-24 18:10:23 +0000 | [diff] [blame] | 711 | |
David Blaikie | 15a430a | 2011-12-04 05:04:18 +0000 | [diff] [blame] | 712 | ConsumeToken(); |
| 713 | |
| 714 | BalancedDelimiterTracker T(*this, tok::l_paren); |
| 715 | if (T.expectAndConsume(diag::err_expected_lparen_after, |
| 716 | "decltype", tok::r_paren)) { |
| 717 | DS.SetTypeSpecError(); |
| 718 | return T.getOpenLocation() == Tok.getLocation() ? |
| 719 | StartLoc : T.getOpenLocation(); |
| 720 | } |
| 721 | |
Richard Smith | 74aeef5 | 2013-04-26 16:15:35 +0000 | [diff] [blame] | 722 | // Check for C++1y 'decltype(auto)'. |
| 723 | if (Tok.is(tok::kw_auto)) { |
| 724 | // No need to disambiguate here: an expression can't start with 'auto', |
| 725 | // because the typename-specifier in a function-style cast operation can't |
| 726 | // be 'auto'. |
| 727 | Diag(Tok.getLocation(), |
| 728 | getLangOpts().CPlusPlus1y |
| 729 | ? diag::warn_cxx11_compat_decltype_auto_type_specifier |
| 730 | : diag::ext_decltype_auto_type_specifier); |
| 731 | ConsumeToken(); |
| 732 | } else { |
| 733 | // Parse the expression |
David Blaikie | 15a430a | 2011-12-04 05:04:18 +0000 | [diff] [blame] | 734 | |
Richard Smith | 74aeef5 | 2013-04-26 16:15:35 +0000 | [diff] [blame] | 735 | // C++11 [dcl.type.simple]p4: |
| 736 | // The operand of the decltype specifier is an unevaluated operand. |
| 737 | EnterExpressionEvaluationContext Unevaluated(Actions, Sema::Unevaluated, |
| 738 | 0, /*IsDecltype=*/true); |
| 739 | Result = ParseExpression(); |
| 740 | if (Result.isInvalid()) { |
| 741 | DS.SetTypeSpecError(); |
Alexey Bataev | ee6507d | 2013-11-18 08:17:37 +0000 | [diff] [blame] | 742 | if (SkipUntil(tok::r_paren, StopAtSemi | StopBeforeMatch)) { |
Richard Smith | 74aeef5 | 2013-04-26 16:15:35 +0000 | [diff] [blame] | 743 | EndLoc = ConsumeParen(); |
Argyrios Kyrtzidis | c38395a | 2012-10-26 22:53:44 +0000 | [diff] [blame] | 744 | } else { |
Richard Smith | 74aeef5 | 2013-04-26 16:15:35 +0000 | [diff] [blame] | 745 | if (PP.isBacktrackEnabled() && Tok.is(tok::semi)) { |
| 746 | // Backtrack to get the location of the last token before the semi. |
| 747 | PP.RevertCachedTokens(2); |
| 748 | ConsumeToken(); // the semi. |
| 749 | EndLoc = ConsumeAnyToken(); |
| 750 | assert(Tok.is(tok::semi)); |
| 751 | } else { |
| 752 | EndLoc = Tok.getLocation(); |
| 753 | } |
Argyrios Kyrtzidis | c38395a | 2012-10-26 22:53:44 +0000 | [diff] [blame] | 754 | } |
Richard Smith | 74aeef5 | 2013-04-26 16:15:35 +0000 | [diff] [blame] | 755 | return EndLoc; |
Argyrios Kyrtzidis | c38395a | 2012-10-26 22:53:44 +0000 | [diff] [blame] | 756 | } |
Richard Smith | 74aeef5 | 2013-04-26 16:15:35 +0000 | [diff] [blame] | 757 | |
| 758 | Result = Actions.ActOnDecltypeExpression(Result.take()); |
David Blaikie | 15a430a | 2011-12-04 05:04:18 +0000 | [diff] [blame] | 759 | } |
| 760 | |
| 761 | // Match the ')' |
| 762 | T.consumeClose(); |
| 763 | if (T.getCloseLocation().isInvalid()) { |
| 764 | DS.SetTypeSpecError(); |
| 765 | // FIXME: this should return the location of the last token |
| 766 | // that was consumed (by "consumeClose()") |
| 767 | return T.getCloseLocation(); |
| 768 | } |
| 769 | |
Richard Smith | fd555f6 | 2012-02-22 02:04:18 +0000 | [diff] [blame] | 770 | if (Result.isInvalid()) { |
| 771 | DS.SetTypeSpecError(); |
| 772 | return T.getCloseLocation(); |
| 773 | } |
| 774 | |
David Blaikie | 15a430a | 2011-12-04 05:04:18 +0000 | [diff] [blame] | 775 | EndLoc = T.getCloseLocation(); |
Anders Carlsson | 74948d0 | 2009-06-24 17:47:40 +0000 | [diff] [blame] | 776 | } |
Richard Smith | 74aeef5 | 2013-04-26 16:15:35 +0000 | [diff] [blame] | 777 | assert(!Result.isInvalid()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 778 | |
Anders Carlsson | 74948d0 | 2009-06-24 17:47:40 +0000 | [diff] [blame] | 779 | const char *PrevSpec = 0; |
John McCall | 49bfce4 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 780 | unsigned DiagID; |
Erik Verbruggen | 888d52a | 2014-01-15 09:15:43 +0000 | [diff] [blame] | 781 | const PrintingPolicy &Policy = Actions.getASTContext().getPrintingPolicy(); |
Anders Carlsson | 74948d0 | 2009-06-24 17:47:40 +0000 | [diff] [blame] | 782 | // Check for duplicate type specifiers (e.g. "int decltype(a)"). |
Richard Smith | 74aeef5 | 2013-04-26 16:15:35 +0000 | [diff] [blame] | 783 | if (Result.get() |
| 784 | ? DS.SetTypeSpecType(DeclSpec::TST_decltype, StartLoc, PrevSpec, |
Erik Verbruggen | 888d52a | 2014-01-15 09:15:43 +0000 | [diff] [blame] | 785 | DiagID, Result.release(), Policy) |
Richard Smith | 74aeef5 | 2013-04-26 16:15:35 +0000 | [diff] [blame] | 786 | : DS.SetTypeSpecType(DeclSpec::TST_decltype_auto, StartLoc, PrevSpec, |
Erik Verbruggen | 888d52a | 2014-01-15 09:15:43 +0000 | [diff] [blame] | 787 | DiagID, Policy)) { |
John McCall | 49bfce4 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 788 | Diag(StartLoc, DiagID) << PrevSpec; |
David Blaikie | 15a430a | 2011-12-04 05:04:18 +0000 | [diff] [blame] | 789 | DS.SetTypeSpecError(); |
| 790 | } |
| 791 | return EndLoc; |
| 792 | } |
| 793 | |
| 794 | void Parser::AnnotateExistingDecltypeSpecifier(const DeclSpec& DS, |
| 795 | SourceLocation StartLoc, |
| 796 | SourceLocation EndLoc) { |
| 797 | // make sure we have a token we can turn into an annotation token |
| 798 | if (PP.isBacktrackEnabled()) |
| 799 | PP.RevertCachedTokens(1); |
| 800 | else |
| 801 | PP.EnterToken(Tok); |
| 802 | |
| 803 | Tok.setKind(tok::annot_decltype); |
Richard Smith | 74aeef5 | 2013-04-26 16:15:35 +0000 | [diff] [blame] | 804 | setExprAnnotation(Tok, |
| 805 | DS.getTypeSpecType() == TST_decltype ? DS.getRepAsExpr() : |
| 806 | DS.getTypeSpecType() == TST_decltype_auto ? ExprResult() : |
| 807 | ExprError()); |
David Blaikie | 15a430a | 2011-12-04 05:04:18 +0000 | [diff] [blame] | 808 | Tok.setAnnotationEndLoc(EndLoc); |
| 809 | Tok.setLocation(StartLoc); |
| 810 | PP.AnnotateCachedTokens(Tok); |
Anders Carlsson | 74948d0 | 2009-06-24 17:47:40 +0000 | [diff] [blame] | 811 | } |
| 812 | |
Alexis Hunt | 4a25707 | 2011-05-19 05:37:45 +0000 | [diff] [blame] | 813 | void Parser::ParseUnderlyingTypeSpecifier(DeclSpec &DS) { |
| 814 | assert(Tok.is(tok::kw___underlying_type) && |
| 815 | "Not an underlying type specifier"); |
| 816 | |
| 817 | SourceLocation StartLoc = ConsumeToken(); |
Douglas Gregor | e7a8e3b | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 818 | BalancedDelimiterTracker T(*this, tok::l_paren); |
| 819 | if (T.expectAndConsume(diag::err_expected_lparen_after, |
| 820 | "__underlying_type", tok::r_paren)) { |
Alexis Hunt | 4a25707 | 2011-05-19 05:37:45 +0000 | [diff] [blame] | 821 | return; |
| 822 | } |
| 823 | |
| 824 | TypeResult Result = ParseTypeName(); |
| 825 | if (Result.isInvalid()) { |
Alexey Bataev | ee6507d | 2013-11-18 08:17:37 +0000 | [diff] [blame] | 826 | SkipUntil(tok::r_paren, StopAtSemi); |
Alexis Hunt | 4a25707 | 2011-05-19 05:37:45 +0000 | [diff] [blame] | 827 | return; |
| 828 | } |
| 829 | |
| 830 | // Match the ')' |
Douglas Gregor | e7a8e3b | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 831 | T.consumeClose(); |
| 832 | if (T.getCloseLocation().isInvalid()) |
Alexis Hunt | 4a25707 | 2011-05-19 05:37:45 +0000 | [diff] [blame] | 833 | return; |
| 834 | |
| 835 | const char *PrevSpec = 0; |
| 836 | unsigned DiagID; |
Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 837 | if (DS.SetTypeSpecType(DeclSpec::TST_underlyingType, StartLoc, PrevSpec, |
Erik Verbruggen | 888d52a | 2014-01-15 09:15:43 +0000 | [diff] [blame] | 838 | DiagID, Result.release(), |
| 839 | Actions.getASTContext().getPrintingPolicy())) |
Alexis Hunt | 4a25707 | 2011-05-19 05:37:45 +0000 | [diff] [blame] | 840 | Diag(StartLoc, DiagID) << PrevSpec; |
Enea Zaffanella | a90af72 | 2013-07-06 18:54:58 +0000 | [diff] [blame] | 841 | DS.setTypeofParensRange(T.getRange()); |
Alexis Hunt | 4a25707 | 2011-05-19 05:37:45 +0000 | [diff] [blame] | 842 | } |
| 843 | |
David Blaikie | 00ee7a08 | 2011-10-25 15:01:20 +0000 | [diff] [blame] | 844 | /// ParseBaseTypeSpecifier - Parse a C++ base-type-specifier which is either a |
| 845 | /// class name or decltype-specifier. Note that we only check that the result |
| 846 | /// names a type; semantic analysis will need to verify that the type names a |
| 847 | /// class. The result is either a type or null, depending on whether a type |
| 848 | /// name was found. |
Douglas Gregor | 831c93f | 2008-11-05 20:51:48 +0000 | [diff] [blame] | 849 | /// |
Richard Smith | 4c96e99 | 2013-02-19 23:47:15 +0000 | [diff] [blame] | 850 | /// base-type-specifier: [C++11 class.derived] |
David Blaikie | 00ee7a08 | 2011-10-25 15:01:20 +0000 | [diff] [blame] | 851 | /// class-or-decltype |
Richard Smith | 4c96e99 | 2013-02-19 23:47:15 +0000 | [diff] [blame] | 852 | /// class-or-decltype: [C++11 class.derived] |
David Blaikie | 00ee7a08 | 2011-10-25 15:01:20 +0000 | [diff] [blame] | 853 | /// nested-name-specifier[opt] class-name |
| 854 | /// decltype-specifier |
Richard Smith | 4c96e99 | 2013-02-19 23:47:15 +0000 | [diff] [blame] | 855 | /// class-name: [C++ class.name] |
Douglas Gregor | 831c93f | 2008-11-05 20:51:48 +0000 | [diff] [blame] | 856 | /// identifier |
Douglas Gregor | d54dfb8 | 2009-02-25 23:52:28 +0000 | [diff] [blame] | 857 | /// simple-template-id |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 858 | /// |
Richard Smith | 4c96e99 | 2013-02-19 23:47:15 +0000 | [diff] [blame] | 859 | /// In C++98, instead of base-type-specifier, we have: |
| 860 | /// |
| 861 | /// ::[opt] nested-name-specifier[opt] class-name |
David Blaikie | 1cd5002 | 2011-10-25 17:10:12 +0000 | [diff] [blame] | 862 | Parser::TypeResult Parser::ParseBaseTypeSpecifier(SourceLocation &BaseLoc, |
| 863 | SourceLocation &EndLocation) { |
David Blaikie | dd58d4c | 2011-10-25 18:46:41 +0000 | [diff] [blame] | 864 | // Ignore attempts to use typename |
| 865 | if (Tok.is(tok::kw_typename)) { |
| 866 | Diag(Tok, diag::err_expected_class_name_not_template) |
| 867 | << FixItHint::CreateRemoval(Tok.getLocation()); |
| 868 | ConsumeToken(); |
| 869 | } |
| 870 | |
David Blaikie | afa155f | 2011-10-25 18:17:58 +0000 | [diff] [blame] | 871 | // Parse optional nested-name-specifier |
| 872 | CXXScopeSpec SS; |
| 873 | ParseOptionalCXXScopeSpecifier(SS, ParsedType(), /*EnteringContext=*/false); |
| 874 | |
| 875 | BaseLoc = Tok.getLocation(); |
| 876 | |
David Blaikie | 1cd5002 | 2011-10-25 17:10:12 +0000 | [diff] [blame] | 877 | // Parse decltype-specifier |
David Blaikie | 15a430a | 2011-12-04 05:04:18 +0000 | [diff] [blame] | 878 | // tok == kw_decltype is just error recovery, it can only happen when SS |
| 879 | // isn't empty |
| 880 | if (Tok.is(tok::kw_decltype) || Tok.is(tok::annot_decltype)) { |
David Blaikie | afa155f | 2011-10-25 18:17:58 +0000 | [diff] [blame] | 881 | if (SS.isNotEmpty()) |
| 882 | Diag(SS.getBeginLoc(), diag::err_unexpected_scope_on_base_decltype) |
| 883 | << FixItHint::CreateRemoval(SS.getRange()); |
David Blaikie | 1cd5002 | 2011-10-25 17:10:12 +0000 | [diff] [blame] | 884 | // Fake up a Declarator to use with ActOnTypeName. |
| 885 | DeclSpec DS(AttrFactory); |
| 886 | |
David Blaikie | 7491e73 | 2011-12-08 04:53:15 +0000 | [diff] [blame] | 887 | EndLocation = ParseDecltypeSpecifier(DS); |
David Blaikie | 1cd5002 | 2011-10-25 17:10:12 +0000 | [diff] [blame] | 888 | |
| 889 | Declarator DeclaratorInfo(DS, Declarator::TypeNameContext); |
| 890 | return Actions.ActOnTypeName(getCurScope(), DeclaratorInfo); |
| 891 | } |
| 892 | |
Douglas Gregor | d54dfb8 | 2009-02-25 23:52:28 +0000 | [diff] [blame] | 893 | // Check whether we have a template-id that names a type. |
| 894 | if (Tok.is(tok::annot_template_id)) { |
Argyrios Kyrtzidis | c0c5dd2 | 2011-06-22 06:09:49 +0000 | [diff] [blame] | 895 | TemplateIdAnnotation *TemplateId = takeTemplateIdAnnotation(Tok); |
Douglas Gregor | 46c5961 | 2010-01-12 17:52:59 +0000 | [diff] [blame] | 896 | if (TemplateId->Kind == TNK_Type_template || |
| 897 | TemplateId->Kind == TNK_Dependent_template_name) { |
Douglas Gregor | e7c2065 | 2011-03-02 00:47:37 +0000 | [diff] [blame] | 898 | AnnotateTemplateIdTokenAsType(); |
Douglas Gregor | d54dfb8 | 2009-02-25 23:52:28 +0000 | [diff] [blame] | 899 | |
| 900 | assert(Tok.is(tok::annot_typename) && "template-id -> type failed"); |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 901 | ParsedType Type = getTypeAnnotation(Tok); |
Douglas Gregor | d54dfb8 | 2009-02-25 23:52:28 +0000 | [diff] [blame] | 902 | EndLocation = Tok.getAnnotationEndLoc(); |
| 903 | ConsumeToken(); |
Douglas Gregor | fe3d7d0 | 2009-04-01 21:51:26 +0000 | [diff] [blame] | 904 | |
| 905 | if (Type) |
| 906 | return Type; |
| 907 | return true; |
Douglas Gregor | d54dfb8 | 2009-02-25 23:52:28 +0000 | [diff] [blame] | 908 | } |
| 909 | |
| 910 | // Fall through to produce an error below. |
| 911 | } |
| 912 | |
Douglas Gregor | 831c93f | 2008-11-05 20:51:48 +0000 | [diff] [blame] | 913 | if (Tok.isNot(tok::identifier)) { |
Chris Lattner | 6d29c10 | 2008-11-18 07:48:38 +0000 | [diff] [blame] | 914 | Diag(Tok, diag::err_expected_class_name); |
Douglas Gregor | fe3d7d0 | 2009-04-01 21:51:26 +0000 | [diff] [blame] | 915 | return true; |
Douglas Gregor | 831c93f | 2008-11-05 20:51:48 +0000 | [diff] [blame] | 916 | } |
| 917 | |
Douglas Gregor | 18473f3 | 2010-01-12 21:28:44 +0000 | [diff] [blame] | 918 | IdentifierInfo *Id = Tok.getIdentifierInfo(); |
| 919 | SourceLocation IdLoc = ConsumeToken(); |
| 920 | |
| 921 | if (Tok.is(tok::less)) { |
| 922 | // It looks the user intended to write a template-id here, but the |
| 923 | // template-name was wrong. Try to fix that. |
| 924 | TemplateNameKind TNK = TNK_Type_template; |
| 925 | TemplateTy Template; |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 926 | if (!Actions.DiagnoseUnknownTemplateName(*Id, IdLoc, getCurScope(), |
Douglas Gregor | e7c2065 | 2011-03-02 00:47:37 +0000 | [diff] [blame] | 927 | &SS, Template, TNK)) { |
Douglas Gregor | 18473f3 | 2010-01-12 21:28:44 +0000 | [diff] [blame] | 928 | Diag(IdLoc, diag::err_unknown_template_name) |
| 929 | << Id; |
| 930 | } |
Kovarththanan Rajaratnam | ba2c652 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 931 | |
Serge Pavlov | b716b3c | 2013-08-10 05:54:47 +0000 | [diff] [blame] | 932 | if (!Template) { |
| 933 | TemplateArgList TemplateArgs; |
| 934 | SourceLocation LAngleLoc, RAngleLoc; |
| 935 | ParseTemplateIdAfterTemplateName(TemplateTy(), IdLoc, SS, |
| 936 | true, LAngleLoc, TemplateArgs, RAngleLoc); |
Douglas Gregor | 18473f3 | 2010-01-12 21:28:44 +0000 | [diff] [blame] | 937 | return true; |
Serge Pavlov | b716b3c | 2013-08-10 05:54:47 +0000 | [diff] [blame] | 938 | } |
Douglas Gregor | 18473f3 | 2010-01-12 21:28:44 +0000 | [diff] [blame] | 939 | |
Kovarththanan Rajaratnam | ba2c652 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 940 | // Form the template name |
Douglas Gregor | 18473f3 | 2010-01-12 21:28:44 +0000 | [diff] [blame] | 941 | UnqualifiedId TemplateName; |
| 942 | TemplateName.setIdentifier(Id, IdLoc); |
Kovarththanan Rajaratnam | ba2c652 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 943 | |
Douglas Gregor | 18473f3 | 2010-01-12 21:28:44 +0000 | [diff] [blame] | 944 | // Parse the full template-id, then turn it into a type. |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 945 | if (AnnotateTemplateIdToken(Template, TNK, SS, SourceLocation(), |
| 946 | TemplateName, true)) |
Douglas Gregor | 18473f3 | 2010-01-12 21:28:44 +0000 | [diff] [blame] | 947 | return true; |
| 948 | if (TNK == TNK_Dependent_template_name) |
Douglas Gregor | e7c2065 | 2011-03-02 00:47:37 +0000 | [diff] [blame] | 949 | AnnotateTemplateIdTokenAsType(); |
Kovarththanan Rajaratnam | ba2c652 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 950 | |
Douglas Gregor | 18473f3 | 2010-01-12 21:28:44 +0000 | [diff] [blame] | 951 | // If we didn't end up with a typename token, there's nothing more we |
| 952 | // can do. |
| 953 | if (Tok.isNot(tok::annot_typename)) |
| 954 | return true; |
Kovarththanan Rajaratnam | ba2c652 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 955 | |
Douglas Gregor | 18473f3 | 2010-01-12 21:28:44 +0000 | [diff] [blame] | 956 | // Retrieve the type from the annotation token, consume that token, and |
| 957 | // return. |
| 958 | EndLocation = Tok.getAnnotationEndLoc(); |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 959 | ParsedType Type = getTypeAnnotation(Tok); |
Douglas Gregor | 18473f3 | 2010-01-12 21:28:44 +0000 | [diff] [blame] | 960 | ConsumeToken(); |
| 961 | return Type; |
| 962 | } |
| 963 | |
Douglas Gregor | 831c93f | 2008-11-05 20:51:48 +0000 | [diff] [blame] | 964 | // We have an identifier; check whether it is actually a type. |
Kaelyn Uhrain | 9cb8e9f | 2012-06-22 23:37:05 +0000 | [diff] [blame] | 965 | IdentifierInfo *CorrectedII = 0; |
Douglas Gregor | e7c2065 | 2011-03-02 00:47:37 +0000 | [diff] [blame] | 966 | ParsedType Type = Actions.getTypeName(*Id, IdLoc, getCurScope(), &SS, true, |
Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 967 | false, ParsedType(), |
Abramo Bagnara | 4244b43 | 2012-01-27 08:46:19 +0000 | [diff] [blame] | 968 | /*IsCtorOrDtorName=*/false, |
Kaelyn Uhrain | 9cb8e9f | 2012-06-22 23:37:05 +0000 | [diff] [blame] | 969 | /*NonTrivialTypeSourceInfo=*/true, |
| 970 | &CorrectedII); |
Kovarththanan Rajaratnam | ba2c652 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 971 | if (!Type) { |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 972 | Diag(IdLoc, diag::err_expected_class_name); |
Douglas Gregor | fe3d7d0 | 2009-04-01 21:51:26 +0000 | [diff] [blame] | 973 | return true; |
Douglas Gregor | 831c93f | 2008-11-05 20:51:48 +0000 | [diff] [blame] | 974 | } |
| 975 | |
| 976 | // Consume the identifier. |
Douglas Gregor | 18473f3 | 2010-01-12 21:28:44 +0000 | [diff] [blame] | 977 | EndLocation = IdLoc; |
Nick Lewycky | 19b9f95 | 2010-07-26 16:56:01 +0000 | [diff] [blame] | 978 | |
| 979 | // Fake up a Declarator to use with ActOnTypeName. |
John McCall | 084e83d | 2011-03-24 11:26:52 +0000 | [diff] [blame] | 980 | DeclSpec DS(AttrFactory); |
Nick Lewycky | 19b9f95 | 2010-07-26 16:56:01 +0000 | [diff] [blame] | 981 | DS.SetRangeStart(IdLoc); |
| 982 | DS.SetRangeEnd(EndLocation); |
Douglas Gregor | e7c2065 | 2011-03-02 00:47:37 +0000 | [diff] [blame] | 983 | DS.getTypeSpecScope() = SS; |
Nick Lewycky | 19b9f95 | 2010-07-26 16:56:01 +0000 | [diff] [blame] | 984 | |
| 985 | const char *PrevSpec = 0; |
| 986 | unsigned DiagID; |
Erik Verbruggen | 888d52a | 2014-01-15 09:15:43 +0000 | [diff] [blame] | 987 | DS.SetTypeSpecType(TST_typename, IdLoc, PrevSpec, DiagID, Type, |
| 988 | Actions.getASTContext().getPrintingPolicy()); |
Nick Lewycky | 19b9f95 | 2010-07-26 16:56:01 +0000 | [diff] [blame] | 989 | |
| 990 | Declarator DeclaratorInfo(DS, Declarator::TypeNameContext); |
| 991 | return Actions.ActOnTypeName(getCurScope(), DeclaratorInfo); |
Douglas Gregor | 831c93f | 2008-11-05 20:51:48 +0000 | [diff] [blame] | 992 | } |
| 993 | |
John McCall | 8d32c05 | 2012-05-22 21:28:12 +0000 | [diff] [blame] | 994 | void Parser::ParseMicrosoftInheritanceClassAttributes(ParsedAttributes &attrs) { |
| 995 | while (Tok.is(tok::kw___single_inheritance) || |
| 996 | Tok.is(tok::kw___multiple_inheritance) || |
| 997 | Tok.is(tok::kw___virtual_inheritance)) { |
| 998 | IdentifierInfo *AttrName = Tok.getIdentifierInfo(); |
| 999 | SourceLocation AttrNameLoc = ConsumeToken(); |
Aaron Ballman | 00e9996 | 2013-08-31 01:11:41 +0000 | [diff] [blame] | 1000 | attrs.addNew(AttrName, AttrNameLoc, 0, AttrNameLoc, 0, 0, |
Aaron Ballman | 8edb5c2 | 2013-12-18 23:44:18 +0000 | [diff] [blame] | 1001 | AttributeList::AS_Keyword); |
John McCall | 8d32c05 | 2012-05-22 21:28:12 +0000 | [diff] [blame] | 1002 | } |
| 1003 | } |
| 1004 | |
Richard Smith | 369b9f9 | 2012-06-25 21:37:02 +0000 | [diff] [blame] | 1005 | /// Determine whether the following tokens are valid after a type-specifier |
| 1006 | /// which could be a standalone declaration. This will conservatively return |
| 1007 | /// true if there's any doubt, and is appropriate for insert-';' fixits. |
Richard Smith | 200f47c | 2012-07-02 19:14:01 +0000 | [diff] [blame] | 1008 | bool Parser::isValidAfterTypeSpecifier(bool CouldBeBitfield) { |
Richard Smith | 369b9f9 | 2012-06-25 21:37:02 +0000 | [diff] [blame] | 1009 | // This switch enumerates the valid "follow" set for type-specifiers. |
| 1010 | switch (Tok.getKind()) { |
| 1011 | default: break; |
| 1012 | case tok::semi: // struct foo {...} ; |
| 1013 | case tok::star: // struct foo {...} * P; |
| 1014 | case tok::amp: // struct foo {...} & R = ... |
Richard Smith | 1ac67d1 | 2013-01-19 03:48:05 +0000 | [diff] [blame] | 1015 | case tok::ampamp: // struct foo {...} && R = ... |
Richard Smith | 369b9f9 | 2012-06-25 21:37:02 +0000 | [diff] [blame] | 1016 | case tok::identifier: // struct foo {...} V ; |
| 1017 | case tok::r_paren: //(struct foo {...} ) {4} |
| 1018 | case tok::annot_cxxscope: // struct foo {...} a:: b; |
| 1019 | case tok::annot_typename: // struct foo {...} a ::b; |
| 1020 | case tok::annot_template_id: // struct foo {...} a<int> ::b; |
| 1021 | case tok::l_paren: // struct foo {...} ( x); |
| 1022 | case tok::comma: // __builtin_offsetof(struct foo{...} , |
Richard Smith | 1ac67d1 | 2013-01-19 03:48:05 +0000 | [diff] [blame] | 1023 | case tok::kw_operator: // struct foo operator ++() {...} |
Alp Toker | d3f79c5 | 2013-11-24 20:24:54 +0000 | [diff] [blame] | 1024 | case tok::kw___declspec: // struct foo {...} __declspec(...) |
Richard Smith | 369b9f9 | 2012-06-25 21:37:02 +0000 | [diff] [blame] | 1025 | return true; |
Richard Smith | 200f47c | 2012-07-02 19:14:01 +0000 | [diff] [blame] | 1026 | case tok::colon: |
| 1027 | return CouldBeBitfield; // enum E { ... } : 2; |
Richard Smith | 369b9f9 | 2012-06-25 21:37:02 +0000 | [diff] [blame] | 1028 | // Type qualifiers |
| 1029 | case tok::kw_const: // struct foo {...} const x; |
| 1030 | case tok::kw_volatile: // struct foo {...} volatile x; |
| 1031 | case tok::kw_restrict: // struct foo {...} restrict x; |
Richard Smith | 1ac67d1 | 2013-01-19 03:48:05 +0000 | [diff] [blame] | 1032 | // Function specifiers |
| 1033 | // Note, no 'explicit'. An explicit function must be either a conversion |
| 1034 | // operator or a constructor. Either way, it can't have a return type. |
| 1035 | case tok::kw_inline: // struct foo inline f(); |
| 1036 | case tok::kw_virtual: // struct foo virtual f(); |
| 1037 | case tok::kw_friend: // struct foo friend f(); |
Richard Smith | 369b9f9 | 2012-06-25 21:37:02 +0000 | [diff] [blame] | 1038 | // Storage-class specifiers |
| 1039 | case tok::kw_static: // struct foo {...} static x; |
| 1040 | case tok::kw_extern: // struct foo {...} extern x; |
| 1041 | case tok::kw_typedef: // struct foo {...} typedef x; |
| 1042 | case tok::kw_register: // struct foo {...} register x; |
| 1043 | case tok::kw_auto: // struct foo {...} auto x; |
| 1044 | case tok::kw_mutable: // struct foo {...} mutable x; |
Richard Smith | 1ac67d1 | 2013-01-19 03:48:05 +0000 | [diff] [blame] | 1045 | case tok::kw_thread_local: // struct foo {...} thread_local x; |
Richard Smith | 369b9f9 | 2012-06-25 21:37:02 +0000 | [diff] [blame] | 1046 | case tok::kw_constexpr: // struct foo {...} constexpr x; |
| 1047 | // As shown above, type qualifiers and storage class specifiers absolutely |
| 1048 | // can occur after class specifiers according to the grammar. However, |
| 1049 | // almost no one actually writes code like this. If we see one of these, |
| 1050 | // it is much more likely that someone missed a semi colon and the |
| 1051 | // type/storage class specifier we're seeing is part of the *next* |
| 1052 | // intended declaration, as in: |
| 1053 | // |
| 1054 | // struct foo { ... } |
| 1055 | // typedef int X; |
| 1056 | // |
| 1057 | // We'd really like to emit a missing semicolon error instead of emitting |
| 1058 | // an error on the 'int' saying that you can't have two type specifiers in |
| 1059 | // the same declaration of X. Because of this, we look ahead past this |
| 1060 | // token to see if it's a type specifier. If so, we know the code is |
| 1061 | // otherwise invalid, so we can produce the expected semi error. |
| 1062 | if (!isKnownToBeTypeSpecifier(NextToken())) |
| 1063 | return true; |
| 1064 | break; |
| 1065 | case tok::r_brace: // struct bar { struct foo {...} } |
| 1066 | // Missing ';' at end of struct is accepted as an extension in C mode. |
| 1067 | if (!getLangOpts().CPlusPlus) |
| 1068 | return true; |
| 1069 | break; |
Richard Smith | 1ac67d1 | 2013-01-19 03:48:05 +0000 | [diff] [blame] | 1070 | // C++11 attributes |
| 1071 | case tok::l_square: // enum E [[]] x |
| 1072 | // Note, no tok::kw_alignas here; alignas cannot appertain to a type. |
| 1073 | return getLangOpts().CPlusPlus11 && NextToken().is(tok::l_square); |
Richard Smith | 52c5b87 | 2013-01-29 04:13:32 +0000 | [diff] [blame] | 1074 | case tok::greater: |
| 1075 | // template<class T = class X> |
| 1076 | return getLangOpts().CPlusPlus; |
Richard Smith | 369b9f9 | 2012-06-25 21:37:02 +0000 | [diff] [blame] | 1077 | } |
| 1078 | return false; |
| 1079 | } |
| 1080 | |
Douglas Gregor | 556877c | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 1081 | /// ParseClassSpecifier - Parse a C++ class-specifier [C++ class] or |
| 1082 | /// elaborated-type-specifier [C++ dcl.type.elab]; we can't tell which |
| 1083 | /// until we reach the start of a definition or see a token that |
Richard Smith | c5b0552 | 2012-03-12 07:56:15 +0000 | [diff] [blame] | 1084 | /// cannot start a definition. |
Douglas Gregor | 556877c | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 1085 | /// |
| 1086 | /// class-specifier: [C++ class] |
| 1087 | /// class-head '{' member-specification[opt] '}' |
| 1088 | /// class-head '{' member-specification[opt] '}' attributes[opt] |
| 1089 | /// class-head: |
| 1090 | /// class-key identifier[opt] base-clause[opt] |
| 1091 | /// class-key nested-name-specifier identifier base-clause[opt] |
| 1092 | /// class-key nested-name-specifier[opt] simple-template-id |
| 1093 | /// base-clause[opt] |
| 1094 | /// [GNU] class-key attributes[opt] identifier[opt] base-clause[opt] |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1095 | /// [GNU] class-key attributes[opt] nested-name-specifier |
Douglas Gregor | 556877c | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 1096 | /// identifier base-clause[opt] |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1097 | /// [GNU] class-key attributes[opt] nested-name-specifier[opt] |
Douglas Gregor | 556877c | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 1098 | /// simple-template-id base-clause[opt] |
| 1099 | /// class-key: |
| 1100 | /// 'class' |
| 1101 | /// 'struct' |
| 1102 | /// 'union' |
| 1103 | /// |
| 1104 | /// elaborated-type-specifier: [C++ dcl.type.elab] |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1105 | /// class-key ::[opt] nested-name-specifier[opt] identifier |
| 1106 | /// class-key ::[opt] nested-name-specifier[opt] 'template'[opt] |
| 1107 | /// simple-template-id |
Douglas Gregor | 556877c | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 1108 | /// |
| 1109 | /// Note that the C++ class-specifier and elaborated-type-specifier, |
| 1110 | /// together, subsume the C99 struct-or-union-specifier: |
| 1111 | /// |
| 1112 | /// struct-or-union-specifier: [C99 6.7.2.1] |
| 1113 | /// struct-or-union identifier[opt] '{' struct-contents '}' |
| 1114 | /// struct-or-union identifier |
| 1115 | /// [GNU] struct-or-union attributes[opt] identifier[opt] '{' struct-contents |
| 1116 | /// '}' attributes[opt] |
| 1117 | /// [GNU] struct-or-union attributes[opt] identifier |
| 1118 | /// struct-or-union: |
| 1119 | /// 'struct' |
| 1120 | /// 'union' |
Chris Lattner | ffaa0e6 | 2009-04-12 21:49:30 +0000 | [diff] [blame] | 1121 | void Parser::ParseClassSpecifier(tok::TokenKind TagTokKind, |
| 1122 | SourceLocation StartLoc, DeclSpec &DS, |
Douglas Gregor | 1b57ff3 | 2009-05-12 23:25:50 +0000 | [diff] [blame] | 1123 | const ParsedTemplateInfo &TemplateInfo, |
Douglas Gregor | df593fb | 2011-11-07 17:33:42 +0000 | [diff] [blame] | 1124 | AccessSpecifier AS, |
Michael Han | 9407e50 | 2012-11-26 22:54:45 +0000 | [diff] [blame] | 1125 | bool EnteringContext, DeclSpecContext DSC, |
Bill Wendling | 4442605 | 2012-12-20 19:22:21 +0000 | [diff] [blame] | 1126 | ParsedAttributesWithRange &Attributes) { |
Joao Matos | e9a3ed4 | 2012-08-31 22:18:20 +0000 | [diff] [blame] | 1127 | DeclSpec::TST TagType; |
| 1128 | if (TagTokKind == tok::kw_struct) |
| 1129 | TagType = DeclSpec::TST_struct; |
| 1130 | else if (TagTokKind == tok::kw___interface) |
| 1131 | TagType = DeclSpec::TST_interface; |
| 1132 | else if (TagTokKind == tok::kw_class) |
| 1133 | TagType = DeclSpec::TST_class; |
| 1134 | else { |
Chris Lattner | ffaa0e6 | 2009-04-12 21:49:30 +0000 | [diff] [blame] | 1135 | assert(TagTokKind == tok::kw_union && "Not a class specifier"); |
| 1136 | TagType = DeclSpec::TST_union; |
| 1137 | } |
Douglas Gregor | 556877c | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 1138 | |
Douglas Gregor | f45b0cf | 2009-09-18 15:37:17 +0000 | [diff] [blame] | 1139 | if (Tok.is(tok::code_completion)) { |
| 1140 | // Code completion for a struct, class, or union name. |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 1141 | Actions.CodeCompleteTag(getCurScope(), TagType); |
Argyrios Kyrtzidis | 5cec2ae | 2011-09-04 03:32:15 +0000 | [diff] [blame] | 1142 | return cutOffParsing(); |
Douglas Gregor | f45b0cf | 2009-09-18 15:37:17 +0000 | [diff] [blame] | 1143 | } |
Kovarththanan Rajaratnam | ba2c652 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 1144 | |
Chandler Carruth | 2d69ec7 | 2010-06-28 08:39:25 +0000 | [diff] [blame] | 1145 | // C++03 [temp.explicit] 14.7.2/8: |
| 1146 | // The usual access checking rules do not apply to names used to specify |
| 1147 | // explicit instantiations. |
| 1148 | // |
| 1149 | // As an extension we do not perform access checking on the names used to |
| 1150 | // specify explicit specializations either. This is important to allow |
| 1151 | // specializing traits classes for private types. |
John McCall | 6347b68 | 2012-05-07 06:16:58 +0000 | [diff] [blame] | 1152 | // |
| 1153 | // Note that we don't suppress if this turns out to be an elaborated |
| 1154 | // type specifier. |
| 1155 | bool shouldDelayDiagsInTag = |
| 1156 | (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation || |
| 1157 | TemplateInfo.Kind == ParsedTemplateInfo::ExplicitSpecialization); |
| 1158 | SuppressAccessChecks diagsFromTag(*this, shouldDelayDiagsInTag); |
Chandler Carruth | 2d69ec7 | 2010-06-28 08:39:25 +0000 | [diff] [blame] | 1159 | |
Alexis Hunt | 6aa9bee | 2012-06-23 05:07:58 +0000 | [diff] [blame] | 1160 | ParsedAttributesWithRange attrs(AttrFactory); |
Douglas Gregor | 556877c | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 1161 | // If attributes exist after tag, parse them. |
Richard Smith | 37a45dd | 2013-10-24 01:21:09 +0000 | [diff] [blame] | 1162 | MaybeParseGNUAttributes(attrs); |
Douglas Gregor | 556877c | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 1163 | |
Steve Naroff | 3a9b7e0 | 2008-12-24 20:59:21 +0000 | [diff] [blame] | 1164 | // If declspecs exist after tag, parse them. |
John McCall | 0f8ccc4 | 2010-08-05 17:13:11 +0000 | [diff] [blame] | 1165 | while (Tok.is(tok::kw___declspec)) |
John McCall | 53fa714 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 1166 | ParseMicrosoftDeclSpec(attrs); |
Kovarththanan Rajaratnam | ba2c652 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 1167 | |
John McCall | 8d32c05 | 2012-05-22 21:28:12 +0000 | [diff] [blame] | 1168 | // Parse inheritance specifiers. |
| 1169 | if (Tok.is(tok::kw___single_inheritance) || |
| 1170 | Tok.is(tok::kw___multiple_inheritance) || |
| 1171 | Tok.is(tok::kw___virtual_inheritance)) |
Richard Smith | 37a45dd | 2013-10-24 01:21:09 +0000 | [diff] [blame] | 1172 | ParseMicrosoftInheritanceClassAttributes(attrs); |
John McCall | 8d32c05 | 2012-05-22 21:28:12 +0000 | [diff] [blame] | 1173 | |
Alexis Hunt | 96d5c76 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 1174 | // If C++0x attributes exist here, parse them. |
| 1175 | // FIXME: Are we consistent with the ordering of parsing of different |
| 1176 | // styles of attributes? |
Richard Smith | 89645bc | 2013-01-02 12:01:23 +0000 | [diff] [blame] | 1177 | MaybeParseCXX11Attributes(attrs); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1178 | |
Michael Han | 309af29 | 2013-01-07 16:57:11 +0000 | [diff] [blame] | 1179 | // Source location used by FIXIT to insert misplaced |
| 1180 | // C++11 attributes |
| 1181 | SourceLocation AttrFixitLoc = Tok.getLocation(); |
| 1182 | |
Alp Toker | 53358e4 | 2013-12-17 14:12:30 +0000 | [diff] [blame] | 1183 | // GNU libstdc++ and libc++ use certain intrinsic names as the |
| 1184 | // name of struct templates, but some are keywords in GCC >= 4.3 |
| 1185 | // MSVC and Clang. For compatibility, convert the token to an identifier |
| 1186 | // and issue a warning diagnostic. |
| 1187 | if (TagType == DeclSpec::TST_struct && !Tok.is(tok::identifier) && |
| 1188 | !Tok.isAnnotation()) { |
| 1189 | const IdentifierInfo *II = Tok.getIdentifierInfo(); |
| 1190 | // We rarely end up here so the following check is efficient. |
| 1191 | if (II && II->getName().startswith("__is_")) |
| 1192 | TryKeywordIdentFallback(true); |
| 1193 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1194 | |
Argyrios Kyrtzidis | 32a0379 | 2008-11-08 16:45:02 +0000 | [diff] [blame] | 1195 | // Parse the (optional) nested-name-specifier. |
John McCall | 9dab4e6 | 2009-12-12 11:40:51 +0000 | [diff] [blame] | 1196 | CXXScopeSpec &SS = DS.getTypeSpecScope(); |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 1197 | if (getLangOpts().CPlusPlus) { |
Chris Lattner | d5c1c9d | 2009-12-10 00:32:41 +0000 | [diff] [blame] | 1198 | // "FOO : BAR" is not a potential typo for "FOO::BAR". |
| 1199 | ColonProtectionRAIIObject X(*this); |
Kovarththanan Rajaratnam | ba2c652 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 1200 | |
Douglas Gregor | df593fb | 2011-11-07 17:33:42 +0000 | [diff] [blame] | 1201 | if (ParseOptionalCXXScopeSpecifier(SS, ParsedType(), EnteringContext)) |
John McCall | 413021a | 2010-07-30 06:26:29 +0000 | [diff] [blame] | 1202 | DS.SetTypeSpecError(); |
John McCall | 1f476a1 | 2010-02-26 08:45:28 +0000 | [diff] [blame] | 1203 | if (SS.isSet()) |
Chris Lattner | d5c1c9d | 2009-12-10 00:32:41 +0000 | [diff] [blame] | 1204 | if (Tok.isNot(tok::identifier) && Tok.isNot(tok::annot_template_id)) |
Alp Toker | ec54327 | 2013-12-24 09:48:30 +0000 | [diff] [blame] | 1205 | Diag(Tok, diag::err_expected) << tok::identifier; |
Chris Lattner | d5c1c9d | 2009-12-10 00:32:41 +0000 | [diff] [blame] | 1206 | } |
Douglas Gregor | 67a6564 | 2009-02-17 23:15:12 +0000 | [diff] [blame] | 1207 | |
Douglas Gregor | 916462b | 2009-10-30 21:46:58 +0000 | [diff] [blame] | 1208 | TemplateParameterLists *TemplateParams = TemplateInfo.TemplateParams; |
| 1209 | |
Douglas Gregor | 67a6564 | 2009-02-17 23:15:12 +0000 | [diff] [blame] | 1210 | // Parse the (optional) class name or simple-template-id. |
Douglas Gregor | 556877c | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 1211 | IdentifierInfo *Name = 0; |
| 1212 | SourceLocation NameLoc; |
Douglas Gregor | 7f74112 | 2009-02-25 19:37:18 +0000 | [diff] [blame] | 1213 | TemplateIdAnnotation *TemplateId = 0; |
Douglas Gregor | 556877c | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 1214 | if (Tok.is(tok::identifier)) { |
| 1215 | Name = Tok.getIdentifierInfo(); |
| 1216 | NameLoc = ConsumeToken(); |
Kovarththanan Rajaratnam | ba2c652 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 1217 | |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 1218 | if (Tok.is(tok::less) && getLangOpts().CPlusPlus) { |
Kovarththanan Rajaratnam | ba2c652 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 1219 | // The name was supposed to refer to a template, but didn't. |
Douglas Gregor | 916462b | 2009-10-30 21:46:58 +0000 | [diff] [blame] | 1220 | // Eat the template argument list and try to continue parsing this as |
| 1221 | // a class (or template thereof). |
| 1222 | TemplateArgList TemplateArgs; |
Douglas Gregor | 916462b | 2009-10-30 21:46:58 +0000 | [diff] [blame] | 1223 | SourceLocation LAngleLoc, RAngleLoc; |
Douglas Gregor | e7c2065 | 2011-03-02 00:47:37 +0000 | [diff] [blame] | 1224 | if (ParseTemplateIdAfterTemplateName(TemplateTy(), NameLoc, SS, |
Douglas Gregor | 916462b | 2009-10-30 21:46:58 +0000 | [diff] [blame] | 1225 | true, LAngleLoc, |
Douglas Gregor | b53edfb | 2009-11-10 19:49:08 +0000 | [diff] [blame] | 1226 | TemplateArgs, RAngleLoc)) { |
Douglas Gregor | 916462b | 2009-10-30 21:46:58 +0000 | [diff] [blame] | 1227 | // We couldn't parse the template argument list at all, so don't |
| 1228 | // try to give any location information for the list. |
| 1229 | LAngleLoc = RAngleLoc = SourceLocation(); |
| 1230 | } |
Kovarththanan Rajaratnam | ba2c652 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 1231 | |
Douglas Gregor | 916462b | 2009-10-30 21:46:58 +0000 | [diff] [blame] | 1232 | Diag(NameLoc, diag::err_explicit_spec_non_template) |
Alp Toker | 01d65e1 | 2014-01-06 12:54:41 +0000 | [diff] [blame] | 1233 | << (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation) |
| 1234 | << TagTokKind << Name << SourceRange(LAngleLoc, RAngleLoc); |
Joao Matos | e9a3ed4 | 2012-08-31 22:18:20 +0000 | [diff] [blame] | 1235 | |
Kovarththanan Rajaratnam | ba2c652 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 1236 | // Strip off the last template parameter list if it was empty, since |
Douglas Gregor | 1d0015f | 2009-10-30 22:09:44 +0000 | [diff] [blame] | 1237 | // we've removed its template argument list. |
| 1238 | if (TemplateParams && TemplateInfo.LastParameterListWasEmpty) { |
| 1239 | if (TemplateParams && TemplateParams->size() > 1) { |
| 1240 | TemplateParams->pop_back(); |
| 1241 | } else { |
| 1242 | TemplateParams = 0; |
Kovarththanan Rajaratnam | ba2c652 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 1243 | const_cast<ParsedTemplateInfo&>(TemplateInfo).Kind |
Douglas Gregor | 1d0015f | 2009-10-30 22:09:44 +0000 | [diff] [blame] | 1244 | = ParsedTemplateInfo::NonTemplate; |
| 1245 | } |
| 1246 | } else if (TemplateInfo.Kind |
| 1247 | == ParsedTemplateInfo::ExplicitInstantiation) { |
| 1248 | // Pretend this is just a forward declaration. |
Douglas Gregor | 916462b | 2009-10-30 21:46:58 +0000 | [diff] [blame] | 1249 | TemplateParams = 0; |
Kovarththanan Rajaratnam | ba2c652 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 1250 | const_cast<ParsedTemplateInfo&>(TemplateInfo).Kind |
Douglas Gregor | 916462b | 2009-10-30 21:46:58 +0000 | [diff] [blame] | 1251 | = ParsedTemplateInfo::NonTemplate; |
Kovarththanan Rajaratnam | ba2c652 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 1252 | const_cast<ParsedTemplateInfo&>(TemplateInfo).TemplateLoc |
Douglas Gregor | 1d0015f | 2009-10-30 22:09:44 +0000 | [diff] [blame] | 1253 | = SourceLocation(); |
| 1254 | const_cast<ParsedTemplateInfo&>(TemplateInfo).ExternLoc |
| 1255 | = SourceLocation(); |
Douglas Gregor | 916462b | 2009-10-30 21:46:58 +0000 | [diff] [blame] | 1256 | } |
Douglas Gregor | 916462b | 2009-10-30 21:46:58 +0000 | [diff] [blame] | 1257 | } |
Douglas Gregor | 7f74112 | 2009-02-25 19:37:18 +0000 | [diff] [blame] | 1258 | } else if (Tok.is(tok::annot_template_id)) { |
Argyrios Kyrtzidis | c0c5dd2 | 2011-06-22 06:09:49 +0000 | [diff] [blame] | 1259 | TemplateId = takeTemplateIdAnnotation(Tok); |
Douglas Gregor | 7f74112 | 2009-02-25 19:37:18 +0000 | [diff] [blame] | 1260 | NameLoc = ConsumeToken(); |
Douglas Gregor | 67a6564 | 2009-02-17 23:15:12 +0000 | [diff] [blame] | 1261 | |
Douglas Gregor | e7c2065 | 2011-03-02 00:47:37 +0000 | [diff] [blame] | 1262 | if (TemplateId->Kind != TNK_Type_template && |
| 1263 | TemplateId->Kind != TNK_Dependent_template_name) { |
Douglas Gregor | 7f74112 | 2009-02-25 19:37:18 +0000 | [diff] [blame] | 1264 | // The template-name in the simple-template-id refers to |
| 1265 | // something other than a class template. Give an appropriate |
| 1266 | // error message and skip to the ';'. |
| 1267 | SourceRange Range(NameLoc); |
| 1268 | if (SS.isNotEmpty()) |
| 1269 | Range.setBegin(SS.getBeginLoc()); |
Douglas Gregor | 67a6564 | 2009-02-17 23:15:12 +0000 | [diff] [blame] | 1270 | |
Richard Smith | 72bfbd8 | 2013-12-04 00:28:23 +0000 | [diff] [blame] | 1271 | // FIXME: Name may be null here. |
Douglas Gregor | 7f74112 | 2009-02-25 19:37:18 +0000 | [diff] [blame] | 1272 | Diag(TemplateId->LAngleLoc, diag::err_template_spec_syntax_non_template) |
Richard Trieu | 30f9385 | 2013-06-19 22:25:01 +0000 | [diff] [blame] | 1273 | << TemplateId->Name << static_cast<int>(TemplateId->Kind) << Range; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1274 | |
Douglas Gregor | 7f74112 | 2009-02-25 19:37:18 +0000 | [diff] [blame] | 1275 | DS.SetTypeSpecError(); |
Alexey Bataev | ee6507d | 2013-11-18 08:17:37 +0000 | [diff] [blame] | 1276 | SkipUntil(tok::semi, StopBeforeMatch); |
Douglas Gregor | 7f74112 | 2009-02-25 19:37:18 +0000 | [diff] [blame] | 1277 | return; |
Douglas Gregor | 67a6564 | 2009-02-17 23:15:12 +0000 | [diff] [blame] | 1278 | } |
Douglas Gregor | 556877c | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 1279 | } |
| 1280 | |
Richard Smith | bfdb108 | 2012-03-12 08:56:40 +0000 | [diff] [blame] | 1281 | // There are four options here. |
| 1282 | // - If we are in a trailing return type, this is always just a reference, |
| 1283 | // and we must not try to parse a definition. For instance, |
| 1284 | // [] () -> struct S { }; |
| 1285 | // does not define a type. |
| 1286 | // - If we have 'struct foo {...', 'struct foo :...', |
| 1287 | // 'struct foo final :' or 'struct foo final {', then this is a definition. |
| 1288 | // - If we have 'struct foo;', then this is either a forward declaration |
| 1289 | // or a friend declaration, which have to be treated differently. |
| 1290 | // - Otherwise we have something like 'struct foo xyz', a reference. |
Michael Han | 9407e50 | 2012-11-26 22:54:45 +0000 | [diff] [blame] | 1291 | // |
| 1292 | // We also detect these erroneous cases to provide better diagnostic for |
| 1293 | // C++11 attributes parsing. |
| 1294 | // - attributes follow class name: |
| 1295 | // struct foo [[]] {}; |
| 1296 | // - attributes appear before or after 'final': |
| 1297 | // struct foo [[]] final [[]] {}; |
| 1298 | // |
Richard Smith | c5b0552 | 2012-03-12 07:56:15 +0000 | [diff] [blame] | 1299 | // However, in type-specifier-seq's, things look like declarations but are |
| 1300 | // just references, e.g. |
| 1301 | // new struct s; |
Sebastian Redl | 2b37272 | 2010-02-03 21:21:43 +0000 | [diff] [blame] | 1302 | // or |
Richard Smith | c5b0552 | 2012-03-12 07:56:15 +0000 | [diff] [blame] | 1303 | // &T::operator struct s; |
Richard Smith | 649c7b06 | 2014-01-08 00:56:48 +0000 | [diff] [blame] | 1304 | // For these, DSC is DSC_type_specifier or DSC_alias_declaration. |
Michael Han | 9407e50 | 2012-11-26 22:54:45 +0000 | [diff] [blame] | 1305 | |
| 1306 | // If there are attributes after class name, parse them. |
Richard Smith | 89645bc | 2013-01-02 12:01:23 +0000 | [diff] [blame] | 1307 | MaybeParseCXX11Attributes(Attributes); |
Michael Han | 9407e50 | 2012-11-26 22:54:45 +0000 | [diff] [blame] | 1308 | |
Erik Verbruggen | 888d52a | 2014-01-15 09:15:43 +0000 | [diff] [blame] | 1309 | const PrintingPolicy &Policy = Actions.getASTContext().getPrintingPolicy(); |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1310 | Sema::TagUseKind TUK; |
Richard Smith | bfdb108 | 2012-03-12 08:56:40 +0000 | [diff] [blame] | 1311 | if (DSC == DSC_trailing) |
| 1312 | TUK = Sema::TUK_Reference; |
| 1313 | else if (Tok.is(tok::l_brace) || |
| 1314 | (getLangOpts().CPlusPlus && Tok.is(tok::colon)) || |
Richard Smith | 89645bc | 2013-01-02 12:01:23 +0000 | [diff] [blame] | 1315 | (isCXX11FinalKeyword() && |
David Blaikie | 9933a5a | 2012-03-12 15:39:49 +0000 | [diff] [blame] | 1316 | (NextToken().is(tok::l_brace) || NextToken().is(tok::colon)))) { |
Douglas Gregor | 3dad842 | 2009-09-26 06:47:28 +0000 | [diff] [blame] | 1317 | if (DS.isFriendSpecified()) { |
| 1318 | // C++ [class.friend]p2: |
| 1319 | // A class shall not be defined in a friend declaration. |
Richard Smith | 0f8ee22 | 2012-01-10 01:33:14 +0000 | [diff] [blame] | 1320 | Diag(Tok.getLocation(), diag::err_friend_decl_defines_type) |
Douglas Gregor | 3dad842 | 2009-09-26 06:47:28 +0000 | [diff] [blame] | 1321 | << SourceRange(DS.getFriendSpecLoc()); |
| 1322 | |
| 1323 | // Skip everything up to the semicolon, so that this looks like a proper |
| 1324 | // friend class (or template thereof) declaration. |
Alexey Bataev | ee6507d | 2013-11-18 08:17:37 +0000 | [diff] [blame] | 1325 | SkipUntil(tok::semi, StopBeforeMatch); |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1326 | TUK = Sema::TUK_Friend; |
Douglas Gregor | 3dad842 | 2009-09-26 06:47:28 +0000 | [diff] [blame] | 1327 | } else { |
| 1328 | // Okay, this is a class definition. |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1329 | TUK = Sema::TUK_Definition; |
Douglas Gregor | 3dad842 | 2009-09-26 06:47:28 +0000 | [diff] [blame] | 1330 | } |
Richard Smith | 434516c | 2013-02-22 06:46:23 +0000 | [diff] [blame] | 1331 | } else if (isCXX11FinalKeyword() && (NextToken().is(tok::l_square) || |
| 1332 | NextToken().is(tok::kw_alignas))) { |
Michael Han | 9407e50 | 2012-11-26 22:54:45 +0000 | [diff] [blame] | 1333 | // We can't tell if this is a definition or reference |
| 1334 | // until we skipped the 'final' and C++11 attribute specifiers. |
| 1335 | TentativeParsingAction PA(*this); |
| 1336 | |
| 1337 | // Skip the 'final' keyword. |
| 1338 | ConsumeToken(); |
| 1339 | |
| 1340 | // Skip C++11 attribute specifiers. |
| 1341 | while (true) { |
| 1342 | if (Tok.is(tok::l_square) && NextToken().is(tok::l_square)) { |
| 1343 | ConsumeBracket(); |
Alexey Bataev | ee6507d | 2013-11-18 08:17:37 +0000 | [diff] [blame] | 1344 | if (!SkipUntil(tok::r_square, StopAtSemi)) |
Michael Han | 9407e50 | 2012-11-26 22:54:45 +0000 | [diff] [blame] | 1345 | break; |
Richard Smith | 434516c | 2013-02-22 06:46:23 +0000 | [diff] [blame] | 1346 | } else if (Tok.is(tok::kw_alignas) && NextToken().is(tok::l_paren)) { |
Michael Han | 9407e50 | 2012-11-26 22:54:45 +0000 | [diff] [blame] | 1347 | ConsumeToken(); |
| 1348 | ConsumeParen(); |
Alexey Bataev | ee6507d | 2013-11-18 08:17:37 +0000 | [diff] [blame] | 1349 | if (!SkipUntil(tok::r_paren, StopAtSemi)) |
Michael Han | 9407e50 | 2012-11-26 22:54:45 +0000 | [diff] [blame] | 1350 | break; |
| 1351 | } else { |
| 1352 | break; |
| 1353 | } |
| 1354 | } |
| 1355 | |
| 1356 | if (Tok.is(tok::l_brace) || Tok.is(tok::colon)) |
| 1357 | TUK = Sema::TUK_Definition; |
| 1358 | else |
| 1359 | TUK = Sema::TUK_Reference; |
| 1360 | |
| 1361 | PA.Revert(); |
Richard Smith | 649c7b06 | 2014-01-08 00:56:48 +0000 | [diff] [blame] | 1362 | } else if (!isTypeSpecifier(DSC) && |
Richard Smith | 369b9f9 | 2012-06-25 21:37:02 +0000 | [diff] [blame] | 1363 | (Tok.is(tok::semi) || |
Richard Smith | 200f47c | 2012-07-02 19:14:01 +0000 | [diff] [blame] | 1364 | (Tok.isAtStartOfLine() && !isValidAfterTypeSpecifier(false)))) { |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1365 | TUK = DS.isFriendSpecified() ? Sema::TUK_Friend : Sema::TUK_Declaration; |
Joao Matos | e9a3ed4 | 2012-08-31 22:18:20 +0000 | [diff] [blame] | 1366 | if (Tok.isNot(tok::semi)) { |
Erik Verbruggen | 888d52a | 2014-01-15 09:15:43 +0000 | [diff] [blame] | 1367 | const PrintingPolicy &PPol = Actions.getASTContext().getPrintingPolicy(); |
Joao Matos | e9a3ed4 | 2012-08-31 22:18:20 +0000 | [diff] [blame] | 1368 | // A semicolon was missing after this declaration. Diagnose and recover. |
Alp Toker | 383d2c4 | 2014-01-01 03:08:43 +0000 | [diff] [blame] | 1369 | ExpectAndConsume(tok::semi, diag::err_expected_after, |
Erik Verbruggen | 888d52a | 2014-01-15 09:15:43 +0000 | [diff] [blame] | 1370 | DeclSpec::getSpecifierName(TagType, PPol)); |
Joao Matos | e9a3ed4 | 2012-08-31 22:18:20 +0000 | [diff] [blame] | 1371 | PP.EnterToken(Tok); |
| 1372 | Tok.setKind(tok::semi); |
| 1373 | } |
Richard Smith | 369b9f9 | 2012-06-25 21:37:02 +0000 | [diff] [blame] | 1374 | } else |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1375 | TUK = Sema::TUK_Reference; |
Douglas Gregor | 556877c | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 1376 | |
Michael Han | 9407e50 | 2012-11-26 22:54:45 +0000 | [diff] [blame] | 1377 | // Forbid misplaced attributes. In cases of a reference, we pass attributes |
| 1378 | // to caller to handle. |
Michael Han | 309af29 | 2013-01-07 16:57:11 +0000 | [diff] [blame] | 1379 | if (TUK != Sema::TUK_Reference) { |
| 1380 | // If this is not a reference, then the only possible |
| 1381 | // valid place for C++11 attributes to appear here |
| 1382 | // is between class-key and class-name. If there are |
| 1383 | // any attributes after class-name, we try a fixit to move |
| 1384 | // them to the right place. |
| 1385 | SourceRange AttrRange = Attributes.Range; |
| 1386 | if (AttrRange.isValid()) { |
| 1387 | Diag(AttrRange.getBegin(), diag::err_attributes_not_allowed) |
| 1388 | << AttrRange |
| 1389 | << FixItHint::CreateInsertionFromRange(AttrFixitLoc, |
| 1390 | CharSourceRange(AttrRange, true)) |
| 1391 | << FixItHint::CreateRemoval(AttrRange); |
| 1392 | |
| 1393 | // Recover by adding misplaced attributes to the attribute list |
| 1394 | // of the class so they can be applied on the class later. |
| 1395 | attrs.takeAllFrom(Attributes); |
| 1396 | } |
| 1397 | } |
Michael Han | 9407e50 | 2012-11-26 22:54:45 +0000 | [diff] [blame] | 1398 | |
John McCall | 6347b68 | 2012-05-07 06:16:58 +0000 | [diff] [blame] | 1399 | // If this is an elaborated type specifier, and we delayed |
| 1400 | // diagnostics before, just merge them into the current pool. |
| 1401 | if (shouldDelayDiagsInTag) { |
| 1402 | diagsFromTag.done(); |
| 1403 | if (TUK == Sema::TUK_Reference) |
| 1404 | diagsFromTag.redelay(); |
| 1405 | } |
| 1406 | |
John McCall | 413021a | 2010-07-30 06:26:29 +0000 | [diff] [blame] | 1407 | if (!Name && !TemplateId && (DS.getTypeSpecType() == DeclSpec::TST_error || |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1408 | TUK != Sema::TUK_Definition)) { |
John McCall | 413021a | 2010-07-30 06:26:29 +0000 | [diff] [blame] | 1409 | if (DS.getTypeSpecType() != DeclSpec::TST_error) { |
| 1410 | // We have a declaration or reference to an anonymous class. |
| 1411 | Diag(StartLoc, diag::err_anon_type_definition) |
Erik Verbruggen | 888d52a | 2014-01-15 09:15:43 +0000 | [diff] [blame] | 1412 | << DeclSpec::getSpecifierName(TagType, Policy); |
John McCall | 413021a | 2010-07-30 06:26:29 +0000 | [diff] [blame] | 1413 | } |
Douglas Gregor | 556877c | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 1414 | |
David Majnemer | 3252fd0 | 2013-12-05 01:36:53 +0000 | [diff] [blame] | 1415 | // If we are parsing a definition and stop at a base-clause, continue on |
| 1416 | // until the semicolon. Continuing from the comma will just trick us into |
| 1417 | // thinking we are seeing a variable declaration. |
| 1418 | if (TUK == Sema::TUK_Definition && Tok.is(tok::colon)) |
| 1419 | SkipUntil(tok::semi, StopBeforeMatch); |
| 1420 | else |
| 1421 | SkipUntil(tok::comma, StopAtSemi); |
Douglas Gregor | 556877c | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 1422 | return; |
| 1423 | } |
| 1424 | |
Douglas Gregor | cd72ba9 | 2009-02-06 22:42:48 +0000 | [diff] [blame] | 1425 | // Create the tag portion of the class or class template. |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1426 | DeclResult TagOrTempResult = true; // invalid |
| 1427 | TypeResult TypeResult = true; // invalid |
Douglas Gregor | 1b57ff3 | 2009-05-12 23:25:50 +0000 | [diff] [blame] | 1428 | |
Douglas Gregor | d6ab874 | 2009-05-28 23:31:59 +0000 | [diff] [blame] | 1429 | bool Owned = false; |
John McCall | 06f6fe8d | 2009-09-04 01:14:41 +0000 | [diff] [blame] | 1430 | if (TemplateId) { |
Douglas Gregor | 1b57ff3 | 2009-05-12 23:25:50 +0000 | [diff] [blame] | 1431 | // Explicit specialization, class template partial specialization, |
| 1432 | // or explicit instantiation. |
Benjamin Kramer | cc4c49d | 2012-08-23 23:38:35 +0000 | [diff] [blame] | 1433 | ASTTemplateArgsPtr TemplateArgsPtr(TemplateId->getTemplateArgs(), |
Douglas Gregor | 7f74112 | 2009-02-25 19:37:18 +0000 | [diff] [blame] | 1434 | TemplateId->NumArgs); |
Douglas Gregor | 1b57ff3 | 2009-05-12 23:25:50 +0000 | [diff] [blame] | 1435 | if (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation && |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1436 | TUK == Sema::TUK_Declaration) { |
Douglas Gregor | 1b57ff3 | 2009-05-12 23:25:50 +0000 | [diff] [blame] | 1437 | // This is an explicit instantiation of a class template. |
Alexis Hunt | 6aa9bee | 2012-06-23 05:07:58 +0000 | [diff] [blame] | 1438 | ProhibitAttributes(attrs); |
| 1439 | |
Douglas Gregor | 1b57ff3 | 2009-05-12 23:25:50 +0000 | [diff] [blame] | 1440 | TagOrTempResult |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 1441 | = Actions.ActOnExplicitInstantiation(getCurScope(), |
Douglas Gregor | 43e7517 | 2009-09-04 06:33:52 +0000 | [diff] [blame] | 1442 | TemplateInfo.ExternLoc, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1443 | TemplateInfo.TemplateLoc, |
Douglas Gregor | 1b57ff3 | 2009-05-12 23:25:50 +0000 | [diff] [blame] | 1444 | TagType, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1445 | StartLoc, |
Douglas Gregor | 1b57ff3 | 2009-05-12 23:25:50 +0000 | [diff] [blame] | 1446 | SS, |
John McCall | 3e56fd4 | 2010-08-23 07:28:44 +0000 | [diff] [blame] | 1447 | TemplateId->Template, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1448 | TemplateId->TemplateNameLoc, |
| 1449 | TemplateId->LAngleLoc, |
Douglas Gregor | 1b57ff3 | 2009-05-12 23:25:50 +0000 | [diff] [blame] | 1450 | TemplateArgsPtr, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1451 | TemplateId->RAngleLoc, |
John McCall | 53fa714 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 1452 | attrs.getList()); |
John McCall | b7c5c27 | 2010-04-14 00:24:33 +0000 | [diff] [blame] | 1453 | |
| 1454 | // Friend template-ids are treated as references unless |
| 1455 | // they have template headers, in which case they're ill-formed |
| 1456 | // (FIXME: "template <class T> friend class A<T>::B<int>;"). |
| 1457 | // We diagnose this error in ActOnClassTemplateSpecialization. |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1458 | } else if (TUK == Sema::TUK_Reference || |
| 1459 | (TUK == Sema::TUK_Friend && |
John McCall | b7c5c27 | 2010-04-14 00:24:33 +0000 | [diff] [blame] | 1460 | TemplateInfo.Kind == ParsedTemplateInfo::NonTemplate)) { |
Alexis Hunt | 6aa9bee | 2012-06-23 05:07:58 +0000 | [diff] [blame] | 1461 | ProhibitAttributes(attrs); |
Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 1462 | TypeResult = Actions.ActOnTagTemplateIdType(TUK, TagType, StartLoc, |
Douglas Gregor | e7c2065 | 2011-03-02 00:47:37 +0000 | [diff] [blame] | 1463 | TemplateId->SS, |
Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 1464 | TemplateId->TemplateKWLoc, |
Douglas Gregor | e7c2065 | 2011-03-02 00:47:37 +0000 | [diff] [blame] | 1465 | TemplateId->Template, |
| 1466 | TemplateId->TemplateNameLoc, |
| 1467 | TemplateId->LAngleLoc, |
| 1468 | TemplateArgsPtr, |
Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 1469 | TemplateId->RAngleLoc); |
Douglas Gregor | 1b57ff3 | 2009-05-12 23:25:50 +0000 | [diff] [blame] | 1470 | } else { |
| 1471 | // This is an explicit specialization or a class template |
| 1472 | // partial specialization. |
| 1473 | TemplateParameterLists FakedParamLists; |
Douglas Gregor | 1b57ff3 | 2009-05-12 23:25:50 +0000 | [diff] [blame] | 1474 | if (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation) { |
| 1475 | // This looks like an explicit instantiation, because we have |
| 1476 | // something like |
| 1477 | // |
| 1478 | // template class Foo<X> |
| 1479 | // |
Douglas Gregor | 2ec748c | 2009-05-14 00:28:11 +0000 | [diff] [blame] | 1480 | // but it actually has a definition. Most likely, this was |
Douglas Gregor | 1b57ff3 | 2009-05-12 23:25:50 +0000 | [diff] [blame] | 1481 | // meant to be an explicit specialization, but the user forgot |
| 1482 | // the '<>' after 'template'. |
Richard Smith | 003c5e1 | 2013-11-08 19:03:29 +0000 | [diff] [blame] | 1483 | // It this is friend declaration however, since it cannot have a |
| 1484 | // template header, it is most likely that the user meant to |
| 1485 | // remove the 'template' keyword. |
Larisse Voufo | b9bbaba | 2013-06-22 13:56:11 +0000 | [diff] [blame] | 1486 | assert((TUK == Sema::TUK_Definition || TUK == Sema::TUK_Friend) && |
Richard Smith | 003c5e1 | 2013-11-08 19:03:29 +0000 | [diff] [blame] | 1487 | "Expected a definition here"); |
Douglas Gregor | 1b57ff3 | 2009-05-12 23:25:50 +0000 | [diff] [blame] | 1488 | |
Richard Smith | 003c5e1 | 2013-11-08 19:03:29 +0000 | [diff] [blame] | 1489 | if (TUK == Sema::TUK_Friend) { |
| 1490 | Diag(DS.getFriendSpecLoc(), diag::err_friend_explicit_instantiation); |
| 1491 | TemplateParams = 0; |
| 1492 | } else { |
| 1493 | SourceLocation LAngleLoc = |
| 1494 | PP.getLocForEndOfToken(TemplateInfo.TemplateLoc); |
| 1495 | Diag(TemplateId->TemplateNameLoc, |
| 1496 | diag::err_explicit_instantiation_with_definition) |
| 1497 | << SourceRange(TemplateInfo.TemplateLoc) |
| 1498 | << FixItHint::CreateInsertion(LAngleLoc, "<>"); |
| 1499 | |
| 1500 | // Create a fake template parameter list that contains only |
| 1501 | // "template<>", so that we treat this construct as a class |
| 1502 | // template specialization. |
| 1503 | FakedParamLists.push_back(Actions.ActOnTemplateParameterList( |
| 1504 | 0, SourceLocation(), TemplateInfo.TemplateLoc, LAngleLoc, 0, 0, |
| 1505 | LAngleLoc)); |
| 1506 | TemplateParams = &FakedParamLists; |
| 1507 | } |
Douglas Gregor | 1b57ff3 | 2009-05-12 23:25:50 +0000 | [diff] [blame] | 1508 | } |
| 1509 | |
| 1510 | // Build the class template specialization. |
| 1511 | TagOrTempResult |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 1512 | = Actions.ActOnClassTemplateSpecialization(getCurScope(), TagType, TUK, |
Douglas Gregor | 3c7cd6a | 2011-09-09 20:53:38 +0000 | [diff] [blame] | 1513 | StartLoc, DS.getModulePrivateSpecLoc(), SS, |
John McCall | 3e56fd4 | 2010-08-23 07:28:44 +0000 | [diff] [blame] | 1514 | TemplateId->Template, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1515 | TemplateId->TemplateNameLoc, |
| 1516 | TemplateId->LAngleLoc, |
Douglas Gregor | 7f74112 | 2009-02-25 19:37:18 +0000 | [diff] [blame] | 1517 | TemplateArgsPtr, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1518 | TemplateId->RAngleLoc, |
John McCall | 53fa714 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 1519 | attrs.getList(), |
Benjamin Kramer | cc4c49d | 2012-08-23 23:38:35 +0000 | [diff] [blame] | 1520 | MultiTemplateParamsArg( |
Douglas Gregor | 67a6564 | 2009-02-17 23:15:12 +0000 | [diff] [blame] | 1521 | TemplateParams? &(*TemplateParams)[0] : 0, |
| 1522 | TemplateParams? TemplateParams->size() : 0)); |
Douglas Gregor | 1b57ff3 | 2009-05-12 23:25:50 +0000 | [diff] [blame] | 1523 | } |
Douglas Gregor | 2ec748c | 2009-05-14 00:28:11 +0000 | [diff] [blame] | 1524 | } else if (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation && |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1525 | TUK == Sema::TUK_Declaration) { |
Douglas Gregor | 2ec748c | 2009-05-14 00:28:11 +0000 | [diff] [blame] | 1526 | // Explicit instantiation of a member of a class template |
| 1527 | // specialization, e.g., |
| 1528 | // |
| 1529 | // template struct Outer<int>::Inner; |
| 1530 | // |
Alexis Hunt | 6aa9bee | 2012-06-23 05:07:58 +0000 | [diff] [blame] | 1531 | ProhibitAttributes(attrs); |
| 1532 | |
Douglas Gregor | 2ec748c | 2009-05-14 00:28:11 +0000 | [diff] [blame] | 1533 | TagOrTempResult |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 1534 | = Actions.ActOnExplicitInstantiation(getCurScope(), |
Douglas Gregor | 43e7517 | 2009-09-04 06:33:52 +0000 | [diff] [blame] | 1535 | TemplateInfo.ExternLoc, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1536 | TemplateInfo.TemplateLoc, |
| 1537 | TagType, StartLoc, SS, Name, |
John McCall | 53fa714 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 1538 | NameLoc, attrs.getList()); |
John McCall | ace48cd | 2010-10-19 01:40:49 +0000 | [diff] [blame] | 1539 | } else if (TUK == Sema::TUK_Friend && |
| 1540 | TemplateInfo.Kind != ParsedTemplateInfo::NonTemplate) { |
Alexis Hunt | 6aa9bee | 2012-06-23 05:07:58 +0000 | [diff] [blame] | 1541 | ProhibitAttributes(attrs); |
| 1542 | |
John McCall | ace48cd | 2010-10-19 01:40:49 +0000 | [diff] [blame] | 1543 | TagOrTempResult = |
| 1544 | Actions.ActOnTemplatedFriendTag(getCurScope(), DS.getFriendSpecLoc(), |
| 1545 | TagType, StartLoc, SS, |
John McCall | 53fa714 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 1546 | Name, NameLoc, attrs.getList(), |
Benjamin Kramer | cc4c49d | 2012-08-23 23:38:35 +0000 | [diff] [blame] | 1547 | MultiTemplateParamsArg( |
John McCall | ace48cd | 2010-10-19 01:40:49 +0000 | [diff] [blame] | 1548 | TemplateParams? &(*TemplateParams)[0] : 0, |
| 1549 | TemplateParams? TemplateParams->size() : 0)); |
Douglas Gregor | 2ec748c | 2009-05-14 00:28:11 +0000 | [diff] [blame] | 1550 | } else { |
Alexis Hunt | 6aa9bee | 2012-06-23 05:07:58 +0000 | [diff] [blame] | 1551 | if (TUK != Sema::TUK_Declaration && TUK != Sema::TUK_Definition) |
| 1552 | ProhibitAttributes(attrs); |
Richard Smith | 003c5e1 | 2013-11-08 19:03:29 +0000 | [diff] [blame] | 1553 | |
Larisse Voufo | 725de3e | 2013-06-21 00:08:46 +0000 | [diff] [blame] | 1554 | if (TUK == Sema::TUK_Definition && |
| 1555 | TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation) { |
| 1556 | // If the declarator-id is not a template-id, issue a diagnostic and |
| 1557 | // recover by ignoring the 'template' keyword. |
| 1558 | Diag(Tok, diag::err_template_defn_explicit_instantiation) |
| 1559 | << 1 << FixItHint::CreateRemoval(TemplateInfo.TemplateLoc); |
Larisse Voufo | b9bbaba | 2013-06-22 13:56:11 +0000 | [diff] [blame] | 1560 | TemplateParams = 0; |
Larisse Voufo | 725de3e | 2013-06-21 00:08:46 +0000 | [diff] [blame] | 1561 | } |
Alexis Hunt | 6aa9bee | 2012-06-23 05:07:58 +0000 | [diff] [blame] | 1562 | |
John McCall | 7f41d98 | 2009-09-11 04:59:25 +0000 | [diff] [blame] | 1563 | bool IsDependent = false; |
| 1564 | |
John McCall | 32723e9 | 2010-10-19 18:40:57 +0000 | [diff] [blame] | 1565 | // Don't pass down template parameter lists if this is just a tag |
| 1566 | // reference. For example, we don't need the template parameters here: |
| 1567 | // template <class T> class A *makeA(T t); |
| 1568 | MultiTemplateParamsArg TParams; |
| 1569 | if (TUK != Sema::TUK_Reference && TemplateParams) |
| 1570 | TParams = |
| 1571 | MultiTemplateParamsArg(&(*TemplateParams)[0], TemplateParams->size()); |
| 1572 | |
Douglas Gregor | 2ec748c | 2009-05-14 00:28:11 +0000 | [diff] [blame] | 1573 | // Declaration or definition of a class type |
John McCall | ace48cd | 2010-10-19 01:40:49 +0000 | [diff] [blame] | 1574 | TagOrTempResult = Actions.ActOnTag(getCurScope(), TagType, TUK, StartLoc, |
John McCall | 53fa714 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 1575 | SS, Name, NameLoc, attrs.getList(), AS, |
Douglas Gregor | 2820e69 | 2011-09-09 19:05:14 +0000 | [diff] [blame] | 1576 | DS.getModulePrivateSpecLoc(), |
Richard Smith | 0f8ee22 | 2012-01-10 01:33:14 +0000 | [diff] [blame] | 1577 | TParams, Owned, IsDependent, |
| 1578 | SourceLocation(), false, |
Richard Smith | 649c7b06 | 2014-01-08 00:56:48 +0000 | [diff] [blame] | 1579 | clang::TypeResult(), |
| 1580 | DSC == DSC_type_specifier); |
John McCall | 7f41d98 | 2009-09-11 04:59:25 +0000 | [diff] [blame] | 1581 | |
| 1582 | // If ActOnTag said the type was dependent, try again with the |
| 1583 | // less common call. |
John McCall | ace48cd | 2010-10-19 01:40:49 +0000 | [diff] [blame] | 1584 | if (IsDependent) { |
| 1585 | assert(TUK == Sema::TUK_Reference || TUK == Sema::TUK_Friend); |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 1586 | TypeResult = Actions.ActOnDependentTag(getCurScope(), TagType, TUK, |
Kovarththanan Rajaratnam | ba2c652 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 1587 | SS, Name, StartLoc, NameLoc); |
John McCall | ace48cd | 2010-10-19 01:40:49 +0000 | [diff] [blame] | 1588 | } |
Douglas Gregor | 2ec748c | 2009-05-14 00:28:11 +0000 | [diff] [blame] | 1589 | } |
Douglas Gregor | 556877c | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 1590 | |
Douglas Gregor | 556877c | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 1591 | // If there is a body, parse it and inform the actions module. |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1592 | if (TUK == Sema::TUK_Definition) { |
John McCall | 2d814c3 | 2009-12-19 21:48:58 +0000 | [diff] [blame] | 1593 | assert(Tok.is(tok::l_brace) || |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 1594 | (getLangOpts().CPlusPlus && Tok.is(tok::colon)) || |
Richard Smith | 89645bc | 2013-01-02 12:01:23 +0000 | [diff] [blame] | 1595 | isCXX11FinalKeyword()); |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 1596 | if (getLangOpts().CPlusPlus) |
Michael Han | 309af29 | 2013-01-07 16:57:11 +0000 | [diff] [blame] | 1597 | ParseCXXMemberSpecification(StartLoc, AttrFixitLoc, attrs, TagType, |
| 1598 | TagOrTempResult.get()); |
Argyrios Kyrtzidis | ed98342 | 2008-07-01 10:37:29 +0000 | [diff] [blame] | 1599 | else |
Douglas Gregor | c08f489 | 2009-03-25 00:13:59 +0000 | [diff] [blame] | 1600 | ParseStructUnionBody(StartLoc, TagType, TagOrTempResult.get()); |
Douglas Gregor | 556877c | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 1601 | } |
| 1602 | |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 1603 | const char *PrevSpec = 0; |
| 1604 | unsigned DiagID; |
| 1605 | bool Result; |
John McCall | 7f41d98 | 2009-09-11 04:59:25 +0000 | [diff] [blame] | 1606 | if (!TypeResult.isInvalid()) { |
Abramo Bagnara | 9875a3c | 2011-03-16 20:16:18 +0000 | [diff] [blame] | 1607 | Result = DS.SetTypeSpecType(DeclSpec::TST_typename, StartLoc, |
| 1608 | NameLoc.isValid() ? NameLoc : StartLoc, |
Erik Verbruggen | 888d52a | 2014-01-15 09:15:43 +0000 | [diff] [blame] | 1609 | PrevSpec, DiagID, TypeResult.get(), Policy); |
John McCall | 7f41d98 | 2009-09-11 04:59:25 +0000 | [diff] [blame] | 1610 | } else if (!TagOrTempResult.isInvalid()) { |
Abramo Bagnara | 9875a3c | 2011-03-16 20:16:18 +0000 | [diff] [blame] | 1611 | Result = DS.SetTypeSpecType(TagType, StartLoc, |
| 1612 | NameLoc.isValid() ? NameLoc : StartLoc, |
Erik Verbruggen | 888d52a | 2014-01-15 09:15:43 +0000 | [diff] [blame] | 1613 | PrevSpec, DiagID, TagOrTempResult.get(), Owned, |
| 1614 | Policy); |
John McCall | 7f41d98 | 2009-09-11 04:59:25 +0000 | [diff] [blame] | 1615 | } else { |
Douglas Gregor | cd72ba9 | 2009-02-06 22:42:48 +0000 | [diff] [blame] | 1616 | DS.SetTypeSpecError(); |
Anders Carlsson | f83c9fa | 2009-05-11 22:27:47 +0000 | [diff] [blame] | 1617 | return; |
| 1618 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1619 | |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 1620 | if (Result) |
John McCall | 49bfce4 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 1621 | Diag(StartLoc, DiagID) << PrevSpec; |
Kovarththanan Rajaratnam | ba2c652 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 1622 | |
Chris Lattner | cf25141 | 2010-02-02 01:23:29 +0000 | [diff] [blame] | 1623 | // At this point, we've successfully parsed a class-specifier in 'definition' |
| 1624 | // form (e.g. "struct foo { int x; }". While we could just return here, we're |
| 1625 | // going to look at what comes after it to improve error recovery. If an |
| 1626 | // impossible token occurs next, we assume that the programmer forgot a ; at |
| 1627 | // the end of the declaration and recover that way. |
| 1628 | // |
Richard Smith | 369b9f9 | 2012-06-25 21:37:02 +0000 | [diff] [blame] | 1629 | // Also enforce C++ [temp]p3: |
| 1630 | // In a template-declaration which defines a class, no declarator |
| 1631 | // is permitted. |
Joao Matos | e9a3ed4 | 2012-08-31 22:18:20 +0000 | [diff] [blame] | 1632 | if (TUK == Sema::TUK_Definition && |
| 1633 | (TemplateInfo.Kind || !isValidAfterTypeSpecifier(false))) { |
Argyrios Kyrtzidis | e6f6913 | 2012-12-17 20:10:43 +0000 | [diff] [blame] | 1634 | if (Tok.isNot(tok::semi)) { |
Erik Verbruggen | 888d52a | 2014-01-15 09:15:43 +0000 | [diff] [blame] | 1635 | const PrintingPolicy &PPol = Actions.getASTContext().getPrintingPolicy(); |
Alp Toker | 383d2c4 | 2014-01-01 03:08:43 +0000 | [diff] [blame] | 1636 | ExpectAndConsume(tok::semi, diag::err_expected_after, |
Erik Verbruggen | 888d52a | 2014-01-15 09:15:43 +0000 | [diff] [blame] | 1637 | DeclSpec::getSpecifierName(TagType, PPol)); |
Argyrios Kyrtzidis | e6f6913 | 2012-12-17 20:10:43 +0000 | [diff] [blame] | 1638 | // Push this token back into the preprocessor and change our current token |
| 1639 | // to ';' so that the rest of the code recovers as though there were an |
| 1640 | // ';' after the definition. |
| 1641 | PP.EnterToken(Tok); |
| 1642 | Tok.setKind(tok::semi); |
| 1643 | } |
Chris Lattner | cf25141 | 2010-02-02 01:23:29 +0000 | [diff] [blame] | 1644 | } |
Douglas Gregor | 556877c | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 1645 | } |
| 1646 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1647 | /// ParseBaseClause - Parse the base-clause of a C++ class [C++ class.derived]. |
Douglas Gregor | 556877c | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 1648 | /// |
| 1649 | /// base-clause : [C++ class.derived] |
| 1650 | /// ':' base-specifier-list |
| 1651 | /// base-specifier-list: |
| 1652 | /// base-specifier '...'[opt] |
| 1653 | /// base-specifier-list ',' base-specifier '...'[opt] |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1654 | void Parser::ParseBaseClause(Decl *ClassDecl) { |
Douglas Gregor | 556877c | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 1655 | assert(Tok.is(tok::colon) && "Not a base clause"); |
| 1656 | ConsumeToken(); |
| 1657 | |
Douglas Gregor | 29a9247 | 2008-10-22 17:49:05 +0000 | [diff] [blame] | 1658 | // Build up an array of parsed base specifiers. |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1659 | SmallVector<CXXBaseSpecifier *, 8> BaseInfo; |
Douglas Gregor | 29a9247 | 2008-10-22 17:49:05 +0000 | [diff] [blame] | 1660 | |
Douglas Gregor | 556877c | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 1661 | while (true) { |
| 1662 | // Parse a base-specifier. |
Douglas Gregor | 29a9247 | 2008-10-22 17:49:05 +0000 | [diff] [blame] | 1663 | BaseResult Result = ParseBaseSpecifier(ClassDecl); |
Douglas Gregor | f829825 | 2009-01-26 22:44:13 +0000 | [diff] [blame] | 1664 | if (Result.isInvalid()) { |
Douglas Gregor | 556877c | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 1665 | // Skip the rest of this base specifier, up until the comma or |
| 1666 | // opening brace. |
Alexey Bataev | ee6507d | 2013-11-18 08:17:37 +0000 | [diff] [blame] | 1667 | SkipUntil(tok::comma, tok::l_brace, StopAtSemi | StopBeforeMatch); |
Douglas Gregor | 29a9247 | 2008-10-22 17:49:05 +0000 | [diff] [blame] | 1668 | } else { |
| 1669 | // Add this to our array of base specifiers. |
Douglas Gregor | f829825 | 2009-01-26 22:44:13 +0000 | [diff] [blame] | 1670 | BaseInfo.push_back(Result.get()); |
Douglas Gregor | 556877c | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 1671 | } |
| 1672 | |
| 1673 | // If the next token is a comma, consume it and keep reading |
| 1674 | // base-specifiers. |
Alp Toker | 9765056 | 2014-01-10 11:19:30 +0000 | [diff] [blame] | 1675 | if (!TryConsumeToken(tok::comma)) |
| 1676 | break; |
Douglas Gregor | 556877c | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 1677 | } |
Douglas Gregor | 29a9247 | 2008-10-22 17:49:05 +0000 | [diff] [blame] | 1678 | |
| 1679 | // Attach the base specifiers |
Jay Foad | 7d0479f | 2009-05-21 09:52:38 +0000 | [diff] [blame] | 1680 | Actions.ActOnBaseSpecifiers(ClassDecl, BaseInfo.data(), BaseInfo.size()); |
Douglas Gregor | 556877c | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 1681 | } |
| 1682 | |
| 1683 | /// ParseBaseSpecifier - Parse a C++ base-specifier. A base-specifier is |
| 1684 | /// one entry in the base class list of a class specifier, for example: |
| 1685 | /// class foo : public bar, virtual private baz { |
| 1686 | /// 'public bar' and 'virtual private baz' are each base-specifiers. |
| 1687 | /// |
| 1688 | /// base-specifier: [C++ class.derived] |
Richard Smith | 4c96e99 | 2013-02-19 23:47:15 +0000 | [diff] [blame] | 1689 | /// attribute-specifier-seq[opt] base-type-specifier |
| 1690 | /// attribute-specifier-seq[opt] 'virtual' access-specifier[opt] |
| 1691 | /// base-type-specifier |
| 1692 | /// attribute-specifier-seq[opt] access-specifier 'virtual'[opt] |
| 1693 | /// base-type-specifier |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1694 | Parser::BaseResult Parser::ParseBaseSpecifier(Decl *ClassDecl) { |
Douglas Gregor | 556877c | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 1695 | bool IsVirtual = false; |
| 1696 | SourceLocation StartLoc = Tok.getLocation(); |
| 1697 | |
Richard Smith | 4c96e99 | 2013-02-19 23:47:15 +0000 | [diff] [blame] | 1698 | ParsedAttributesWithRange Attributes(AttrFactory); |
| 1699 | MaybeParseCXX11Attributes(Attributes); |
| 1700 | |
Douglas Gregor | 556877c | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 1701 | // Parse the 'virtual' keyword. |
Alp Toker | 9765056 | 2014-01-10 11:19:30 +0000 | [diff] [blame] | 1702 | if (TryConsumeToken(tok::kw_virtual)) |
Douglas Gregor | 556877c | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 1703 | IsVirtual = true; |
Douglas Gregor | 556877c | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 1704 | |
Richard Smith | 4c96e99 | 2013-02-19 23:47:15 +0000 | [diff] [blame] | 1705 | CheckMisplacedCXX11Attribute(Attributes, StartLoc); |
| 1706 | |
Douglas Gregor | 556877c | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 1707 | // Parse an (optional) access specifier. |
| 1708 | AccessSpecifier Access = getAccessSpecifierIfPresent(); |
John McCall | 553c079 | 2010-01-23 00:46:32 +0000 | [diff] [blame] | 1709 | if (Access != AS_none) |
Douglas Gregor | 556877c | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 1710 | ConsumeToken(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1711 | |
Richard Smith | 4c96e99 | 2013-02-19 23:47:15 +0000 | [diff] [blame] | 1712 | CheckMisplacedCXX11Attribute(Attributes, StartLoc); |
| 1713 | |
Douglas Gregor | 556877c | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 1714 | // Parse the 'virtual' keyword (again!), in case it came after the |
| 1715 | // access specifier. |
| 1716 | if (Tok.is(tok::kw_virtual)) { |
| 1717 | SourceLocation VirtualLoc = ConsumeToken(); |
| 1718 | if (IsVirtual) { |
| 1719 | // Complain about duplicate 'virtual' |
Chris Lattner | 6d29c10 | 2008-11-18 07:48:38 +0000 | [diff] [blame] | 1720 | Diag(VirtualLoc, diag::err_dup_virtual) |
Douglas Gregor | a771f46 | 2010-03-31 17:46:05 +0000 | [diff] [blame] | 1721 | << FixItHint::CreateRemoval(VirtualLoc); |
Douglas Gregor | 556877c | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 1722 | } |
| 1723 | |
| 1724 | IsVirtual = true; |
| 1725 | } |
| 1726 | |
Richard Smith | 4c96e99 | 2013-02-19 23:47:15 +0000 | [diff] [blame] | 1727 | CheckMisplacedCXX11Attribute(Attributes, StartLoc); |
| 1728 | |
Douglas Gregor | 831c93f | 2008-11-05 20:51:48 +0000 | [diff] [blame] | 1729 | // Parse the class-name. |
Douglas Gregor | d54dfb8 | 2009-02-25 23:52:28 +0000 | [diff] [blame] | 1730 | SourceLocation EndLocation; |
David Blaikie | 1cd5002 | 2011-10-25 17:10:12 +0000 | [diff] [blame] | 1731 | SourceLocation BaseLoc; |
| 1732 | TypeResult BaseType = ParseBaseTypeSpecifier(BaseLoc, EndLocation); |
Douglas Gregor | fe3d7d0 | 2009-04-01 21:51:26 +0000 | [diff] [blame] | 1733 | if (BaseType.isInvalid()) |
Douglas Gregor | 831c93f | 2008-11-05 20:51:48 +0000 | [diff] [blame] | 1734 | return true; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1735 | |
Douglas Gregor | 752a595 | 2011-01-03 22:36:02 +0000 | [diff] [blame] | 1736 | // Parse the optional ellipsis (for a pack expansion). The ellipsis is |
| 1737 | // actually part of the base-specifier-list grammar productions, but we |
| 1738 | // parse it here for convenience. |
| 1739 | SourceLocation EllipsisLoc; |
Alp Toker | 9765056 | 2014-01-10 11:19:30 +0000 | [diff] [blame] | 1740 | TryConsumeToken(tok::ellipsis, EllipsisLoc); |
| 1741 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1742 | // Find the complete source range for the base-specifier. |
Douglas Gregor | d54dfb8 | 2009-02-25 23:52:28 +0000 | [diff] [blame] | 1743 | SourceRange Range(StartLoc, EndLocation); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1744 | |
Douglas Gregor | 556877c | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 1745 | // Notify semantic analysis that we have parsed a complete |
| 1746 | // base-specifier. |
Richard Smith | 4c96e99 | 2013-02-19 23:47:15 +0000 | [diff] [blame] | 1747 | return Actions.ActOnBaseSpecifier(ClassDecl, Range, Attributes, IsVirtual, |
| 1748 | Access, BaseType.get(), BaseLoc, |
| 1749 | EllipsisLoc); |
Douglas Gregor | 556877c | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 1750 | } |
| 1751 | |
| 1752 | /// getAccessSpecifierIfPresent - Determine whether the next token is |
| 1753 | /// a C++ access-specifier. |
| 1754 | /// |
| 1755 | /// access-specifier: [C++ class.derived] |
| 1756 | /// 'private' |
| 1757 | /// 'protected' |
| 1758 | /// 'public' |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1759 | AccessSpecifier Parser::getAccessSpecifierIfPresent() const { |
Douglas Gregor | 556877c | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 1760 | switch (Tok.getKind()) { |
| 1761 | default: return AS_none; |
| 1762 | case tok::kw_private: return AS_private; |
| 1763 | case tok::kw_protected: return AS_protected; |
| 1764 | case tok::kw_public: return AS_public; |
| 1765 | } |
| 1766 | } |
Argyrios Kyrtzidis | 7bbb20e | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1767 | |
Douglas Gregor | 433e053 | 2012-04-16 18:27:27 +0000 | [diff] [blame] | 1768 | /// \brief If the given declarator has any parts for which parsing has to be |
Richard Smith | 2331bbf | 2012-05-02 22:22:32 +0000 | [diff] [blame] | 1769 | /// delayed, e.g., default arguments, create a late-parsed method declaration |
| 1770 | /// record to handle the parsing at the end of the class definition. |
Douglas Gregor | 433e053 | 2012-04-16 18:27:27 +0000 | [diff] [blame] | 1771 | void Parser::HandleMemberFunctionDeclDelays(Declarator& DeclaratorInfo, |
| 1772 | Decl *ThisDecl) { |
Eli Friedman | 3af2a77 | 2009-07-22 21:45:50 +0000 | [diff] [blame] | 1773 | // We just declared a member function. If this member function |
Richard Smith | 2331bbf | 2012-05-02 22:22:32 +0000 | [diff] [blame] | 1774 | // has any default arguments, we'll need to parse them later. |
Eli Friedman | 3af2a77 | 2009-07-22 21:45:50 +0000 | [diff] [blame] | 1775 | LateParsedMethodDeclaration *LateMethod = 0; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1776 | DeclaratorChunk::FunctionTypeInfo &FTI |
Abramo Bagnara | 924a8f3 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 1777 | = DeclaratorInfo.getFunctionTypeInfo(); |
Douglas Gregor | 433e053 | 2012-04-16 18:27:27 +0000 | [diff] [blame] | 1778 | |
Eli Friedman | 3af2a77 | 2009-07-22 21:45:50 +0000 | [diff] [blame] | 1779 | for (unsigned ParamIdx = 0; ParamIdx < FTI.NumArgs; ++ParamIdx) { |
| 1780 | if (LateMethod || FTI.ArgInfo[ParamIdx].DefaultArgTokens) { |
| 1781 | if (!LateMethod) { |
| 1782 | // Push this method onto the stack of late-parsed method |
| 1783 | // declarations. |
Douglas Gregor | efc4695 | 2010-10-12 16:25:54 +0000 | [diff] [blame] | 1784 | LateMethod = new LateParsedMethodDeclaration(this, ThisDecl); |
| 1785 | getCurrentClass().LateParsedDeclarations.push_back(LateMethod); |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 1786 | LateMethod->TemplateScope = getCurScope()->isTemplateParamScope(); |
Eli Friedman | 3af2a77 | 2009-07-22 21:45:50 +0000 | [diff] [blame] | 1787 | |
| 1788 | // Add all of the parameters prior to this one (they don't |
| 1789 | // have default arguments). |
| 1790 | LateMethod->DefaultArgs.reserve(FTI.NumArgs); |
| 1791 | for (unsigned I = 0; I < ParamIdx; ++I) |
| 1792 | LateMethod->DefaultArgs.push_back( |
Douglas Gregor | 1d85d29 | 2010-03-02 01:29:43 +0000 | [diff] [blame] | 1793 | LateParsedDefaultArgument(FTI.ArgInfo[I].Param)); |
Eli Friedman | 3af2a77 | 2009-07-22 21:45:50 +0000 | [diff] [blame] | 1794 | } |
| 1795 | |
Douglas Gregor | 433e053 | 2012-04-16 18:27:27 +0000 | [diff] [blame] | 1796 | // Add this parameter to the list of parameters (it may or may |
Eli Friedman | 3af2a77 | 2009-07-22 21:45:50 +0000 | [diff] [blame] | 1797 | // not have a default argument). |
| 1798 | LateMethod->DefaultArgs.push_back( |
| 1799 | LateParsedDefaultArgument(FTI.ArgInfo[ParamIdx].Param, |
| 1800 | FTI.ArgInfo[ParamIdx].DefaultArgTokens)); |
| 1801 | } |
| 1802 | } |
| 1803 | } |
| 1804 | |
Richard Smith | 89645bc | 2013-01-02 12:01:23 +0000 | [diff] [blame] | 1805 | /// isCXX11VirtSpecifier - Determine whether the given token is a C++11 |
Anders Carlsson | 11fdbbc | 2011-01-16 23:56:42 +0000 | [diff] [blame] | 1806 | /// virt-specifier. |
| 1807 | /// |
| 1808 | /// virt-specifier: |
| 1809 | /// override |
| 1810 | /// final |
Richard Smith | 89645bc | 2013-01-02 12:01:23 +0000 | [diff] [blame] | 1811 | VirtSpecifiers::Specifier Parser::isCXX11VirtSpecifier(const Token &Tok) const { |
Alp Toker | bb4b86a | 2014-01-09 00:13:52 +0000 | [diff] [blame] | 1812 | if (!getLangOpts().CPlusPlus || Tok.isNot(tok::identifier)) |
Anders Carlsson | 4b63d0e | 2011-01-22 16:56:46 +0000 | [diff] [blame] | 1813 | return VirtSpecifiers::VS_None; |
| 1814 | |
Alp Toker | bb4b86a | 2014-01-09 00:13:52 +0000 | [diff] [blame] | 1815 | IdentifierInfo *II = Tok.getIdentifierInfo(); |
Anders Carlsson | 11fdbbc | 2011-01-16 23:56:42 +0000 | [diff] [blame] | 1816 | |
Alp Toker | bb4b86a | 2014-01-09 00:13:52 +0000 | [diff] [blame] | 1817 | // Initialize the contextual keywords. |
| 1818 | if (!Ident_final) { |
| 1819 | Ident_final = &PP.getIdentifierTable().get("final"); |
| 1820 | if (getLangOpts().MicrosoftExt) |
| 1821 | Ident_sealed = &PP.getIdentifierTable().get("sealed"); |
| 1822 | Ident_override = &PP.getIdentifierTable().get("override"); |
Anders Carlsson | 5610490 | 2011-01-17 03:05:47 +0000 | [diff] [blame] | 1823 | } |
| 1824 | |
Alp Toker | bb4b86a | 2014-01-09 00:13:52 +0000 | [diff] [blame] | 1825 | if (II == Ident_override) |
| 1826 | return VirtSpecifiers::VS_Override; |
| 1827 | |
| 1828 | if (II == Ident_sealed) |
| 1829 | return VirtSpecifiers::VS_Sealed; |
| 1830 | |
| 1831 | if (II == Ident_final) |
| 1832 | return VirtSpecifiers::VS_Final; |
| 1833 | |
Anders Carlsson | 5610490 | 2011-01-17 03:05:47 +0000 | [diff] [blame] | 1834 | return VirtSpecifiers::VS_None; |
Anders Carlsson | 11fdbbc | 2011-01-16 23:56:42 +0000 | [diff] [blame] | 1835 | } |
| 1836 | |
Richard Smith | 89645bc | 2013-01-02 12:01:23 +0000 | [diff] [blame] | 1837 | /// ParseOptionalCXX11VirtSpecifierSeq - Parse a virt-specifier-seq. |
Anders Carlsson | 11fdbbc | 2011-01-16 23:56:42 +0000 | [diff] [blame] | 1838 | /// |
| 1839 | /// virt-specifier-seq: |
| 1840 | /// virt-specifier |
| 1841 | /// virt-specifier-seq virt-specifier |
Richard Smith | 89645bc | 2013-01-02 12:01:23 +0000 | [diff] [blame] | 1842 | void Parser::ParseOptionalCXX11VirtSpecifierSeq(VirtSpecifiers &VS, |
John McCall | db632ac | 2012-09-25 07:32:39 +0000 | [diff] [blame] | 1843 | bool IsInterface) { |
Anders Carlsson | 5610490 | 2011-01-17 03:05:47 +0000 | [diff] [blame] | 1844 | while (true) { |
Richard Smith | 89645bc | 2013-01-02 12:01:23 +0000 | [diff] [blame] | 1845 | VirtSpecifiers::Specifier Specifier = isCXX11VirtSpecifier(); |
Anders Carlsson | 5610490 | 2011-01-17 03:05:47 +0000 | [diff] [blame] | 1846 | if (Specifier == VirtSpecifiers::VS_None) |
| 1847 | return; |
| 1848 | |
| 1849 | // C++ [class.mem]p8: |
| 1850 | // A virt-specifier-seq shall contain at most one of each virt-specifier. |
Anders Carlsson | 4b63d0e | 2011-01-22 16:56:46 +0000 | [diff] [blame] | 1851 | const char *PrevSpec = 0; |
Anders Carlsson | f2ca389 | 2011-01-22 15:58:16 +0000 | [diff] [blame] | 1852 | if (VS.SetSpecifier(Specifier, Tok.getLocation(), PrevSpec)) |
Anders Carlsson | 5610490 | 2011-01-17 03:05:47 +0000 | [diff] [blame] | 1853 | Diag(Tok.getLocation(), diag::err_duplicate_virt_specifier) |
| 1854 | << PrevSpec |
| 1855 | << FixItHint::CreateRemoval(Tok.getLocation()); |
| 1856 | |
David Majnemer | a543308 | 2013-10-18 00:33:31 +0000 | [diff] [blame] | 1857 | if (IsInterface && (Specifier == VirtSpecifiers::VS_Final || |
| 1858 | Specifier == VirtSpecifiers::VS_Sealed)) { |
John McCall | db632ac | 2012-09-25 07:32:39 +0000 | [diff] [blame] | 1859 | Diag(Tok.getLocation(), diag::err_override_control_interface) |
| 1860 | << VirtSpecifiers::getSpecifierName(Specifier); |
David Majnemer | a543308 | 2013-10-18 00:33:31 +0000 | [diff] [blame] | 1861 | } else if (Specifier == VirtSpecifiers::VS_Sealed) { |
| 1862 | Diag(Tok.getLocation(), diag::ext_ms_sealed_keyword); |
John McCall | db632ac | 2012-09-25 07:32:39 +0000 | [diff] [blame] | 1863 | } else { |
David Majnemer | a543308 | 2013-10-18 00:33:31 +0000 | [diff] [blame] | 1864 | Diag(Tok.getLocation(), |
| 1865 | getLangOpts().CPlusPlus11 |
| 1866 | ? diag::warn_cxx98_compat_override_control_keyword |
| 1867 | : diag::ext_override_control_keyword) |
| 1868 | << VirtSpecifiers::getSpecifierName(Specifier); |
John McCall | db632ac | 2012-09-25 07:32:39 +0000 | [diff] [blame] | 1869 | } |
Anders Carlsson | 5610490 | 2011-01-17 03:05:47 +0000 | [diff] [blame] | 1870 | ConsumeToken(); |
| 1871 | } |
Anders Carlsson | 11fdbbc | 2011-01-16 23:56:42 +0000 | [diff] [blame] | 1872 | } |
| 1873 | |
Richard Smith | 89645bc | 2013-01-02 12:01:23 +0000 | [diff] [blame] | 1874 | /// isCXX11FinalKeyword - Determine whether the next token is a C++11 |
Alp Toker | bb4b86a | 2014-01-09 00:13:52 +0000 | [diff] [blame] | 1875 | /// 'final' or Microsoft 'sealed' contextual keyword. |
Richard Smith | 89645bc | 2013-01-02 12:01:23 +0000 | [diff] [blame] | 1876 | bool Parser::isCXX11FinalKeyword() const { |
Alp Toker | bb4b86a | 2014-01-09 00:13:52 +0000 | [diff] [blame] | 1877 | VirtSpecifiers::Specifier Specifier = isCXX11VirtSpecifier(); |
| 1878 | return Specifier == VirtSpecifiers::VS_Final || |
| 1879 | Specifier == VirtSpecifiers::VS_Sealed; |
Anders Carlsson | 4b63d0e | 2011-01-22 16:56:46 +0000 | [diff] [blame] | 1880 | } |
| 1881 | |
Richard Smith | 72553fc | 2014-01-23 23:53:27 +0000 | [diff] [blame] | 1882 | /// \brief Parse a C++ member-declarator up to, but not including, the optional |
| 1883 | /// brace-or-equal-initializer or pure-specifier. |
| 1884 | void Parser::ParseCXXMemberDeclaratorBeforeInitializer( |
| 1885 | Declarator &DeclaratorInfo, VirtSpecifiers &VS, ExprResult &BitfieldSize, |
| 1886 | LateParsedAttrList &LateParsedAttrs) { |
| 1887 | // member-declarator: |
| 1888 | // declarator pure-specifier[opt] |
| 1889 | // declarator brace-or-equal-initializer[opt] |
| 1890 | // identifier[opt] ':' constant-expression |
| 1891 | if (Tok.isNot(tok::colon)) { |
| 1892 | // Don't parse FOO:BAR as if it were a typo for FOO::BAR, in this context it |
| 1893 | // is a bitfield. |
| 1894 | // FIXME: This should only apply when parsing the id-expression (see |
| 1895 | // PR18587). |
| 1896 | ColonProtectionRAIIObject X(*this); |
| 1897 | ParseDeclarator(DeclaratorInfo); |
| 1898 | } |
| 1899 | |
| 1900 | if (!DeclaratorInfo.isFunctionDeclarator() && TryConsumeToken(tok::colon)) { |
| 1901 | BitfieldSize = ParseConstantExpression(); |
| 1902 | if (BitfieldSize.isInvalid()) |
| 1903 | SkipUntil(tok::comma, StopAtSemi | StopBeforeMatch); |
| 1904 | } else |
| 1905 | ParseOptionalCXX11VirtSpecifierSeq(VS, getCurrentClass().IsInterface); |
| 1906 | |
| 1907 | // If a simple-asm-expr is present, parse it. |
| 1908 | if (Tok.is(tok::kw_asm)) { |
| 1909 | SourceLocation Loc; |
| 1910 | ExprResult AsmLabel(ParseSimpleAsm(&Loc)); |
| 1911 | if (AsmLabel.isInvalid()) |
| 1912 | SkipUntil(tok::comma, StopAtSemi | StopBeforeMatch); |
| 1913 | |
| 1914 | DeclaratorInfo.setAsmLabel(AsmLabel.release()); |
| 1915 | DeclaratorInfo.SetRangeEnd(Loc); |
| 1916 | } |
| 1917 | |
| 1918 | // If attributes exist after the declarator, but before an '{', parse them. |
| 1919 | MaybeParseGNUAttributes(DeclaratorInfo, &LateParsedAttrs); |
Richard Smith | 4b5a949 | 2014-01-24 22:34:35 +0000 | [diff] [blame] | 1920 | |
| 1921 | // For compatibility with code written to older Clang, also accept a |
| 1922 | // virt-specifier *after* the GNU attributes. |
| 1923 | // FIXME: If we saw any attributes that are known to GCC followed by a |
| 1924 | // virt-specifier, issue a GCC-compat warning. |
| 1925 | if (BitfieldSize.isUnset() && VS.isUnset()) |
| 1926 | ParseOptionalCXX11VirtSpecifierSeq(VS, getCurrentClass().IsInterface); |
Richard Smith | 72553fc | 2014-01-23 23:53:27 +0000 | [diff] [blame] | 1927 | } |
| 1928 | |
Argyrios Kyrtzidis | 7bbb20e | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1929 | /// ParseCXXClassMemberDeclaration - Parse a C++ class member declaration. |
| 1930 | /// |
| 1931 | /// member-declaration: |
| 1932 | /// decl-specifier-seq[opt] member-declarator-list[opt] ';' |
| 1933 | /// function-definition ';'[opt] |
| 1934 | /// ::[opt] nested-name-specifier template[opt] unqualified-id ';'[TODO] |
| 1935 | /// using-declaration [TODO] |
Anders Carlsson | f24fcff6 | 2009-03-11 16:27:10 +0000 | [diff] [blame] | 1936 | /// [C++0x] static_assert-declaration |
Anders Carlsson | dfbbdf6 | 2009-03-26 00:52:18 +0000 | [diff] [blame] | 1937 | /// template-declaration |
Chris Lattner | d19c1c0 | 2008-12-18 01:12:00 +0000 | [diff] [blame] | 1938 | /// [GNU] '__extension__' member-declaration |
Argyrios Kyrtzidis | 7bbb20e | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1939 | /// |
| 1940 | /// member-declarator-list: |
| 1941 | /// member-declarator |
| 1942 | /// member-declarator-list ',' member-declarator |
| 1943 | /// |
| 1944 | /// member-declarator: |
Anders Carlsson | 11fdbbc | 2011-01-16 23:56:42 +0000 | [diff] [blame] | 1945 | /// declarator virt-specifier-seq[opt] pure-specifier[opt] |
Argyrios Kyrtzidis | 7bbb20e | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1946 | /// declarator constant-initializer[opt] |
Richard Smith | 938f40b | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 1947 | /// [C++11] declarator brace-or-equal-initializer[opt] |
Argyrios Kyrtzidis | 7bbb20e | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1948 | /// identifier[opt] ':' constant-expression |
| 1949 | /// |
Anders Carlsson | 11fdbbc | 2011-01-16 23:56:42 +0000 | [diff] [blame] | 1950 | /// virt-specifier-seq: |
| 1951 | /// virt-specifier |
| 1952 | /// virt-specifier-seq virt-specifier |
| 1953 | /// |
| 1954 | /// virt-specifier: |
| 1955 | /// override |
| 1956 | /// final |
David Majnemer | a543308 | 2013-10-18 00:33:31 +0000 | [diff] [blame] | 1957 | /// [MS] sealed |
Anders Carlsson | 11fdbbc | 2011-01-16 23:56:42 +0000 | [diff] [blame] | 1958 | /// |
Sebastian Redl | 42e92c4 | 2009-04-12 17:16:29 +0000 | [diff] [blame] | 1959 | /// pure-specifier: |
Argyrios Kyrtzidis | 7bbb20e | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1960 | /// '= 0' |
| 1961 | /// |
| 1962 | /// constant-initializer: |
| 1963 | /// '=' constant-expression |
| 1964 | /// |
Douglas Gregor | 3447e76 | 2009-08-20 22:52:58 +0000 | [diff] [blame] | 1965 | void Parser::ParseCXXClassMemberDeclaration(AccessSpecifier AS, |
Erik Verbruggen | ca98f2a | 2011-10-13 09:41:32 +0000 | [diff] [blame] | 1966 | AttributeList *AccessAttrs, |
John McCall | 796c2a5 | 2010-07-16 08:13:16 +0000 | [diff] [blame] | 1967 | const ParsedTemplateInfo &TemplateInfo, |
| 1968 | ParsingDeclRAIIObject *TemplateDiags) { |
Douglas Gregor | 23c8476 | 2011-04-14 17:21:19 +0000 | [diff] [blame] | 1969 | if (Tok.is(tok::at)) { |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 1970 | if (getLangOpts().ObjC1 && NextToken().isObjCAtKeyword(tok::objc_defs)) |
Douglas Gregor | 23c8476 | 2011-04-14 17:21:19 +0000 | [diff] [blame] | 1971 | Diag(Tok, diag::err_at_defs_cxx); |
| 1972 | else |
| 1973 | Diag(Tok, diag::err_at_in_class); |
Richard Smith | da35e96 | 2013-11-09 04:52:51 +0000 | [diff] [blame] | 1974 | |
Douglas Gregor | 23c8476 | 2011-04-14 17:21:19 +0000 | [diff] [blame] | 1975 | ConsumeToken(); |
Alexey Bataev | ee6507d | 2013-11-18 08:17:37 +0000 | [diff] [blame] | 1976 | SkipUntil(tok::r_brace, StopAtSemi); |
Douglas Gregor | 23c8476 | 2011-04-14 17:21:19 +0000 | [diff] [blame] | 1977 | return; |
| 1978 | } |
Richard Smith | da35e96 | 2013-11-09 04:52:51 +0000 | [diff] [blame] | 1979 | |
John McCall | a009726 | 2009-12-11 02:10:03 +0000 | [diff] [blame] | 1980 | // Access declarations. |
Richard Smith | 45855df | 2012-05-09 08:23:23 +0000 | [diff] [blame] | 1981 | bool MalformedTypeSpec = false; |
John McCall | a009726 | 2009-12-11 02:10:03 +0000 | [diff] [blame] | 1982 | if (!TemplateInfo.Kind && |
Richard Smith | 45855df | 2012-05-09 08:23:23 +0000 | [diff] [blame] | 1983 | (Tok.is(tok::identifier) || Tok.is(tok::coloncolon))) { |
| 1984 | if (TryAnnotateCXXScopeToken()) |
| 1985 | MalformedTypeSpec = true; |
| 1986 | |
| 1987 | bool isAccessDecl; |
| 1988 | if (Tok.isNot(tok::annot_cxxscope)) |
| 1989 | isAccessDecl = false; |
| 1990 | else if (NextToken().is(tok::identifier)) |
John McCall | a009726 | 2009-12-11 02:10:03 +0000 | [diff] [blame] | 1991 | isAccessDecl = GetLookAheadToken(2).is(tok::semi); |
| 1992 | else |
| 1993 | isAccessDecl = NextToken().is(tok::kw_operator); |
| 1994 | |
| 1995 | if (isAccessDecl) { |
| 1996 | // Collect the scope specifier token we annotated earlier. |
| 1997 | CXXScopeSpec SS; |
Douglas Gregor | df593fb | 2011-11-07 17:33:42 +0000 | [diff] [blame] | 1998 | ParseOptionalCXXScopeSpecifier(SS, ParsedType(), |
| 1999 | /*EnteringContext=*/false); |
John McCall | a009726 | 2009-12-11 02:10:03 +0000 | [diff] [blame] | 2000 | |
| 2001 | // Try to parse an unqualified-id. |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2002 | SourceLocation TemplateKWLoc; |
John McCall | a009726 | 2009-12-11 02:10:03 +0000 | [diff] [blame] | 2003 | UnqualifiedId Name; |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2004 | if (ParseUnqualifiedId(SS, false, true, true, ParsedType(), |
| 2005 | TemplateKWLoc, Name)) { |
John McCall | a009726 | 2009-12-11 02:10:03 +0000 | [diff] [blame] | 2006 | SkipUntil(tok::semi); |
| 2007 | return; |
| 2008 | } |
| 2009 | |
| 2010 | // TODO: recover from mistakenly-qualified operator declarations. |
Alp Toker | 383d2c4 | 2014-01-01 03:08:43 +0000 | [diff] [blame] | 2011 | if (ExpectAndConsume(tok::semi, diag::err_expected_after, |
| 2012 | "access declaration")) { |
| 2013 | SkipUntil(tok::semi); |
John McCall | a009726 | 2009-12-11 02:10:03 +0000 | [diff] [blame] | 2014 | return; |
Alp Toker | 383d2c4 | 2014-01-01 03:08:43 +0000 | [diff] [blame] | 2015 | } |
John McCall | a009726 | 2009-12-11 02:10:03 +0000 | [diff] [blame] | 2016 | |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 2017 | Actions.ActOnUsingDeclaration(getCurScope(), AS, |
Enea Zaffanella | e05a3cf | 2013-07-22 10:54:09 +0000 | [diff] [blame] | 2018 | /* HasUsingKeyword */ false, |
| 2019 | SourceLocation(), |
John McCall | a009726 | 2009-12-11 02:10:03 +0000 | [diff] [blame] | 2020 | SS, Name, |
| 2021 | /* AttrList */ 0, |
Enea Zaffanella | e05a3cf | 2013-07-22 10:54:09 +0000 | [diff] [blame] | 2022 | /* HasTypenameKeyword */ false, |
John McCall | a009726 | 2009-12-11 02:10:03 +0000 | [diff] [blame] | 2023 | SourceLocation()); |
| 2024 | return; |
| 2025 | } |
| 2026 | } |
| 2027 | |
Anders Carlsson | f24fcff6 | 2009-03-11 16:27:10 +0000 | [diff] [blame] | 2028 | // static_assert-declaration |
Peter Collingbourne | 3d9cbdc | 2011-04-15 00:35:57 +0000 | [diff] [blame] | 2029 | if (Tok.is(tok::kw_static_assert) || Tok.is(tok::kw__Static_assert)) { |
Douglas Gregor | 3447e76 | 2009-08-20 22:52:58 +0000 | [diff] [blame] | 2030 | // FIXME: Check for templates |
Chris Lattner | 49836b4 | 2009-04-02 04:16:50 +0000 | [diff] [blame] | 2031 | SourceLocation DeclEnd; |
| 2032 | ParseStaticAssertDeclaration(DeclEnd); |
Chris Lattner | 5bbb3c8 | 2009-03-29 16:50:03 +0000 | [diff] [blame] | 2033 | return; |
| 2034 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2035 | |
Chris Lattner | 5bbb3c8 | 2009-03-29 16:50:03 +0000 | [diff] [blame] | 2036 | if (Tok.is(tok::kw_template)) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2037 | assert(!TemplateInfo.TemplateParams && |
Douglas Gregor | 3447e76 | 2009-08-20 22:52:58 +0000 | [diff] [blame] | 2038 | "Nested template improperly parsed?"); |
Chris Lattner | 49836b4 | 2009-04-02 04:16:50 +0000 | [diff] [blame] | 2039 | SourceLocation DeclEnd; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2040 | ParseDeclarationStartingWithTemplate(Declarator::MemberContext, DeclEnd, |
Erik Verbruggen | ca98f2a | 2011-10-13 09:41:32 +0000 | [diff] [blame] | 2041 | AS, AccessAttrs); |
Chris Lattner | 5bbb3c8 | 2009-03-29 16:50:03 +0000 | [diff] [blame] | 2042 | return; |
| 2043 | } |
Anders Carlsson | dfbbdf6 | 2009-03-26 00:52:18 +0000 | [diff] [blame] | 2044 | |
Chris Lattner | d19c1c0 | 2008-12-18 01:12:00 +0000 | [diff] [blame] | 2045 | // Handle: member-declaration ::= '__extension__' member-declaration |
| 2046 | if (Tok.is(tok::kw___extension__)) { |
| 2047 | // __extension__ silences extension warnings in the subexpression. |
| 2048 | ExtensionRAIIObject O(Diags); // Use RAII to do this. |
| 2049 | ConsumeToken(); |
Erik Verbruggen | ca98f2a | 2011-10-13 09:41:32 +0000 | [diff] [blame] | 2050 | return ParseCXXClassMemberDeclaration(AS, AccessAttrs, |
| 2051 | TemplateInfo, TemplateDiags); |
Chris Lattner | d19c1c0 | 2008-12-18 01:12:00 +0000 | [diff] [blame] | 2052 | } |
Douglas Gregor | fec5263 | 2009-06-20 00:51:54 +0000 | [diff] [blame] | 2053 | |
John McCall | 084e83d | 2011-03-24 11:26:52 +0000 | [diff] [blame] | 2054 | ParsedAttributesWithRange attrs(AttrFactory); |
Michael Han | ddc016d | 2012-11-28 23:17:40 +0000 | [diff] [blame] | 2055 | ParsedAttributesWithRange FnAttrs(AttrFactory); |
Richard Smith | 89645bc | 2013-01-02 12:01:23 +0000 | [diff] [blame] | 2056 | // Optional C++11 attribute-specifier |
| 2057 | MaybeParseCXX11Attributes(attrs); |
Michael Han | ddc016d | 2012-11-28 23:17:40 +0000 | [diff] [blame] | 2058 | // We need to keep these attributes for future diagnostic |
| 2059 | // before they are taken over by declaration specifier. |
| 2060 | FnAttrs.addAll(attrs.getList()); |
| 2061 | FnAttrs.Range = attrs.Range; |
| 2062 | |
John McCall | 53fa714 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 2063 | MaybeParseMicrosoftAttributes(attrs); |
Alexis Hunt | 96d5c76 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 2064 | |
Douglas Gregor | fec5263 | 2009-06-20 00:51:54 +0000 | [diff] [blame] | 2065 | if (Tok.is(tok::kw_using)) { |
John McCall | 53fa714 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 2066 | ProhibitAttributes(attrs); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2067 | |
Douglas Gregor | fec5263 | 2009-06-20 00:51:54 +0000 | [diff] [blame] | 2068 | // Eat 'using'. |
| 2069 | SourceLocation UsingLoc = ConsumeToken(); |
| 2070 | |
| 2071 | if (Tok.is(tok::kw_namespace)) { |
| 2072 | Diag(UsingLoc, diag::err_using_namespace_in_class); |
Alexey Bataev | ee6507d | 2013-11-18 08:17:37 +0000 | [diff] [blame] | 2073 | SkipUntil(tok::semi, StopBeforeMatch); |
Chris Lattner | 916dbf1 | 2010-02-02 00:43:15 +0000 | [diff] [blame] | 2074 | } else { |
Douglas Gregor | fec5263 | 2009-06-20 00:51:54 +0000 | [diff] [blame] | 2075 | SourceLocation DeclEnd; |
Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 2076 | // Otherwise, it must be a using-declaration or an alias-declaration. |
John McCall | 9b72f89 | 2010-11-10 02:40:36 +0000 | [diff] [blame] | 2077 | ParseUsingDeclaration(Declarator::MemberContext, TemplateInfo, |
| 2078 | UsingLoc, DeclEnd, AS); |
Douglas Gregor | fec5263 | 2009-06-20 00:51:54 +0000 | [diff] [blame] | 2079 | } |
| 2080 | return; |
| 2081 | } |
| 2082 | |
DeLesley Hutchins | bd2ee13 | 2012-03-02 22:12:59 +0000 | [diff] [blame] | 2083 | // Hold late-parsed attributes so we can attach a Decl to them later. |
| 2084 | LateParsedAttrList CommonLateParsedAttrs; |
| 2085 | |
Argyrios Kyrtzidis | 7bbb20e | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 2086 | // decl-specifier-seq: |
| 2087 | // Parse the common declaration-specifiers piece. |
John McCall | 796c2a5 | 2010-07-16 08:13:16 +0000 | [diff] [blame] | 2088 | ParsingDeclSpec DS(*this, TemplateDiags); |
John McCall | 53fa714 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 2089 | DS.takeAttributesFrom(attrs); |
Richard Smith | 45855df | 2012-05-09 08:23:23 +0000 | [diff] [blame] | 2090 | if (MalformedTypeSpec) |
| 2091 | DS.SetTypeSpecError(); |
Richard Smith | 72553fc | 2014-01-23 23:53:27 +0000 | [diff] [blame] | 2092 | |
| 2093 | { |
| 2094 | // Don't parse FOO:BAR as if it were a typo for FOO::BAR, in this context it |
| 2095 | // is a bitfield. |
| 2096 | ColonProtectionRAIIObject X(*this); |
| 2097 | ParseDeclarationSpecifiers(DS, TemplateInfo, AS, DSC_class, |
| 2098 | &CommonLateParsedAttrs); |
| 2099 | } |
Argyrios Kyrtzidis | 7bbb20e | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 2100 | |
Richard Smith | 404dfb4 | 2013-11-19 22:47:36 +0000 | [diff] [blame] | 2101 | // If we had a free-standing type definition with a missing semicolon, we |
| 2102 | // may get this far before the problem becomes obvious. |
| 2103 | if (DS.hasTagDefinition() && |
| 2104 | TemplateInfo.Kind == ParsedTemplateInfo::NonTemplate && |
| 2105 | DiagnoseMissingSemiAfterTagDefinition(DS, AS, DSC_class, |
| 2106 | &CommonLateParsedAttrs)) |
| 2107 | return; |
| 2108 | |
Benjamin Kramer | cc4c49d | 2012-08-23 23:38:35 +0000 | [diff] [blame] | 2109 | MultiTemplateParamsArg TemplateParams( |
John McCall | 11083da | 2009-09-16 22:47:08 +0000 | [diff] [blame] | 2110 | TemplateInfo.TemplateParams? TemplateInfo.TemplateParams->data() : 0, |
| 2111 | TemplateInfo.TemplateParams? TemplateInfo.TemplateParams->size() : 0); |
| 2112 | |
Alp Toker | 35d8703 | 2013-12-30 23:29:50 +0000 | [diff] [blame] | 2113 | if (TryConsumeToken(tok::semi)) { |
Michael Han | ddc016d | 2012-11-28 23:17:40 +0000 | [diff] [blame] | 2114 | if (DS.isFriendSpecified()) |
| 2115 | ProhibitAttributes(FnAttrs); |
| 2116 | |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 2117 | Decl *TheDecl = |
Chandler Carruth | 7c9856d | 2011-05-03 18:35:10 +0000 | [diff] [blame] | 2118 | Actions.ParsedFreeStandingDeclSpec(getCurScope(), AS, DS, TemplateParams); |
John McCall | 796c2a5 | 2010-07-16 08:13:16 +0000 | [diff] [blame] | 2119 | DS.complete(TheDecl); |
John McCall | 07e91c0 | 2009-08-06 02:15:43 +0000 | [diff] [blame] | 2120 | return; |
Argyrios Kyrtzidis | 7bbb20e | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 2121 | } |
Argyrios Kyrtzidis | ed98342 | 2008-07-01 10:37:29 +0000 | [diff] [blame] | 2122 | |
John McCall | 28a6aea | 2009-11-04 02:18:39 +0000 | [diff] [blame] | 2123 | ParsingDeclarator DeclaratorInfo(*this, DS, Declarator::MemberContext); |
Nico Weber | 24b2a82 | 2011-01-28 06:07:34 +0000 | [diff] [blame] | 2124 | VirtSpecifiers VS; |
Argyrios Kyrtzidis | 7bbb20e | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 2125 | |
Caitlin Sadowski | 9385dd7 | 2011-09-08 17:42:22 +0000 | [diff] [blame] | 2126 | // Hold late-parsed attributes so we can attach a Decl to them later. |
| 2127 | LateParsedAttrList LateParsedAttrs; |
| 2128 | |
Douglas Gregor | 50cefbf | 2011-10-17 17:09:53 +0000 | [diff] [blame] | 2129 | SourceLocation EqualLoc; |
| 2130 | bool HasInitializer = false; |
| 2131 | ExprResult Init; |
Chris Lattner | 17c3b1f | 2009-12-10 01:59:24 +0000 | [diff] [blame] | 2132 | |
Richard Smith | 72553fc | 2014-01-23 23:53:27 +0000 | [diff] [blame] | 2133 | SmallVector<Decl *, 8> DeclsInGroup; |
| 2134 | ExprResult BitfieldSize; |
| 2135 | bool ExpectSemi = true; |
Argyrios Kyrtzidis | 7bbb20e | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 2136 | |
Richard Smith | 72553fc | 2014-01-23 23:53:27 +0000 | [diff] [blame] | 2137 | // Parse the first declarator. |
| 2138 | ParseCXXMemberDeclaratorBeforeInitializer(DeclaratorInfo, VS, BitfieldSize, |
| 2139 | LateParsedAttrs); |
Nico Weber | 24b2a82 | 2011-01-28 06:07:34 +0000 | [diff] [blame] | 2140 | |
Richard Smith | 72553fc | 2014-01-23 23:53:27 +0000 | [diff] [blame] | 2141 | // If this has neither a name nor a bit width, something has gone seriously |
| 2142 | // wrong. Skip until the semi-colon or }. |
Richard Smith | 4b5a949 | 2014-01-24 22:34:35 +0000 | [diff] [blame] | 2143 | if (!DeclaratorInfo.hasName() && BitfieldSize.isUnset()) { |
Richard Smith | 72553fc | 2014-01-23 23:53:27 +0000 | [diff] [blame] | 2144 | // If so, skip until the semi-colon or a }. |
| 2145 | SkipUntil(tok::r_brace, StopAtSemi | StopBeforeMatch); |
| 2146 | TryConsumeToken(tok::semi); |
| 2147 | return; |
| 2148 | } |
John Thompson | 5bc5cbe | 2009-11-25 22:58:06 +0000 | [diff] [blame] | 2149 | |
Richard Smith | 72553fc | 2014-01-23 23:53:27 +0000 | [diff] [blame] | 2150 | // Check for a member function definition. |
Richard Smith | 4b5a949 | 2014-01-24 22:34:35 +0000 | [diff] [blame] | 2151 | if (BitfieldSize.isUnset()) { |
Richard Smith | 72553fc | 2014-01-23 23:53:27 +0000 | [diff] [blame] | 2152 | // MSVC permits pure specifier on inline functions defined at class scope. |
Francois Pichet | 3abc9b8 | 2011-05-11 02:14:46 +0000 | [diff] [blame] | 2153 | // Hence check for =0 before checking for function definition. |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 2154 | if (getLangOpts().MicrosoftExt && Tok.is(tok::equal) && |
Richard Smith | 72553fc | 2014-01-23 23:53:27 +0000 | [diff] [blame] | 2155 | DeclaratorInfo.isFunctionDeclarator() && |
Francois Pichet | 3abc9b8 | 2011-05-11 02:14:46 +0000 | [diff] [blame] | 2156 | NextToken().is(tok::numeric_constant)) { |
Douglas Gregor | 50cefbf | 2011-10-17 17:09:53 +0000 | [diff] [blame] | 2157 | EqualLoc = ConsumeToken(); |
Francois Pichet | 3abc9b8 | 2011-05-11 02:14:46 +0000 | [diff] [blame] | 2158 | Init = ParseInitializer(); |
| 2159 | if (Init.isInvalid()) |
Alexey Bataev | ee6507d | 2013-11-18 08:17:37 +0000 | [diff] [blame] | 2160 | SkipUntil(tok::comma, StopAtSemi | StopBeforeMatch); |
Douglas Gregor | 50cefbf | 2011-10-17 17:09:53 +0000 | [diff] [blame] | 2161 | else |
| 2162 | HasInitializer = true; |
Francois Pichet | 3abc9b8 | 2011-05-11 02:14:46 +0000 | [diff] [blame] | 2163 | } |
| 2164 | |
Douglas Gregor | 5d1b4e3 | 2011-11-07 20:56:01 +0000 | [diff] [blame] | 2165 | FunctionDefinitionKind DefinitionKind = FDK_Declaration; |
Argyrios Kyrtzidis | f4ebe9e | 2008-06-28 08:10:48 +0000 | [diff] [blame] | 2166 | // function-definition: |
Richard Smith | 938f40b | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 2167 | // |
| 2168 | // In C++11, a non-function declarator followed by an open brace is a |
| 2169 | // braced-init-list for an in-class member initialization, not an |
| 2170 | // erroneous function definition. |
Richard Smith | 2bf7fdb | 2013-01-02 11:42:31 +0000 | [diff] [blame] | 2171 | if (Tok.is(tok::l_brace) && !getLangOpts().CPlusPlus11) { |
Douglas Gregor | 5d1b4e3 | 2011-11-07 20:56:01 +0000 | [diff] [blame] | 2172 | DefinitionKind = FDK_Definition; |
Alexis Hunt | 5a7fa25 | 2011-05-12 06:15:49 +0000 | [diff] [blame] | 2173 | } else if (DeclaratorInfo.isFunctionDeclarator()) { |
Richard Smith | 938f40b | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 2174 | if (Tok.is(tok::l_brace) || Tok.is(tok::colon) || Tok.is(tok::kw_try)) { |
Douglas Gregor | 5d1b4e3 | 2011-11-07 20:56:01 +0000 | [diff] [blame] | 2175 | DefinitionKind = FDK_Definition; |
Alexis Hunt | 5a7fa25 | 2011-05-12 06:15:49 +0000 | [diff] [blame] | 2176 | } else if (Tok.is(tok::equal)) { |
| 2177 | const Token &KW = NextToken(); |
Douglas Gregor | 5d1b4e3 | 2011-11-07 20:56:01 +0000 | [diff] [blame] | 2178 | if (KW.is(tok::kw_default)) |
| 2179 | DefinitionKind = FDK_Defaulted; |
| 2180 | else if (KW.is(tok::kw_delete)) |
| 2181 | DefinitionKind = FDK_Deleted; |
Alexis Hunt | 5a7fa25 | 2011-05-12 06:15:49 +0000 | [diff] [blame] | 2182 | } |
| 2183 | } |
| 2184 | |
Michael Han | ddc016d | 2012-11-28 23:17:40 +0000 | [diff] [blame] | 2185 | // C++11 [dcl.attr.grammar] p4: If an attribute-specifier-seq appertains |
| 2186 | // to a friend declaration, that declaration shall be a definition. |
| 2187 | if (DeclaratorInfo.isFunctionDeclarator() && |
| 2188 | DefinitionKind != FDK_Definition && DS.isFriendSpecified()) { |
| 2189 | // Diagnose attributes that appear before decl specifier: |
| 2190 | // [[]] friend int foo(); |
| 2191 | ProhibitAttributes(FnAttrs); |
| 2192 | } |
| 2193 | |
Douglas Gregor | 5d1b4e3 | 2011-11-07 20:56:01 +0000 | [diff] [blame] | 2194 | if (DefinitionKind) { |
Argyrios Kyrtzidis | f4ebe9e | 2008-06-28 08:10:48 +0000 | [diff] [blame] | 2195 | if (!DeclaratorInfo.isFunctionDeclarator()) { |
Richard Trieu | 0d73054 | 2012-01-21 02:59:18 +0000 | [diff] [blame] | 2196 | Diag(DeclaratorInfo.getIdentifierLoc(), diag::err_func_def_no_params); |
Argyrios Kyrtzidis | f4ebe9e | 2008-06-28 08:10:48 +0000 | [diff] [blame] | 2197 | ConsumeBrace(); |
Alexey Bataev | ee6507d | 2013-11-18 08:17:37 +0000 | [diff] [blame] | 2198 | SkipUntil(tok::r_brace); |
Michael Han | ddc016d | 2012-11-28 23:17:40 +0000 | [diff] [blame] | 2199 | |
Douglas Gregor | 8a4db83 | 2011-01-19 16:41:58 +0000 | [diff] [blame] | 2200 | // Consume the optional ';' |
Alp Toker | 35d8703 | 2013-12-30 23:29:50 +0000 | [diff] [blame] | 2201 | TryConsumeToken(tok::semi); |
| 2202 | |
Chris Lattner | 5bbb3c8 | 2009-03-29 16:50:03 +0000 | [diff] [blame] | 2203 | return; |
Argyrios Kyrtzidis | f4ebe9e | 2008-06-28 08:10:48 +0000 | [diff] [blame] | 2204 | } |
Argyrios Kyrtzidis | 7bbb20e | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 2205 | |
Argyrios Kyrtzidis | f4ebe9e | 2008-06-28 08:10:48 +0000 | [diff] [blame] | 2206 | if (DS.getStorageClassSpec() == DeclSpec::SCS_typedef) { |
Richard Trieu | 0d73054 | 2012-01-21 02:59:18 +0000 | [diff] [blame] | 2207 | Diag(DeclaratorInfo.getIdentifierLoc(), |
| 2208 | diag::err_function_declared_typedef); |
Douglas Gregor | 8a4db83 | 2011-01-19 16:41:58 +0000 | [diff] [blame] | 2209 | |
Richard Smith | 2603b09 | 2012-11-15 22:54:20 +0000 | [diff] [blame] | 2210 | // Recover by treating the 'typedef' as spurious. |
| 2211 | DS.ClearStorageClassSpecs(); |
Argyrios Kyrtzidis | f4ebe9e | 2008-06-28 08:10:48 +0000 | [diff] [blame] | 2212 | } |
| 2213 | |
Caitlin Sadowski | 9385dd7 | 2011-09-08 17:42:22 +0000 | [diff] [blame] | 2214 | Decl *FunDecl = |
Erik Verbruggen | ca98f2a | 2011-10-13 09:41:32 +0000 | [diff] [blame] | 2215 | ParseCXXInlineMethodDef(AS, AccessAttrs, DeclaratorInfo, TemplateInfo, |
Douglas Gregor | 5d1b4e3 | 2011-11-07 20:56:01 +0000 | [diff] [blame] | 2216 | VS, DefinitionKind, Init); |
Caitlin Sadowski | 9385dd7 | 2011-09-08 17:42:22 +0000 | [diff] [blame] | 2217 | |
David Majnemer | 23252a3 | 2013-08-01 04:22:55 +0000 | [diff] [blame] | 2218 | if (FunDecl) { |
| 2219 | for (unsigned i = 0, ni = CommonLateParsedAttrs.size(); i < ni; ++i) { |
| 2220 | CommonLateParsedAttrs[i]->addDecl(FunDecl); |
| 2221 | } |
| 2222 | for (unsigned i = 0, ni = LateParsedAttrs.size(); i < ni; ++i) { |
| 2223 | LateParsedAttrs[i]->addDecl(FunDecl); |
| 2224 | } |
Caitlin Sadowski | 9385dd7 | 2011-09-08 17:42:22 +0000 | [diff] [blame] | 2225 | } |
| 2226 | LateParsedAttrs.clear(); |
Alexis Hunt | 5a7fa25 | 2011-05-12 06:15:49 +0000 | [diff] [blame] | 2227 | |
| 2228 | // Consume the ';' - it's optional unless we have a delete or default |
Richard Trieu | 2f7dc46 | 2012-05-16 19:04:59 +0000 | [diff] [blame] | 2229 | if (Tok.is(tok::semi)) |
Richard Smith | 87f5dc5 | 2012-07-23 05:45:25 +0000 | [diff] [blame] | 2230 | ConsumeExtraSemi(AfterMemberFunctionDefinition); |
Douglas Gregor | 8a4db83 | 2011-01-19 16:41:58 +0000 | [diff] [blame] | 2231 | |
Chris Lattner | 5bbb3c8 | 2009-03-29 16:50:03 +0000 | [diff] [blame] | 2232 | return; |
Argyrios Kyrtzidis | f4ebe9e | 2008-06-28 08:10:48 +0000 | [diff] [blame] | 2233 | } |
Argyrios Kyrtzidis | 7bbb20e | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 2234 | } |
| 2235 | |
| 2236 | // member-declarator-list: |
| 2237 | // member-declarator |
| 2238 | // member-declarator-list ',' member-declarator |
| 2239 | |
Argyrios Kyrtzidis | 7bbb20e | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 2240 | while (1) { |
Richard Smith | 2b01318 | 2012-06-10 03:12:00 +0000 | [diff] [blame] | 2241 | InClassInitStyle HasInClassInit = ICIS_NoInit; |
Douglas Gregor | 50cefbf | 2011-10-17 17:09:53 +0000 | [diff] [blame] | 2242 | if ((Tok.is(tok::equal) || Tok.is(tok::l_brace)) && !HasInitializer) { |
Richard Smith | 938f40b | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 2243 | if (BitfieldSize.get()) { |
| 2244 | Diag(Tok, diag::err_bitfield_member_init); |
Alexey Bataev | ee6507d | 2013-11-18 08:17:37 +0000 | [diff] [blame] | 2245 | SkipUntil(tok::comma, StopAtSemi | StopBeforeMatch); |
Richard Smith | 938f40b | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 2246 | } else { |
Douglas Gregor | 728d00b | 2011-10-10 14:49:18 +0000 | [diff] [blame] | 2247 | HasInitializer = true; |
Richard Smith | 2b01318 | 2012-06-10 03:12:00 +0000 | [diff] [blame] | 2248 | if (!DeclaratorInfo.isDeclarationOfFunction() && |
| 2249 | DeclaratorInfo.getDeclSpec().getStorageClassSpec() |
Richard Smith | 2b01318 | 2012-06-10 03:12:00 +0000 | [diff] [blame] | 2250 | != DeclSpec::SCS_typedef) |
| 2251 | HasInClassInit = Tok.is(tok::equal) ? ICIS_CopyInit : ICIS_ListInit; |
Richard Smith | 938f40b | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 2252 | } |
| 2253 | } |
| 2254 | |
Argyrios Kyrtzidis | ed98342 | 2008-07-01 10:37:29 +0000 | [diff] [blame] | 2255 | // NOTE: If Sema is the Action module and declarator is an instance field, |
Chris Lattner | 5bbb3c8 | 2009-03-29 16:50:03 +0000 | [diff] [blame] | 2256 | // this call will *not* return the created decl; It will return null. |
Argyrios Kyrtzidis | ed98342 | 2008-07-01 10:37:29 +0000 | [diff] [blame] | 2257 | // See Sema::ActOnCXXMemberDeclarator for details. |
John McCall | 07e91c0 | 2009-08-06 02:15:43 +0000 | [diff] [blame] | 2258 | |
Rafael Espindola | 0a67e2f | 2013-01-08 20:44:06 +0000 | [diff] [blame] | 2259 | NamedDecl *ThisDecl = 0; |
John McCall | 07e91c0 | 2009-08-06 02:15:43 +0000 | [diff] [blame] | 2260 | if (DS.isFriendSpecified()) { |
Richard Smith | 72553fc | 2014-01-23 23:53:27 +0000 | [diff] [blame] | 2261 | // C++11 [dcl.attr.grammar] p4: If an attribute-specifier-seq appertains |
Michael Han | ddc016d | 2012-11-28 23:17:40 +0000 | [diff] [blame] | 2262 | // to a friend declaration, that declaration shall be a definition. |
| 2263 | // |
Richard Smith | 72553fc | 2014-01-23 23:53:27 +0000 | [diff] [blame] | 2264 | // Diagnose attributes that appear in a friend member function declarator: |
| 2265 | // friend int foo [[]] (); |
Michael Han | ddc016d | 2012-11-28 23:17:40 +0000 | [diff] [blame] | 2266 | SmallVector<SourceRange, 4> Ranges; |
| 2267 | DeclaratorInfo.getCXX11AttributeRanges(Ranges); |
Richard Smith | 72553fc | 2014-01-23 23:53:27 +0000 | [diff] [blame] | 2268 | for (SmallVectorImpl<SourceRange>::iterator I = Ranges.begin(), |
| 2269 | E = Ranges.end(); I != E; ++I) |
| 2270 | Diag((*I).getBegin(), diag::err_attributes_not_allowed) << *I; |
Michael Han | ddc016d | 2012-11-28 23:17:40 +0000 | [diff] [blame] | 2271 | |
Richard Smith | 72553fc | 2014-01-23 23:53:27 +0000 | [diff] [blame] | 2272 | // TODO: handle initializers, VS, bitfields, 'delete' |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 2273 | ThisDecl = Actions.ActOnFriendFunctionDecl(getCurScope(), DeclaratorInfo, |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2274 | TemplateParams); |
Douglas Gregor | 3447e76 | 2009-08-20 22:52:58 +0000 | [diff] [blame] | 2275 | } else { |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 2276 | ThisDecl = Actions.ActOnCXXMemberDeclarator(getCurScope(), AS, |
John McCall | 07e91c0 | 2009-08-06 02:15:43 +0000 | [diff] [blame] | 2277 | DeclaratorInfo, |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2278 | TemplateParams, |
John McCall | 07e91c0 | 2009-08-06 02:15:43 +0000 | [diff] [blame] | 2279 | BitfieldSize.release(), |
Richard Smith | 2b01318 | 2012-06-10 03:12:00 +0000 | [diff] [blame] | 2280 | VS, HasInClassInit); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 2281 | |
| 2282 | if (VarTemplateDecl *VT = |
| 2283 | ThisDecl ? dyn_cast<VarTemplateDecl>(ThisDecl) : 0) |
| 2284 | // Re-direct this decl to refer to the templated decl so that we can |
| 2285 | // initialize it. |
| 2286 | ThisDecl = VT->getTemplatedDecl(); |
| 2287 | |
David Majnemer | 23252a3 | 2013-08-01 04:22:55 +0000 | [diff] [blame] | 2288 | if (ThisDecl && AccessAttrs) |
Richard Smith | f8a75c3 | 2013-08-29 00:47:48 +0000 | [diff] [blame] | 2289 | Actions.ProcessDeclAttributeList(getCurScope(), ThisDecl, AccessAttrs); |
Douglas Gregor | 3447e76 | 2009-08-20 22:52:58 +0000 | [diff] [blame] | 2290 | } |
Caitlin Sadowski | 9385dd7 | 2011-09-08 17:42:22 +0000 | [diff] [blame] | 2291 | |
Douglas Gregor | 728d00b | 2011-10-10 14:49:18 +0000 | [diff] [blame] | 2292 | // Handle the initializer. |
David Blaikie | 35506f8 | 2013-01-30 01:22:18 +0000 | [diff] [blame] | 2293 | if (HasInClassInit != ICIS_NoInit && |
| 2294 | DeclaratorInfo.getDeclSpec().getStorageClassSpec() != |
| 2295 | DeclSpec::SCS_static) { |
Douglas Gregor | 728d00b | 2011-10-10 14:49:18 +0000 | [diff] [blame] | 2296 | // The initializer was deferred; parse it and cache the tokens. |
David Majnemer | 23252a3 | 2013-08-01 04:22:55 +0000 | [diff] [blame] | 2297 | Diag(Tok, getLangOpts().CPlusPlus11 |
| 2298 | ? diag::warn_cxx98_compat_nonstatic_member_init |
| 2299 | : diag::ext_nonstatic_member_init); |
Richard Smith | 5d164bc | 2011-10-15 05:09:34 +0000 | [diff] [blame] | 2300 | |
Richard Smith | 938f40b | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 2301 | if (DeclaratorInfo.isArrayOfUnknownBound()) { |
Richard Smith | 2b01318 | 2012-06-10 03:12:00 +0000 | [diff] [blame] | 2302 | // C++11 [dcl.array]p3: An array bound may also be omitted when the |
| 2303 | // declarator is followed by an initializer. |
Richard Smith | 938f40b | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 2304 | // |
| 2305 | // A brace-or-equal-initializer for a member-declarator is not an |
David Blaikie | cdd91db | 2012-02-14 09:00:46 +0000 | [diff] [blame] | 2306 | // initializer in the grammar, so this is ill-formed. |
Richard Smith | 938f40b | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 2307 | Diag(Tok, diag::err_incomplete_array_member_init); |
Alexey Bataev | ee6507d | 2013-11-18 08:17:37 +0000 | [diff] [blame] | 2308 | SkipUntil(tok::comma, StopAtSemi | StopBeforeMatch); |
David Majnemer | 23252a3 | 2013-08-01 04:22:55 +0000 | [diff] [blame] | 2309 | |
| 2310 | // Avoid later warnings about a class member of incomplete type. |
David Blaikie | cdd91db | 2012-02-14 09:00:46 +0000 | [diff] [blame] | 2311 | if (ThisDecl) |
David Blaikie | cdd91db | 2012-02-14 09:00:46 +0000 | [diff] [blame] | 2312 | ThisDecl->setInvalidDecl(); |
Richard Smith | 938f40b | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 2313 | } else |
| 2314 | ParseCXXNonStaticMemberInitializer(ThisDecl); |
Douglas Gregor | 728d00b | 2011-10-10 14:49:18 +0000 | [diff] [blame] | 2315 | } else if (HasInitializer) { |
| 2316 | // Normal initializer. |
Douglas Gregor | 50cefbf | 2011-10-17 17:09:53 +0000 | [diff] [blame] | 2317 | if (!Init.isUsable()) |
David Majnemer | 23252a3 | 2013-08-01 04:22:55 +0000 | [diff] [blame] | 2318 | Init = ParseCXXMemberInitializer( |
| 2319 | ThisDecl, DeclaratorInfo.isDeclarationOfFunction(), EqualLoc); |
| 2320 | |
Douglas Gregor | 728d00b | 2011-10-10 14:49:18 +0000 | [diff] [blame] | 2321 | if (Init.isInvalid()) |
Alexey Bataev | ee6507d | 2013-11-18 08:17:37 +0000 | [diff] [blame] | 2322 | SkipUntil(tok::comma, StopAtSemi | StopBeforeMatch); |
Douglas Gregor | 728d00b | 2011-10-10 14:49:18 +0000 | [diff] [blame] | 2323 | else if (ThisDecl) |
Sebastian Redl | eef474c | 2012-02-22 10:50:08 +0000 | [diff] [blame] | 2324 | Actions.AddInitializerToDecl(ThisDecl, Init.get(), EqualLoc.isInvalid(), |
Richard Smith | 74aeef5 | 2013-04-26 16:15:35 +0000 | [diff] [blame] | 2325 | DS.containsPlaceholderType()); |
David Majnemer | 23252a3 | 2013-08-01 04:22:55 +0000 | [diff] [blame] | 2326 | } else if (ThisDecl && DS.getStorageClassSpec() == DeclSpec::SCS_static) |
Douglas Gregor | 728d00b | 2011-10-10 14:49:18 +0000 | [diff] [blame] | 2327 | // No initializer. |
Richard Smith | 74aeef5 | 2013-04-26 16:15:35 +0000 | [diff] [blame] | 2328 | Actions.ActOnUninitializedDecl(ThisDecl, DS.containsPlaceholderType()); |
David Majnemer | 23252a3 | 2013-08-01 04:22:55 +0000 | [diff] [blame] | 2329 | |
Douglas Gregor | 728d00b | 2011-10-10 14:49:18 +0000 | [diff] [blame] | 2330 | if (ThisDecl) { |
David Majnemer | 23252a3 | 2013-08-01 04:22:55 +0000 | [diff] [blame] | 2331 | if (!ThisDecl->isInvalidDecl()) { |
| 2332 | // Set the Decl for any late parsed attributes |
| 2333 | for (unsigned i = 0, ni = CommonLateParsedAttrs.size(); i < ni; ++i) |
| 2334 | CommonLateParsedAttrs[i]->addDecl(ThisDecl); |
| 2335 | |
| 2336 | for (unsigned i = 0, ni = LateParsedAttrs.size(); i < ni; ++i) |
| 2337 | LateParsedAttrs[i]->addDecl(ThisDecl); |
| 2338 | } |
Douglas Gregor | 728d00b | 2011-10-10 14:49:18 +0000 | [diff] [blame] | 2339 | Actions.FinalizeDeclaration(ThisDecl); |
| 2340 | DeclsInGroup.push_back(ThisDecl); |
David Majnemer | 23252a3 | 2013-08-01 04:22:55 +0000 | [diff] [blame] | 2341 | |
| 2342 | if (DeclaratorInfo.isFunctionDeclarator() && |
| 2343 | DeclaratorInfo.getDeclSpec().getStorageClassSpec() != |
| 2344 | DeclSpec::SCS_typedef) |
| 2345 | HandleMemberFunctionDeclDelays(DeclaratorInfo, ThisDecl); |
Douglas Gregor | 728d00b | 2011-10-10 14:49:18 +0000 | [diff] [blame] | 2346 | } |
David Majnemer | 23252a3 | 2013-08-01 04:22:55 +0000 | [diff] [blame] | 2347 | LateParsedAttrs.clear(); |
Douglas Gregor | 728d00b | 2011-10-10 14:49:18 +0000 | [diff] [blame] | 2348 | |
| 2349 | DeclaratorInfo.complete(ThisDecl); |
Richard Smith | 938f40b | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 2350 | |
Argyrios Kyrtzidis | 7bbb20e | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 2351 | // If we don't have a comma, it is either the end of the list (a ';') |
| 2352 | // or an error, bail out. |
Alp Toker | 094e521 | 2014-01-05 03:27:11 +0000 | [diff] [blame] | 2353 | SourceLocation CommaLoc; |
| 2354 | if (!TryConsumeToken(tok::comma, CommaLoc)) |
Argyrios Kyrtzidis | 7bbb20e | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 2355 | break; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2356 | |
Richard Smith | c8a7903 | 2012-01-09 22:31:44 +0000 | [diff] [blame] | 2357 | if (Tok.isAtStartOfLine() && |
| 2358 | !MightBeDeclarator(Declarator::MemberContext)) { |
| 2359 | // This comma was followed by a line-break and something which can't be |
| 2360 | // the start of a declarator. The comma was probably a typo for a |
| 2361 | // semicolon. |
| 2362 | Diag(CommaLoc, diag::err_expected_semi_declaration) |
| 2363 | << FixItHint::CreateReplacement(CommaLoc, ";"); |
| 2364 | ExpectSemi = false; |
| 2365 | break; |
| 2366 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2367 | |
Argyrios Kyrtzidis | 7bbb20e | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 2368 | // Parse the next declarator. |
| 2369 | DeclaratorInfo.clear(); |
Nico Weber | 24b2a82 | 2011-01-28 06:07:34 +0000 | [diff] [blame] | 2370 | VS.clear(); |
Douglas Gregor | 728d00b | 2011-10-10 14:49:18 +0000 | [diff] [blame] | 2371 | BitfieldSize = true; |
Douglas Gregor | 50cefbf | 2011-10-17 17:09:53 +0000 | [diff] [blame] | 2372 | Init = true; |
| 2373 | HasInitializer = false; |
Richard Smith | 8d06f42 | 2012-01-12 23:53:29 +0000 | [diff] [blame] | 2374 | DeclaratorInfo.setCommaLoc(CommaLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2375 | |
Richard Smith | 72553fc | 2014-01-23 23:53:27 +0000 | [diff] [blame] | 2376 | // GNU attributes are allowed before the second and subsequent declarator. |
John McCall | 53fa714 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 2377 | MaybeParseGNUAttributes(DeclaratorInfo); |
Argyrios Kyrtzidis | 7bbb20e | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 2378 | |
Richard Smith | 72553fc | 2014-01-23 23:53:27 +0000 | [diff] [blame] | 2379 | ParseCXXMemberDeclaratorBeforeInitializer(DeclaratorInfo, VS, BitfieldSize, |
| 2380 | LateParsedAttrs); |
Argyrios Kyrtzidis | 7bbb20e | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 2381 | } |
| 2382 | |
Richard Smith | c8a7903 | 2012-01-09 22:31:44 +0000 | [diff] [blame] | 2383 | if (ExpectSemi && |
| 2384 | ExpectAndConsume(tok::semi, diag::err_expected_semi_decl_list)) { |
Chris Lattner | 916dbf1 | 2010-02-02 00:43:15 +0000 | [diff] [blame] | 2385 | // Skip to end of block or statement. |
Alexey Bataev | ee6507d | 2013-11-18 08:17:37 +0000 | [diff] [blame] | 2386 | SkipUntil(tok::r_brace, StopAtSemi | StopBeforeMatch); |
Chris Lattner | 916dbf1 | 2010-02-02 00:43:15 +0000 | [diff] [blame] | 2387 | // If we stopped at a ';', eat it. |
Alp Toker | 35d8703 | 2013-12-30 23:29:50 +0000 | [diff] [blame] | 2388 | TryConsumeToken(tok::semi); |
Chris Lattner | 5bbb3c8 | 2009-03-29 16:50:03 +0000 | [diff] [blame] | 2389 | return; |
Argyrios Kyrtzidis | 7bbb20e | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 2390 | } |
| 2391 | |
Rafael Espindola | ab41769 | 2013-07-09 12:05:01 +0000 | [diff] [blame] | 2392 | Actions.FinalizeDeclaratorGroup(getCurScope(), DS, DeclsInGroup); |
Argyrios Kyrtzidis | 7bbb20e | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 2393 | } |
| 2394 | |
Richard Smith | 938f40b | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 2395 | /// ParseCXXMemberInitializer - Parse the brace-or-equal-initializer or |
| 2396 | /// pure-specifier. Also detect and reject any attempted defaulted/deleted |
| 2397 | /// function definition. The location of the '=', if any, will be placed in |
| 2398 | /// EqualLoc. |
| 2399 | /// |
| 2400 | /// pure-specifier: |
| 2401 | /// '= 0' |
Sebastian Redl | eef474c | 2012-02-22 10:50:08 +0000 | [diff] [blame] | 2402 | /// |
Richard Smith | 938f40b | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 2403 | /// brace-or-equal-initializer: |
| 2404 | /// '=' initializer-expression |
Sebastian Redl | eef474c | 2012-02-22 10:50:08 +0000 | [diff] [blame] | 2405 | /// braced-init-list |
| 2406 | /// |
Richard Smith | 938f40b | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 2407 | /// initializer-clause: |
| 2408 | /// assignment-expression |
Sebastian Redl | eef474c | 2012-02-22 10:50:08 +0000 | [diff] [blame] | 2409 | /// braced-init-list |
| 2410 | /// |
Richard Smith | da35e96 | 2013-11-09 04:52:51 +0000 | [diff] [blame] | 2411 | /// defaulted/deleted function-definition: |
Richard Smith | 938f40b | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 2412 | /// '=' 'default' |
| 2413 | /// '=' 'delete' |
| 2414 | /// |
| 2415 | /// Prior to C++0x, the assignment-expression in an initializer-clause must |
| 2416 | /// be a constant-expression. |
Douglas Gregor | 926410d | 2012-02-21 02:22:07 +0000 | [diff] [blame] | 2417 | ExprResult Parser::ParseCXXMemberInitializer(Decl *D, bool IsFunction, |
Richard Smith | 938f40b | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 2418 | SourceLocation &EqualLoc) { |
| 2419 | assert((Tok.is(tok::equal) || Tok.is(tok::l_brace)) |
| 2420 | && "Data member initializer not starting with '=' or '{'"); |
| 2421 | |
Douglas Gregor | 926410d | 2012-02-21 02:22:07 +0000 | [diff] [blame] | 2422 | EnterExpressionEvaluationContext Context(Actions, |
| 2423 | Sema::PotentiallyEvaluated, |
| 2424 | D); |
Alp Toker | 094e521 | 2014-01-05 03:27:11 +0000 | [diff] [blame] | 2425 | if (TryConsumeToken(tok::equal, EqualLoc)) { |
Richard Smith | 938f40b | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 2426 | if (Tok.is(tok::kw_delete)) { |
| 2427 | // In principle, an initializer of '= delete p;' is legal, but it will |
| 2428 | // never type-check. It's better to diagnose it as an ill-formed expression |
| 2429 | // than as an ill-formed deleted non-function member. |
| 2430 | // An initializer of '= delete p, foo' will never be parsed, because |
| 2431 | // a top-level comma always ends the initializer expression. |
| 2432 | const Token &Next = NextToken(); |
| 2433 | if (IsFunction || Next.is(tok::semi) || Next.is(tok::comma) || |
Richard Smith | 34f3051 | 2013-11-23 04:06:09 +0000 | [diff] [blame] | 2434 | Next.is(tok::eof)) { |
Richard Smith | 938f40b | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 2435 | if (IsFunction) |
| 2436 | Diag(ConsumeToken(), diag::err_default_delete_in_multiple_declaration) |
| 2437 | << 1 /* delete */; |
| 2438 | else |
| 2439 | Diag(ConsumeToken(), diag::err_deleted_non_function); |
| 2440 | return ExprResult(); |
| 2441 | } |
| 2442 | } else if (Tok.is(tok::kw_default)) { |
Richard Smith | 938f40b | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 2443 | if (IsFunction) |
| 2444 | Diag(Tok, diag::err_default_delete_in_multiple_declaration) |
| 2445 | << 0 /* default */; |
| 2446 | else |
| 2447 | Diag(ConsumeToken(), diag::err_default_special_members); |
| 2448 | return ExprResult(); |
| 2449 | } |
| 2450 | |
Sebastian Redl | eef474c | 2012-02-22 10:50:08 +0000 | [diff] [blame] | 2451 | } |
| 2452 | return ParseInitializer(); |
Richard Smith | 938f40b | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 2453 | } |
| 2454 | |
Argyrios Kyrtzidis | 7bbb20e | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 2455 | /// ParseCXXMemberSpecification - Parse the class definition. |
| 2456 | /// |
| 2457 | /// member-specification: |
| 2458 | /// member-declaration member-specification[opt] |
| 2459 | /// access-specifier ':' member-specification[opt] |
| 2460 | /// |
Joao Matos | e9a3ed4 | 2012-08-31 22:18:20 +0000 | [diff] [blame] | 2461 | void Parser::ParseCXXMemberSpecification(SourceLocation RecordLoc, |
Michael Han | 309af29 | 2013-01-07 16:57:11 +0000 | [diff] [blame] | 2462 | SourceLocation AttrFixitLoc, |
Richard Smith | 4c96e99 | 2013-02-19 23:47:15 +0000 | [diff] [blame] | 2463 | ParsedAttributesWithRange &Attrs, |
Joao Matos | e9a3ed4 | 2012-08-31 22:18:20 +0000 | [diff] [blame] | 2464 | unsigned TagType, Decl *TagDecl) { |
| 2465 | assert((TagType == DeclSpec::TST_struct || |
| 2466 | TagType == DeclSpec::TST_interface || |
| 2467 | TagType == DeclSpec::TST_union || |
| 2468 | TagType == DeclSpec::TST_class) && "Invalid TagType!"); |
| 2469 | |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2470 | PrettyDeclStackTraceEntry CrashInfo(Actions, TagDecl, RecordLoc, |
| 2471 | "parsing struct/union/class body"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2472 | |
Douglas Gregor | edf8f39 | 2010-01-16 20:52:59 +0000 | [diff] [blame] | 2473 | // Determine whether this is a non-nested class. Note that local |
| 2474 | // classes are *not* considered to be nested classes. |
| 2475 | bool NonNestedClass = true; |
| 2476 | if (!ClassStack.empty()) { |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 2477 | for (const Scope *S = getCurScope(); S; S = S->getParent()) { |
Douglas Gregor | edf8f39 | 2010-01-16 20:52:59 +0000 | [diff] [blame] | 2478 | if (S->isClassScope()) { |
| 2479 | // We're inside a class scope, so this is a nested class. |
| 2480 | NonNestedClass = false; |
John McCall | db632ac | 2012-09-25 07:32:39 +0000 | [diff] [blame] | 2481 | |
| 2482 | // The Microsoft extension __interface does not permit nested classes. |
| 2483 | if (getCurrentClass().IsInterface) { |
| 2484 | Diag(RecordLoc, diag::err_invalid_member_in_interface) |
| 2485 | << /*ErrorType=*/6 |
| 2486 | << (isa<NamedDecl>(TagDecl) |
| 2487 | ? cast<NamedDecl>(TagDecl)->getQualifiedNameAsString() |
| 2488 | : "<anonymous>"); |
| 2489 | } |
Douglas Gregor | edf8f39 | 2010-01-16 20:52:59 +0000 | [diff] [blame] | 2490 | break; |
| 2491 | } |
| 2492 | |
| 2493 | if ((S->getFlags() & Scope::FnScope)) { |
| 2494 | // If we're in a function or function template declared in the |
| 2495 | // body of a class, then this is a local class rather than a |
| 2496 | // nested class. |
| 2497 | const Scope *Parent = S->getParent(); |
| 2498 | if (Parent->isTemplateParamScope()) |
| 2499 | Parent = Parent->getParent(); |
| 2500 | if (Parent->isClassScope()) |
| 2501 | break; |
| 2502 | } |
| 2503 | } |
| 2504 | } |
Argyrios Kyrtzidis | 7bbb20e | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 2505 | |
| 2506 | // Enter a scope for the class. |
Douglas Gregor | 658b955 | 2009-01-09 22:42:13 +0000 | [diff] [blame] | 2507 | ParseScope ClassScope(this, Scope::ClassScope|Scope::DeclScope); |
Argyrios Kyrtzidis | 7bbb20e | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 2508 | |
Douglas Gregor | e44a2ad | 2009-05-27 23:11:45 +0000 | [diff] [blame] | 2509 | // Note that we are parsing a new (potentially-nested) class definition. |
John McCall | db632ac | 2012-09-25 07:32:39 +0000 | [diff] [blame] | 2510 | ParsingClassDefinition ParsingDef(*this, TagDecl, NonNestedClass, |
| 2511 | TagType == DeclSpec::TST_interface); |
Douglas Gregor | e44a2ad | 2009-05-27 23:11:45 +0000 | [diff] [blame] | 2512 | |
Douglas Gregor | cd72ba9 | 2009-02-06 22:42:48 +0000 | [diff] [blame] | 2513 | if (TagDecl) |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 2514 | Actions.ActOnTagStartDefinition(getCurScope(), TagDecl); |
John McCall | 2d814c3 | 2009-12-19 21:48:58 +0000 | [diff] [blame] | 2515 | |
Anders Carlsson | f9eb63b | 2011-03-25 14:46:08 +0000 | [diff] [blame] | 2516 | SourceLocation FinalLoc; |
David Majnemer | a543308 | 2013-10-18 00:33:31 +0000 | [diff] [blame] | 2517 | bool IsFinalSpelledSealed = false; |
Anders Carlsson | f9eb63b | 2011-03-25 14:46:08 +0000 | [diff] [blame] | 2518 | |
| 2519 | // Parse the optional 'final' keyword. |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 2520 | if (getLangOpts().CPlusPlus && Tok.is(tok::identifier)) { |
David Majnemer | a543308 | 2013-10-18 00:33:31 +0000 | [diff] [blame] | 2521 | VirtSpecifiers::Specifier Specifier = isCXX11VirtSpecifier(Tok); |
| 2522 | assert((Specifier == VirtSpecifiers::VS_Final || |
| 2523 | Specifier == VirtSpecifiers::VS_Sealed) && |
| 2524 | "not a class definition"); |
Richard Smith | da26111 | 2011-10-15 04:21:46 +0000 | [diff] [blame] | 2525 | FinalLoc = ConsumeToken(); |
David Majnemer | a543308 | 2013-10-18 00:33:31 +0000 | [diff] [blame] | 2526 | IsFinalSpelledSealed = Specifier == VirtSpecifiers::VS_Sealed; |
Anders Carlsson | f9eb63b | 2011-03-25 14:46:08 +0000 | [diff] [blame] | 2527 | |
David Majnemer | a543308 | 2013-10-18 00:33:31 +0000 | [diff] [blame] | 2528 | if (TagType == DeclSpec::TST_interface) |
John McCall | db632ac | 2012-09-25 07:32:39 +0000 | [diff] [blame] | 2529 | Diag(FinalLoc, diag::err_override_control_interface) |
David Majnemer | a543308 | 2013-10-18 00:33:31 +0000 | [diff] [blame] | 2530 | << VirtSpecifiers::getSpecifierName(Specifier); |
| 2531 | else if (Specifier == VirtSpecifiers::VS_Final) |
| 2532 | Diag(FinalLoc, getLangOpts().CPlusPlus11 |
| 2533 | ? diag::warn_cxx98_compat_override_control_keyword |
| 2534 | : diag::ext_override_control_keyword) |
| 2535 | << VirtSpecifiers::getSpecifierName(Specifier); |
| 2536 | else if (Specifier == VirtSpecifiers::VS_Sealed) |
| 2537 | Diag(FinalLoc, diag::ext_ms_sealed_keyword); |
Michael Han | 9407e50 | 2012-11-26 22:54:45 +0000 | [diff] [blame] | 2538 | |
Michael Han | 309af29 | 2013-01-07 16:57:11 +0000 | [diff] [blame] | 2539 | // Parse any C++11 attributes after 'final' keyword. |
| 2540 | // These attributes are not allowed to appear here, |
| 2541 | // and the only possible place for them to appertain |
| 2542 | // to the class would be between class-key and class-name. |
Richard Smith | 4c96e99 | 2013-02-19 23:47:15 +0000 | [diff] [blame] | 2543 | CheckMisplacedCXX11Attribute(Attrs, AttrFixitLoc); |
Anders Carlsson | f9eb63b | 2011-03-25 14:46:08 +0000 | [diff] [blame] | 2544 | } |
Anders Carlsson | 4b63d0e | 2011-01-22 16:56:46 +0000 | [diff] [blame] | 2545 | |
John McCall | 2d814c3 | 2009-12-19 21:48:58 +0000 | [diff] [blame] | 2546 | if (Tok.is(tok::colon)) { |
| 2547 | ParseBaseClause(TagDecl); |
| 2548 | |
| 2549 | if (!Tok.is(tok::l_brace)) { |
| 2550 | Diag(Tok, diag::err_expected_lbrace_after_base_specifiers); |
John McCall | 2ff380a | 2010-03-17 00:38:33 +0000 | [diff] [blame] | 2551 | |
| 2552 | if (TagDecl) |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 2553 | Actions.ActOnTagDefinitionError(getCurScope(), TagDecl); |
John McCall | 2d814c3 | 2009-12-19 21:48:58 +0000 | [diff] [blame] | 2554 | return; |
| 2555 | } |
| 2556 | } |
| 2557 | |
| 2558 | assert(Tok.is(tok::l_brace)); |
Douglas Gregor | e7a8e3b | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 2559 | BalancedDelimiterTracker T(*this, tok::l_brace); |
| 2560 | T.consumeOpen(); |
John McCall | 2d814c3 | 2009-12-19 21:48:58 +0000 | [diff] [blame] | 2561 | |
John McCall | 08bede4 | 2010-05-28 08:11:17 +0000 | [diff] [blame] | 2562 | if (TagDecl) |
Anders Carlsson | 30f2944 | 2011-03-25 14:31:08 +0000 | [diff] [blame] | 2563 | Actions.ActOnStartCXXMemberDeclarations(getCurScope(), TagDecl, FinalLoc, |
David Majnemer | a543308 | 2013-10-18 00:33:31 +0000 | [diff] [blame] | 2564 | IsFinalSpelledSealed, |
Douglas Gregor | e7a8e3b | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 2565 | T.getOpenLocation()); |
John McCall | 1c7e6ec | 2009-12-20 07:58:13 +0000 | [diff] [blame] | 2566 | |
Argyrios Kyrtzidis | 7bbb20e | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 2567 | // C++ 11p3: Members of a class defined with the keyword class are private |
| 2568 | // by default. Members of a class defined with the keywords struct or union |
| 2569 | // are public by default. |
| 2570 | AccessSpecifier CurAS; |
| 2571 | if (TagType == DeclSpec::TST_class) |
| 2572 | CurAS = AS_private; |
| 2573 | else |
| 2574 | CurAS = AS_public; |
Erik Verbruggen | ca98f2a | 2011-10-13 09:41:32 +0000 | [diff] [blame] | 2575 | ParsedAttributes AccessAttrs(AttrFactory); |
Argyrios Kyrtzidis | 7bbb20e | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 2576 | |
Douglas Gregor | 9377c82 | 2010-06-21 22:31:09 +0000 | [diff] [blame] | 2577 | if (TagDecl) { |
| 2578 | // While we still have something to read, read the member-declarations. |
Richard Smith | 34f3051 | 2013-11-23 04:06:09 +0000 | [diff] [blame] | 2579 | while (Tok.isNot(tok::r_brace) && !isEofOrEom()) { |
Douglas Gregor | 9377c82 | 2010-06-21 22:31:09 +0000 | [diff] [blame] | 2580 | // Each iteration of this loop reads one member-declaration. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2581 | |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 2582 | if (getLangOpts().MicrosoftExt && (Tok.is(tok::kw___if_exists) || |
Francois Pichet | 8f981d5 | 2011-05-25 10:19:49 +0000 | [diff] [blame] | 2583 | Tok.is(tok::kw___if_not_exists))) { |
| 2584 | ParseMicrosoftIfExistsClassDeclaration((DeclSpec::TST)TagType, CurAS); |
| 2585 | continue; |
| 2586 | } |
| 2587 | |
Douglas Gregor | 9377c82 | 2010-06-21 22:31:09 +0000 | [diff] [blame] | 2588 | // Check for extraneous top-level semicolon. |
| 2589 | if (Tok.is(tok::semi)) { |
Richard Smith | 87f5dc5 | 2012-07-23 05:45:25 +0000 | [diff] [blame] | 2590 | ConsumeExtraSemi(InsideStruct, TagType); |
Douglas Gregor | 9377c82 | 2010-06-21 22:31:09 +0000 | [diff] [blame] | 2591 | continue; |
| 2592 | } |
| 2593 | |
Eli Friedman | ec52f92 | 2012-02-23 23:47:16 +0000 | [diff] [blame] | 2594 | if (Tok.is(tok::annot_pragma_vis)) { |
| 2595 | HandlePragmaVisibility(); |
| 2596 | continue; |
| 2597 | } |
| 2598 | |
| 2599 | if (Tok.is(tok::annot_pragma_pack)) { |
| 2600 | HandlePragmaPack(); |
| 2601 | continue; |
| 2602 | } |
| 2603 | |
Argyrios Kyrtzidis | 5c2021b | 2012-10-12 17:39:59 +0000 | [diff] [blame] | 2604 | if (Tok.is(tok::annot_pragma_align)) { |
| 2605 | HandlePragmaAlign(); |
| 2606 | continue; |
| 2607 | } |
| 2608 | |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 2609 | if (Tok.is(tok::annot_pragma_openmp)) { |
| 2610 | ParseOpenMPDeclarativeDirective(); |
| 2611 | continue; |
| 2612 | } |
| 2613 | |
David Majnemer | 4bb0980 | 2014-02-10 19:50:15 +0000 | [diff] [blame] | 2614 | if (Tok.is(tok::annot_pragma_ms_pointers_to_members)) { |
| 2615 | HandlePragmaMSPointersToMembers(); |
| 2616 | continue; |
| 2617 | } |
| 2618 | |
Richard Smith | da35e96 | 2013-11-09 04:52:51 +0000 | [diff] [blame] | 2619 | // If we see a namespace here, a close brace was missing somewhere. |
| 2620 | if (Tok.is(tok::kw_namespace)) { |
Richard Smith | 2ac43ad | 2013-11-15 23:00:02 +0000 | [diff] [blame] | 2621 | DiagnoseUnexpectedNamespace(cast<NamedDecl>(TagDecl)); |
Richard Smith | da35e96 | 2013-11-09 04:52:51 +0000 | [diff] [blame] | 2622 | break; |
| 2623 | } |
| 2624 | |
Douglas Gregor | 9377c82 | 2010-06-21 22:31:09 +0000 | [diff] [blame] | 2625 | AccessSpecifier AS = getAccessSpecifierIfPresent(); |
| 2626 | if (AS != AS_none) { |
| 2627 | // Current token is a C++ access specifier. |
| 2628 | CurAS = AS; |
| 2629 | SourceLocation ASLoc = Tok.getLocation(); |
David Blaikie | eba32c2 | 2011-10-13 06:08:43 +0000 | [diff] [blame] | 2630 | unsigned TokLength = Tok.getLength(); |
Douglas Gregor | 9377c82 | 2010-06-21 22:31:09 +0000 | [diff] [blame] | 2631 | ConsumeToken(); |
Erik Verbruggen | ca98f2a | 2011-10-13 09:41:32 +0000 | [diff] [blame] | 2632 | AccessAttrs.clear(); |
| 2633 | MaybeParseGNUAttributes(AccessAttrs); |
| 2634 | |
David Blaikie | eba32c2 | 2011-10-13 06:08:43 +0000 | [diff] [blame] | 2635 | SourceLocation EndLoc; |
Alp Toker | 35d8703 | 2013-12-30 23:29:50 +0000 | [diff] [blame] | 2636 | if (TryConsumeToken(tok::colon, EndLoc)) { |
| 2637 | } else if (TryConsumeToken(tok::semi, EndLoc)) { |
| 2638 | Diag(EndLoc, diag::err_expected) |
| 2639 | << tok::colon << FixItHint::CreateReplacement(EndLoc, ":"); |
David Blaikie | eba32c2 | 2011-10-13 06:08:43 +0000 | [diff] [blame] | 2640 | } else { |
| 2641 | EndLoc = ASLoc.getLocWithOffset(TokLength); |
Alp Toker | 35d8703 | 2013-12-30 23:29:50 +0000 | [diff] [blame] | 2642 | Diag(EndLoc, diag::err_expected) |
| 2643 | << tok::colon << FixItHint::CreateInsertion(EndLoc, ":"); |
David Blaikie | eba32c2 | 2011-10-13 06:08:43 +0000 | [diff] [blame] | 2644 | } |
Erik Verbruggen | fd979b1 | 2011-10-17 09:54:52 +0000 | [diff] [blame] | 2645 | |
John McCall | db632ac | 2012-09-25 07:32:39 +0000 | [diff] [blame] | 2646 | // The Microsoft extension __interface does not permit non-public |
| 2647 | // access specifiers. |
| 2648 | if (TagType == DeclSpec::TST_interface && CurAS != AS_public) { |
| 2649 | Diag(ASLoc, diag::err_access_specifier_interface) |
| 2650 | << (CurAS == AS_protected); |
| 2651 | } |
| 2652 | |
Erik Verbruggen | fd979b1 | 2011-10-17 09:54:52 +0000 | [diff] [blame] | 2653 | if (Actions.ActOnAccessSpecifier(AS, ASLoc, EndLoc, |
| 2654 | AccessAttrs.getList())) { |
| 2655 | // found another attribute than only annotations |
| 2656 | AccessAttrs.clear(); |
| 2657 | } |
| 2658 | |
Douglas Gregor | 9377c82 | 2010-06-21 22:31:09 +0000 | [diff] [blame] | 2659 | continue; |
| 2660 | } |
| 2661 | |
Douglas Gregor | 9377c82 | 2010-06-21 22:31:09 +0000 | [diff] [blame] | 2662 | // Parse all the comma separated declarators. |
Erik Verbruggen | ca98f2a | 2011-10-13 09:41:32 +0000 | [diff] [blame] | 2663 | ParseCXXClassMemberDeclaration(CurAS, AccessAttrs.getList()); |
Argyrios Kyrtzidis | 7bbb20e | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 2664 | } |
| 2665 | |
Douglas Gregor | e7a8e3b | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 2666 | T.consumeClose(); |
Douglas Gregor | 9377c82 | 2010-06-21 22:31:09 +0000 | [diff] [blame] | 2667 | } else { |
Alexey Bataev | ee6507d | 2013-11-18 08:17:37 +0000 | [diff] [blame] | 2668 | SkipUntil(tok::r_brace); |
Argyrios Kyrtzidis | 7bbb20e | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 2669 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2670 | |
Argyrios Kyrtzidis | 7bbb20e | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 2671 | // If attributes exist after class contents, parse them. |
John McCall | 084e83d | 2011-03-24 11:26:52 +0000 | [diff] [blame] | 2672 | ParsedAttributes attrs(AttrFactory); |
John McCall | 53fa714 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 2673 | MaybeParseGNUAttributes(attrs); |
Argyrios Kyrtzidis | 7bbb20e | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 2674 | |
John McCall | 08bede4 | 2010-05-28 08:11:17 +0000 | [diff] [blame] | 2675 | if (TagDecl) |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 2676 | Actions.ActOnFinishCXXMemberSpecification(getCurScope(), RecordLoc, TagDecl, |
Douglas Gregor | e7a8e3b | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 2677 | T.getOpenLocation(), |
| 2678 | T.getCloseLocation(), |
John McCall | 53fa714 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 2679 | attrs.getList()); |
Argyrios Kyrtzidis | 7bbb20e | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 2680 | |
Douglas Gregor | 433e053 | 2012-04-16 18:27:27 +0000 | [diff] [blame] | 2681 | // C++11 [class.mem]p2: |
| 2682 | // Within the class member-specification, the class is regarded as complete |
Richard Smith | 2331bbf | 2012-05-02 22:22:32 +0000 | [diff] [blame] | 2683 | // within function bodies, default arguments, and |
Douglas Gregor | 433e053 | 2012-04-16 18:27:27 +0000 | [diff] [blame] | 2684 | // brace-or-equal-initializers for non-static data members (including such |
| 2685 | // things in nested classes). |
Douglas Gregor | 9377c82 | 2010-06-21 22:31:09 +0000 | [diff] [blame] | 2686 | if (TagDecl && NonNestedClass) { |
Argyrios Kyrtzidis | 7bbb20e | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 2687 | // We are not inside a nested class. This class and its nested classes |
Douglas Gregor | 4d87df5 | 2008-12-16 21:30:33 +0000 | [diff] [blame] | 2688 | // are complete and we can parse the delayed portions of method |
Caitlin Sadowski | 9385dd7 | 2011-09-08 17:42:22 +0000 | [diff] [blame] | 2689 | // declarations and the lexed inline method definitions, along with any |
| 2690 | // delayed attributes. |
Douglas Gregor | 428119e | 2010-06-16 23:45:56 +0000 | [diff] [blame] | 2691 | SourceLocation SavedPrevTokLocation = PrevTokLocation; |
Caitlin Sadowski | 9385dd7 | 2011-09-08 17:42:22 +0000 | [diff] [blame] | 2692 | ParseLexedAttributes(getCurrentClass()); |
Douglas Gregor | e44a2ad | 2009-05-27 23:11:45 +0000 | [diff] [blame] | 2693 | ParseLexedMethodDeclarations(getCurrentClass()); |
Richard Smith | 84973e5 | 2012-04-21 18:42:51 +0000 | [diff] [blame] | 2694 | |
| 2695 | // We've finished with all pending member declarations. |
| 2696 | Actions.ActOnFinishCXXMemberDecls(); |
| 2697 | |
Richard Smith | 938f40b | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 2698 | ParseLexedMemberInitializers(getCurrentClass()); |
Douglas Gregor | e44a2ad | 2009-05-27 23:11:45 +0000 | [diff] [blame] | 2699 | ParseLexedMethodDefs(getCurrentClass()); |
Douglas Gregor | 428119e | 2010-06-16 23:45:56 +0000 | [diff] [blame] | 2700 | PrevTokLocation = SavedPrevTokLocation; |
Argyrios Kyrtzidis | 7bbb20e | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 2701 | } |
| 2702 | |
John McCall | 08bede4 | 2010-05-28 08:11:17 +0000 | [diff] [blame] | 2703 | if (TagDecl) |
Douglas Gregor | e7a8e3b | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 2704 | Actions.ActOnTagFinishDefinition(getCurScope(), TagDecl, |
| 2705 | T.getCloseLocation()); |
John McCall | 2ff380a | 2010-03-17 00:38:33 +0000 | [diff] [blame] | 2706 | |
Argyrios Kyrtzidis | 7bbb20e | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 2707 | // Leave the class scope. |
Douglas Gregor | e44a2ad | 2009-05-27 23:11:45 +0000 | [diff] [blame] | 2708 | ParsingDef.Pop(); |
Douglas Gregor | 7307d6c | 2008-12-10 06:34:36 +0000 | [diff] [blame] | 2709 | ClassScope.Exit(); |
Argyrios Kyrtzidis | 7bbb20e | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 2710 | } |
Douglas Gregor | e8381c0 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 2711 | |
Richard Smith | 2ac43ad | 2013-11-15 23:00:02 +0000 | [diff] [blame] | 2712 | void Parser::DiagnoseUnexpectedNamespace(NamedDecl *D) { |
Richard Smith | da35e96 | 2013-11-09 04:52:51 +0000 | [diff] [blame] | 2713 | assert(Tok.is(tok::kw_namespace)); |
| 2714 | |
| 2715 | // FIXME: Suggest where the close brace should have gone by looking |
| 2716 | // at indentation changes within the definition body. |
Richard Smith | 2ac43ad | 2013-11-15 23:00:02 +0000 | [diff] [blame] | 2717 | Diag(D->getLocation(), |
| 2718 | diag::err_missing_end_of_definition) << D; |
Richard Smith | da35e96 | 2013-11-09 04:52:51 +0000 | [diff] [blame] | 2719 | Diag(Tok.getLocation(), |
Richard Smith | 2ac43ad | 2013-11-15 23:00:02 +0000 | [diff] [blame] | 2720 | diag::note_missing_end_of_definition_before) << D; |
Richard Smith | da35e96 | 2013-11-09 04:52:51 +0000 | [diff] [blame] | 2721 | |
| 2722 | // Push '};' onto the token stream to recover. |
| 2723 | PP.EnterToken(Tok); |
| 2724 | |
| 2725 | Tok.startToken(); |
| 2726 | Tok.setLocation(PP.getLocForEndOfToken(PrevTokLocation)); |
| 2727 | Tok.setKind(tok::semi); |
| 2728 | PP.EnterToken(Tok); |
| 2729 | |
| 2730 | Tok.setKind(tok::r_brace); |
| 2731 | } |
| 2732 | |
Douglas Gregor | e8381c0 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 2733 | /// ParseConstructorInitializer - Parse a C++ constructor initializer, |
| 2734 | /// which explicitly initializes the members or base classes of a |
| 2735 | /// class (C++ [class.base.init]). For example, the three initializers |
| 2736 | /// after the ':' in the Derived constructor below: |
| 2737 | /// |
| 2738 | /// @code |
| 2739 | /// class Base { }; |
| 2740 | /// class Derived : Base { |
| 2741 | /// int x; |
| 2742 | /// float f; |
| 2743 | /// public: |
| 2744 | /// Derived(float f) : Base(), x(17), f(f) { } |
| 2745 | /// }; |
| 2746 | /// @endcode |
| 2747 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2748 | /// [C++] ctor-initializer: |
| 2749 | /// ':' mem-initializer-list |
Douglas Gregor | e8381c0 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 2750 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2751 | /// [C++] mem-initializer-list: |
Douglas Gregor | 44e7df6 | 2011-01-04 00:32:56 +0000 | [diff] [blame] | 2752 | /// mem-initializer ...[opt] |
| 2753 | /// mem-initializer ...[opt] , mem-initializer-list |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 2754 | void Parser::ParseConstructorInitializer(Decl *ConstructorDecl) { |
Douglas Gregor | e8381c0 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 2755 | assert(Tok.is(tok::colon) && "Constructor initializer always starts with ':'"); |
| 2756 | |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 2757 | // Poison the SEH identifiers so they are flagged as illegal in constructor initializers |
| 2758 | PoisonSEHIdentifiersRAIIObject PoisonSEHIdentifiers(*this, true); |
Douglas Gregor | e8381c0 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 2759 | SourceLocation ColonLoc = ConsumeToken(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2760 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2761 | SmallVector<CXXCtorInitializer*, 4> MemInitializers; |
Douglas Gregor | 7ae2d77 | 2010-01-31 09:12:51 +0000 | [diff] [blame] | 2762 | bool AnyErrors = false; |
Kovarththanan Rajaratnam | ba2c652 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 2763 | |
Douglas Gregor | e8381c0 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 2764 | do { |
Douglas Gregor | eaeeca9 | 2010-08-28 00:00:50 +0000 | [diff] [blame] | 2765 | if (Tok.is(tok::code_completion)) { |
Dmitri Gribenko | 27cb3dd0 | 2013-06-23 22:58:02 +0000 | [diff] [blame] | 2766 | Actions.CodeCompleteConstructorInitializer(ConstructorDecl, |
| 2767 | MemInitializers); |
Argyrios Kyrtzidis | 5cec2ae | 2011-09-04 03:32:15 +0000 | [diff] [blame] | 2768 | return cutOffParsing(); |
Douglas Gregor | eaeeca9 | 2010-08-28 00:00:50 +0000 | [diff] [blame] | 2769 | } else { |
| 2770 | MemInitResult MemInit = ParseMemInitializer(ConstructorDecl); |
| 2771 | if (!MemInit.isInvalid()) |
| 2772 | MemInitializers.push_back(MemInit.get()); |
| 2773 | else |
| 2774 | AnyErrors = true; |
| 2775 | } |
| 2776 | |
Douglas Gregor | e8381c0 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 2777 | if (Tok.is(tok::comma)) |
| 2778 | ConsumeToken(); |
| 2779 | else if (Tok.is(tok::l_brace)) |
| 2780 | break; |
Douglas Gregor | 3465e26 | 2010-09-07 14:35:10 +0000 | [diff] [blame] | 2781 | // If the next token looks like a base or member initializer, assume that |
| 2782 | // we're just missing a comma. |
Douglas Gregor | ce66d02 | 2010-09-07 14:51:08 +0000 | [diff] [blame] | 2783 | else if (Tok.is(tok::identifier) || Tok.is(tok::coloncolon)) { |
| 2784 | SourceLocation Loc = PP.getLocForEndOfToken(PrevTokLocation); |
| 2785 | Diag(Loc, diag::err_ctor_init_missing_comma) |
| 2786 | << FixItHint::CreateInsertion(Loc, ", "); |
| 2787 | } else { |
Douglas Gregor | e8381c0 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 2788 | // Skip over garbage, until we get to '{'. Don't eat the '{'. |
Alp Toker | ec54327 | 2013-12-24 09:48:30 +0000 | [diff] [blame] | 2789 | Diag(Tok.getLocation(), diag::err_expected_either) << tok::l_brace |
| 2790 | << tok::comma; |
Alexey Bataev | ee6507d | 2013-11-18 08:17:37 +0000 | [diff] [blame] | 2791 | SkipUntil(tok::l_brace, StopAtSemi | StopBeforeMatch); |
Douglas Gregor | e8381c0 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 2792 | break; |
| 2793 | } |
| 2794 | } while (true); |
| 2795 | |
David Blaikie | 3fc2f91 | 2013-01-17 05:26:25 +0000 | [diff] [blame] | 2796 | Actions.ActOnMemInitializers(ConstructorDecl, ColonLoc, MemInitializers, |
Douglas Gregor | 7ae2d77 | 2010-01-31 09:12:51 +0000 | [diff] [blame] | 2797 | AnyErrors); |
Douglas Gregor | e8381c0 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 2798 | } |
| 2799 | |
| 2800 | /// ParseMemInitializer - Parse a C++ member initializer, which is |
| 2801 | /// part of a constructor initializer that explicitly initializes one |
| 2802 | /// member or base class (C++ [class.base.init]). See |
| 2803 | /// ParseConstructorInitializer for an example. |
| 2804 | /// |
| 2805 | /// [C++] mem-initializer: |
| 2806 | /// mem-initializer-id '(' expression-list[opt] ')' |
Sebastian Redl | 3da3489 | 2011-06-05 12:23:16 +0000 | [diff] [blame] | 2807 | /// [C++0x] mem-initializer-id braced-init-list |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2808 | /// |
Douglas Gregor | e8381c0 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 2809 | /// [C++] mem-initializer-id: |
| 2810 | /// '::'[opt] nested-name-specifier[opt] class-name |
| 2811 | /// identifier |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 2812 | Parser::MemInitResult Parser::ParseMemInitializer(Decl *ConstructorDecl) { |
Fariborz Jahanian | 302bb66 | 2009-06-30 23:26:25 +0000 | [diff] [blame] | 2813 | // parse '::'[opt] nested-name-specifier[opt] |
| 2814 | CXXScopeSpec SS; |
Douglas Gregor | df593fb | 2011-11-07 17:33:42 +0000 | [diff] [blame] | 2815 | ParseOptionalCXXScopeSpecifier(SS, ParsedType(), /*EnteringContext=*/false); |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 2816 | ParsedType TemplateTypeTy; |
Fariborz Jahanian | c1fc3ec | 2009-07-01 19:21:19 +0000 | [diff] [blame] | 2817 | if (Tok.is(tok::annot_template_id)) { |
Argyrios Kyrtzidis | c0c5dd2 | 2011-06-22 06:09:49 +0000 | [diff] [blame] | 2818 | TemplateIdAnnotation *TemplateId = takeTemplateIdAnnotation(Tok); |
Douglas Gregor | 46c5961 | 2010-01-12 17:52:59 +0000 | [diff] [blame] | 2819 | if (TemplateId->Kind == TNK_Type_template || |
| 2820 | TemplateId->Kind == TNK_Dependent_template_name) { |
Douglas Gregor | e7c2065 | 2011-03-02 00:47:37 +0000 | [diff] [blame] | 2821 | AnnotateTemplateIdTokenAsType(); |
Fariborz Jahanian | c1fc3ec | 2009-07-01 19:21:19 +0000 | [diff] [blame] | 2822 | assert(Tok.is(tok::annot_typename) && "template-id -> type failed"); |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 2823 | TemplateTypeTy = getTypeAnnotation(Tok); |
Fariborz Jahanian | c1fc3ec | 2009-07-01 19:21:19 +0000 | [diff] [blame] | 2824 | } |
Fariborz Jahanian | c1fc3ec | 2009-07-01 19:21:19 +0000 | [diff] [blame] | 2825 | } |
David Blaikie | 186a889 | 2012-01-24 06:03:59 +0000 | [diff] [blame] | 2826 | // Uses of decltype will already have been converted to annot_decltype by |
| 2827 | // ParseOptionalCXXScopeSpecifier at this point. |
| 2828 | if (!TemplateTypeTy && Tok.isNot(tok::identifier) |
| 2829 | && Tok.isNot(tok::annot_decltype)) { |
Chris Lattner | 6d29c10 | 2008-11-18 07:48:38 +0000 | [diff] [blame] | 2830 | Diag(Tok, diag::err_expected_member_or_base_name); |
Douglas Gregor | e8381c0 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 2831 | return true; |
| 2832 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2833 | |
David Blaikie | 186a889 | 2012-01-24 06:03:59 +0000 | [diff] [blame] | 2834 | IdentifierInfo *II = 0; |
| 2835 | DeclSpec DS(AttrFactory); |
| 2836 | SourceLocation IdLoc = Tok.getLocation(); |
| 2837 | if (Tok.is(tok::annot_decltype)) { |
| 2838 | // Get the decltype expression, if there is one. |
| 2839 | ParseDecltypeSpecifier(DS); |
| 2840 | } else { |
| 2841 | if (Tok.is(tok::identifier)) |
| 2842 | // Get the identifier. This may be a member name or a class name, |
| 2843 | // but we'll let the semantic analysis determine which it is. |
| 2844 | II = Tok.getIdentifierInfo(); |
| 2845 | ConsumeToken(); |
| 2846 | } |
| 2847 | |
Douglas Gregor | e8381c0 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 2848 | |
| 2849 | // Parse the '('. |
Richard Smith | 2bf7fdb | 2013-01-02 11:42:31 +0000 | [diff] [blame] | 2850 | if (getLangOpts().CPlusPlus11 && Tok.is(tok::l_brace)) { |
Richard Smith | 5d164bc | 2011-10-15 05:09:34 +0000 | [diff] [blame] | 2851 | Diag(Tok, diag::warn_cxx98_compat_generalized_initializer_lists); |
| 2852 | |
Sebastian Redl | a74948d | 2011-09-24 17:48:25 +0000 | [diff] [blame] | 2853 | ExprResult InitList = ParseBraceInitializer(); |
| 2854 | if (InitList.isInvalid()) |
| 2855 | return true; |
| 2856 | |
| 2857 | SourceLocation EllipsisLoc; |
Alp Toker | 094e521 | 2014-01-05 03:27:11 +0000 | [diff] [blame] | 2858 | TryConsumeToken(tok::ellipsis, EllipsisLoc); |
Sebastian Redl | a74948d | 2011-09-24 17:48:25 +0000 | [diff] [blame] | 2859 | |
| 2860 | return Actions.ActOnMemInitializer(ConstructorDecl, getCurScope(), SS, II, |
David Blaikie | 186a889 | 2012-01-24 06:03:59 +0000 | [diff] [blame] | 2861 | TemplateTypeTy, DS, IdLoc, |
| 2862 | InitList.take(), EllipsisLoc); |
Sebastian Redl | 3da3489 | 2011-06-05 12:23:16 +0000 | [diff] [blame] | 2863 | } else if(Tok.is(tok::l_paren)) { |
Douglas Gregor | e7a8e3b | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 2864 | BalancedDelimiterTracker T(*this, tok::l_paren); |
| 2865 | T.consumeOpen(); |
Douglas Gregor | e8381c0 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 2866 | |
Sebastian Redl | 3da3489 | 2011-06-05 12:23:16 +0000 | [diff] [blame] | 2867 | // Parse the optional expression-list. |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 2868 | ExprVector ArgExprs; |
Sebastian Redl | 3da3489 | 2011-06-05 12:23:16 +0000 | [diff] [blame] | 2869 | CommaLocsTy CommaLocs; |
| 2870 | if (Tok.isNot(tok::r_paren) && ParseExpressionList(ArgExprs, CommaLocs)) { |
Alexey Bataev | ee6507d | 2013-11-18 08:17:37 +0000 | [diff] [blame] | 2871 | SkipUntil(tok::r_paren, StopAtSemi); |
Sebastian Redl | 3da3489 | 2011-06-05 12:23:16 +0000 | [diff] [blame] | 2872 | return true; |
| 2873 | } |
| 2874 | |
Douglas Gregor | e7a8e3b | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 2875 | T.consumeClose(); |
Sebastian Redl | 3da3489 | 2011-06-05 12:23:16 +0000 | [diff] [blame] | 2876 | |
| 2877 | SourceLocation EllipsisLoc; |
Alp Toker | 9765056 | 2014-01-10 11:19:30 +0000 | [diff] [blame] | 2878 | TryConsumeToken(tok::ellipsis, EllipsisLoc); |
Sebastian Redl | 3da3489 | 2011-06-05 12:23:16 +0000 | [diff] [blame] | 2879 | |
| 2880 | return Actions.ActOnMemInitializer(ConstructorDecl, getCurScope(), SS, II, |
David Blaikie | 186a889 | 2012-01-24 06:03:59 +0000 | [diff] [blame] | 2881 | TemplateTypeTy, DS, IdLoc, |
Dmitri Gribenko | 139474d | 2013-05-09 23:51:52 +0000 | [diff] [blame] | 2882 | T.getOpenLocation(), ArgExprs, |
| 2883 | T.getCloseLocation(), EllipsisLoc); |
Douglas Gregor | e8381c0 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 2884 | } |
| 2885 | |
Alp Toker | ec54327 | 2013-12-24 09:48:30 +0000 | [diff] [blame] | 2886 | if (getLangOpts().CPlusPlus11) |
| 2887 | return Diag(Tok, diag::err_expected_either) << tok::l_paren << tok::l_brace; |
| 2888 | else |
| 2889 | return Diag(Tok, diag::err_expected) << tok::l_paren; |
Douglas Gregor | e8381c0 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 2890 | } |
Douglas Gregor | 2afd0be | 2008-11-25 03:22:00 +0000 | [diff] [blame] | 2891 | |
Sebastian Redl | 965b0e3 | 2011-03-05 14:45:16 +0000 | [diff] [blame] | 2892 | /// \brief Parse a C++ exception-specification if present (C++0x [except.spec]). |
Douglas Gregor | 2afd0be | 2008-11-25 03:22:00 +0000 | [diff] [blame] | 2893 | /// |
Douglas Gregor | 356513d | 2008-12-01 18:00:20 +0000 | [diff] [blame] | 2894 | /// exception-specification: |
Sebastian Redl | 965b0e3 | 2011-03-05 14:45:16 +0000 | [diff] [blame] | 2895 | /// dynamic-exception-specification |
| 2896 | /// noexcept-specification |
| 2897 | /// |
| 2898 | /// noexcept-specification: |
| 2899 | /// 'noexcept' |
| 2900 | /// 'noexcept' '(' constant-expression ')' |
| 2901 | ExceptionSpecificationType |
Richard Smith | 2331bbf | 2012-05-02 22:22:32 +0000 | [diff] [blame] | 2902 | Parser::tryParseExceptionSpecification( |
Douglas Gregor | 433e053 | 2012-04-16 18:27:27 +0000 | [diff] [blame] | 2903 | SourceRange &SpecificationRange, |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2904 | SmallVectorImpl<ParsedType> &DynamicExceptions, |
| 2905 | SmallVectorImpl<SourceRange> &DynamicExceptionRanges, |
Richard Smith | 2331bbf | 2012-05-02 22:22:32 +0000 | [diff] [blame] | 2906 | ExprResult &NoexceptExpr) { |
Sebastian Redl | 965b0e3 | 2011-03-05 14:45:16 +0000 | [diff] [blame] | 2907 | ExceptionSpecificationType Result = EST_None; |
| 2908 | |
| 2909 | // See if there's a dynamic specification. |
| 2910 | if (Tok.is(tok::kw_throw)) { |
| 2911 | Result = ParseDynamicExceptionSpecification(SpecificationRange, |
| 2912 | DynamicExceptions, |
| 2913 | DynamicExceptionRanges); |
| 2914 | assert(DynamicExceptions.size() == DynamicExceptionRanges.size() && |
| 2915 | "Produced different number of exception types and ranges."); |
| 2916 | } |
| 2917 | |
| 2918 | // If there's no noexcept specification, we're done. |
| 2919 | if (Tok.isNot(tok::kw_noexcept)) |
| 2920 | return Result; |
| 2921 | |
Richard Smith | b15c11c | 2011-10-17 23:06:20 +0000 | [diff] [blame] | 2922 | Diag(Tok, diag::warn_cxx98_compat_noexcept_decl); |
| 2923 | |
Sebastian Redl | 965b0e3 | 2011-03-05 14:45:16 +0000 | [diff] [blame] | 2924 | // If we already had a dynamic specification, parse the noexcept for, |
| 2925 | // recovery, but emit a diagnostic and don't store the results. |
| 2926 | SourceRange NoexceptRange; |
| 2927 | ExceptionSpecificationType NoexceptType = EST_None; |
| 2928 | |
| 2929 | SourceLocation KeywordLoc = ConsumeToken(); |
| 2930 | if (Tok.is(tok::l_paren)) { |
| 2931 | // There is an argument. |
Douglas Gregor | e7a8e3b | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 2932 | BalancedDelimiterTracker T(*this, tok::l_paren); |
| 2933 | T.consumeOpen(); |
Sebastian Redl | 965b0e3 | 2011-03-05 14:45:16 +0000 | [diff] [blame] | 2934 | NoexceptType = EST_ComputedNoexcept; |
| 2935 | NoexceptExpr = ParseConstantExpression(); |
Sebastian Redl | fa453cf | 2011-03-12 11:50:43 +0000 | [diff] [blame] | 2936 | // The argument must be contextually convertible to bool. We use |
| 2937 | // ActOnBooleanCondition for this purpose. |
| 2938 | if (!NoexceptExpr.isInvalid()) |
| 2939 | NoexceptExpr = Actions.ActOnBooleanCondition(getCurScope(), KeywordLoc, |
| 2940 | NoexceptExpr.get()); |
Douglas Gregor | e7a8e3b | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 2941 | T.consumeClose(); |
| 2942 | NoexceptRange = SourceRange(KeywordLoc, T.getCloseLocation()); |
Sebastian Redl | 965b0e3 | 2011-03-05 14:45:16 +0000 | [diff] [blame] | 2943 | } else { |
| 2944 | // There is no argument. |
| 2945 | NoexceptType = EST_BasicNoexcept; |
| 2946 | NoexceptRange = SourceRange(KeywordLoc, KeywordLoc); |
| 2947 | } |
| 2948 | |
| 2949 | if (Result == EST_None) { |
| 2950 | SpecificationRange = NoexceptRange; |
| 2951 | Result = NoexceptType; |
| 2952 | |
| 2953 | // If there's a dynamic specification after a noexcept specification, |
| 2954 | // parse that and ignore the results. |
| 2955 | if (Tok.is(tok::kw_throw)) { |
| 2956 | Diag(Tok.getLocation(), diag::err_dynamic_and_noexcept_specification); |
| 2957 | ParseDynamicExceptionSpecification(NoexceptRange, DynamicExceptions, |
| 2958 | DynamicExceptionRanges); |
| 2959 | } |
| 2960 | } else { |
| 2961 | Diag(Tok.getLocation(), diag::err_dynamic_and_noexcept_specification); |
| 2962 | } |
| 2963 | |
| 2964 | return Result; |
| 2965 | } |
| 2966 | |
Richard Smith | 8ca78a1 | 2013-06-13 02:02:51 +0000 | [diff] [blame] | 2967 | static void diagnoseDynamicExceptionSpecification( |
| 2968 | Parser &P, const SourceRange &Range, bool IsNoexcept) { |
| 2969 | if (P.getLangOpts().CPlusPlus11) { |
| 2970 | const char *Replacement = IsNoexcept ? "noexcept" : "noexcept(false)"; |
| 2971 | P.Diag(Range.getBegin(), diag::warn_exception_spec_deprecated) << Range; |
| 2972 | P.Diag(Range.getBegin(), diag::note_exception_spec_deprecated) |
| 2973 | << Replacement << FixItHint::CreateReplacement(Range, Replacement); |
| 2974 | } |
| 2975 | } |
| 2976 | |
Sebastian Redl | 965b0e3 | 2011-03-05 14:45:16 +0000 | [diff] [blame] | 2977 | /// ParseDynamicExceptionSpecification - Parse a C++ |
| 2978 | /// dynamic-exception-specification (C++ [except.spec]). |
| 2979 | /// |
| 2980 | /// dynamic-exception-specification: |
Douglas Gregor | 356513d | 2008-12-01 18:00:20 +0000 | [diff] [blame] | 2981 | /// 'throw' '(' type-id-list [opt] ')' |
| 2982 | /// [MS] 'throw' '(' '...' ')' |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2983 | /// |
Douglas Gregor | 356513d | 2008-12-01 18:00:20 +0000 | [diff] [blame] | 2984 | /// type-id-list: |
Douglas Gregor | 830837d | 2010-12-20 23:57:46 +0000 | [diff] [blame] | 2985 | /// type-id ... [opt] |
| 2986 | /// type-id-list ',' type-id ... [opt] |
Douglas Gregor | 2afd0be | 2008-11-25 03:22:00 +0000 | [diff] [blame] | 2987 | /// |
Sebastian Redl | 965b0e3 | 2011-03-05 14:45:16 +0000 | [diff] [blame] | 2988 | ExceptionSpecificationType Parser::ParseDynamicExceptionSpecification( |
| 2989 | SourceRange &SpecificationRange, |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2990 | SmallVectorImpl<ParsedType> &Exceptions, |
| 2991 | SmallVectorImpl<SourceRange> &Ranges) { |
Douglas Gregor | 2afd0be | 2008-11-25 03:22:00 +0000 | [diff] [blame] | 2992 | assert(Tok.is(tok::kw_throw) && "expected throw"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2993 | |
Sebastian Redl | 965b0e3 | 2011-03-05 14:45:16 +0000 | [diff] [blame] | 2994 | SpecificationRange.setBegin(ConsumeToken()); |
Douglas Gregor | e7a8e3b | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 2995 | BalancedDelimiterTracker T(*this, tok::l_paren); |
| 2996 | if (T.consumeOpen()) { |
Sebastian Redl | 965b0e3 | 2011-03-05 14:45:16 +0000 | [diff] [blame] | 2997 | Diag(Tok, diag::err_expected_lparen_after) << "throw"; |
| 2998 | SpecificationRange.setEnd(SpecificationRange.getBegin()); |
Sebastian Redl | fa453cf | 2011-03-12 11:50:43 +0000 | [diff] [blame] | 2999 | return EST_DynamicNone; |
Douglas Gregor | 2afd0be | 2008-11-25 03:22:00 +0000 | [diff] [blame] | 3000 | } |
Douglas Gregor | 2afd0be | 2008-11-25 03:22:00 +0000 | [diff] [blame] | 3001 | |
Douglas Gregor | 356513d | 2008-12-01 18:00:20 +0000 | [diff] [blame] | 3002 | // Parse throw(...), a Microsoft extension that means "this function |
| 3003 | // can throw anything". |
| 3004 | if (Tok.is(tok::ellipsis)) { |
| 3005 | SourceLocation EllipsisLoc = ConsumeToken(); |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 3006 | if (!getLangOpts().MicrosoftExt) |
Douglas Gregor | 356513d | 2008-12-01 18:00:20 +0000 | [diff] [blame] | 3007 | Diag(EllipsisLoc, diag::ext_ellipsis_exception_spec); |
Douglas Gregor | e7a8e3b | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 3008 | T.consumeClose(); |
| 3009 | SpecificationRange.setEnd(T.getCloseLocation()); |
Richard Smith | 8ca78a1 | 2013-06-13 02:02:51 +0000 | [diff] [blame] | 3010 | diagnoseDynamicExceptionSpecification(*this, SpecificationRange, false); |
Sebastian Redl | fa453cf | 2011-03-12 11:50:43 +0000 | [diff] [blame] | 3011 | return EST_MSAny; |
Douglas Gregor | 356513d | 2008-12-01 18:00:20 +0000 | [diff] [blame] | 3012 | } |
| 3013 | |
Douglas Gregor | 2afd0be | 2008-11-25 03:22:00 +0000 | [diff] [blame] | 3014 | // Parse the sequence of type-ids. |
Sebastian Redl | d643456 | 2009-05-29 18:02:33 +0000 | [diff] [blame] | 3015 | SourceRange Range; |
Douglas Gregor | 2afd0be | 2008-11-25 03:22:00 +0000 | [diff] [blame] | 3016 | while (Tok.isNot(tok::r_paren)) { |
Sebastian Redl | d643456 | 2009-05-29 18:02:33 +0000 | [diff] [blame] | 3017 | TypeResult Res(ParseTypeName(&Range)); |
Sebastian Redl | 965b0e3 | 2011-03-05 14:45:16 +0000 | [diff] [blame] | 3018 | |
Douglas Gregor | 830837d | 2010-12-20 23:57:46 +0000 | [diff] [blame] | 3019 | if (Tok.is(tok::ellipsis)) { |
| 3020 | // C++0x [temp.variadic]p5: |
| 3021 | // - In a dynamic-exception-specification (15.4); the pattern is a |
| 3022 | // type-id. |
| 3023 | SourceLocation Ellipsis = ConsumeToken(); |
Sebastian Redl | 965b0e3 | 2011-03-05 14:45:16 +0000 | [diff] [blame] | 3024 | Range.setEnd(Ellipsis); |
Douglas Gregor | 830837d | 2010-12-20 23:57:46 +0000 | [diff] [blame] | 3025 | if (!Res.isInvalid()) |
| 3026 | Res = Actions.ActOnPackExpansion(Res.get(), Ellipsis); |
| 3027 | } |
Sebastian Redl | 965b0e3 | 2011-03-05 14:45:16 +0000 | [diff] [blame] | 3028 | |
Sebastian Redl | d643456 | 2009-05-29 18:02:33 +0000 | [diff] [blame] | 3029 | if (!Res.isInvalid()) { |
Sebastian Redl | 2b9cacb | 2009-04-29 17:30:04 +0000 | [diff] [blame] | 3030 | Exceptions.push_back(Res.get()); |
Sebastian Redl | d643456 | 2009-05-29 18:02:33 +0000 | [diff] [blame] | 3031 | Ranges.push_back(Range); |
| 3032 | } |
Alp Toker | 9765056 | 2014-01-10 11:19:30 +0000 | [diff] [blame] | 3033 | |
| 3034 | if (!TryConsumeToken(tok::comma)) |
Douglas Gregor | 2afd0be | 2008-11-25 03:22:00 +0000 | [diff] [blame] | 3035 | break; |
| 3036 | } |
| 3037 | |
Douglas Gregor | e7a8e3b | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 3038 | T.consumeClose(); |
| 3039 | SpecificationRange.setEnd(T.getCloseLocation()); |
Richard Smith | 8ca78a1 | 2013-06-13 02:02:51 +0000 | [diff] [blame] | 3040 | diagnoseDynamicExceptionSpecification(*this, SpecificationRange, |
| 3041 | Exceptions.empty()); |
Sebastian Redl | fa453cf | 2011-03-12 11:50:43 +0000 | [diff] [blame] | 3042 | return Exceptions.empty() ? EST_DynamicNone : EST_Dynamic; |
Douglas Gregor | 2afd0be | 2008-11-25 03:22:00 +0000 | [diff] [blame] | 3043 | } |
Douglas Gregor | e44a2ad | 2009-05-27 23:11:45 +0000 | [diff] [blame] | 3044 | |
Douglas Gregor | 7fb2541 | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 3045 | /// ParseTrailingReturnType - Parse a trailing return type on a new-style |
| 3046 | /// function declaration. |
Douglas Gregor | db0b9f1 | 2011-08-04 15:30:47 +0000 | [diff] [blame] | 3047 | TypeResult Parser::ParseTrailingReturnType(SourceRange &Range) { |
Douglas Gregor | 7fb2541 | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 3048 | assert(Tok.is(tok::arrow) && "expected arrow"); |
| 3049 | |
| 3050 | ConsumeToken(); |
| 3051 | |
Richard Smith | bfdb108 | 2012-03-12 08:56:40 +0000 | [diff] [blame] | 3052 | return ParseTypeName(&Range, Declarator::TrailingReturnContext); |
Douglas Gregor | 7fb2541 | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 3053 | } |
| 3054 | |
Douglas Gregor | e44a2ad | 2009-05-27 23:11:45 +0000 | [diff] [blame] | 3055 | /// \brief We have just started parsing the definition of a new class, |
| 3056 | /// so push that class onto our stack of classes that is currently |
| 3057 | /// being parsed. |
John McCall | c146582 | 2011-02-14 07:13:47 +0000 | [diff] [blame] | 3058 | Sema::ParsingClassState |
John McCall | db632ac | 2012-09-25 07:32:39 +0000 | [diff] [blame] | 3059 | Parser::PushParsingClass(Decl *ClassDecl, bool NonNestedClass, |
| 3060 | bool IsInterface) { |
Douglas Gregor | edf8f39 | 2010-01-16 20:52:59 +0000 | [diff] [blame] | 3061 | assert((NonNestedClass || !ClassStack.empty()) && |
Douglas Gregor | e44a2ad | 2009-05-27 23:11:45 +0000 | [diff] [blame] | 3062 | "Nested class without outer class"); |
John McCall | db632ac | 2012-09-25 07:32:39 +0000 | [diff] [blame] | 3063 | ClassStack.push(new ParsingClass(ClassDecl, NonNestedClass, IsInterface)); |
John McCall | c146582 | 2011-02-14 07:13:47 +0000 | [diff] [blame] | 3064 | return Actions.PushParsingClass(); |
Douglas Gregor | e44a2ad | 2009-05-27 23:11:45 +0000 | [diff] [blame] | 3065 | } |
| 3066 | |
| 3067 | /// \brief Deallocate the given parsed class and all of its nested |
| 3068 | /// classes. |
| 3069 | void Parser::DeallocateParsedClasses(Parser::ParsingClass *Class) { |
Douglas Gregor | efc4695 | 2010-10-12 16:25:54 +0000 | [diff] [blame] | 3070 | for (unsigned I = 0, N = Class->LateParsedDeclarations.size(); I != N; ++I) |
| 3071 | delete Class->LateParsedDeclarations[I]; |
Douglas Gregor | e44a2ad | 2009-05-27 23:11:45 +0000 | [diff] [blame] | 3072 | delete Class; |
| 3073 | } |
| 3074 | |
| 3075 | /// \brief Pop the top class of the stack of classes that are |
| 3076 | /// currently being parsed. |
| 3077 | /// |
| 3078 | /// This routine should be called when we have finished parsing the |
| 3079 | /// definition of a class, but have not yet popped the Scope |
| 3080 | /// associated with the class's definition. |
John McCall | c146582 | 2011-02-14 07:13:47 +0000 | [diff] [blame] | 3081 | void Parser::PopParsingClass(Sema::ParsingClassState state) { |
Douglas Gregor | e44a2ad | 2009-05-27 23:11:45 +0000 | [diff] [blame] | 3082 | assert(!ClassStack.empty() && "Mismatched push/pop for class parsing"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3083 | |
John McCall | c146582 | 2011-02-14 07:13:47 +0000 | [diff] [blame] | 3084 | Actions.PopParsingClass(state); |
| 3085 | |
Douglas Gregor | e44a2ad | 2009-05-27 23:11:45 +0000 | [diff] [blame] | 3086 | ParsingClass *Victim = ClassStack.top(); |
| 3087 | ClassStack.pop(); |
| 3088 | if (Victim->TopLevelClass) { |
| 3089 | // Deallocate all of the nested classes of this class, |
| 3090 | // recursively: we don't need to keep any of this information. |
| 3091 | DeallocateParsedClasses(Victim); |
| 3092 | return; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3093 | } |
Douglas Gregor | e44a2ad | 2009-05-27 23:11:45 +0000 | [diff] [blame] | 3094 | assert(!ClassStack.empty() && "Missing top-level class?"); |
| 3095 | |
Douglas Gregor | efc4695 | 2010-10-12 16:25:54 +0000 | [diff] [blame] | 3096 | if (Victim->LateParsedDeclarations.empty()) { |
Douglas Gregor | e44a2ad | 2009-05-27 23:11:45 +0000 | [diff] [blame] | 3097 | // The victim is a nested class, but we will not need to perform |
| 3098 | // any processing after the definition of this class since it has |
| 3099 | // no members whose handling was delayed. Therefore, we can just |
| 3100 | // remove this nested class. |
Douglas Gregor | efc4695 | 2010-10-12 16:25:54 +0000 | [diff] [blame] | 3101 | DeallocateParsedClasses(Victim); |
Douglas Gregor | e44a2ad | 2009-05-27 23:11:45 +0000 | [diff] [blame] | 3102 | return; |
| 3103 | } |
| 3104 | |
| 3105 | // This nested class has some members that will need to be processed |
| 3106 | // after the top-level class is completely defined. Therefore, add |
| 3107 | // it to the list of nested classes within its parent. |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 3108 | assert(getCurScope()->isClassScope() && "Nested class outside of class scope?"); |
Douglas Gregor | efc4695 | 2010-10-12 16:25:54 +0000 | [diff] [blame] | 3109 | ClassStack.top()->LateParsedDeclarations.push_back(new LateParsedClass(this, Victim)); |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 3110 | Victim->TemplateScope = getCurScope()->getParent()->isTemplateParamScope(); |
Douglas Gregor | e44a2ad | 2009-05-27 23:11:45 +0000 | [diff] [blame] | 3111 | } |
Alexis Hunt | 96d5c76 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 3112 | |
Richard Smith | 3dff251 | 2012-04-10 03:25:07 +0000 | [diff] [blame] | 3113 | /// \brief Try to parse an 'identifier' which appears within an attribute-token. |
| 3114 | /// |
| 3115 | /// \return the parsed identifier on success, and 0 if the next token is not an |
| 3116 | /// attribute-token. |
| 3117 | /// |
| 3118 | /// C++11 [dcl.attr.grammar]p3: |
| 3119 | /// If a keyword or an alternative token that satisfies the syntactic |
| 3120 | /// requirements of an identifier is contained in an attribute-token, |
| 3121 | /// it is considered an identifier. |
| 3122 | IdentifierInfo *Parser::TryParseCXX11AttributeIdentifier(SourceLocation &Loc) { |
| 3123 | switch (Tok.getKind()) { |
| 3124 | default: |
| 3125 | // Identifiers and keywords have identifier info attached. |
| 3126 | if (IdentifierInfo *II = Tok.getIdentifierInfo()) { |
| 3127 | Loc = ConsumeToken(); |
| 3128 | return II; |
| 3129 | } |
| 3130 | return 0; |
| 3131 | |
| 3132 | case tok::ampamp: // 'and' |
| 3133 | case tok::pipe: // 'bitor' |
| 3134 | case tok::pipepipe: // 'or' |
| 3135 | case tok::caret: // 'xor' |
| 3136 | case tok::tilde: // 'compl' |
| 3137 | case tok::amp: // 'bitand' |
| 3138 | case tok::ampequal: // 'and_eq' |
| 3139 | case tok::pipeequal: // 'or_eq' |
| 3140 | case tok::caretequal: // 'xor_eq' |
| 3141 | case tok::exclaim: // 'not' |
| 3142 | case tok::exclaimequal: // 'not_eq' |
| 3143 | // Alternative tokens do not have identifier info, but their spelling |
| 3144 | // starts with an alphabetical character. |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 3145 | SmallString<8> SpellingBuf; |
Richard Smith | 3dff251 | 2012-04-10 03:25:07 +0000 | [diff] [blame] | 3146 | StringRef Spelling = PP.getSpelling(Tok.getLocation(), SpellingBuf); |
Jordan Rose | a7d0384 | 2013-02-08 22:30:41 +0000 | [diff] [blame] | 3147 | if (isLetter(Spelling[0])) { |
Richard Smith | 3dff251 | 2012-04-10 03:25:07 +0000 | [diff] [blame] | 3148 | Loc = ConsumeToken(); |
Benjamin Kramer | 5c17f9c | 2012-04-22 20:43:30 +0000 | [diff] [blame] | 3149 | return &PP.getIdentifierTable().get(Spelling); |
Richard Smith | 3dff251 | 2012-04-10 03:25:07 +0000 | [diff] [blame] | 3150 | } |
| 3151 | return 0; |
| 3152 | } |
| 3153 | } |
| 3154 | |
Michael Han | 23214e5 | 2012-10-03 01:56:22 +0000 | [diff] [blame] | 3155 | static bool IsBuiltInOrStandardCXX11Attribute(IdentifierInfo *AttrName, |
| 3156 | IdentifierInfo *ScopeName) { |
| 3157 | switch (AttributeList::getKind(AttrName, ScopeName, |
| 3158 | AttributeList::AS_CXX11)) { |
| 3159 | case AttributeList::AT_CarriesDependency: |
| 3160 | case AttributeList::AT_FallThrough: |
Richard Smith | 10876ef | 2013-01-17 01:30:42 +0000 | [diff] [blame] | 3161 | case AttributeList::AT_CXX11NoReturn: { |
Michael Han | 23214e5 | 2012-10-03 01:56:22 +0000 | [diff] [blame] | 3162 | return true; |
| 3163 | } |
| 3164 | |
| 3165 | default: |
| 3166 | return false; |
| 3167 | } |
| 3168 | } |
| 3169 | |
Richard Smith | 3dff251 | 2012-04-10 03:25:07 +0000 | [diff] [blame] | 3170 | /// ParseCXX11AttributeSpecifier - Parse a C++11 attribute-specifier. Currently |
Peter Collingbourne | 49eedec | 2011-09-29 18:04:05 +0000 | [diff] [blame] | 3171 | /// only parses standard attributes. |
Alexis Hunt | 96d5c76 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 3172 | /// |
Richard Smith | 7bdcc4a | 2012-04-10 01:32:12 +0000 | [diff] [blame] | 3173 | /// [C++11] attribute-specifier: |
Alexis Hunt | 96d5c76 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 3174 | /// '[' '[' attribute-list ']' ']' |
Peter Collingbourne | 2f3cf4b | 2011-09-29 18:04:28 +0000 | [diff] [blame] | 3175 | /// alignment-specifier |
Alexis Hunt | 96d5c76 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 3176 | /// |
Richard Smith | 7bdcc4a | 2012-04-10 01:32:12 +0000 | [diff] [blame] | 3177 | /// [C++11] attribute-list: |
Alexis Hunt | 96d5c76 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 3178 | /// attribute[opt] |
| 3179 | /// attribute-list ',' attribute[opt] |
Richard Smith | 3dff251 | 2012-04-10 03:25:07 +0000 | [diff] [blame] | 3180 | /// attribute '...' |
| 3181 | /// attribute-list ',' attribute '...' |
Alexis Hunt | 96d5c76 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 3182 | /// |
Richard Smith | 7bdcc4a | 2012-04-10 01:32:12 +0000 | [diff] [blame] | 3183 | /// [C++11] attribute: |
Alexis Hunt | 96d5c76 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 3184 | /// attribute-token attribute-argument-clause[opt] |
| 3185 | /// |
Richard Smith | 7bdcc4a | 2012-04-10 01:32:12 +0000 | [diff] [blame] | 3186 | /// [C++11] attribute-token: |
Alexis Hunt | 96d5c76 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 3187 | /// identifier |
| 3188 | /// attribute-scoped-token |
| 3189 | /// |
Richard Smith | 7bdcc4a | 2012-04-10 01:32:12 +0000 | [diff] [blame] | 3190 | /// [C++11] attribute-scoped-token: |
Alexis Hunt | 96d5c76 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 3191 | /// attribute-namespace '::' identifier |
| 3192 | /// |
Richard Smith | 7bdcc4a | 2012-04-10 01:32:12 +0000 | [diff] [blame] | 3193 | /// [C++11] attribute-namespace: |
Alexis Hunt | 96d5c76 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 3194 | /// identifier |
| 3195 | /// |
Richard Smith | 7bdcc4a | 2012-04-10 01:32:12 +0000 | [diff] [blame] | 3196 | /// [C++11] attribute-argument-clause: |
Alexis Hunt | 96d5c76 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 3197 | /// '(' balanced-token-seq ')' |
| 3198 | /// |
Richard Smith | 7bdcc4a | 2012-04-10 01:32:12 +0000 | [diff] [blame] | 3199 | /// [C++11] balanced-token-seq: |
Alexis Hunt | 96d5c76 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 3200 | /// balanced-token |
| 3201 | /// balanced-token-seq balanced-token |
| 3202 | /// |
Richard Smith | 7bdcc4a | 2012-04-10 01:32:12 +0000 | [diff] [blame] | 3203 | /// [C++11] balanced-token: |
Alexis Hunt | 96d5c76 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 3204 | /// '(' balanced-token-seq ')' |
| 3205 | /// '[' balanced-token-seq ']' |
| 3206 | /// '{' balanced-token-seq '}' |
| 3207 | /// any token but '(', ')', '[', ']', '{', or '}' |
Richard Smith | 3dff251 | 2012-04-10 03:25:07 +0000 | [diff] [blame] | 3208 | void Parser::ParseCXX11AttributeSpecifier(ParsedAttributes &attrs, |
Peter Collingbourne | 49eedec | 2011-09-29 18:04:05 +0000 | [diff] [blame] | 3209 | SourceLocation *endLoc) { |
Peter Collingbourne | 2f3cf4b | 2011-09-29 18:04:28 +0000 | [diff] [blame] | 3210 | if (Tok.is(tok::kw_alignas)) { |
Richard Smith | f679b5b | 2011-10-14 20:48:27 +0000 | [diff] [blame] | 3211 | Diag(Tok.getLocation(), diag::warn_cxx98_compat_alignas); |
Peter Collingbourne | 2f3cf4b | 2011-09-29 18:04:28 +0000 | [diff] [blame] | 3212 | ParseAlignmentSpecifier(attrs, endLoc); |
| 3213 | return; |
| 3214 | } |
| 3215 | |
Alexis Hunt | 96d5c76 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 3216 | assert(Tok.is(tok::l_square) && NextToken().is(tok::l_square) |
Richard Smith | 7bdcc4a | 2012-04-10 01:32:12 +0000 | [diff] [blame] | 3217 | && "Not a C++11 attribute list"); |
Alexis Hunt | 96d5c76 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 3218 | |
Richard Smith | f679b5b | 2011-10-14 20:48:27 +0000 | [diff] [blame] | 3219 | Diag(Tok.getLocation(), diag::warn_cxx98_compat_attribute); |
| 3220 | |
Alexis Hunt | 96d5c76 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 3221 | ConsumeBracket(); |
| 3222 | ConsumeBracket(); |
Kovarththanan Rajaratnam | ba2c652 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 3223 | |
Richard Smith | 10876ef | 2013-01-17 01:30:42 +0000 | [diff] [blame] | 3224 | llvm::SmallDenseMap<IdentifierInfo*, SourceLocation, 4> SeenAttrs; |
| 3225 | |
Richard Smith | 3dff251 | 2012-04-10 03:25:07 +0000 | [diff] [blame] | 3226 | while (Tok.isNot(tok::r_square)) { |
Alexis Hunt | 96d5c76 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 3227 | // attribute not present |
Alp Toker | 9765056 | 2014-01-10 11:19:30 +0000 | [diff] [blame] | 3228 | if (TryConsumeToken(tok::comma)) |
Alexis Hunt | 96d5c76 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 3229 | continue; |
Alexis Hunt | 96d5c76 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 3230 | |
Richard Smith | 3dff251 | 2012-04-10 03:25:07 +0000 | [diff] [blame] | 3231 | SourceLocation ScopeLoc, AttrLoc; |
| 3232 | IdentifierInfo *ScopeName = 0, *AttrName = 0; |
| 3233 | |
| 3234 | AttrName = TryParseCXX11AttributeIdentifier(AttrLoc); |
| 3235 | if (!AttrName) |
| 3236 | // Break out to the "expected ']'" diagnostic. |
| 3237 | break; |
Kovarththanan Rajaratnam | ba2c652 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 3238 | |
Alexis Hunt | 96d5c76 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 3239 | // scoped attribute |
Alp Toker | 9765056 | 2014-01-10 11:19:30 +0000 | [diff] [blame] | 3240 | if (TryConsumeToken(tok::coloncolon)) { |
Richard Smith | 3dff251 | 2012-04-10 03:25:07 +0000 | [diff] [blame] | 3241 | ScopeName = AttrName; |
| 3242 | ScopeLoc = AttrLoc; |
| 3243 | |
| 3244 | AttrName = TryParseCXX11AttributeIdentifier(AttrLoc); |
| 3245 | if (!AttrName) { |
Alp Toker | ec54327 | 2013-12-24 09:48:30 +0000 | [diff] [blame] | 3246 | Diag(Tok.getLocation(), diag::err_expected) << tok::identifier; |
Alexey Bataev | ee6507d | 2013-11-18 08:17:37 +0000 | [diff] [blame] | 3247 | SkipUntil(tok::r_square, tok::comma, StopAtSemi | StopBeforeMatch); |
Alexis Hunt | 96d5c76 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 3248 | continue; |
| 3249 | } |
Alexis Hunt | 96d5c76 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 3250 | } |
| 3251 | |
Michael Han | 23214e5 | 2012-10-03 01:56:22 +0000 | [diff] [blame] | 3252 | bool StandardAttr = IsBuiltInOrStandardCXX11Attribute(AttrName,ScopeName); |
Alexis Hunt | 96d5c76 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 3253 | bool AttrParsed = false; |
Alexis Hunt | 96d5c76 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 3254 | |
Richard Smith | 10876ef | 2013-01-17 01:30:42 +0000 | [diff] [blame] | 3255 | if (StandardAttr && |
| 3256 | !SeenAttrs.insert(std::make_pair(AttrName, AttrLoc)).second) |
| 3257 | Diag(AttrLoc, diag::err_cxx11_attribute_repeated) |
| 3258 | << AttrName << SourceRange(SeenAttrs[AttrName]); |
| 3259 | |
Michael Han | 23214e5 | 2012-10-03 01:56:22 +0000 | [diff] [blame] | 3260 | // Parse attribute arguments |
| 3261 | if (Tok.is(tok::l_paren)) { |
| 3262 | if (ScopeName && ScopeName->getName() == "gnu") { |
| 3263 | ParseGNUAttributeArgs(AttrName, AttrLoc, attrs, endLoc, |
Nick Lewycky | 35a6ef4 | 2014-01-11 02:50:57 +0000 | [diff] [blame] | 3264 | ScopeName, ScopeLoc, AttributeList::AS_CXX11, 0); |
Michael Han | 23214e5 | 2012-10-03 01:56:22 +0000 | [diff] [blame] | 3265 | AttrParsed = true; |
| 3266 | } else { |
| 3267 | if (StandardAttr) |
| 3268 | Diag(Tok.getLocation(), diag::err_cxx11_attribute_forbids_arguments) |
| 3269 | << AttrName->getName(); |
| 3270 | |
| 3271 | // FIXME: handle other formats of c++11 attribute arguments |
| 3272 | ConsumeParen(); |
Alexey Bataev | ee6507d | 2013-11-18 08:17:37 +0000 | [diff] [blame] | 3273 | SkipUntil(tok::r_paren); |
Michael Han | 23214e5 | 2012-10-03 01:56:22 +0000 | [diff] [blame] | 3274 | } |
| 3275 | } |
| 3276 | |
| 3277 | if (!AttrParsed) |
Richard Smith | 84837d5 | 2012-05-03 18:27:39 +0000 | [diff] [blame] | 3278 | attrs.addNew(AttrName, |
| 3279 | SourceRange(ScopeLoc.isValid() ? ScopeLoc : AttrLoc, |
| 3280 | AttrLoc), |
Aaron Ballman | 00e9996 | 2013-08-31 01:11:41 +0000 | [diff] [blame] | 3281 | ScopeName, ScopeLoc, 0, 0, AttributeList::AS_CXX11); |
Richard Smith | 7bdcc4a | 2012-04-10 01:32:12 +0000 | [diff] [blame] | 3282 | |
Alp Toker | 9765056 | 2014-01-10 11:19:30 +0000 | [diff] [blame] | 3283 | if (TryConsumeToken(tok::ellipsis)) |
Michael Han | 23214e5 | 2012-10-03 01:56:22 +0000 | [diff] [blame] | 3284 | Diag(Tok, diag::err_cxx11_attribute_forbids_ellipsis) |
| 3285 | << AttrName->getName(); |
Alexis Hunt | 96d5c76 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 3286 | } |
| 3287 | |
Alp Toker | 383d2c4 | 2014-01-01 03:08:43 +0000 | [diff] [blame] | 3288 | if (ExpectAndConsume(tok::r_square)) |
Alexey Bataev | ee6507d | 2013-11-18 08:17:37 +0000 | [diff] [blame] | 3289 | SkipUntil(tok::r_square); |
Peter Collingbourne | 49eedec | 2011-09-29 18:04:05 +0000 | [diff] [blame] | 3290 | if (endLoc) |
| 3291 | *endLoc = Tok.getLocation(); |
Alp Toker | 383d2c4 | 2014-01-01 03:08:43 +0000 | [diff] [blame] | 3292 | if (ExpectAndConsume(tok::r_square)) |
Alexey Bataev | ee6507d | 2013-11-18 08:17:37 +0000 | [diff] [blame] | 3293 | SkipUntil(tok::r_square); |
Peter Collingbourne | 49eedec | 2011-09-29 18:04:05 +0000 | [diff] [blame] | 3294 | } |
Alexis Hunt | 96d5c76 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 3295 | |
Alexis Hunt | 6aa9bee | 2012-06-23 05:07:58 +0000 | [diff] [blame] | 3296 | /// ParseCXX11Attributes - Parse a C++11 attribute-specifier-seq. |
Peter Collingbourne | 49eedec | 2011-09-29 18:04:05 +0000 | [diff] [blame] | 3297 | /// |
| 3298 | /// attribute-specifier-seq: |
| 3299 | /// attribute-specifier-seq[opt] attribute-specifier |
Richard Smith | 3dff251 | 2012-04-10 03:25:07 +0000 | [diff] [blame] | 3300 | void Parser::ParseCXX11Attributes(ParsedAttributesWithRange &attrs, |
Peter Collingbourne | 49eedec | 2011-09-29 18:04:05 +0000 | [diff] [blame] | 3301 | SourceLocation *endLoc) { |
Richard Smith | 4cabd04 | 2013-02-22 09:15:49 +0000 | [diff] [blame] | 3302 | assert(getLangOpts().CPlusPlus11); |
| 3303 | |
Peter Collingbourne | 49eedec | 2011-09-29 18:04:05 +0000 | [diff] [blame] | 3304 | SourceLocation StartLoc = Tok.getLocation(), Loc; |
| 3305 | if (!endLoc) |
| 3306 | endLoc = &Loc; |
| 3307 | |
Douglas Gregor | 6f98100 | 2011-10-07 20:35:25 +0000 | [diff] [blame] | 3308 | do { |
Richard Smith | 3dff251 | 2012-04-10 03:25:07 +0000 | [diff] [blame] | 3309 | ParseCXX11AttributeSpecifier(attrs, endLoc); |
Richard Smith | 7bdcc4a | 2012-04-10 01:32:12 +0000 | [diff] [blame] | 3310 | } while (isCXX11AttributeSpecifier()); |
Peter Collingbourne | 49eedec | 2011-09-29 18:04:05 +0000 | [diff] [blame] | 3311 | |
| 3312 | attrs.Range = SourceRange(StartLoc, *endLoc); |
Alexis Hunt | 96d5c76 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 3313 | } |
| 3314 | |
Richard Smith | c2c8bb8 | 2013-10-15 01:34:54 +0000 | [diff] [blame] | 3315 | void Parser::DiagnoseAndSkipCXX11Attributes() { |
| 3316 | if (!isCXX11AttributeSpecifier()) |
| 3317 | return; |
| 3318 | |
| 3319 | // Start and end location of an attribute or an attribute list. |
| 3320 | SourceLocation StartLoc = Tok.getLocation(); |
| 3321 | SourceLocation EndLoc; |
| 3322 | |
| 3323 | do { |
| 3324 | if (Tok.is(tok::l_square)) { |
| 3325 | BalancedDelimiterTracker T(*this, tok::l_square); |
| 3326 | T.consumeOpen(); |
| 3327 | T.skipToEnd(); |
| 3328 | EndLoc = T.getCloseLocation(); |
| 3329 | } else { |
| 3330 | assert(Tok.is(tok::kw_alignas) && "not an attribute specifier"); |
| 3331 | ConsumeToken(); |
| 3332 | BalancedDelimiterTracker T(*this, tok::l_paren); |
| 3333 | if (!T.consumeOpen()) |
| 3334 | T.skipToEnd(); |
| 3335 | EndLoc = T.getCloseLocation(); |
| 3336 | } |
| 3337 | } while (isCXX11AttributeSpecifier()); |
| 3338 | |
| 3339 | if (EndLoc.isValid()) { |
| 3340 | SourceRange Range(StartLoc, EndLoc); |
| 3341 | Diag(StartLoc, diag::err_attributes_not_allowed) |
| 3342 | << Range; |
| 3343 | } |
| 3344 | } |
| 3345 | |
Francois Pichet | c2bc5ac | 2010-10-11 12:59:39 +0000 | [diff] [blame] | 3346 | /// ParseMicrosoftAttributes - Parse a Microsoft attribute [Attr] |
| 3347 | /// |
| 3348 | /// [MS] ms-attribute: |
| 3349 | /// '[' token-seq ']' |
| 3350 | /// |
| 3351 | /// [MS] ms-attribute-seq: |
| 3352 | /// ms-attribute[opt] |
| 3353 | /// ms-attribute ms-attribute-seq |
John McCall | 53fa714 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 3354 | void Parser::ParseMicrosoftAttributes(ParsedAttributes &attrs, |
| 3355 | SourceLocation *endLoc) { |
Francois Pichet | c2bc5ac | 2010-10-11 12:59:39 +0000 | [diff] [blame] | 3356 | assert(Tok.is(tok::l_square) && "Not a Microsoft attribute list"); |
| 3357 | |
| 3358 | while (Tok.is(tok::l_square)) { |
Richard Smith | 7bdcc4a | 2012-04-10 01:32:12 +0000 | [diff] [blame] | 3359 | // FIXME: If this is actually a C++11 attribute, parse it as one. |
Francois Pichet | c2bc5ac | 2010-10-11 12:59:39 +0000 | [diff] [blame] | 3360 | ConsumeBracket(); |
Alexey Bataev | ee6507d | 2013-11-18 08:17:37 +0000 | [diff] [blame] | 3361 | SkipUntil(tok::r_square, StopAtSemi | StopBeforeMatch); |
John McCall | 53fa714 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 3362 | if (endLoc) *endLoc = Tok.getLocation(); |
Alp Toker | 383d2c4 | 2014-01-01 03:08:43 +0000 | [diff] [blame] | 3363 | ExpectAndConsume(tok::r_square); |
Francois Pichet | c2bc5ac | 2010-10-11 12:59:39 +0000 | [diff] [blame] | 3364 | } |
| 3365 | } |
Francois Pichet | 8f981d5 | 2011-05-25 10:19:49 +0000 | [diff] [blame] | 3366 | |
| 3367 | void Parser::ParseMicrosoftIfExistsClassDeclaration(DeclSpec::TST TagType, |
| 3368 | AccessSpecifier& CurAS) { |
Douglas Gregor | 43edb32 | 2011-10-24 22:31:10 +0000 | [diff] [blame] | 3369 | IfExistsCondition Result; |
Francois Pichet | 8f981d5 | 2011-05-25 10:19:49 +0000 | [diff] [blame] | 3370 | if (ParseMicrosoftIfExistsCondition(Result)) |
| 3371 | return; |
| 3372 | |
Douglas Gregor | 43edb32 | 2011-10-24 22:31:10 +0000 | [diff] [blame] | 3373 | BalancedDelimiterTracker Braces(*this, tok::l_brace); |
| 3374 | if (Braces.consumeOpen()) { |
Alp Toker | ec54327 | 2013-12-24 09:48:30 +0000 | [diff] [blame] | 3375 | Diag(Tok, diag::err_expected) << tok::l_brace; |
Francois Pichet | 8f981d5 | 2011-05-25 10:19:49 +0000 | [diff] [blame] | 3376 | return; |
| 3377 | } |
Francois Pichet | 8f981d5 | 2011-05-25 10:19:49 +0000 | [diff] [blame] | 3378 | |
Douglas Gregor | 43edb32 | 2011-10-24 22:31:10 +0000 | [diff] [blame] | 3379 | switch (Result.Behavior) { |
| 3380 | case IEB_Parse: |
| 3381 | // Parse the declarations below. |
| 3382 | break; |
| 3383 | |
| 3384 | case IEB_Dependent: |
| 3385 | Diag(Result.KeywordLoc, diag::warn_microsoft_dependent_exists) |
| 3386 | << Result.IsIfExists; |
| 3387 | // Fall through to skip. |
| 3388 | |
| 3389 | case IEB_Skip: |
| 3390 | Braces.skipToEnd(); |
Francois Pichet | 8f981d5 | 2011-05-25 10:19:49 +0000 | [diff] [blame] | 3391 | return; |
| 3392 | } |
| 3393 | |
Richard Smith | 34f3051 | 2013-11-23 04:06:09 +0000 | [diff] [blame] | 3394 | while (Tok.isNot(tok::r_brace) && !isEofOrEom()) { |
Francois Pichet | 8f981d5 | 2011-05-25 10:19:49 +0000 | [diff] [blame] | 3395 | // __if_exists, __if_not_exists can nest. |
| 3396 | if ((Tok.is(tok::kw___if_exists) || Tok.is(tok::kw___if_not_exists))) { |
| 3397 | ParseMicrosoftIfExistsClassDeclaration((DeclSpec::TST)TagType, CurAS); |
| 3398 | continue; |
| 3399 | } |
| 3400 | |
| 3401 | // Check for extraneous top-level semicolon. |
| 3402 | if (Tok.is(tok::semi)) { |
Richard Smith | 87f5dc5 | 2012-07-23 05:45:25 +0000 | [diff] [blame] | 3403 | ConsumeExtraSemi(InsideStruct, TagType); |
Francois Pichet | 8f981d5 | 2011-05-25 10:19:49 +0000 | [diff] [blame] | 3404 | continue; |
| 3405 | } |
| 3406 | |
| 3407 | AccessSpecifier AS = getAccessSpecifierIfPresent(); |
| 3408 | if (AS != AS_none) { |
| 3409 | // Current token is a C++ access specifier. |
| 3410 | CurAS = AS; |
| 3411 | SourceLocation ASLoc = Tok.getLocation(); |
| 3412 | ConsumeToken(); |
| 3413 | if (Tok.is(tok::colon)) |
| 3414 | Actions.ActOnAccessSpecifier(AS, ASLoc, Tok.getLocation()); |
| 3415 | else |
Alp Toker | 35d8703 | 2013-12-30 23:29:50 +0000 | [diff] [blame] | 3416 | Diag(Tok, diag::err_expected) << tok::colon; |
Francois Pichet | 8f981d5 | 2011-05-25 10:19:49 +0000 | [diff] [blame] | 3417 | ConsumeToken(); |
| 3418 | continue; |
| 3419 | } |
| 3420 | |
| 3421 | // Parse all the comma separated declarators. |
Erik Verbruggen | ca98f2a | 2011-10-13 09:41:32 +0000 | [diff] [blame] | 3422 | ParseCXXClassMemberDeclaration(CurAS, 0); |
Francois Pichet | 8f981d5 | 2011-05-25 10:19:49 +0000 | [diff] [blame] | 3423 | } |
Douglas Gregor | 43edb32 | 2011-10-24 22:31:10 +0000 | [diff] [blame] | 3424 | |
| 3425 | Braces.consumeClose(); |
Francois Pichet | 8f981d5 | 2011-05-25 10:19:49 +0000 | [diff] [blame] | 3426 | } |