This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/24847] New: Instantiates un-called copy constructor


enum A{b,c};
template<typename T, int i, A x>
struct foo {
explicit    foo(T& t);
explicit    foo(foo<T, 0, x>);
};

int main() {
    int i;
    foo<int, 5, b> v(i);
    }


gets you:

~/ootbc/members/src$ g++ foo.cc
foo.cc: In instantiation of `foo<int, 0,  b>':
foo.cc:10:   instantiated from here
foo.cc:5: error: invalid constructor; you probably meant `foo<int, 0,  b>
(const foo<int, 0,  b>&)'

The error arises because it thinks I am instantiating "foo<T, 0,A>(foo<T, 0,
A>)", i.e. a copy constructor that is not taking a const reference argument.
But I'm not; I'm instantiating the plain constructor "foo<T, int, A>(int&)". 

The second constructor is intended to catch the case: "foo<T, 5, A>(foo<T, 0,
A>", i.e. to convert an instance of foo with second argument zero to a foo with
any other second argument. It looks like when it is expanding the argument type
of the second constructor (i.e. "foo<T, 0, A>") that it is not just parsing the
resulting template but also applying the "valid copy constructor?" check for
that type. But as that second constructor is never called by anyone it the
compiler should just syntax check it (valid) and not semantic check it (invalid
for "foo(T, 0, A)" but valid for everything else).

Ivan


-- 
           Summary: Instantiates un-called copy constructor
           Product: gcc
           Version: 3.4.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: igodard at pacbell dot net


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=24847


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]