Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,8 @@ Bug Fixes to Attribute Support
(#GH141504) and on types returned from indirect calls (#GH142453).
- Fixes some late parsed attributes, when applied to function definitions, not being parsed
in function try blocks, and some situations where parsing of the function body
is skipped, such as error recovery and code completion. (#GH153551)
is skipped, such as error recovery, code completion, and msvc-compatible delayed
template parsing. (#GH153551)
- Using ``[[gnu::cleanup(some_func)]]`` where some_func is annotated with
``[[gnu::error("some error")]]`` now correctly triggers an error. (#GH146520)
- Fix a crash when the function name is empty in the `swift_name` attribute. (#GH157075)
Expand Down
11 changes: 5 additions & 6 deletions clang/lib/Parse/Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1272,7 +1272,7 @@ Decl *Parser::ParseFunctionDefinition(ParsingDeclarator &D,
// tokens and store them for late parsing at the end of the translation unit.
if (getLangOpts().DelayedTemplateParsing && Tok.isNot(tok::equal) &&
TemplateInfo.Kind == ParsedTemplateKind::Template &&
Actions.canDelayFunctionBody(D)) {
LateParsedAttrs->empty() && Actions.canDelayFunctionBody(D)) {
MultiTemplateParamsArg TemplateParameterLists(*TemplateInfo.TemplateParams);

ParseScope BodyScope(this, Scope::FnScope | Scope::DeclScope |
Expand Down Expand Up @@ -1301,10 +1301,8 @@ Decl *Parser::ParseFunctionDefinition(ParsingDeclarator &D,
}
return DP;
}
else if (CurParsedObjCImpl &&
!TemplateInfo.TemplateParams &&
(Tok.is(tok::l_brace) || Tok.is(tok::kw_try) ||
Tok.is(tok::colon)) &&
if (CurParsedObjCImpl && !TemplateInfo.TemplateParams &&
(Tok.is(tok::l_brace) || Tok.is(tok::kw_try) || Tok.is(tok::colon)) &&
Actions.CurContext->isTranslationUnit()) {
ParseScope BodyScope(this, Scope::FnScope | Scope::DeclScope |
Scope::CompoundStmtScope);
Expand Down Expand Up @@ -1420,7 +1418,8 @@ Decl *Parser::ParseFunctionDefinition(ParsingDeclarator &D,

// Late attributes are parsed in the same scope as the function body.
if (LateParsedAttrs)
ParseLexedAttributeList(*LateParsedAttrs, Res, false, true);
ParseLexedAttributeList(*LateParsedAttrs, Res, /*EnterScope=*/false,
/*OnDefinition=*/true);

if (SkipFunctionBodies && (!Res || Actions.canSkipFunctionBody(Res)) &&
trySkippingFunctionBody()) {
Expand Down
13 changes: 11 additions & 2 deletions clang/test/Parser/DelayedTemplateParsing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ void undeclared()

}

template <class T> void foo5() {} //expected-note {{previous definition is here}}
template <class T> void foo5() {} //expected-note {{previous definition is here}}
template <class T> void foo5() {} // expected-error {{redefinition of 'foo5'}}




namespace PR11931 {
Expand Down Expand Up @@ -195,3 +195,12 @@ template <typename> struct PR38460_2 {
}
};
template struct PR38460_2<int>;

namespace LateParsedAttrs {
template <class>
void f(int a) __attribute__((__diagnose_if__(a > 0, "foo", "error"))) {}
// expected-note@-1 {{from 'diagnose_if' attribute on 'f<int>'}}
void g() {
f<int>(1); // expected-error {{foo}}
}
} // namespace LateParsedAttrs