std::is_constructible on incomplete typesSFINAE with std::enable_if and std::is_default_constructible for incomplete type in libc++Expecting different types depending of point of instantiationWhy is “using namespace std” considered bad practice?How can I get sizeof a vector::value_type?Replacing a 32-bit loop counter with 64-bit introduces crazy performance deviationsstd::is_convertible inconsistant with std::functionCan I instantiate an std::reference_wrapper<T> where T is an incomplete type?What is the correct result of std::is_constructible<void()>::value?unique_ptr pimpl and incomplete typesclang 5: std::optional instantiation screws std::is_constructible trait of the parameter typeinvalid use of incomplete type ‘class std::promise<int>’ error while compile using arm-linux-gnueabi-g++-5Does the C++ standard allow for an uninitialized bool to crash a program?

simple conditions equation

What does KSP mean?

Please, smoke with good manners

Is the 5 MB static resource size limit 5,242,880 bytes or 5,000,000 bytes?

Sci-fi novel series with instant travel between planets through gates. A river runs through the gates

Unexpected email from Yorkshire Bank

The Defining Moment

What are the potential pitfalls when using metals as a currency?

What is the relationship between spectral sequences and obstruction theory?

Mac Pro install disk keeps ejecting itself

Packing rectangles: Does rotation ever help?

Why isn't the definition of absolute value applied when squaring a radical containing a variable?

Phrase for the opposite of "foolproof"

Don’t seats that recline flat defeat the purpose of having seatbelts?

What route did the Hindenburg take when traveling from Germany to the U.S.?

Any examples of headwear for races with animal ears?

What does the "ep" capability mean?

A Strange Latex Symbol

Was there a Viking Exchange as well as a Columbian one?

Examples of subgroups where it's nontrivial to show closure under multiplication?

Realistic Necromancy?

How to reduce LED flash rate (frequency)

What is the strongest case that can be made in favour of the UK regaining some control over fishing policy after Brexit?

Is there a way to get a compiler for the original B programming language?



std::is_constructible on incomplete types


SFINAE with std::enable_if and std::is_default_constructible for incomplete type in libc++Expecting different types depending of point of instantiationWhy is “using namespace std” considered bad practice?How can I get sizeof a vector::value_type?Replacing a 32-bit loop counter with 64-bit introduces crazy performance deviationsstd::is_convertible inconsistant with std::functionCan I instantiate an std::reference_wrapper<T> where T is an incomplete type?What is the correct result of std::is_constructible<void()>::value?unique_ptr pimpl and incomplete typesclang 5: std::optional instantiation screws std::is_constructible trait of the parameter typeinvalid use of incomplete type ‘class std::promise<int>’ error while compile using arm-linux-gnueabi-g++-5Does the C++ standard allow for an uninitialized bool to crash a program?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








22















I have the following code:



#include <iostream>

class A;

int main()

std::cout << std::is_constructible<A>::value << std::endl;



When I use GCC 8.3, this code compiles. However, when I use Clang 8.0, I get a compilation error that incomplete types cannot be used in type traits.



Which one is correct? Am I allowed to use is_constructible on an incomplete type (with an expected value of false), or am I not allowed to?










