Skip to content

Conversation

philnik777
Copy link
Contributor

The SFINAE isn't required, since the primary tuple class already does the SFINAE checks. This removes a bit of code that was only used for these constraints.

This also moves the tuple_element specialization for tuple to __fwd/tuple.h to avoid a dependency on __tuple/sfinae_helpers.h (which should be moved in a follow-up).

@philnik777 philnik777 force-pushed the simplify_tuple branch 2 times, most recently from b749b78 to d8b4b28 Compare August 2, 2025 06:19
@philnik777 philnik777 marked this pull request as ready for review August 5, 2025 07:48
@philnik777 philnik777 requested a review from a team as a code owner August 5, 2025 07:48
@philnik777 philnik777 merged commit 091c33b into llvm:main Aug 5, 2025
76 of 77 checks passed
@philnik777 philnik777 deleted the simplify_tuple branch August 5, 2025 07:48
@llvmbot llvmbot added the libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. label Aug 5, 2025
@llvmbot
Copy link
Member

llvmbot commented Aug 5, 2025

@llvm/pr-subscribers-libcxx

Author: Nikolas Klauser (philnik777)

Changes

The SFINAE isn't required, since the primary tuple class already does the SFINAE checks. This removes a bit of code that was only used for these constraints.

This also moves the tuple_element specialization for tuple to __fwd/tuple.h to avoid a dependency on __tuple/sfinae_helpers.h (which should be moved in a follow-up).


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

7 Files Affected:

  • (modified) libcxx/include/__fwd/tuple.h (+5)
  • (modified) libcxx/include/__memory/uses_allocator_construction.h (+1)
  • (modified) libcxx/include/__memory_resource/polymorphic_allocator.h (+1)
  • (modified) libcxx/include/__tuple/sfinae_helpers.h (-43)
  • (modified) libcxx/include/module.modulemap.in (+4-1)
  • (modified) libcxx/include/tuple (+2-5)
  • (modified) libcxx/test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple_element.verify.cpp (+1-1)
diff --git a/libcxx/include/__fwd/tuple.h b/libcxx/include/__fwd/tuple.h
index fb922b29f3d3f..39ed94d9806e5 100644
--- a/libcxx/include/__fwd/tuple.h
+++ b/libcxx/include/__fwd/tuple.h
@@ -26,6 +26,11 @@ struct tuple_element;
 template <class...>
 class tuple;
 
+template <size_t _Ip, class... _Tp>
+struct tuple_element<_Ip, tuple<_Tp...> > {
+  using type _LIBCPP_NODEBUG = __type_pack_element<_Ip, _Tp...>;
+};
+
 template <class>
 struct tuple_size;
 
diff --git a/libcxx/include/__memory/uses_allocator_construction.h b/libcxx/include/__memory/uses_allocator_construction.h
index 49ddf99d9cc95..6733f5cf6fc35 100644
--- a/libcxx/include/__memory/uses_allocator_construction.h
+++ b/libcxx/include/__memory/uses_allocator_construction.h
@@ -17,6 +17,7 @@
 #include <__type_traits/remove_cv.h>
 #include <__utility/declval.h>
 #include <__utility/pair.h>
+#include <__utility/piecewise_construct.h>
 #include <tuple>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
diff --git a/libcxx/include/__memory_resource/polymorphic_allocator.h b/libcxx/include/__memory_resource/polymorphic_allocator.h
index 6e7a9afc25deb..9a351199b5b16 100644
--- a/libcxx/include/__memory_resource/polymorphic_allocator.h
+++ b/libcxx/include/__memory_resource/polymorphic_allocator.h
@@ -18,6 +18,7 @@
 #include <__new/exceptions.h>
 #include <__new/placement_new_delete.h>
 #include <__utility/exception_guard.h>
+#include <__utility/piecewise_construct.h>
 #include <limits>
 #include <tuple>
 
