From 84407ba82a10235962901ce269b7b3276d17f01d Mon Sep 17 00:00:00 2001 From: Sebastian Redl Date: Wed, 14 Mar 2012 15:54:00 +0000 Subject: [PATCH] Parse brace initializers as default arguments. PR12236. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@152721 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Parse/ParseCXXInlineMethods.cpp | 6 +++++- lib/Parse/ParseDecl.cpp | 7 ++++++- test/SemaCXX/cxx0x-initializer-scalars.cpp | 7 +++++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/lib/Parse/ParseCXXInlineMethods.cpp b/lib/Parse/ParseCXXInlineMethods.cpp index 7ee74ecc76..8a6e1ce33f 100644 --- a/lib/Parse/ParseCXXInlineMethods.cpp +++ b/lib/Parse/ParseCXXInlineMethods.cpp @@ -319,7 +319,11 @@ void Parser::ParseLexedMethodDeclaration(LateParsedMethodDeclaration &LM) { Sema::PotentiallyEvaluatedIfUsed, LM.DefaultArgs[I].Param); - ExprResult DefArgResult(ParseAssignmentExpression()); + ExprResult DefArgResult; + if (Tok.is(tok::l_brace)) + DefArgResult = ParseBraceInitializer(); + else + DefArgResult = ParseAssignmentExpression(); if (DefArgResult.isInvalid()) Actions.ActOnParamDefaultArgumentError(LM.DefaultArgs[I].Param); else { diff --git a/lib/Parse/ParseDecl.cpp b/lib/Parse/ParseDecl.cpp index 31a898cf5a..3ff9da035f 100644 --- a/lib/Parse/ParseDecl.cpp +++ b/lib/Parse/ParseDecl.cpp @@ -4169,6 +4169,7 @@ void Parser::ParseFunctionDeclaratorIdentifierList( /// parameter-declaration: [C99 6.7.5] /// declaration-specifiers declarator /// [C++] declaration-specifiers declarator '=' assignment-expression +/// [C++11] initializer-clause /// [GNU] declaration-specifiers declarator attributes /// declaration-specifiers abstract-declarator[opt] /// [C++] declaration-specifiers abstract-declarator[opt] @@ -4280,7 +4281,11 @@ void Parser::ParseParameterDeclarationClause( Sema::PotentiallyEvaluatedIfUsed, Param); - ExprResult DefArgResult(ParseAssignmentExpression()); + ExprResult DefArgResult; + if (Tok.is(tok::l_brace)) + DefArgResult = ParseBraceInitializer(); + else + DefArgResult = ParseAssignmentExpression(); if (DefArgResult.isInvalid()) { Actions.ActOnParamDefaultArgumentError(Param); SkipUntil(tok::comma, tok::r_paren, true, true); diff --git a/test/SemaCXX/cxx0x-initializer-scalars.cpp b/test/SemaCXX/cxx0x-initializer-scalars.cpp index 91fbaad8b1..627855e96e 100644 --- a/test/SemaCXX/cxx0x-initializer-scalars.cpp +++ b/test/SemaCXX/cxx0x-initializer-scalars.cpp @@ -96,6 +96,13 @@ namespace integral { (void) int({0}); // expected-error {{functional-style cast}} new int({0}); // expected-error {{cannot initialize}} } + + void default_argument(int i = {}) { + } + struct DefaultArgument { + void default_argument(int i = {}) { + } + }; } namespace PR12118 { -- 2.40.0