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;
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
add a comment |
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
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 wouldis_constructible
determine ifA
is constructible ifA
is not a complete type?
– François Andrieux
Apr 24 at 13:56
1
@FrançoisAndrieux: IfA
isn't complete, we can't construct it (A a;
on an incomplete classA
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 ifstd::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 templatedclass A
that only had specific parameters instantiated. We then used SFINAE withstd::is_constructible
so that only certain types of types were allowed through. This is easily done correctly by explicitly instantiating a defaultclass 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
add a comment |
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
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
c++ c++11 language-lawyer
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 wouldis_constructible
determine ifA
is constructible ifA
is not a complete type?
– François Andrieux
Apr 24 at 13:56
1
@FrançoisAndrieux: IfA
isn't complete, we can't construct it (A a;
on an incomplete classA
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 ifstd::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 templatedclass A
that only had specific parameters instantiated. We then used SFINAE withstd::is_constructible
so that only certain types of types were allowed through. This is easily done correctly by explicitly instantiating a defaultclass 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
add a comment |
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 wouldis_constructible
determine ifA
is constructible ifA
is not a complete type?
– François Andrieux
Apr 24 at 13:56
1
@FrançoisAndrieux: IfA
isn't complete, we can't construct it (A a;
on an incomplete classA
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 ifstd::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 templatedclass A
that only had specific parameters instantiated. We then used SFINAE withstd::is_constructible
so that only certain types of types were allowed through. This is easily done correctly by explicitly instantiating a defaultclass 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
add a comment |
3 Answers
3
active
oldest
votes
The behavior is undefined.
[meta.unary.prop]
template <class T, class... Args> struct is_constructible;
T
and all types in the parameter packArgs
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.
add a comment |
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.
add a comment |
Your code has undefined behavior. Per [meta.unary.prop] table 47 std::is_constructible
requires
T
and all types in the template parameter packArgs
shall be complete types, cvvoid
, or arrays of unknown bound.
emphasis mine
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
The behavior is undefined.
[meta.unary.prop]
template <class T, class... Args> struct is_constructible;
T
and all types in the parameter packArgs
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.
add a comment |
The behavior is undefined.
[meta.unary.prop]
template <class T, class... Args> struct is_constructible;
T
and all types in the parameter packArgs
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.
add a comment |
The behavior is undefined.
[meta.unary.prop]
template <class T, class... Args> struct is_constructible;
T
and all types in the parameter packArgs
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.
The behavior is undefined.
[meta.unary.prop]
template <class T, class... Args> struct is_constructible;
T
and all types in the parameter packArgs
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.
edited Apr 24 at 18:23
answered Apr 24 at 13:47
StoryTellerStoryTeller
107k15224288
107k15224288
add a comment |
add a comment |
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.
add a comment |
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.
add a comment |
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.
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.
answered Apr 24 at 13:47
Nellie DanielyanNellie Danielyan
807517
807517
add a comment |
add a comment |
Your code has undefined behavior. Per [meta.unary.prop] table 47 std::is_constructible
requires
T
and all types in the template parameter packArgs
shall be complete types, cvvoid
, or arrays of unknown bound.
emphasis mine
add a comment |
Your code has undefined behavior. Per [meta.unary.prop] table 47 std::is_constructible
requires
T
and all types in the template parameter packArgs
shall be complete types, cvvoid
, or arrays of unknown bound.
emphasis mine
add a comment |
Your code has undefined behavior. Per [meta.unary.prop] table 47 std::is_constructible
requires
T
and all types in the template parameter packArgs
shall be complete types, cvvoid
, or arrays of unknown bound.
emphasis mine
Your code has undefined behavior. Per [meta.unary.prop] table 47 std::is_constructible
requires
T
and all types in the template parameter packArgs
shall be complete types, cvvoid
, or arrays of unknown bound.
emphasis mine
answered Apr 24 at 13:48
NathanOliverNathanOliver
100k16139221
100k16139221
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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 ifA
is constructible ifA
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 classA
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 withstd::is_constructible
so that only certain types of types were allowed through. This is easily done correctly by explicitly instantiating a defaultclass 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