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 9271615

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T15:39:54+00:00 2026-06-18T15:39:54+00:00

The following program, when compiled with either GCC 4.7 and clang 3.2, produces 1

  • 0

The following program, when compiled with either GCC 4.7 and clang 3.2, produces “1” as output.

#include <type_traits>

struct foo {
    template<typename T>
    foo(T) {
        static_assert(not std::is_same<int, T>(), "no ints please");
    }
};

#include <iostream>    
int main() {
    std::cout << std::is_constructible<foo, int>();
}

This is confusing. foo is quite clearly not constructible from int! If I change main to the following, both compilers reject it due to the static assertion failing:

int main() {
    foo(0);
}

How come both compilers say it is constructible?

  • 0 0 Answers
  • 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-18T15:39:55+00:00Added an answer on June 18, 2026 at 3:39 pm

    This is what the standard has to say (§20.9.5/6), with my emphasis:

    Given the following function prototype:

    template <class T>
    typename add_rvalue_reference<T>::type create();
    

    the predicate condition for a template specialization
    is_constructible<T, Args...> shall be satisfied if and only if the
    following variable definition would be well-formed for some invented
    variable t:

    T t(create<Args>()...);
    

    [ Note: These tokens are never interpreted as a function
    declaration. —end note ]

    Access checking is performed as if in a context unrelated to T and
    any of the Args. Only the validity of the immediate context of the
    variable initialization is considered.
    [ Note: The evaluation of the
    initialization can result in side effects such as the instantiation of
    class template specializations and function template specializations,
    the generation of implicitly-defined functions, and so on. Such side
    effects are not in the “immediate context” and can result in the
    program being ill-formed. —end note ]

    The assertion only fails when the template constructor is instantiated. However, as cleared up in the note, that assertion is not in the immediate context of the variable definition that is considered, and thus does not affect its “validity”. So the compilers can count that definition as valid, and thus claim that foo is indeed constructible from int, even if actually attempting to construct a foo from an int results in an ill-formed program.

    Note that the compilers are also allowed to, instead of having is_constructible yield false, just reject the original program based on the assertion, even though neither one does.

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

Sidebar

Related Questions

I successfully compiled the following program simple.cc: #include <gtkmm.h> int main (int argc, char
I compiled the following program with gcc -fprofile-arcs -ftest-coverage test.c: int main() { int
The following program, compiled with g++ 4.6, yields the error request for member ‘y’
The following C++ program compiles and runs as expected: #include <stdio.h> int main(int argc,
I'm trying to compile the following program: #include<functional> #include<iostream> int main(int argc, char* argv[],
Hi I have the following program. When I compile on the terminal gcc main.c
I compile my C++ program to LLVM IR using the following command. clang++ -O4
Consider the following C++ Program #include<map> #include<iostream> int main() { int a = 5,
I compiled the following code: // Triangle.cpp // Our first OpenGL program that will
I tried to run my program compiled with Apple GCC 3.2.1 (forced 32-bit mode,

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.