share|improve this question
























  • Related question SFINAE with std::enable_if and std::is_default_constructible for incomplete type in libc++

    – t.niese
    Apr 24 at 13:47












  • How would is_constructible determine if A is constructible if A is not a complete type?

    – François Andrieux
    Apr 24 at 13:56






  • 1





    @FrançoisAndrieux: If A isn't complete, we can't construct it (A a; on an incomplete class A causes a compiler error) - that's the way it was working in our code base in the past, but it appears that was just luck of the draw due to undefined behavior.

    – R_Kapp
    Apr 24 at 13:59






  • 3





    Re: "we can't construct it" -- type traits are about the properties of a type. It would be really disturbing if std::is_constuctible<A> changed its result depending on what headers you included. In one place it's constructible and in another it isn't?

    – Pete Becker
    Apr 24 at 14:33












  • @PeteBecker: That's a fair point that I hadn't considered - the original use case was a templated class A that only had specific parameters instantiated. We then used SFINAE with std::is_constructible so that only certain types of types were allowed through. This is easily done correctly by explicitly instantiating a default class A where constructors are explicitly deleted (which is what I've done), but the thought process was from that angle. Hadn't considered the (what should have been obvious) "forward-declared-class-that-actually-exists" angle...

    – R_Kapp
    Apr 24 at 19:10

















22















I have the following code:



#include <iostream>

class A;

int main()

std::cout << std::is_constructible<A>::value << std::endl;



When I use GCC 8.3, this code compiles. However, when I use Clang 8.0, I get a compilation error that incomplete types cannot be used in type traits.



Which one is correct? Am I allowed to use is_constructible on an incomplete type (with an expected value of false), or am I not allowed to?










share|improve this question
























  • Related question SFINAE with std::enable_if and std::is_default_constructible for incomplete type in libc++

    – t.niese
    Apr 24 at 13:47












  • How would is_constructible determine if A is constructible if A is not a complete type?

    – François Andrieux
    Apr 24 at 13:56






  • 1





    @FrançoisAndrieux: If A isn't complete, we can't construct it (A a; on an incomplete class A causes a compiler error) - that's the way it was working in our code base in the past, but it appears that was just luck of the draw due to undefined behavior.

    – R_Kapp
    Apr 24 at 13:59






  • 3





    Re: "we can't construct it" -- type traits are about the properties of a type. It would be really disturbing if std::is_constuctible<A> changed its result depending on what headers you included. In one place it's constructible and in another it isn't?

    – Pete Becker
    Apr 24 at 14:33












  • @PeteBecker: That's a fair point that I hadn't considered - the original use case was a templated class A that only had specific parameters instantiated. We then used SFINAE with std::is_constructible so that only certain types of types were allowed through. This is easily done correctly by explicitly instantiating a default class A where constructors are explicitly deleted (which is what I've done), but the thought process was from that angle. Hadn't considered the (what should have been obvious) "forward-declared-class-that-actually-exists" angle...

    – R_Kapp
    Apr 24 at 19:10













22












22








22


2






I have the following code:



#include <iostream>

class A;

int main()

std::cout << std::is_constructible<A>::value << std::endl;



When I use GCC 8.3, this code compiles. However, when I use Clang 8.0, I get a compilation error that incomplete types cannot be used in type traits.



Which one is correct? Am I allowed to use is_constructible on an incomplete type (with an expected value of false), or am I not allowed to?










share|improve this question
















I have the following code:



#include <iostream>

class A;

int main()

std::cout << std::is_constructible<A>::value << std::endl;



When I use GCC 8.3, this code compiles. However, when I use Clang 8.0, I get a compilation error that incomplete types cannot be used in type traits.



Which one is correct? Am I allowed to use is_constructible on an incomplete type (with an expected value of false), or am I not allowed to?







c++ c++11 language-lawyer






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Apr 24 at 14:02









StoryTeller

107k15224288




107k15224288










asked Apr 24 at 13:42









R_KappR_Kapp

1,94711124




1,94711124












  • Related question SFINAE with std::enable_if and std::is_default_constructible for incomplete type in libc++

    – t.niese
    Apr 24 at 13:47












  • How would is_constructible determine if A is constructible if A is not a complete type?

    – François Andrieux
    Apr 24 at 13:56






  • 1





    @FrançoisAndrieux: If A isn't complete, we can't construct it (A a; on an incomplete class A causes a compiler error) - that's the way it was working in our code base in the past, but it appears that was just luck of the draw due to undefined behavior.

    – R_Kapp
    Apr 24 at 13:59






  • 3





    Re: "we can't construct it" -- type traits are about the properties of a type. It would be really disturbing if std::is_constuctible<A> changed its result depending on what headers you included. In one place it's constructible and in another it isn't?

    – Pete Becker
    Apr 24 at 14:33












  • @PeteBecker: That's a fair point that I hadn't considered - the original use case was a templated class A that only had specific parameters instantiated. We then used SFINAE with std::is_constructible so that only certain types of types were allowed through. This is easily done correctly by explicitly instantiating a default class A where constructors are explicitly deleted (which is what I've done), but the thought process was from that angle. Hadn't considered the (what should have been obvious) "forward-declared-class-that-actually-exists" angle...

    – R_Kapp
    Apr 24 at 19:10

















  • Related question SFINAE with std::enable_if and std::is_default_constructible for incomplete type in libc++

    – t.niese
    Apr 24 at 13:47












  • How would is_constructible determine if A is constructible if A is not a complete type?

    – François Andrieux
    Apr 24 at 13:56






  • 1





    @FrançoisAndrieux: If A isn't complete, we can't construct it (A a; on an incomplete class A causes a compiler error) - that's the way it was working in our code base in the past, but it appears that was just luck of the draw due to undefined behavior.

    – R_Kapp
    Apr 24 at 13:59






  • 3





    Re: "we can't construct it" -- type traits are about the properties of a type. It would be really disturbing if std::is_constuctible<A> changed its result depending on what headers you included. In one place it's constructible and in another it isn't?

    – Pete Becker
    Apr 24 at 14:33












  • @PeteBecker: That's a fair point that I hadn't considered - the original use case was a templated class A that only had specific parameters instantiated. We then used SFINAE with std::is_constructible so that only certain types of types were allowed through. This is easily done correctly by explicitly instantiating a default class A where constructors are explicitly deleted (which is what I've done), but the thought process was from that angle. Hadn't considered the (what should have been obvious) "forward-declared-class-that-actually-exists" angle...

    – R_Kapp
    Apr 24 at 19:10
















Related question SFINAE with std::enable_if and std::is_default_constructible for incomplete type in libc++

– t.niese
Apr 24 at 13:47






Related question SFINAE with std::enable_if and std::is_default_constructible for incomplete type in libc++

– t.niese
Apr 24 at 13:47














How would is_constructible determine if A is constructible if A is not a complete type?

– François Andrieux
Apr 24 at 13:56





How would is_constructible determine if A is constructible if A is not a complete type?

– François Andrieux
Apr 24 at 13:56




1




1





@FrançoisAndrieux: If A isn't complete, we can't construct it (A a; on an incomplete class A causes a compiler error) - that's the way it was working in our code base in the past, but it appears that was just luck of the draw due to undefined behavior.

– R_Kapp
Apr 24 at 13:59





@FrançoisAndrieux: If A isn't complete, we can't construct it (A a; on an incomplete class A causes a compiler error) - that's the way it was working in our code base in the past, but it appears that was just luck of the draw due to undefined behavior.

– R_Kapp
Apr 24 at 13:59




3




3





Re: "we can't construct it" -- type traits are about the properties of a type. It would be really disturbing if std::is_constuctible<A> changed its result depending on what headers you included. In one place it's constructible and in another it isn't?

– Pete Becker
Apr 24 at 14:33






Re: "we can't construct it" -- type traits are about the properties of a type. It would be really disturbing if std::is_constuctible<A> changed its result depending on what headers you included. In one place it's constructible and in another it isn't?

– Pete Becker
Apr 24 at 14:33














@PeteBecker: That's a fair point that I hadn't considered - the original use case was a templated class A that only had specific parameters instantiated. We then used SFINAE with std::is_constructible so that only certain types of types were allowed through. This is easily done correctly by explicitly instantiating a default class A where constructors are explicitly deleted (which is what I've done), but the thought process was from that angle. Hadn't considered the (what should have been obvious) "forward-declared-class-that-actually-exists" angle...

– R_Kapp
Apr 24 at 19:10





@PeteBecker: That's a fair point that I hadn't considered - the original use case was a templated class A that only had specific parameters instantiated. We then used SFINAE with std::is_constructible so that only certain types of types were allowed through. This is easily done correctly by explicitly instantiating a default class A where constructors are explicitly deleted (which is what I've done), but the thought process was from that angle. Hadn't considered the (what should have been obvious) "forward-declared-class-that-actually-exists" angle...

– R_Kapp
Apr 24 at 19:10












3 Answers
3






active

oldest

votes


















22














The behavior is undefined.




[meta.unary.prop]



template <class T, class... Args> struct is_constructible;


T and all types in the parameter pack Args shall be complete types,
(possibly cv-qualified) void, or arrays of unknown bound.




That's a precondition of the meta-function. A contract that your code violates. libc++ is being generous by notifying you.




Mind you, that putting that precondition there and leaving it undefined otherwise is for a reason. A program where two points of instantiation of a template have different meanings is ill-formed NDR. The only sane course of action is demand complete types. And after all, that's when the trait is most useful anyway.






share|improve this answer
































    16














    Your code causes undefined behavior.



    Cppreference states:




    template< class T, class... Args >
    struct is_constructible;



    T and all types in the parameter pack Args shall each be a complete type, (possibly cv-qualified) void, or an array of unknown bound. Otherwise, the behavior is undefined.







    share|improve this answer






























      7














      Your code has undefined behavior. Per [meta.unary.prop] table 47 std::is_constructible requires




      T and all types in the template parameter pack Args shall be complete types, cv void, or arrays of unknown bound.




      emphasis mine






      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%2f55831521%2fstdis-constructible-on-incomplete-types%23new-answer', 'question_page');

        );

        Post as a guest















        Required, but never shown

























        3 Answers
        3






        active

        oldest

        votes








        3 Answers
        3






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes









        22














        The behavior is undefined.




        [meta.unary.prop]



        template <class T, class... Args> struct is_constructible;


        T and all types in the parameter pack Args shall be complete types,
        (possibly cv-qualified) void, or arrays of unknown bound.




        That's a precondition of the meta-function. A contract that your code violates. libc++ is being generous by notifying you.




        Mind you, that putting that precondition there and leaving it undefined otherwise is for a reason. A program where two points of instantiation of a template have different meanings is ill-formed NDR. The only sane course of action is demand complete types. And after all, that's when the trait is most useful anyway.






        share|improve this answer





























          22














          The behavior is undefined.




          [meta.unary.prop]



          template <class T, class... Args> struct is_constructible;


          T and all types in the parameter pack Args shall be complete types,
          (possibly cv-qualified) void, or arrays of unknown bound.




          That's a precondition of the meta-function. A contract that your code violates. libc++ is being generous by notifying you.




          Mind you, that putting that precondition there and leaving it undefined otherwise is for a reason. A program where two points of instantiation of a template have different meanings is ill-formed NDR. The only sane course of action is demand complete types. And after all, that's when the trait is most useful anyway.






          share|improve this answer



























            22












            22








            22







            The behavior is undefined.




            [meta.unary.prop]



            template <class T, class... Args> struct is_constructible;


            T and all types in the parameter pack Args shall be complete types,
            (possibly cv-qualified) void, or arrays of unknown bound.




            That's a precondition of the meta-function. A contract that your code violates. libc++ is being generous by notifying you.




            Mind you, that putting that precondition there and leaving it undefined otherwise is for a reason. A program where two points of instantiation of a template have different meanings is ill-formed NDR. The only sane course of action is demand complete types. And after all, that's when the trait is most useful anyway.






            share|improve this answer















            The behavior is undefined.




            [meta.unary.prop]



            template <class T, class... Args> struct is_constructible;


            T and all types in the parameter pack Args shall be complete types,
            (possibly cv-qualified) void, or arrays of unknown bound.




            That's a precondition of the meta-function. A contract that your code violates. libc++ is being generous by notifying you.




            Mind you, that putting that precondition there and leaving it undefined otherwise is for a reason. A program where two points of instantiation of a template have different meanings is ill-formed NDR. The only sane course of action is demand complete types. And after all, that's when the trait is most useful anyway.







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Apr 24 at 18:23

























            answered Apr 24 at 13:47









            StoryTellerStoryTeller

            107k15224288




            107k15224288























                16














                Your code causes undefined behavior.



                Cppreference states:




                template< class T, class... Args >
                struct is_constructible;



                T and all types in the parameter pack Args shall each be a complete type, (possibly cv-qualified) void, or an array of unknown bound. Otherwise, the behavior is undefined.







                share|improve this answer



























                  16














                  Your code causes undefined behavior.



                  Cppreference states:




                  template< class T, class... Args >
                  struct is_constructible;



                  T and all types in the parameter pack Args shall each be a complete type, (possibly cv-qualified) void, or an array of unknown bound. Otherwise, the behavior is undefined.







                  share|improve this answer

























                    16












                    16








                    16







                    Your code causes undefined behavior.



                    Cppreference states:




                    template< class T, class... Args >
                    struct is_constructible;



                    T and all types in the parameter pack Args shall each be a complete type, (possibly cv-qualified) void, or an array of unknown bound. Otherwise, the behavior is undefined.







                    share|improve this answer













                    Your code causes undefined behavior.



                    Cppreference states:




                    template< class T, class... Args >
                    struct is_constructible;



                    T and all types in the parameter pack Args shall each be a complete type, (possibly cv-qualified) void, or an array of unknown bound. Otherwise, the behavior is undefined.








                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Apr 24 at 13:47









                    Nellie DanielyanNellie Danielyan

                    807517




                    807517





















                        7














                        Your code has undefined behavior. Per [meta.unary.prop] table 47 std::is_constructible requires




                        T and all types in the template parameter pack Args shall be complete types, cv void, or arrays of unknown bound.




                        emphasis mine






                        share|improve this answer



























                          7














                          Your code has undefined behavior. Per [meta.unary.prop] table 47 std::is_constructible requires




                          T and all types in the template parameter pack Args shall be complete types, cv void, or arrays of unknown bound.




                          emphasis mine






                          share|improve this answer

























                            7












                            7








                            7







                            Your code has undefined behavior. Per [meta.unary.prop] table 47 std::is_constructible requires




                            T and all types in the template parameter pack Args shall be complete types, cv void, or arrays of unknown bound.




                            emphasis mine






                            share|improve this answer













                            Your code has undefined behavior. Per [meta.unary.prop] table 47 std::is_constructible requires




                            T and all types in the template parameter pack Args shall be complete types, cv void, or arrays of unknown bound.




                            emphasis mine







                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Apr 24 at 13:48









                            NathanOliverNathanOliver

                            100k16139221




                            100k16139221



























                                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%2f55831521%2fstdis-constructible-on-incomplete-types%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

                                Get product attribute by attribute group code in magento 2get product attribute by product attribute group in magento 2Magento 2 Log Bundle Product Data in List Page?How to get all product attribute of a attribute group of Default attribute set?Magento 2.1 Create a filter in the product grid by new attributeMagento 2 : Get Product Attribute values By GroupMagento 2 How to get all existing values for one attributeMagento 2 get custom attribute of a single product inside a pluginMagento 2.3 How to get all the Multi Source Inventory (MSI) locations collection in custom module?Magento2: how to develop rest API to get new productsGet product attribute by attribute group code ( [attribute_group_code] ) in magento 2

                                Category:9 (number) SubcategoriesMedia in category "9 (number)"Navigation menuUpload mediaGND ID: 4485639-8Library of Congress authority ID: sh85091979ReasonatorScholiaStatistics

                                Magento 2.3: How do i solve this, Not registered handle, on custom form?How can i rewrite TierPrice Block in Magento2magento 2 captcha not rendering if I override layout xmlmain.CRITICAL: Plugin class doesn't existMagento 2 : Problem while adding custom button order view page?Magento 2.2.5: Overriding Admin Controller sales/orderMagento 2.2.5: Add, Update and Delete existing products Custom OptionsMagento 2.3 : File Upload issue in UI Component FormMagento2 Not registered handleHow to configured Form Builder Js in my custom magento 2.3.0 module?Magento 2.3. How to create image upload field in an admin form