Skip to content

Conversation

@yronglin
Copy link
Contributor

Use fold expression to refine the implementation of dependency_directives_scan::Token::isOneOf.

…ives_scan::Token::isOneOf

Signed-off-by: yronglin <yronglin777@gmail.com>
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Jul 24, 2025
@llvmbot
Copy link
Member

llvmbot commented Jul 24, 2025

@llvm/pr-subscribers-clang

Author: None (yronglin)

Changes

Use fold expression to refine the implementation of dependency_directives_scan::Token::isOneOf.


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

1 Files Affected:

  • (modified) clang/include/clang/Lex/DependencyDirectivesScanner.h (+4-5)
diff --git a/clang/include/clang/Lex/DependencyDirectivesScanner.h b/clang/include/clang/Lex/DependencyDirectivesScanner.h
index acdc9e2bf9aa4..f9fec3998ca53 100644
--- a/clang/include/clang/Lex/DependencyDirectivesScanner.h
+++ b/clang/include/clang/Lex/DependencyDirectivesScanner.h
@@ -47,11 +47,10 @@ struct Token {
 
   bool is(tok::TokenKind K) const { return Kind == K; }
   bool isNot(tok::TokenKind K) const { return Kind != K; }
-  bool isOneOf(tok::TokenKind K1, tok::TokenKind K2) const {
-    return is(K1) || is(K2);
-  }
-  template <typename... Ts> bool isOneOf(tok::TokenKind K1, Ts... Ks) const {
-    return is(K1) || isOneOf(Ks...);
+  template <typename... Ts> bool isOneOf(Ts... Ks) const {
+    static_assert(sizeof...(Ts) > 0,
+                  "requires at least one tok::TokenKind specified");
+    return (is(Ks) || ...);
   }
 };
 

@yronglin yronglin requested review from AaronBallman, Bigcheese, JDevlieghere and erichkeane and removed request for JDevlieghere July 24, 2025 14:50
Copy link
Collaborator

@erichkeane erichkeane left a comment

Choose a reason for hiding this comment

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

This seems fine to me, though SEEING this dependency-scanner just brings up more questions than anything :)

@yronglin
Copy link
Contributor Author

Thanks for the review!

@yronglin yronglin merged commit d96579b into llvm:main Jul 24, 2025
12 checks passed
mahesh-attarde pushed a commit to mahesh-attarde/llvm-project that referenced this pull request Jul 28, 2025
…ives_scan::Token::isOneOf (llvm#150433)

Use fold expression to refine the implementation of
`dependency_directives_scan::Token::isOneOf`.

Signed-off-by: yronglin <yronglin777@gmail.com>
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.

3 participants