diff --git a/libcxx/include/__tuple/sfinae_helpers.h b/libcxx/include/__tuple/sfinae_helpers.h
index 9fe5e84e2f3ca..f314381d0a48d 100644
--- a/libcxx/include/__tuple/sfinae_helpers.h
+++ b/libcxx/include/__tuple/sfinae_helpers.h
@@ -10,20 +10,6 @@
 #define _LIBCPP___TUPLE_SFINAE_HELPERS_H
 
 #include <__config>
-#include <__cstddef/size_t.h>
-#include <__fwd/tuple.h>
-#include <__tuple/make_tuple_types.h>
-#include <__tuple/tuple_element.h>
-#include <__tuple/tuple_like_ext.h>
-#include <__tuple/tuple_size.h>
-#include <__tuple/tuple_types.h>
-#include <__type_traits/conjunction.h>
-#include <__type_traits/enable_if.h>
-#include <__type_traits/integral_constant.h>
-#include <__type_traits/is_constructible.h>
-#include <__type_traits/is_same.h>
-#include <__type_traits/remove_cvref.h>
-#include <__type_traits/remove_reference.h>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #  pragma GCC system_header
@@ -33,35 +19,6 @@ _LIBCPP_BEGIN_NAMESPACE_STD
 
 #ifndef _LIBCPP_CXX03_LANG
 
