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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T22:59:05+00:00 2026-05-21T22:59:05+00:00

Consider next example : #include <iostream> template< int a > void foo(); int main(int

  • 0

Consider next example :

#include <iostream>

template< int a >
void foo();

int main(int argn, char* argv[])
{
    foo<1>();
}

template<>
void foo<1>()
{
    std::cout<<1<<std::endl;
}

The compilation fails with next error messages :

rg.cpp:12: error: specialization of ‘void foo() [with int a = 1]’ after instantiation

What paragraph in the standard explains this error?

PS :I know that if I move the function definition in front of main will make the error go away.

  • 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-21T22:59:05+00:00Added an answer on May 21, 2026 at 10:59 pm

    I think that’s undefined behavior according to the standard. There are no restrictions on what a toolchain can do in cases of UB, generating a compiler error is one of the friendlier possibilities.


    Section [temp.spec], 14.7p5 says

    For a given template and a given set of template-arguments,

    • an explicit instantiation definition shall appear at most once in a program,
    • an explicit specialization shall be defined at most once in a program (according to 3.2), and
    • both an explicit instantiation and a declaration of an explicit specialization shall not appear in a
      program unless the explicit instantiation follows a declaration of the explicit specialization.

    An implementation is not required to diagnose a violation of this rule.

    Section [temp.expl.spec] 14.7.3p6 says:

    If a template, a member template or a member of a class template is explicitly specialized then that specialization shall be declared before the first use of that specialization that would cause an implicit instantiation to take place, in every translation unit in which such a use occurs; no diagnostic is required.


    Your program violates these requirements.

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

Sidebar

Related Questions

Consider following example. #include <iostream> #include <boost/optional.hpp> template < typename A > int boo(
Consider the following code: #include <stdio.h> #include <ctype.h> char* Mstrupr(char* szCad); int main() {
Consider the following example program: next :: Int -> Int next i | 0
Consider these two function definitions: void foo() { } void foo(void) { } Is
Consider this example: struct { int num; } s, *ps; s.num = 0; ps
Consider this example : T(n) = T(7n/8) + 2n I assumed T(1) = 0
Consider the following simple example: One team has many players and a player may
Let me illustrate this with an example. Consider there are 10 books (there may
Consider this simple example: labNames <- c('xLab','yLabl') plot(c(1:10),xlab=expression(paste(labName[1], x^2)),ylab=expression(paste(labName[2], y^2))) What I want is
Consider the following setup: A windows PC with a LAN interface and a WiFi

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.