summaryrefslogtreecommitdiffstats
path: root/clang/lib/Parse/ParseDecl.cpp
diff options
context:
space:
mode:
authorReid Kleckner <reid@kleckner.net>2014-12-15 23:16:32 +0000
committerReid Kleckner <reid@kleckner.net>2014-12-15 23:16:32 +0000
commitd61a3110106abaa9073d255472a1331473612fcd (patch)
treedd89f41124872f21656f875204bf6790a8c1852b /clang/lib/Parse/ParseDecl.cpp
parent42102b110eafdd73d70613d6f960452c5f82cea4 (diff)
downloadbcm5719-llvm-d61a3110106abaa9073d255472a1331473612fcd.tar.gz
bcm5719-llvm-d61a3110106abaa9073d255472a1331473612fcd.zip
Diagnose function template definitions inside functions
The parser can only be tricked into parsing a function template definition by inserting a typename keyword before the function template declaration. This used to make us crash, and now it's fixed. While here, remove an unneeded boolean parameter from ParseDeclGroup. This boolean always corresponded to non-typedef declarators at file scope. ParseDeclGroup already has precise diagnostics for the function definition typedef case, so we can let that through. Fixes PR21839. llvm-svn: 224287
Diffstat (limited to 'clang/lib/Parse/ParseDecl.cpp')
-rw-r--r--clang/lib/Parse/ParseDecl.cpp8
1 files changed, 5 insertions, 3 deletions
diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp
index 03e827e69c0..0b84f2fbbd5 100644
--- a/clang/lib/Parse/ParseDecl.cpp
+++ b/clang/lib/Parse/ParseDecl.cpp
@@ -1466,7 +1466,7 @@ Parser::ParseSimpleDeclaration(unsigned Context,
}
DS.takeAttributesFrom(Attrs);
- return ParseDeclGroup(DS, Context, /*FunctionDefs=*/ false, &DeclEnd, FRI);
+ return ParseDeclGroup(DS, Context, &DeclEnd, FRI);
}
/// Returns true if this might be the start of a declarator, or a common typo
@@ -1621,7 +1621,6 @@ void Parser::SkipMalformedDecl() {
/// result.
Parser::DeclGroupPtrTy Parser::ParseDeclGroup(ParsingDeclSpec &DS,
unsigned Context,
- bool AllowFunctionDefinitions,
SourceLocation *DeclEnd,
ForRangeInit *FRI) {
// Parse the first declarator.
@@ -1669,7 +1668,10 @@ Parser::DeclGroupPtrTy Parser::ParseDeclGroup(ParsingDeclSpec &DS,
// start of a function definition in GCC-extended K&R C.
!isDeclarationAfterDeclarator()) {
- if (AllowFunctionDefinitions) {
+ // Function definitions are only allowed at file scope and in C++ classes.
+ // The C++ inline method definition case is handled elsewhere, so we only
+ // need to handle the file scope definition case.
+ if (Context == Declarator::FileContext) {
if (isStartOfFunctionDefinition(D)) {
if (DS.getStorageClassSpec() == DeclSpec::SCS_typedef) {
Diag(Tok, diag::err_function_declared_typedef);
OpenPOWER on IntegriCloud