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 4036152
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T12:11:17+00:00 2026-05-20T12:11:17+00:00

In C++11, should the operation of static_assert within a template depend on whether that

  • 0

In C++11, should the operation of static_assert within a template depend on whether that template has been instantiated or not? For example, with the following code

template <int I>
void sa() { static_assert(0,"Hello."); }

int main(int argc, char *argv[]) { return 0; }

GCC 4.5.0 will fail the assertion, and produce the “Hello.” message.
The Digital Mars Compiler version 8.42n on the other hand, gives no message.

  • 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-05-20T12:11:18+00:00Added an answer on May 20, 2026 at 12:11 pm

    GCC is correct and the other compiler is correct too. Refer to 14.6p8 in the spec

    If no valid specialization can be generated for a template definition, and that template is not instantiated, the template definition is ill-formed, no diagnostic required.

    Therefor, a compiler is free to reject the following

    template<typename T>
    void f() {
      static_assert(0, "may trigger immediately!");
      static_assert(sizeof(T) == 0, "may trigger immediately!");
    }
    

    If you want to go safe, you have to arrange it so the compiler cannot know until instantiation whether the boolean expression will be true or false. For example, get the value by getvalue<T>::value, with getvalue being a class template (one could specialize it, so the compiler cannot possibly know the boolean value already).

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

Sidebar

Related Questions

Why bitwise operation (~0); prints -1 ? In binary , not 0 should be
I am trying to persist an object into the database. This operation should touch
I am trying to figure out where should I put database operation for each
Should timestamps always use UTC (as in 2012-06-14T10:32:11+00:00 ) and not local time (as
I have recently been in a situation where I needed to perform an operation
There should be an error/omission in the next code but I can't see where
ive been asking myself : why should i use lock to only one statement...
I have some old code (pre Java 1.5) that uses classes to implement type
So I have the following the code: namespace ConsoleApplication1 { public delegate int Transformer(int
We use boost - so using that library should be fine. But I've never

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.