Skip to content

Conversation

mizvekov
Copy link
Contributor

@mizvekov mizvekov commented Oct 15, 2025

This simply ignores 'delayed template parsing' when functions have late parsed attributes, since these are not MSVC compatible anyway.

Besides ignoring the attribute, this would also cause a memory leak.

@mizvekov mizvekov self-assigned this Oct 15, 2025
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Oct 15, 2025
@llvmbot
Copy link
Member

llvmbot commented Oct 15, 2025

@llvm/pr-subscribers-clang

Author: Matheus Izvekov (mizvekov)

Changes

Besides ignoring the attribute, this would also cause a memory leak.


Full diff: https://github.com/llvm/llvm-project/pull/163483.diff

3 Files Affected:

  • (modified) clang/docs/ReleaseNotes.rst (+2-1)
  • (modified) clang/lib/Parse/Parser.cpp (+3)
  • (modified) clang/test/Parser/DelayedTemplateParsing.cpp (+11-2)
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index db2b0f6fd5027..e4a66fad29c83 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -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)
diff --git a/clang/lib/Parse/Parser.cpp b/clang/lib/Parse/Parser.cpp
index bbff627d46600..95e6d497221dd 100644
--- a/clang/lib/Parse/Parser.cpp
+++ b/clang/lib/Parse/Parser.cpp
@@ -1285,6 +1285,9 @@ Decl *Parser::ParseFunctionDefinition(ParsingDeclarator &D,
     D.complete(DP);
     D.getMutableDeclSpec().abort();
 
+    if (LateParsedAttrs)
+      ParseLexedAttributeList(*LateParsedAttrs, DP, /*EnterScope=*/false, /*OnDefinition=*/true);
+
     if (SkipFunctionBodies && (!DP || Actions.canSkipFunctionBody(DP)) &&
         trySkippingFunctionBody()) {
       BodyScope.Exit();
diff --git a/clang/test/Parser/DelayedTemplateParsing.cpp b/clang/test/Parser/DelayedTemplateParsing.cpp
index bcd286ae04492..ba0d71ba2f0a0 100644
--- a/clang/test/Parser/DelayedTemplateParsing.cpp
+++ b/clang/test/Parser/DelayedTemplateParsing.cpp
@@ -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 {
@@ -195,3 +195,12 @@ template <typename> struct PR38460_2 {
   }
 };
 template struct PR38460_2<int>;
+
+namespace LateParsedAttrs {
+  template <class>
+  void f() __attribute__((__diagnose_if__(true, "foo", "error"))) {}
+  // expected-note@-1 {{from 'diagnose_if' attribute on 'f<int>'}}
+  void g() {
+    f<int>(); // expected-error {{foo}}
+  }
+} // namespace LateParsedAttrs

Copy link

github-actions bot commented Oct 15, 2025

✅ With the latest revision this PR passed the C/C++ code formatter.

@mizvekov mizvekov force-pushed the users/mizvekov/fix-late-parsed-attrs-delayed-template branch from a4e0439 to 2372be2 Compare October 15, 2025 01:17
@mizvekov mizvekov marked this pull request as draft October 15, 2025 01:41
…arsing

Besides ignoring the attribute, this would also cause a memory
leak.
@mizvekov mizvekov force-pushed the users/mizvekov/fix-late-parsed-attrs-delayed-template branch from 2372be2 to 43ac945 Compare October 15, 2025 02:07
@mizvekov mizvekov marked this pull request as ready for review October 15, 2025 02:07
@mizvekov mizvekov requested a review from AaronBallman October 15, 2025 13:06
Copy link
Collaborator

@AaronBallman AaronBallman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@mizvekov mizvekov merged commit acf4e17 into main Oct 15, 2025
13 checks passed
@mizvekov mizvekov deleted the users/mizvekov/fix-late-parsed-attrs-delayed-template branch October 15, 2025 13:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants