Can't compile C++ 17 structured bindings












1















The following code



#include <iostream>
#include <tuple>

int main()
{
auto [i, c, d] = std::make_tuple(1, 'a', 2.3);
std::cout << "i=" << i << " c=" << c << " d=" << d << 'n';
return 0;
}


doesn't get compiled on my computer. I get these error messages:



error: use of undeclared identifier 'i'
error: expected unqualified-id


and some more of the same type.



I'm using: Mac OS X 10.11.6 El Capitan, CLion. I did choose the C++ 17 option when I created the project and my CMakeList.txt has this line:set(CMAKE_CXX_STANDARD 17).



clang --version - Apple LLVM version 8.0.0 (clang-800.0.42.1)



What do I need to do to compile this code?










share|improve this question




















  • 1





    Are you compiling as C++17 (-std=c++17 command line option)?

    – Jesper Juhl
    Jan 3 at 19:47






  • 2





    When compiling with cmake-generated Makefiles, you can verify the -std=c++17 flag with make VERBOSE=1. Or export a compilation database and inspect it. The code should compile just fine.

    – lubgr
    Jan 3 at 19:49






  • 1





    My suggestion doesn't have anything to do with an IDE, manually compiling the code via make VERBOSE=1 requires a terminal (but you should even be able to open one in CLion I guess) and knowing the path to your project build directory. Exporting a compilation data base is indeed done by editing a CMakeLists.txt.

    – lubgr
    Jan 3 at 19:54








  • 1





    @alekscooper: Please edit your question (the title and example particularly) to make it clear that it is not about C++17 or structured bindings but about using CLion, then.

    – Davis Herring
    Jan 3 at 20:14






  • 2





    That older version of Xcode does not have complete C++17 support. (The current version has much better support, but not yet complete, iirc.)

    – Eljay
    Jan 3 at 20:32
















1















The following code



#include <iostream>
#include <tuple>

int main()
{
auto [i, c, d] = std::make_tuple(1, 'a', 2.3);
std::cout << "i=" << i << " c=" << c << " d=" << d << 'n';
return 0;
}


doesn't get compiled on my computer. I get these error messages:



error: use of undeclared identifier 'i'
error: expected unqualified-id


and some more of the same type.



I'm using: Mac OS X 10.11.6 El Capitan, CLion. I did choose the C++ 17 option when I created the project and my CMakeList.txt has this line:set(CMAKE_CXX_STANDARD 17).



clang --version - Apple LLVM version 8.0.0 (clang-800.0.42.1)



What do I need to do to compile this code?










share|improve this question




















  • 1





    Are you compiling as C++17 (-std=c++17 command line option)?

    – Jesper Juhl
    Jan 3 at 19:47






  • 2





    When compiling with cmake-generated Makefiles, you can verify the -std=c++17 flag with make VERBOSE=1. Or export a compilation database and inspect it. The code should compile just fine.

    – lubgr
    Jan 3 at 19:49






  • 1





    My suggestion doesn't have anything to do with an IDE, manually compiling the code via make VERBOSE=1 requires a terminal (but you should even be able to open one in CLion I guess) and knowing the path to your project build directory. Exporting a compilation data base is indeed done by editing a CMakeLists.txt.

    – lubgr
    Jan 3 at 19:54








  • 1





    @alekscooper: Please edit your question (the title and example particularly) to make it clear that it is not about C++17 or structured bindings but about using CLion, then.

    – Davis Herring
    Jan 3 at 20:14






  • 2





    That older version of Xcode does not have complete C++17 support. (The current version has much better support, but not yet complete, iirc.)

    – Eljay
    Jan 3 at 20:32














1












1








1








The following code



#include <iostream>
#include <tuple>

int main()
{
auto [i, c, d] = std::make_tuple(1, 'a', 2.3);
std::cout << "i=" << i << " c=" << c << " d=" << d << 'n';
return 0;
}


doesn't get compiled on my computer. I get these error messages:



error: use of undeclared identifier 'i'
error: expected unqualified-id


and some more of the same type.



I'm using: Mac OS X 10.11.6 El Capitan, CLion. I did choose the C++ 17 option when I created the project and my CMakeList.txt has this line:set(CMAKE_CXX_STANDARD 17).



