Skip to content

Conversation

kazutakahirata
Copy link
Contributor

has_FlowTraits has two implementations:

  • "class has_FlowTraits" says false on non-class types.
  • "struct has_FlowTraits" checks for a "flow" member on class types.

This patch eliminates the former because std::is_class is redundant if
we are checking to see if &U::flow is well formed. The comment block
being removed in this patch has been around since 2012. I'd assume
that host compilers have improved since then. Note that we are now
using is_detected, which wasn't the case back in 2012.

has_FlowTraits has two implementations:

- "class has_FlowTraits" says false on non-class types.
- "struct has_FlowTraits" checks for a "flow" member on class types.

This patch eliminates the former because std::is_class is redundant if
we are checking to see if &U::flow is well formed.  The comment block
being removed in this patch has been around since 2012.  I'd assume
that host compilers have improved since then.  Note that we are now
using is_detected, which wasn't the case back in 2012.
@llvmbot
Copy link
Member

llvmbot commented Sep 17, 2025

@llvm/pr-subscribers-llvm-support

Author: Kazu Hirata (kazutakahirata)

Changes

has_FlowTraits has two implementations:

  • "class has_FlowTraits" says false on non-class types.
  • "struct has_FlowTraits" checks for a "flow" member on class types.

This patch eliminates the former because std::is_class is redundant if
we are checking to see if &U::flow is well formed. The comment block
being removed in this patch has been around since 2012. I'd assume
that host compilers have improved since then. Note that we are now
using is_detected, which wasn't the case back in 2012.


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

1 Files Affected:

  • (modified) llvm/include/llvm/Support/YAMLTraits.h (+2-9)
diff --git a/llvm/include/llvm/Support/YAMLTraits.h b/llvm/include/llvm/Support/YAMLTraits.h
index bbc12a2fcbe7a..81e3e2e41e86d 100644
--- a/llvm/include/llvm/Support/YAMLTraits.h
+++ b/llvm/include/llvm/Support/YAMLTraits.h
@@ -442,15 +442,8 @@ template <class T> struct has_CustomMappingTraits {
       is_detected<check, CustomMappingTraits<T>>::value;
 };
 
-// has_FlowTraits<int> will cause an error with some compilers because
-// it subclasses int.  Using this wrapper only instantiates the
-// real has_FlowTraits only if the template type is a class.
-template <typename T, bool Enabled = std::is_class_v<T>> class has_FlowTraits {
-public:
-  static constexpr bool value = false;
-};
-
-template <class T> struct has_FlowTraits<T, true> {
+// Test if flow is defined on type T.
+template <typename T> struct has_FlowTraits {
   template <class U> using check = decltype(&U::flow);
 
   static constexpr bool value = is_detected<check, T>::value;

@kazutakahirata kazutakahirata merged commit 901eaee into llvm:main Sep 17, 2025
11 checks passed
@kazutakahirata kazutakahirata deleted the cleanup_20250916_Support_YAML_has_FlowTraits branch September 17, 2025 14:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants