Bug 27339 - [4.1 Regression] out-of-class definition of value template parameter with private type
Summary: [4.1 Regression] out-of-class definition of value template parameter with pri...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.1.0
: P1 normal
Target Milestone: 4.1.1
Assignee: Mark Mitchell
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2006-04-27 16:28 UTC by Dirk Moermans
Modified: 2006-05-16 14:55 UTC (History)
5 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2006-04-30 16:29:22


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Dirk Moermans 2006-04-27 16:28:02 UTC
Following code does not compile with gcc 4.1.
It compiles with gcc 3.4.0 and gcc 4.0.2 and comeau online.

=============================
class A 
{
private: 
  enum private_enum {a};

  template<A::private_enum v>  // OK 
  struct B
  {
    void bm();
  }; 
public: 
  void am() 
  { 
    B<a> instance; //OK
    instance.bm();
  }
};

template<A::private_enum v>  // FAIL
void
A::B<v>::bm(){}
=============================
The error message is:
a.cc:4: error: 'enum A::private_enum' is private
a.cc:19: error: within this context

If the member template function gets defined inline, the code compiles. 
I don't have the c++ standard available, but a technicality like an inline/outline definition should have no impact on the validity of the code imho. 

The same error occurrs if the enum gets replaced by a function template typedef, or if the inner-class gets replaced by a member-function-template.

A related bug is 10849
Comment 1 Andrew Pinski 2006-04-30 16:29:22 UTC
Confirmed.

Janis, could you do a regression hunt on this bug?
Thanks.
Comment 2 Janis Johnson 2006-05-02 16:16:49 UTC
A regression hunt on powerpc-linux identified this patch:

    http://gcc.gnu.org/viewcvs?view=rev&rev=105682

    r105682 | mmitchel | 2005-10-20 18:01:52 +0000 (Thu, 20 Oct 2005)
Comment 3 Mark Mitchell 2006-05-16 05:40:19 UTC
Subject: Bug 27339

Author: mmitchel
Date: Tue May 16 05:39:49 2006
New Revision: 113819

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=113819
Log:
	PR c++/27339
	* cp-tree.h (perform_access_checks): New function.
	* semantics.c (perform_access_checks): New function.
	(perform_deferred_access_checks): Use it.
	* parser.c (cp_parser_simple_declaration): Adjust call to
	cp_parser_init_declarator.
	(cp_parser_type_parameter): Do not defer checks in default
	arguments.
	(cp_parser_explicit_specialization): Adjust call to
	cp_parser_single_declaration.
	(cp_parser_init_declarator): Perform template-parameter access
	checks. 
	(cp_parser_parameter_declaration): Do not defer checks for
	template parameter default arguments.
	(cp_parser_template_declaration_after_export): Gather access
	checks for template parameters, and pass them to
	cp_parser_single_declaration.
	(cp_parser_template_parameter_access_checks): New function.
	(cp_parser_single_declaration): Add checks parameter.
	PR c++/27339
	* g++.dg/parser/access8.C: Adjust error marker.
	* g++.dg/template/access17.C: New test.
	* g++.dg/template/access18.C: Likewise.

Added:
    trunk/gcc/testsuite/g++.dg/template/access17.C
    trunk/gcc/testsuite/g++.dg/template/access18.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/cp-tree.h
    trunk/gcc/cp/parser.c
    trunk/gcc/cp/semantics.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/g++.dg/parse/access8.C

Comment 4 Mark Mitchell 2006-05-16 05:43:22 UTC
Fixed in 4.2.0.
Comment 5 Mark Mitchell 2006-05-16 14:55:16 UTC
Fixed in 4.1.1.
Comment 6 Mark Mitchell 2006-05-16 14:55:38 UTC
Subject: Bug 27339

Author: mmitchel
Date: Tue May 16 14:54:55 2006
New Revision: 113825

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=113825
Log:
	PR c++/27339
	* cp-tree.h (perform_access_checks): New function.
	* semantics.c (perform_access_checks): New function.
	(perform_deferred_access_checks): Use it.
	* parser.c (cp_parser_simple_declaration): Adjust call to
	cp_parser_init_declarator.
	(cp_parser_type_parameter): Do not defer checks in default
	arguments.
	(cp_parser_explicit_specialization): Adjust call to
	cp_parser_single_declaration.
	(cp_parser_init_declarator): Perform template-parameter access
	checks. 
	(cp_parser_parameter_declaration): Do not defer checks for
	template parameter default arguments.
	(cp_parser_template_declaration_after_export): Gather access
	checks for template parameters, and pass them to
	cp_parser_single_declaration.
	(cp_parser_template_parameter_access_checks): New function.
	(cp_parser_single_declaration): Add checks parameter.
	PR c++/27339
	* g++.dg/parser/access8.C: Adjust error marker.
	* g++.dg/template/access17.C: New test.
	* g++.dg/template/access18.C: Likewise.

Added:
    branches/gcc-4_1-branch/gcc/testsuite/g++.dg/template/access17.C
    branches/gcc-4_1-branch/gcc/testsuite/g++.dg/template/access18.C
Modified:
    branches/gcc-4_1-branch/gcc/cp/ChangeLog
    branches/gcc-4_1-branch/gcc/cp/cp-tree.h
    branches/gcc-4_1-branch/gcc/cp/parser.c
    branches/gcc-4_1-branch/gcc/cp/semantics.c
    branches/gcc-4_1-branch/gcc/testsuite/ChangeLog
    branches/gcc-4_1-branch/gcc/testsuite/g++.dg/parse/access8.C