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

  • SEARCH
  • Home
  • 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 9311557
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T01:23:59+00:00 2026-06-19T01:23:59+00:00

The following code compiles with clang (libc++) and fails with gcc (libstdc++). Why does

  • 0

The following code compiles with clang (libc++) and fails with gcc (libstdc++). Why does gcc (libstdc++) complains about an initializer list? I thought the return argument was using uniform initialization syntax.

std::tuple<double,double> dummy() {
  return {2.0, 3.0};
}

int main() {   
  std::tuple<double,double> a = dummy();   
  return 0;
}

Error: line 22: converting to ‘std::tuple’ from initializer \
list would use explicit constructor ‘constexpr std::tuple<_T1, _T2>::tuple(_U1&\
&, _U2&&) [with _U1 = double; _U2 = double; = void; _T\
1 = double; _T2 = double]’

Note: GCC (libstdc++) (and clang (libc++)) accept

std::tuple<double,double> dummy {1.0, 2.0};

Isn’t it the same case?

Update: this is a libc++ extension, see http://llvm.org/bugs/show_bug.cgi?id=15299 and also answer by Howard Hinnant below.

  • 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-19T01:24:01+00:00Added an answer on June 19, 2026 at 1:24 am

    Unlike for pair<>, implicit construction of a tuple<> is not possible unfortunately. You have to use make_tuple():

    #include <tuple>
    
    std::tuple<double,double> dummy()
    {
        return std::make_tuple(2.0, 3.0); // OK
    }
    
    int main() 
    {   
        std::tuple<double,double> a = dummy();   
        return 0;
    }
    

    std::tuple has a variadic constructor, but it is marked as explicit. Thus, it cannot be used in this situation, where a temporary must be implicitly constructible. Per Paragraph 20.4.2 of the C++11 Standard:

    namespace std {
        template <class... Types>
        class tuple {
        public:
    
            [...]
            explicit tuple(const Types&...); // Marked as explicit!
    
            template <class... UTypes>
            explicit tuple(UTypes&&...);     // Marked as explicit!
    

    For the same reason it is illegal to use copy-initialization syntax for initializing tuples:

    std::tuple<double, double> a = {1.0, 2.0}; // ERROR!
    std::tuple<double, double> a{1.0, 2.0}; // OK
    

    Or to construct a tuple implicitly when passing it as an argument to a function:

    void f(std::tuple<double, double> t) { ... }
    ...
    f({1.0, 2.0}); // ERROR!
    f(make_tuple(1.0, 2.0)); // OK
    

    Accordingly, if you construct your std::tuple explicitly when returning it in dummy(), no compilation error will occur:

    #include <tuple>
    
    std::tuple<double,double> dummy()
    {
        return std::tuple<double, double>{2.0, 3.0}; // OK
    }
    
    int main() 
    {   
        std::tuple<double,double> a = dummy();   
        return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The following code compiles in Visual C++ and gcc, but fails with Code Warrior
The following code compiles with GCC 4.7 and clang 3.0, but not with MSVC
The following code neither compiles with -std=c++11 under gcc-4.7.1 nor clang-3.2. So I think
The following code does not compiles using clang 3.0, is this because I have
The following code compiles fine with g++ (GCC) 4.7.1 20120721 , but fails with
The following code does not compile with gcc 4.7 (20120114) , but compiles fine
I have following piece of code: It compiles without problems under gcc-3.4, gcc-4.3, intel
The following code compiles with g++ 4.7.1 but not clang 3.1 struct A {
The following code doesn't compile with clang 3.1, using libc++ (don't know the version,
For example, GCC and clang both fail to compile the following code: struct S

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.