diff options
author | Anders Carlsson <andersca@mac.com> | 2009-06-24 17:47:40 +0000 |
---|---|---|
committer | Anders Carlsson <andersca@mac.com> | 2009-06-24 17:47:40 +0000 |
commit | 74948d070112d3baa1aa5857dbc8ac15b62f8cc8 (patch) | |
tree | 746acf1ff7fffffb53659541b02304eb2c330284 /clang/lib/Parse/ParseDeclCXX.cpp | |
parent | 4d9e93c4207a987bcf68698b55a8094021fe78fd (diff) | |
download | bcm5719-llvm-74948d070112d3baa1aa5857dbc8ac15b62f8cc8.tar.gz bcm5719-llvm-74948d070112d3baa1aa5857dbc8ac15b62f8cc8.zip |
Parse the C++0x decltype specifier.
llvm-svn: 74086
Diffstat (limited to 'clang/lib/Parse/ParseDeclCXX.cpp')
-rw-r--r-- | clang/lib/Parse/ParseDeclCXX.cpp | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp index 44f231a6678..188580de20a 100644 --- a/clang/lib/Parse/ParseDeclCXX.cpp +++ b/clang/lib/Parse/ParseDeclCXX.cpp @@ -355,6 +355,53 @@ Parser::DeclPtrTy Parser::ParseStaticAssertDeclaration(SourceLocation &DeclEnd){ move(AssertMessage)); } +/// ParseDecltypeSpecifier - Parse a C++0x decltype specifier. +/// +/// 'decltype' ( expression ) +/// +void Parser::ParseDecltypeSpecifier(DeclSpec &DS) { + assert(Tok.is(tok::kw_decltype) && "Not a decltype specifier"); + + SourceLocation StartLoc = ConsumeToken(); + SourceLocation LParenLoc = Tok.getLocation(); + + + if (ExpectAndConsume(tok::l_paren, diag::err_expected_lparen_after, + "decltype")) { + SkipUntil(tok::r_paren); + return; + } + + + // Parse the expression + + // C++0x [dcl.type.simple]p4: + // The operand of the decltype specifier is an unevaluated operand. + EnterExpressionEvaluationContext Unevaluated(Actions, + Action::Unevaluated); + OwningExprResult Result = ParseExpression(); + if (Result.isInvalid()) { + SkipUntil(tok::r_paren); + return; + } + + // Match the ')' + SourceLocation RParenLoc; + if (Tok.is(tok::r_paren)) + RParenLoc = ConsumeParen(); + else + MatchRHSPunctuation(tok::r_paren, LParenLoc); + + if (RParenLoc.isInvalid()) + return; + + const char *PrevSpec = 0; + // Check for duplicate type specifiers (e.g. "int decltype(a)"). + if (DS.SetTypeSpecType(DeclSpec::TST_decltype, StartLoc, PrevSpec, + Result.release())) + Diag(StartLoc, diag::err_invalid_decl_spec_combination) << PrevSpec; +} + /// ParseClassName - Parse a C++ class-name, which names a class. Note /// that we only check that the result names a type; semantic analysis /// will need to verify that the type names a class. The result is |