clang --version - Apple LLVM version 8.0.0 (clang-800.0.42.1)



What do I need to do to compile this code?










share|improve this question
















The following code



#include <iostream>
#include <tuple>

int main()
{
auto [i, c, d] = std::make_tuple(1, 'a', 2.3);
std::cout << "i=" << i << " c=" << c << " d=" << d << 'n';
return 0;
}


doesn't get compiled on my computer. I get these error messages:



error: use of undeclared identifier 'i'
error: expected unqualified-id


and some more of the same type.



I'm using: Mac OS X 10.11.6 El Capitan, CLion. I did choose the C++ 17 option when I created the project and my CMakeList.txt has this line:set(CMAKE_CXX_STANDARD 17).



clang --version - Apple LLVM version 8.0.0 (clang-800.0.42.1)



What do I need to do to compile this code?







c++ c++17 clion






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 3 at 20:38









Nicol Bolas

291k34481658




291k34481658










asked Jan 3 at 19:43









alekscooperalekscooper

327312




327312








  • 1





    Are you compiling as C++17 (-std=c++17 command line option)?

    – Jesper Juhl
    Jan 3 at 19:47






  • 2





    When compiling with cmake-generated Makefiles, you can verify the -std=c++17 flag with make VERBOSE=1. Or export a compilation database and inspect it. The code should compile just fine.

    – lubgr
    Jan 3 at 19:49






  • 1





    My suggestion doesn't have anything to do with an IDE, manually compiling the code via make VERBOSE=1 requires a terminal (but you should even be able to open one in CLion I guess) and knowing the path to your project build directory. Exporting a compilation data base is indeed done by editing a CMakeLists.txt.

    – lubgr
    Jan 3 at 19:54








  • 1





    @alekscooper: Please edit your question (the title and example particularly) to make it clear that it is not about C++17 or structured bindings but about using CLion, then.

    – Davis Herring
    Jan 3 at 20:14






  • 2





    That older version of Xcode does not have complete C++17 support. (The current version has much better support, but not yet complete, iirc.)

    – Eljay
    Jan 3 at 20:32














  • 1





    Are you compiling as C++17 (-std=c++17 command line option)?

    – Jesper Juhl
    Jan 3 at 19:47






  • 2





    When compiling with cmake-generated Makefiles, you can verify the -std=c++17 flag with make VERBOSE=1. Or export a compilation database and inspect it. The code should compile just fine.

    – lubgr
    Jan 3 at 19:49






  • 1





    My suggestion doesn't have anything to do with an IDE, manually compiling the code via make VERBOSE=1 requires a terminal (but you should even be able to open one in CLion I guess) and knowing the path to your project build directory. Exporting a compilation data base is indeed done by editing a CMakeLists.txt.

    – lubgr
    Jan 3 at 19:54








  • 1





    @alekscooper: Please edit your question (the title and example particularly) to make it clear that it is not about C++17 or structured bindings but about using CLion, then.

    – Davis Herring
    Jan 3 at 20:14






  • 2





    That older version of Xcode does not have complete C++17 support. (The current version has much better support, but not yet complete, iirc.)

    – Eljay
    Jan 3 at 20:32








1




1





Are you compiling as C++17 (-std=c++17 command line option)?

– Jesper Juhl
Jan 3 at 19:47





Are you compiling as C++17 (-std=c++17 command line option)?

– Jesper Juhl
Jan 3 at 19:47




2




2





When compiling with cmake-generated Makefiles, you can verify the -std=c++17 flag with make VERBOSE=1. Or export a compilation database and inspect it. The code should compile just fine.

– lubgr
Jan 3 at 19:49





When compiling with cmake-generated Makefiles, you can verify the -std=c++17 flag with make VERBOSE=1. Or export a compilation database and inspect it. The code should compile just fine.

– lubgr
Jan 3 at 19:49




1




1





My suggestion doesn't have anything to do with an IDE, manually compiling the code via make VERBOSE=1 requires a terminal (but you should even be able to open one in CLion I guess) and knowing the path to your project build directory. Exporting a compilation data base is indeed done by editing a CMakeLists.txt.

– lubgr
Jan 3 at 19:54







