User account creation filtered due to spam.

Bug 48657 - [4.6/4.7 Regression] could not convert template argument ‘VectorDimension’ to ‘unsigned int’
Summary: [4.6/4.7 Regression] could not convert template argument ‘VectorDimension’ to...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.6.0
: P3 major
Target Milestone: 4.6.1
Assignee: Jason Merrill
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2011-04-18 01:43 UTC by daviddoria
Modified: 2011-05-27 18:10 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work: 4.5.3
Known to fail:
Last reconfirmed: 2011-04-18 09:33:44


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description daviddoria 2011-04-18 01:43:00 UTC
Please see this code:

http://stackoverflow.com/questions/5697546/converting-const-unsigned-int-to-unsigned-int-in-template-parameter

This works fine:

typedef Vector< int, 4 > VectorPixelType;

Where this produces the error:

  const unsigned int VectorDimension = 4;
  typedef Vector< int, VectorDimension >     VectorPixelType;
Comment 1 Jonathan Wakely 2011-04-18 09:33:44 UTC
Confirmed as a regression

template< class T, unsigned int NVectorDimension = 3 >
class Vector
{
};

template< unsigned int TDimension >
int RunTest( void )
{
  const unsigned int VectorDimension = 4;
  typedef Vector< int, VectorDimension >     VectorPixelType;
}

int main()
{
  return 0;
}
Comment 2 Jakub Jelinek 2011-04-18 10:31:47 UTC
Started with http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=166011
Comment 3 Jakub Jelinek 2011-04-18 13:47:57 UTC
VectorDimension's DECL_INITIAL has different type (int rather than unsigned int), and when build_integral_nontype_arg_conv calls convert_like for ck_identity conversion that DECL_INITIAL is returned, which doesn't have correct type and thus caller complains.
Comment 4 Jason Merrill 2011-04-20 19:39:05 UTC
Author: jason
Date: Wed Apr 20 19:39:02 2011
New Revision: 172790

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=172790
Log:
	PR c++/48657
	* decl.c (cp_finish_decl): Simplify template handling.

Added:
    trunk/gcc/testsuite/g++.dg/template/const4.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/decl.c
    trunk/gcc/testsuite/ChangeLog
Comment 5 Jason Merrill 2011-04-20 19:39:29 UTC
Author: jason
Date: Wed Apr 20 19:39:26 2011
New Revision: 172791

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=172791
Log:
	PR c++/48657
	* decl.c (cp_finish_decl): Handle non-member constant variables
	in templates, too.

Added:
    branches/gcc-4_6-branch/gcc/testsuite/g++.dg/template/const4.C
Modified:
    branches/gcc-4_6-branch/gcc/cp/ChangeLog
    branches/gcc-4_6-branch/gcc/cp/decl.c
    branches/gcc-4_6-branch/gcc/testsuite/ChangeLog
Comment 6 Jason Merrill 2011-04-20 22:19:44 UTC
Fixed
Comment 7 Jason Merrill 2011-05-27 18:10:52 UTC
Author: jason
Date: Fri May 27 18:10:48 2011
New Revision: 174346

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=174346
Log:
	PR c++/48657
	PR c++/49176
	* decl.c (cp_finish_decl): Simplify template handling.

Added:
    branches/gcc-4_6-branch/gcc/testsuite/g++.dg/template/const5.C
Modified:
    branches/gcc-4_6-branch/gcc/cp/ChangeLog
    branches/gcc-4_6-branch/gcc/cp/decl.c
    branches/gcc-4_6-branch/gcc/testsuite/ChangeLog