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

  • Home
  • SEARCH
  • 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 6999371
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:31:57+00:00 2026-05-27T20:31:57+00:00

Old GCC 4.1.2 accepts , and new GCC 4.5.1 accepts , the following program.

  • 0

Old GCC 4.1.2 accepts, and new GCC 4.5.1 accepts, the following program.

But is it actually correct? What does the standard say about declaring a constructor with the type’s template parameter like this?

(I find it interesting that I’m not allowed to do the same in the out-of-line definition.)

#include <iostream>
template <typename T>
struct Foo {
   Foo<T>(); // <---
};

template <typename T>
Foo<T>::Foo() {
  std::cout << ":)";
}

int main() {
   Foo<int> f;
}

The reason I ask is that it was proposed in comments on this answer that GCC may be in error here.

  • 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-27T20:31:58+00:00Added an answer on May 27, 2026 at 8:31 pm

    I will put a mail copy of a possible DR I recently sent out on Christmas here

    Is the following code well formed?

    template<typename T>
    struct A {
      A<T>();
    };
    

    The several compilers that I tested (clang, g++ and comeau conline)
    accept this. Indeed 12.1 does not forbid this (A<T> is a name of that
    class and is not a typedef-name), but 8.3p1 says

    An unqualified-id occurring in a declarator-id shall be a simple
    identifier except for the declaration of some special functions (12.3,
    12.4, 13.5) …

    A constructor is a special member function, but the list of cross
    references does not include 12.1. Does that mean that the above code
    is ill-formed? Or is this an accidental omission?

    If you do the same in an out-of-line definition, you will try to pass template arguments to a constructor. This is valid code

    struct A {
      template<typename T> A();
    };
    
    template<> A::A<int>() { }
    

    The spec says that when the injected class name is used in a qualified name when looking into the scope of the class (just as in A::A), then when name lookup accepts function/constructor names, the injected class name reference will be translated to be resolved to the constructor(s) of that class (if the name lookup context only accepts types, then the name will remain the injected class name, and will denote the class type). After A::A, name lookup is complete and yields the constructor. The <int> can then only be parsed as a template argument list. If there is no template among your constructors, your code will be invalid.

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

Sidebar

Related Questions

I know the C11 standard is only a month old, but the drafts for
I try to compile an old program (which was compiled by cc) using gcc.
I have some old fortran 77 I'm trying to port to gcc on Windows.
Scenario: old legacy code in rpg have to consume data from a new web
Back in the old days, Help was not trivial but possible: generate some funky
I want to build my program with LSB C++ Compiler from the Linux Standard
I am reading an old book about code obfuscation in C (the book was
I'm trying to port some old MSVC C++ code to MinGW/GCC. One problem is
Keeping the old question. See below for resolution. It is probably something simple, but
to use cas, gcc provides some useful functions such as __sync_bool_compare_and_swap but we can

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.