My suggestion doesn't have anything to do with an IDE, manually compiling the code via make VERBOSE=1 requires a terminal (but you should even be able to open one in CLion I guess) and knowing the path to your project build directory. Exporting a compilation data base is indeed done by editing a CMakeLists.txt.

– lubgr
Jan 3 at 19:54






1




1





@alekscooper: Please edit your question (the title and example particularly) to make it clear that it is not about C++17 or structured bindings but about using CLion, then.

– Davis Herring
Jan 3 at 20:14





@alekscooper: Please edit your question (the title and example particularly) to make it clear that it is not about C++17 or structured bindings but about using CLion, then.

– Davis Herring
Jan 3 at 20:14




2




2





That older version of Xcode does not have complete C++17 support. (The current version has much better support, but not yet complete, iirc.)

– Eljay
Jan 3 at 20:32





That older version of Xcode does not have complete C++17 support. (The current version has much better support, but not yet complete, iirc.)

– Eljay
Jan 3 at 20:32












1 Answer
1






active

oldest

votes


















1














As @Eljay said in the comments, older versions of clang did (do) not have complete C++17 support.



I have reproduced this issue w/o CLion.



On a 10.11.6 machine, using "Apple LLVM version 8.0.0 (clang-800.0.42.1)"



clang++ -std=c++1z junk.cpp


gives the errors that the OP reported. (Note that -std=c++17 is not a valid option here - that came later)



On a 10.14.2 machine, using "Apple LLVM version 10.0.0 (clang-1000.10.44.4)"



clang++ -std=c++17 junk.cpp


compiles w/o error.






share|improve this answer
























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54028803%2fcant-compile-c-17-structured-bindings%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    As @Eljay said in the comments, older versions of clang did (do) not have complete C++17 support.



    I have reproduced this issue w/o CLion.



    On a 10.11.6 machine, using "Apple LLVM version 8.0.0 (clang-800.0.42.1)"



    clang++ -std=c++1z junk.cpp


    gives the errors that the OP reported. (Note that -std=c++17 is not a valid option here - that came later)



    On a 10.14.2 machine, using "Apple LLVM version 10.0.0 (clang-1000.10.44.4)"



    clang++ -std=c++17 junk.cpp


    compiles w/o error.






    share|improve this answer




























      1














      As @Eljay said in the comments, older versions of clang did (do) not have complete C++17 support.



      I have reproduced this issue w/o CLion.



      On a 10.11.6 machine, using "Apple LLVM version 8.0.0 (clang-800.0.42.1)"



      clang++ -std=c++1z junk.cpp


      gives the errors that the OP reported. (Note that -std=c++17 is not a valid option here - that came later)



      On a 10.14.2 machine, using "Apple LLVM version 10.0.0 (clang-1000.10.44.4)"



      clang++ -std=c++17 junk.cpp


      compiles w/o error.






      share|improve this answer


























        1












        1








        1







        As @Eljay said in the comments, older versions of clang did (do) not have complete C++17 support.



        I have reproduced this issue w/o CLion.



        On a 10.11.6 machine, using "Apple LLVM version 8.0.0 (clang-800.0.42.1)"



        clang++ -std=c++1z junk.cpp


        gives the errors that the OP reported. (Note that -std=c++17 is not a valid option here - that came later)



        On a 10.14.2 machine, using "Apple LLVM version 10.0.0 (clang-1000.10.44.4)"



        clang++ -std=c++17 junk.cpp


        compiles w/o error.






        share|improve this answer













        As @Eljay said in the comments, older versions of clang did (do) not have complete C++17 support.



        I have reproduced this issue w/o CLion.



        On a 10.11.6 machine, using "Apple LLVM version 8.0.0 (clang-800.0.42.1)"



        clang++ -std=c++1z junk.cpp


        gives the errors that the OP reported. (Note that -std=c++17 is not a valid option here - that came later)



        On a 10.14.2 machine, using "Apple LLVM version 10.0.0 (clang-1000.10.44.4)"



        clang++ -std=c++17 junk.cpp


        compiles w/o error.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jan 3 at 21:49









        Marshall ClowMarshall Clow

        7,4521533




        7,4521533
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54028803%2fcant-compile-c-17-structured-bindings%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Monofisismo

            Angular Downloading a file using contenturl with Basic Authentication

            Olmecas