Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8077675
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T15:32:38+00:00 2026-06-05T15:32:38+00:00

#include <iostream> #include <tuple> int main(){ auto bt=std::make_tuple(std::tuple<>(),std::tuple<std::tuple<>>()); //Line 1 auto bt2=std::make_tuple(std::tuple<>(),std::tuple<>()); //Line 2

  • 0
#include <iostream>
#include <tuple>
int main(){

auto bt=std::make_tuple(std::tuple<>(),std::tuple<std::tuple<>>()); //Line 1
auto bt2=std::make_tuple(std::tuple<>(),std::tuple<>());             //Line 2
}

Why does Line 1 gives a compile error while Line 2 compiles fine? (tested in both Gcc&Clang)

Is there a possible workaround?

error message for clang

/usr/include/c++/4.6/tuple:150:50: error: ambiguous conversion from derived class 'std::_Tuple_impl<0, std::tuple<>,
      std::tuple<std::tuple<> > >' to base class 'std::_Head_base<0, std::tuple<>, true>':
    struct std::_Tuple_impl<0, class std::tuple<>, class std::tuple<class std::tuple<> > > -> _Tuple_impl<0UL + 1, class std::tuple<class std::tuple<> > > -> _Head_base<1UL, class std::tuple<class std::tuple<> >, std::is_empty<class tuple<class tuple<> > >::value> -> class std::tuple<class std::tuple<> > -> _Tuple_impl<0, class std::tuple<> > -> _Head_base<0UL, class std::tuple<>, std::is_empty<class tuple<> >::value>
    struct std::_Tuple_impl<0, class std::tuple<>, class std::tuple<class std::tuple<> > > -> _Head_base<0UL, class std::tuple<>, std::is_empty<class tuple<> >::value>
      _Head&            _M_head()       { return _Base::_M_head(); }
                                                 ^~~~~
/usr/include/c++/4.6/tuple:173:33: note: in instantiation of member function 'std::_Tuple_impl<0, std::tuple<>,
      std::tuple<std::tuple<> > >::_M_head' requested here
        _Base(std::forward<_Head>(__in._M_head())) { }
                                       ^
/usr/include/c++/4.6/tuple:334:9: note: in instantiation of member function 'std::_Tuple_impl<0, std::tuple<>,
      std::tuple<std::tuple<> > >::_Tuple_impl' requested here
      : _Inherited(static_cast<_Inherited&&>(__in)) { }
        ^
gcc_bug.cpp:5:10: note: in instantiation of member function
      'std::tuple<std::tuple<>, std::tuple<std::tuple<> > >::tuple' requested here
        auto bt=std::make_tuple(std::tuple<>(),std::tuple<std::tuple<>>());
                ^
1 error generated.
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T15:32:40+00:00Added an answer on June 5, 2026 at 3:32 pm

    Looks like you found a bug in libstdc++! (This code works in clang with libc++). A reduced test case:

    #include <tuple>
    
    int main(){
        auto b = std::tuple<std::tuple<std::tuple<>>>{};
    }
    

    The problem is due to how std::tuple is implemented in libstdc++. The tuple implementation uses “recursion” with multiple-inheritance. You can think of tuple<X, Y, Z> as inheriting from both X and tuple<Y, Z>. This means tuple<tuple<>> will inherit from both tuple<> and tuple<> and that will cause an ambiguous base error. Of course the real problem isn’t like this, because tuple<tuple<>> doesn’t produce any error.

    The real implementation that caused the error is like this:

    template<size_t _Idx, typename _Head>
    struct _Head_base : public _Head
    {};
    
    template<size_t _Idx, typename... _Elements>
    struct _Tuple_impl;
    
    template<size_t _Idx>
    struct _Tuple_impl<_Idx> {};
    
    template<size_t _Idx, typename _Head, typename... _Tail>
    struct _Tuple_impl<_Idx, _Head, _Tail...>
        : public _Tuple_impl<_Idx + 1, _Tail...>,
          private _Head_base<_Idx, _Head>
    {
        typedef _Tuple_impl<_Idx + 1, _Tail...> _Inherited;
        constexpr _Tuple_impl() = default;
        constexpr _Tuple_impl(_Tuple_impl&& __in) : _Inherited(std::move(__in)) {}
    };
    
    template<typename... _Elements>
    struct tuple : public _Tuple_impl<0, _Elements...> {};
    

    When we instantiate tuple<tuple<tuple<>>>, we get this inheritance hierarchy:

    inheritance diagram of <code>tuple<tuple<tuple<>>></code> in libstdc++

    We see that _Tuple_impl<1> is reachable in two different paths. This is not yet the problem, the problem is in the move constructor, who invokes the move-conversion constructor of _Tuple_impl<1>. Which _Tuple_impl<1> do you want? The compiler doesn’t know, so it chooses the give up.

    (In your case it’s because of _Head_base<0, tuple<>> as you are instantiating tuple<tuple<>, tuple<tuple<>>> instead, but the principle is the same.)


    Why libc++ does not have the same problem? There are two main reasons:

    1. tuple<T...> in libc++ use composition instead of inheritance to refer to __tuple_impl<...>.
    2. As a result, the empty base class optimization in __tuple_leaf<tuple<tuple<>>> does not kick in, i.e. __tuple_leaf<tuple<tuple<>>> won’t inherit from tuple<tuple<>>
    3. Therefore, the ambiguous base class problem won’t happen.
    4. (and each base is unique as mentioned by @mitchnull, but that is not a main difference here.)

    inheritance diagram of <code>tuple<tuple<tuple<>>></code> in libc++

    As we can see above, if tuple<...> uses inheritance instead of composition, OP’s tuple<tuple<>, tuple<tuple<>>> will still inherit from __tuple_leaf<0, tuple<>> twice, which might be a problem.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

#include <iostream> #include <fstream> using namespace std; int main () { ofstream myfile; myfile.open
#include <iostream> using namespace std; int main() { cout << !!!Hello World!!! << endl;
#include <iostream> #include <vector> using namespace std; int main(void) { int i, s, g;
#include <iostream> #include <string> #include <vector> #include <algorithm> using namespace std; int main(void) {
#include iostream #include string using namespace std; #define AA(bb) \ string(::##bb); int main (int
#include <iostream> using namespace std; int main (void) { cout << 1\t2\t3\t4\t5\t6\t7\t8\t9 << endl
I've been experimenting with std::tuple in combination with references: #include <iostream> #include <tuple> int
#include <iostream> #include <string> #include <fstream> using namespace std ; string strWord( int index
#include <iostream> using namespace std; struct testarray{ int element; public: testarray(int a):element(a){} }; class
#include<iostream> using namespace std; struct sample { int data[3][2]; }; struct sample* function() {

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.