Bug 18747 - "template<> int i;" accepted
Summary: "template<> int i;" accepted
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.0.0
: P2 normal
Target Milestone: 4.8.0
Assignee: Not yet assigned to anyone
URL:
Keywords: accepts-invalid, monitored
: 41875 (view as bug list)
Depends on:
Blocks:
 
Reported: 2004-12-01 02:12 UTC by Volker Reichelt
Modified: 2012-09-05 15:13 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2006-09-17 07:48:26


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Volker Reichelt 2004-12-01 02:12:35 UTC
The following invalid line of code is accepted since at least gcc 2.95.x:

===========================
template<> int i;
===========================
Comment 1 Andrew Pinski 2004-12-01 03:01:55 UTC
Confirmed.
Comment 2 Sambit Kumar Dash 2006-06-05 06:29:28 UTC
So is:

struct A
{
};

template<> A i;

which means the specilization syntax does not mandate a need the qualifying class needs to be a template type. That looks interesting!!!
Comment 3 Sambit Kumar Dash 2006-06-05 13:46:13 UTC
From the C++ standard draft specification

An explicit specialization of any of the following:
— function template
— class template
— member function of a class template
— static data member of a class template
— member class of a class template
— member class template of a class template
— member function template of a class template
can be declared by a declaration introduced by template<>; that is:
explicit specialization:
template < > declaration

Hence this is a bug. 
Comment 4 Volker Reichelt 2009-10-30 12:41:15 UTC
*** Bug 41875 has been marked as a duplicate of this bug. ***
Comment 5 Paolo Carlini 2012-08-23 13:06:51 UTC
Looking into it.
Comment 6 Jason Merrill 2012-08-31 21:35:38 UTC
Author: jason
Date: Fri Aug 31 21:35:33 2012
New Revision: 190842

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=190842
Log:
	PR c++/18747
	* pt.c (check_template_variable): New.
	(num_template_headers_for_class): Split out...
	* decl.c (grokdeclarator): ...from here.
	(start_decl): Remove redundant diagnostic.
	* cp-tree.h: Declare them
	* parser.c (cp_parser_single_declaration): Call check_template_variable.
.

Added:
    trunk/gcc/testsuite/g++.dg/parse/error50.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/cp-tree.h
    trunk/gcc/cp/decl.c
    trunk/gcc/cp/parser.c
    trunk/gcc/cp/pt.c
    trunk/gcc/testsuite/ChangeLog
Comment 7 Paolo Carlini 2012-09-05 15:13:20 UTC
Ah, this is fixed, then.