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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T18:35:55+00:00 2026-06-02T18:35:55+00:00

From the book – C++ Templates: The Complete Guide by David, Nicolai Thus, templates

  • 0

From the book – C++ Templates: The Complete Guide by David, Nicolai

Thus, templates are compiled twice:

  1. Without instantiation, the template code itself is checked for correct syntax. Syntax errors are discovered, such as missing
    semicolons.
  2. At the time of instantiation, the template code is checked to ensure that all calls are valid. Invalid calls are discovered, such as
    unsupported function calls.

Keeping the first point, I wrote –

template<typename T>
void foo( T x)
{
   some illegal text
}

int main()
{
   return 0;
}

It build fine on Visual Studio 2010 with out any warnings with optimizations turned off. How ever, it failed on gcc-4.3.4. Which one is complying to the C++ standard ? Is it mandatory for template code to get compiled even with out template instantiation ?

  • 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-06-02T18:35:57+00:00Added an answer on June 2, 2026 at 6:35 pm

    The program in question is ill-formed, but the C++ standard does not require a diagnostic in this case, so both Visual Studio and GCC are behaving in a compliant fashion. From §14.6/7 of the C++03 standard (emphasis mine):

    Knowing which names are type names allows the syntax of every template definition to be checked. No
    diagnostic shall be issued for a template definition for which a valid specialization can be generated. 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.
    If a type used in a non-dependent name is incomplete
    at the point at which a template is defined but is complete at the point at which an instantiation is done, and
    if the completeness of that type affects whether or not the program is well-formed or affects the semantics
    of the program, the program is ill-formed; no diagnostic is required. [Note: if a template is instantiated,
    errors will be diagnosed according to the other rules in this Standard. Exactly when these errors are diagnosed
    is a quality of implementation issue. ] [Example:

    int j;
    template<class T> class X {
        // ...
        void f(T t, int i, char* p)
        {
            t = i; // diagnosed if X::f is instantiated
                   // and the assignment to t is an error
            p = i; // may be diagnosed even if X::f is
                   // not instantiated
            p = j; // may be diagnosed even if X::f is
                   // not instantiated
        }
        void g(T t) {
            +; //may be diagnosed even if X::g is
               // not instantiated
        }
    };
    

    —end example]

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

Sidebar

Related Questions

From the book Groovy and Grails recipes I'm using the following code snippet: String
I get this code from a book but i could not get it work.
The following code snippet is from book Effective C#, public event AddMessageEventHandler Log; public
I am learning jQuery from book Learning jQuery, and found part of code that
From book Java Concurrency in Practice page 26: You can use volatile variables only
From the book Agile Web Development With Rails class Order < ActiveRecord::Base named_scope :last_n_days,
From a book A common convention is to use .inc for all include files.
Excerpt from a book: A float value consists of a 24-bit signed mantissa and
How to access Offline Address Book (from exchange server/outlook configured to exchange machine) using
Here's an excerpt from a book I'm reading about application design with MVC: Ideally,

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.