Bug 40055 - Failing instantiation of template with enums
Summary: Failing instantiation of template with enums
Status: RESOLVED WORKSFORME
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.4.0
: P3 normal
Target Milestone: 4.5.0
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-05-07 09:43 UTC by Alexandre Hamez
Modified: 2009-12-25 22:17 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work: 4.5.0
Known to fail: 4.4.2
Last reconfirmed:


Attachments
Associated temporary file (257 bytes, application/octet-stream)
2009-05-07 09:45 UTC, Alexandre Hamez
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Alexandre Hamez 2009-05-07 09:43:23 UTC
The  following code failed with the message (no options are given to the compiler): 

instance.cc: In function 'int main()':
instance.cc:30: error: no matching function for call to 'c_struct<a_tags, a_struct>::c_struct(a0_type&)'
instance.cc:14: note: candidates are: c_struct<a_tags, a_struct>::c_struct(const c_struct<a_tags, a_struct>&)

---------------------------------------

enum a_tags { A0, A1 };
enum b_tags { B0, B1 };

template < a_tags Tag >
struct a_struct
{};

template < b_tags Tag >
struct b_struct
{};

template < typename tags, template < tags > class Element >
struct c_struct
{
  template < tags Tag >
  c_struct(Element< Tag >)
  {}
};

typedef c_struct< a_tags, a_struct > a_type;
typedef c_struct< b_tags, b_struct > b_type;
typedef a_struct< A0 > a0_type;
typedef b_struct< B0 > b0_type;

int main()
{
  a0_type a0;
  b0_type b0;
  b_type b_instance(b0);
  a_type a_instance(a0);
}

------------------------------

But if one of the line:
    b_type b_instance(b0);
    a_type a_instance(a0);
is commented out, then the compilation succeeds.

---------------------------
My g++ version, although I've been able to reproduce this bug with older versions of gcc:
% /usr/local/env/gcc-4.4.0/bin/g++ -v 
Using built-in specs.
Target: i386-apple-darwin9.6.0
Configured with: ../gcc-4.4.0/configure --prefix=/usr/local/env/gcc-4.4.0 --disable-nls --enable-languages=c,c++
Thread model: posix
gcc version 4.4.0 (GCC)
Comment 1 Alexandre Hamez 2009-05-07 09:45:25 UTC
Created attachment 17816 [details]
Associated temporary file
Comment 2 Francois-Xavier Coudert 2009-06-03 21:29:43 UTC
Not target-specific, can reproduce on x86_64-linux (don't know what you expect, though).
Comment 3 Paolo Carlini 2009-12-25 22:17:09 UTC
Works in mainline, not a regression, thus closing as fixed.