-struct __tuple_sfinae_base {
-  template <template <class, class...> class _Trait, class... _LArgs, class... _RArgs>
-  static auto __do_test(__tuple_types<_LArgs...>,
-                        __tuple_types<_RArgs...>) -> __all<__enable_if_t<_Trait<_LArgs, _RArgs>::value, bool>{true}...>;
-  template <template <class...> class>
-  static auto __do_test(...) -> false_type;
-
-  template <class _FromArgs, class _ToArgs>
-  using __constructible _LIBCPP_NODEBUG = decltype(__do_test<is_constructible>(_ToArgs{}, _FromArgs{}));
-};
-
-// __tuple_constructible
-
-template <class _Tp,
-          class _Up,
-          bool = __tuple_like_ext<__libcpp_remove_reference_t<_Tp> >::value,
-          bool = __tuple_like_ext<_Up>::value>
-struct __tuple_constructible : public false_type {};
-
-template <class _Tp, class _Up>
-struct __tuple_constructible<_Tp, _Up, true, true>
-    : public __tuple_sfinae_base::__constructible< typename __make_tuple_types<_Tp>::type,
-                                                   typename __make_tuple_types<_Up>::type > {};
-
-template <size_t _Ip, class... _Tp>
-struct tuple_element<_Ip, tuple<_Tp...> > {
-  using type _LIBCPP_NODEBUG = typename tuple_element<_Ip, __tuple_types<_Tp...> >::type;
-};
-
 struct _LIBCPP_EXPORTED_FROM_ABI __check_tuple_constructor_fail {
   static _LIBCPP_HIDE_FROM_ABI constexpr bool __enable_explicit_default() { return false; }
   static _LIBCPP_HIDE_FROM_ABI constexpr bool __enable_implicit_default() { return false; }
diff --git a/libcxx/include/module.modulemap.in b/libcxx/include/module.modulemap.in
index 5857a83b5fe14..b07a153eacfae 100644
--- a/libcxx/include/module.modulemap.in
+++ b/libcxx/include/module.modulemap.in
@@ -2168,7 +2168,10 @@ module std [system] {
     module is_valid_range             { header "__utility/is_valid_range.h" }
     module move                       { header "__utility/move.h" }
     module no_destroy                 { header "__utility/no_destroy.h" }
-    module pair                       { header "__utility/pair.h" }
+    module pair                       {
+      header "__utility/pair.h"
+      export std.utility.piecewise_construct
+    }
     module piecewise_construct        { header "__utility/piecewise_construct.h" }
     module priority_tag               { header "__utility/priority_tag.h" }
     module private_constructor_tag    { header "__utility/private_constructor_tag.h" }
diff --git a/libcxx/include/tuple b/libcxx/include/tuple
index 1946034aeecbe..b854d615f7192 100644
--- a/libcxx/include/tuple
+++ b/libcxx/include/tuple
@@ -227,7 +227,6 @@ template <class... Types>
 #  include <__tuple/find_index.h>
 #  include <__tuple/ignore.h>
 #  include <__tuple/make_tuple_types.h>
-#  include <__tuple/sfinae_helpers.h>
 #  include <__tuple/tuple_element.h>
 #  include <__tuple/tuple_like_ext.h>
 #  include <__tuple/tuple_size.h>
@@ -240,7 +239,6 @@ template <class... Types>
 #  include <__type_traits/disjunction.h>
 #  include <__type_traits/enable_if.h>
 #  include <__type_traits/invoke.h>
-#  include <__type_traits/is_arithmetic.h>
 #  include <__type_traits/is_assignable.h>
 #  include <__type_traits/is_constructible.h>
 #  include <__type_traits/is_convertible.h>
@@ -267,7 +265,6 @@ template <class... Types>
 #  include <__utility/forward.h>
 #  include <__utility/integer_sequence.h>
 #  include <__utility/move.h>
-#  include <__utility/piecewise_construct.h>
 #  include <__utility/swap.h>
 #  include <version>
 
@@ -471,7 +468,7 @@ struct _LIBCPP_DECLSPEC_EMPTY_BASES
       allocator_arg_t, const _Alloc& __alloc, __forward_args, _Args&&... __args)
       : __tuple_leaf<_Indx, _Tp>(__uses_alloc_ctor<_Tp, _Alloc, _Args>(), __alloc, std::forward<_Args>(__args))... {}
 
-  template <class _Tuple, __enable_if_t<__tuple_constructible<_Tuple, tuple<_Tp...> >::value, int> = 0>
+  template <class _Tuple>
   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 __tuple_impl(_Tuple&& __t) noexcept(
       (__all<is_nothrow_constructible<
            _Tp,
@@ -480,7 +477,7 @@ struct _LIBCPP_DECLSPEC_EMPTY_BASES
             std::forward<typename tuple_element<_Indx, typename __make_tuple_types<_Tuple>::type>::type>(
                 std::get<_Indx>(__t)))... {}
 
-  template <class _Alloc, class _Tuple, __enable_if_t<__tuple_constructible<_Tuple, tuple<_Tp...> >::value, int> = 0>
+  template <class _Alloc, class _Tuple>
   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 __tuple_impl(allocator_arg_t, const _Alloc& __a, _Tuple&& __t)
       : __tuple_leaf<_Indx, _Tp>(
             __uses_alloc_ctor<_Tp,
diff --git a/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple_element.verify.cpp b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple_element.verify.cpp
index 2edeeefde0b8f..8a8b049275d7f 100644
--- a/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple_element.verify.cpp
+++ b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple_element.verify.cpp
@@ -23,4 +23,4 @@
 using T =  std::tuple<int, long, void*>;
 using E1 = typename std::tuple_element<1, T &>::type; // expected-error{{undefined template}}
 using E2 = typename std::tuple_element<3, T>::type;
-using E3 = typename std::tuple_element<4, T const>::type; // expected-error@*:* 2 {{static assertion failed}}
+using E3 = typename std::tuple_element<4, T const>::type; // expected-error@*:* 2 {{out of bounds index}}

@alexfh
Copy link
Contributor

alexfh commented Aug 20, 2025

Hi @philnik777,
this is breaking some of our code. A standalone reproducer: https://gcc.godbolt.org/z/95jYc7bq7

#include <optional>
#include <tuple>
#include <variant>

struct S {
    S(const S&) = delete;
    S& operator=(const S&) = delete;
    S(S&&) = default;
    S& operator=(S&&) = default;
};

std::optional<std::tuple<const std::variant<S>>> x;

The code above started generating an error and causing a Clang crash:

In file included from <source>:1:
In file included from /opt/compiler-explorer/clang-assertions-trunk-20250820/bin/../include/c++/v1/optional:1378:
In file included from /opt/compiler-explorer/clang-assertions-trunk-20250820/bin/../include/c++/v1/iterator:755:
In file included from /opt/compiler-explorer/clang-assertions-trunk-20250820/bin/../include/c++/v1/variant:1655:
In file included from /opt/compiler-explorer/clang-assertions-trunk-20250820/bin/../include/c++/v1/tuple:235:
/opt/compiler-explorer/clang-assertions-trunk-20250820/bin/../include/c++/v1/__tuple/make_tuple_types.h:59:61: error: implicit instantiation of undefined template 'std::tuple_size<std::__tuple_impl<std::__integer_sequence<unsigned long, 0>, const std::variant<S>>>'
   59 |       __make_tuple_types_flat<_RawTp, __make_index_sequence<tuple_size<__libcpp_remove_reference_t<_Tp>>::value>>;
      |                                                             ^
/opt/compiler-explorer/clang-assertions-trunk-20250820/bin/../include/c++/v1/tuple:544:51: note: in instantiation of template class 'std::__make_tuple_types<std::__tuple_impl<std::__integer_sequence<unsigned long, 0>, const std::variant<S>>>' requested here
  544 |            typename tuple_element<_Indx, typename __make_tuple_types<_Tuple>::type>::type>::value...>::value))
      |                                                   ^
/opt/compiler-explorer/clang-assertions-trunk-20250820/bin/../include/c++/v1/tuple:589:10: note: in instantiation of exception specification for '__tuple_impl<std::__tuple_impl<std::__integer_sequence<unsigned long, 0>, const std::variant<S>>>' requested here
  589 |   _BaseT __base_;
      |          ^
/opt/compiler-explorer/clang-assertions-trunk-20250820/bin/../include/c++/v1/__type_traits/is_trivially_constructible.h:44:31: note: in evaluation of exception specification for 'std::tuple<const std::variant<S>>::tuple' needed here
   44 |     : integral_constant<bool, __is_trivially_constructible(_Tp, __add_rvalue_reference_t<_Tp>)> {};
      |                               ^
/opt/compiler-explorer/clang-assertions-trunk-20250820/bin/../include/c++/v1/optional:554:59: note: in instantiation of template class 'std::is_trivially_move_constructible<std::tuple<const std::variant<S>>>' requested here
  554 |           bool = is_trivially_destructible<_Tp>::value && is_trivially_move_constructible<_Tp>::value &&
      |                                                           ^
/opt/compiler-explorer/clang-assertions-trunk-20250820/bin/../include/c++/v1/optional:612:15: note: in instantiation of default argument for '__optional_move_assign_base<std::tuple<const std::variant<S>>>' required here
  612 |     : private __optional_move_assign_base<_Tp>,
      |               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<source>:12:50: note: in instantiation of template class 'std::optional<std::tuple<const std::variant<S>>>' requested here
   12 | std::optional<std::tuple<const std::variant<S>>> x;
      |                                                  ^
/opt/compiler-explorer/clang-assertions-trunk-20250820/bin/../include/c++/v1/__tuple/tuple_size.h:28:8: note: template is declared here
   28 | struct tuple_size;
      |        ^
should not generate implicit declarations for dependent cases
UNREACHABLE executed at /root/llvm-project/llvm/tools/clang/lib/Sema/SemaDeclCXX.cpp:237!
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0.	Program arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/clang++ -g -o /app/output.s -mllvm --x86-asm-syntax=intel -fno-verbose-asm -S --gcc-toolchain=/opt/compiler-explorer/gcc-snapshot -fcolor-diagnostics -fno-crash-diagnostics -stdlib=libc++ <source>
1.	<source>:12:51: current parser token ';'
2.	/opt/compiler-explorer/clang-assertions-trunk-20250820/bin/../include/c++/v1/optional:611:36: instantiating class definition 'std::optional<std::tuple<const std::variant<S>>>'
3.	/opt/compiler-explorer/clang-assertions-trunk-20250820/bin/../include/c++/v1/__type_traits/is_trivially_constructible.h:43:35: instantiating class definition 'std::is_trivially_move_constructible<std::tuple<const std::variant<S>>>'
 #0 0x0000000004038188 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4038188)
 #1 0x00000000040355b4 llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x40355b4)
 #2 0x0000000003f79e28 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
 #3 0x000076dbcd442520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #4 0x000076dbcd4969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
 #5 0x000076dbcd442476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
 #6 0x000076dbcd4287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
 #7 0x0000000003f854fa (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3f854fa)
 #8 0x0000000006b2ae84 clang::Sema::ImplicitExceptionSpecification::CalledDecl(clang::SourceLocation, clang::CXXMethodDecl const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6b2ae84)
 #9 0x0000000006b2b0c3 (anonymous namespace)::SpecialMemberExceptionSpecInfo::visitClassSubobject(clang::CXXRecordDecl*, llvm::PointerUnion<clang::CXXBaseSpecifier*, clang::FieldDecl*>, unsigned int) SemaDeclCXX.cpp:0:0
#10 0x0000000006b8459e ComputeDefaultedSpecialMemberExceptionSpec(clang::Sema&, clang::SourceLocation, clang::CXXMethodDecl*, clang::CXXSpecialMemberKind, clang::Sema::InheritedConstructorInfo*) SemaDeclCXX.cpp:0:0
#11 0x0000000006b84c0d clang::Sema::EvaluateImplicitExceptionSpec(clang::SourceLocation, clang::FunctionDecl*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6b84c0d)
#12 0x0000000006bb7a8d clang::Sema::ResolveExceptionSpec(clang::SourceLocation, clang::FunctionProtoType const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6bb7a8d)
#13 0x0000000006c309af clang::Sema::MarkFunctionReferenced(clang::SourceLocation, clang::FunctionDecl*, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6c309af)
#14 0x0000000006b290f7 clang::Sema::BuildCXXConstructExpr(clang::SourceLocation, clang::QualType, clang::CXXConstructorDecl*, bool, llvm::MutableArrayRef<clang::Expr*>, bool, bool, bool, bool, clang::CXXConstructionKind, clang::SourceRange) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6b290f7)
#15 0x0000000006b8cf74 clang::Sema::BuildCXXConstructExpr(clang::SourceLocation, clang::QualType, clang::NamedDecl*, clang::CXXConstructorDecl*, llvm::MutableArrayRef<clang::Expr*>, bool, bool, bool, bool, clang::CXXConstructionKind, clang::SourceRange) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6b8cf74)
#16 0x0000000006d802e9 PerformConstructorInitialization(clang::Sema&, clang::InitializedEntity const&, clang::InitializationKind const&, llvm::MutableArrayRef<clang::Expr*>, clang::InitializationSequence::Step const&, bool&, bool, bool, clang::SourceLocation, clang::SourceLocation) SemaInit.cpp:0:0
#17 0x0000000006d8fdc2 clang::InitializationSequence::Perform(clang::Sema&, clang::InitializedEntity const&, clang::InitializationKind const&, llvm::MutableArrayRef<clang::Expr*>, clang::QualType*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6d8fdc2)
#18 0x000000000733a492 EvaluateBooleanTypeTrait(clang::Sema&, clang::TypeTrait, clang::SourceLocation, llvm::ArrayRef<clang::TypeSourceInfo*>, clang::SourceLocation, bool) SemaTypeTraits.cpp:0:0
#19 0x000000000733ab3e clang::Sema::BuildTypeTrait(clang::TypeTrait, clang::SourceLocation, llvm::ArrayRef<clang::TypeSourceInfo*>, clang::SourceLocation) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x733ab3e)
#20 0x0000000007264bab clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformTypeTraitExpr(clang::TypeTraitExpr*) SemaTemplateInstantiate.cpp:0:0
#21 0x000000000722b51b clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformExpr(clang::Expr*) SemaTemplateInstantiate.cpp:0:0
#22 0x000000000724351b clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformTemplateArgument(clang::TemplateArgumentLoc const&, clang::TemplateArgumentLoc&, bool) SemaTemplateInstantiate.cpp:0:0
#23 0x0000000007243d08 (anonymous namespace)::TemplateInstantiator::TransformTemplateArgument(clang::TemplateArgumentLoc const&, clang::TemplateArgumentLoc&, bool) SemaTemplateInstantiate.cpp:0:0
#24 0x000000000725f6d8 clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformTemplateSpecializationType(clang::TypeLocBuilder&, clang::TemplateSpecializationTypeLoc) SemaTemplateInstantiate.cpp:0:0
#25 0x0000000007236125 clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformType(clang::TypeLocBuilder&, clang::TypeLoc) SemaTemplateInstantiate.cpp:0:0
#26 0x000000000723aa1a clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformType(clang::TypeSourceInfo*) SemaTemplateInstantiate.cpp:0:0
#27 0x00000000072404ae clang::Sema::SubstType(clang::TypeSourceInfo*, clang::MultiLevelTemplateArgumentList const&, clang::SourceLocation, clang::DeclarationName, bool) (.constprop.0) SemaTemplateInstantiate.cpp:0:0
#28 0x00000000072409e5 clang::Sema::SubstBaseSpecifiers(clang::CXXRecordDecl*, clang::CXXRecordDecl*, clang::MultiLevelTemplateArgumentList const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x72409e5)
#29 0x0000000007241407 clang::Sema::InstantiateClass(clang::SourceLocation, clang::CXXRecordDecl*, clang::CXXRecordDecl*, clang::MultiLevelTemplateArgumentList const&, clang::TemplateSpecializationKind, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x7241407)
#30 0x00000000072795b8 clang::Sema::InstantiateClassTemplateSpecialization(clang::SourceLocation, clang::ClassTemplateSpecializationDecl*, clang::TemplateSpecializationKind, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x72795b8)
#31 0x00000000072f994e void llvm::function_ref<void ()>::callback_fn<clang::Sema::RequireCompleteTypeImpl(clang::SourceLocation, clang::QualType, clang::Sema::CompleteTypeKind, clang::Sema::TypeDiagnoser*)::'lambda'()>(long) SemaType.cpp:0:0
#32 0x0000000007fd9ca1 clang::StackExhaustionHandler::runWithSufficientStackSpace(clang::SourceLocation, llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x7fd9ca1)
#33 0x00000000073050c3 clang::Sema::RequireCompleteTypeImpl(clang::SourceLocation, clang::QualType, clang::Sema::CompleteTypeKind, clang::Sema::TypeDiagnoser*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x73050c3)
#34 0x000000000730555f clang::Sema::RequireCompleteType(clang::SourceLocation, clang::QualType, clang::Sema::CompleteTypeKind, clang::Sema::TypeDiagnoser&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x730555f)
#35 0x0000000006913443 clang::Sema::RequireCompleteDeclContext(clang::CXXScopeSpec&, clang::DeclContext*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6913443)
#36 0x0000000006dd7fa4 clang::Sema::LookupParsedName(clang::LookupResult&, clang::Scope*, clang::CXXScopeSpec*, clang::QualType, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6dd7fa4)
#37 0x0000000006c28160 clang::Sema::BuildQualifiedDeclarationNameExpr(clang::CXXScopeSpec&, clang::DeclarationNameInfo const&, bool, clang::TypeSourceInfo**) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6c28160)
#38 0x00000000072474d4 clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformDependentScopeDeclRefExpr(clang::DependentScopeDeclRefExpr*, bool, clang::TypeSourceInfo**) SemaTemplateInstantiate.cpp:0:0
#39 0x000000000722b21d clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformExpr(clang::Expr*) SemaTemplateInstantiate.cpp:0:0
#40 0x0000000007258ca5 clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformInitializer(clang::Expr*, bool) (.part.0) SemaTemplateInstantiate.cpp:0:0
#41 0x00000000072592d0 clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformBinaryOperator(clang::BinaryOperator*) SemaTemplateInstantiate.cpp:0:0
#42 0x000000000722aeca clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformExpr(clang::Expr*) SemaTemplateInstantiate.cpp:0:0
#43 0x0000000007259288 clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformBinaryOperator(clang::BinaryOperator*) SemaTemplateInstantiate.cpp:0:0
#44 0x000000000722aeca clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformExpr(clang::Expr*) SemaTemplateInstantiate.cpp:0:0
#45 0x000000000724351b clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformTemplateArgument(clang::TemplateArgumentLoc const&, clang::TemplateArgumentLoc&, bool) SemaTemplateInstantiate.cpp:0:0
#46 0x0000000007262ae2 clang::Sema::SubstTemplateArgument(clang::TemplateArgumentLoc const&, clang::MultiLevelTemplateArgumentList const&, clang::TemplateArgumentLoc&, clang::SourceLocation, clang::DeclarationName const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x7262ae2)
#47 0x00000000070adb74 clang::Sema::SubstDefaultTemplateArgumentIfAvailable(clang::TemplateDecl*, clang::SourceLocation, clang::SourceLocation, clang::SourceLocation, clang::Decl*, llvm::ArrayRef<clang::TemplateArgument>, llvm::ArrayRef<clang::TemplateArgument>, bool&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x70adb74)
#48 0x00000000070ce89d clang::Sema::CheckTemplateArgumentList(clang::TemplateDecl*, clang::SourceLocation, clang::TemplateArgumentListInfo&, clang::DefaultArguments const&, bool, clang::Sema::CheckTemplateArgumentInfo&, bool, bool*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x70ce89d)
#49 0x00000000070d8e3a clang::Sema::CheckTemplateIdType(clang::ElaboratedTypeKeyword, clang::TemplateName, clang::SourceLocation, clang::TemplateArgumentListInfo&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x70d8e3a)
#50 0x000000000725f7b4 clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformTemplateSpecializationType(clang::TypeLocBuilder&, clang::TemplateSpecializationTypeLoc) SemaTemplateInstantiate.cpp:0:0
#51 0x0000000007236125 clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformType(clang::TypeLocBuilder&, clang::TypeLoc) SemaTemplateInstantiate.cpp:0:0
#52 0x000000000723aa1a clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformType(clang::TypeSourceInfo*) SemaTemplateInstantiate.cpp:0:0
#53 0x00000000072404ae clang::Sema::SubstType(clang::TypeSourceInfo*, clang::MultiLevelTemplateArgumentList const&, clang::SourceLocation, clang::DeclarationName, bool) (.constprop.0) SemaTemplateInstantiate.cpp:0:0
#54 0x00000000072409e5 clang::Sema::SubstBaseSpecifiers(clang::CXXRecordDecl*, clang::CXXRecordDecl*, clang::MultiLevelTemplateArgumentList const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x72409e5)
#55 0x0000000007241407 clang::Sema::InstantiateClass(clang::SourceLocation, clang::CXXRecordDecl*, clang::CXXRecordDecl*, clang::MultiLevelTemplateArgumentList const&, clang::TemplateSpecializationKind, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x7241407)
#56 0x00000000072795b8 clang::Sema::InstantiateClassTemplateSpecialization(clang::SourceLocation, clang::ClassTemplateSpecializationDecl*, clang::TemplateSpecializationKind, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x72795b8)
#57 0x00000000072f994e void llvm::function_ref<void ()>::callback_fn<clang::Sema::RequireCompleteTypeImpl(clang::SourceLocation, clang::QualType, clang::Sema::CompleteTypeKind, clang::Sema::TypeDiagnoser*)::'lambda'()>(long) SemaType.cpp:0:0
#58 0x0000000007fd9ca1 clang::StackExhaustionHandler::runWithSufficientStackSpace(clang::SourceLocation, llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x7fd9ca1)
#59 0x00000000073050c3 clang::Sema::RequireCompleteTypeImpl(clang::SourceLocation, clang::QualType, clang::Sema::CompleteTypeKind, clang::Sema::TypeDiagnoser*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x73050c3)
#60 0x000000000730555f clang::Sema::RequireCompleteType(clang::SourceLocation, clang::QualType, clang::Sema::CompleteTypeKind, clang::Sema::TypeDiagnoser&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x730555f)
#61 0x0000000007305b45 clang::Sema::RequireCompleteType(clang::SourceLocation, clang::QualType, clang::Sema::CompleteTypeKind, unsigned int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x7305b45)
#62 0x0000000006abdd2a clang::Sema::ActOnUninitializedDecl(clang::Decl*) (.part.0) SemaDecl.cpp:0:0
#63 0x0000000006725d8b clang::Parser::ParseDeclarationAfterDeclaratorAndAttributes(clang::Declarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::ForRangeInit*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6725d8b)
#64 0x0000000006735189 clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, clang::DeclaratorContext, clang::ParsedAttributes&, clang::Parser::ParsedTemplateInfo&, clang::SourceLocation*, clang::Parser::ForRangeInit*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6735189)
#65 0x00000000066f250e clang::Parser::ParseDeclOrFunctionDefInternal(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec&, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x66f250e)
#66 0x00000000066f2caf clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x66f2caf)
#67 0x00000000066faaea clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x66faaea)
#68 0x00000000066fba85 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x66fba85)
#69 0x00000000066ed60a clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x66ed60a)
#70 0x00000000049dc9e8 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x49dc9e8)
#71 0x0000000004cd15a5 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4cd15a5)
#72 0x0000000004c4d74e clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4c4d74e)
#73 0x0000000004dc30b1 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4dc30b1)
#74 0x0000000000db1a9f cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xdb1a9f)
#75 0x0000000000da874a ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#76 0x0000000004a449c9 void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const::'lambda'()>(long) Job.cpp:0:0
#77 0x0000000003f7a2c4 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3f7a2c4)
#78 0x0000000004a44fdf clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const (.part.0) Job.cpp:0:0
#79 0x0000000004a06c9d clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4a06c9d)
#80 0x0000000004a07d2e clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4a07d2e)
#81 0x0000000004a0f965 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4a0f965)
#82 0x0000000000dadf55 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xdadf55)
#83 0x0000000000c61ba4 main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xc61ba4)
#84 0x000076dbcd429d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#85 0x000076dbcd429e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#86 0x0000000000da81f5 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xda81f5)
clang++: error: clang frontend command failed with exit code 134 (use -v to see invocation)
Compiler returned: 134

@philnik777
Copy link
Contributor Author

@alexfh Could you file a bug for the crash? Re. the libc++ part the fix should be fairly trivial. We can just add another tag, which avoids the instantiation when evaluating __tuple_imple(__tuple_impl&&). Working on a patch right now.

@alexfh
Copy link
Contributor

alexfh commented Aug 20, 2025

Could you file a bug for the crash?

I'll wait till your libc++ fix lands and will check if the crash goes away to see if it's a crash-on-valid or crash-on-invalid.

@frederick-vs-ja
Copy link
Contributor

Aha, I've reduced the example to:

template<class>
struct Trait;

template<class T>
constexpr bool TraitV = Trait<T>::value;

template<class T>
struct S {
    S() noexcept(TraitV<T>) = default;
};

template<class T>
struct S2 : S<T> {};

S2<char> s;

Godbolt link

This should be crash-on-invalid .

@alexfh
Copy link
Contributor

alexfh commented Aug 25, 2025

Aha, I've reduced the example to:

template<class>
struct Trait;

template<class T>
constexpr bool TraitV = Trait<T>::value;

template<class T>
struct S {
    S() noexcept(TraitV<T>) = default;
};

template<class T>
struct S2 : S<T> {};

S2<char> s;

Godbolt link

This should be crash-on-invalid .

Thanks for reducing this! The crash doesn't reproduce after #154517, so it's indeed a crash-on-invalid. Filed #155320

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants