[Bug c++/52008] [C++0x] ICE when adding partial specialization for variadic-templated structure

2012-11-06 Thread daniel.kruegler at googlemail dot com

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

Daniel Krügler daniel.kruegler at googlemail dot com changed:

   What|Removed |Added

 CC||daniel.kruegler at
   ||googlemail dot com

--- Comment #11 from Daniel Krügler daniel.kruegler at googlemail dot com 
2012-11-06 19:23:51 UTC ---
The associated core issue 

http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#1495

has now ready state, so I think this issue could now be unsuspended


[Bug c++/52008] [C++0x] ICE when adding partial specialization for variadic-templated structure

2012-04-23 Thread ethouris at gmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52008

--- Comment #10 from Michal Malecki ethouris at gmail dot com 2012-04-23 
12:38:47 UTC ---
(In reply to comment #9)
 (In reply to comment #8)
  2. The code is rejected the following way: the template specialization
  definition is itself rejected because due to not covered explicitly all
  explicit parameters (that is, all but parameter pack) this is not considered
  template specialization.
 
 Right, because the partial specialization doesn't specialize the Type1
 parameter, it is not more specialized than the primary template.

It's not the problem that it's not more specialized (because it is, as long
as we state it's correct), but rather that it's not correctly defined partial
specialization.

I have tried to find some confirmation in the C++ standard; I think the
14.5.5/4 should make things clear:

(...)
Specifically, the order of the template arguments is the sequence in which they
appear in the template parameter list.
(...)

There are no specific statements for template specializations in case of
variadic parameters. It's important because there are two theoretical
possibilities:

1. First there happens the parameter pack expansion, and then the potential
specialization is verified against the primary template. This way the
specialization can only be rejected if the resulting parameter list does not
match the primary template.

2. First the potential specialization is verified against the primary template,
and then the parameter pack is expanded. In this case the mentioned code is
invalid because the second definition cannot be considered partial
specialization of the tuple_sliced class.

By literally adhering to this rule in the standard, the #2 solution should be
taken. It would be also hard to apply #1 for templates that are also variadic
(to expand the parameter pack, it must be instantiated, and after
instantiation, specializations can no longer be considered).

So, this code should be rejected already at the place of definition of the
specialization, with the explanation, that the arguments passed to the
specialization must exactly match arguments defined in the primary template
(even if it's a parameter pack).

The only thing I have doubts of is whether this is then correct:

template class A, typename... V class X;
template class B, class C, typename... V class Xint, B, C, V...;

According to the cited rule in the standard, it's not - the only allowed would
be int, V... or C, V

 You should rewrite your code the way I did, and then do something to address
 the ambiguity; possibly a third partial specialization.

It's not a problem to rewrite the above code so that it works as expected:

templatebool cond, typename TypeIfSo, typename TypeIfNot
struct TypeIf { typedef TypeIfNot type; };

templatetypename TypeIfSo, typename TypeIfNot
struct TypeIftrue, TypeIfSo, TypeIfNot { typedef TypeIfSo type; };

template size_t B, typename Type1, typename... Types
struct tuple_sliced
{
typedef typename
TypeIfB==0,
tupleTypes...,
tuple_slicedB-1, Types...
::type type;
};

Important thing is that the initial code, even though incorrect, should result
in correct rejection and error report.


[Bug c++/52008] [C++0x] ICE when adding partial specialization for variadic-templated structure

2012-04-21 Thread ethouris at gmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52008

--- Comment #8 from Michal Malecki ethouris at gmail dot com 2012-04-21 
12:06:36 UTC ---
Jason,

There is no better or worse specialization - the first one is a primary
template, not a specialization.

The example of tuple_slice1, int, int, int will just not match the
specialization with first argument 0 because, simply, here the first argument
is 1.

I have stated that the parameter pack is itself not a type specification, just
a higher level construct that will be first resolved to the actual list of
arguments and only then checked for anything else. But I'm not exactly sure of
that, so maybe the argument pack specification should undergo specialization
rules by itself.

There are, for me, only two logical methods to solve this problem:

1. The code is accepted, even though it violates the standard a bit; pedantic
flags may turn it off. In particular, the specialization is treated as really a
specialization because it matches the name and all tries to instantiate the
primary template can be redirected to the specialization, as long as it matches
the specialized argument. Both the specialization and the primary template are
considered only after the argument pack is expanded, in which case both will
expand to exactly the same list of arguments - so the expanded versions will
have the primary-specialization relationship.

2. The code is rejected the following way: the template specialization
definition is itself rejected because due to not covered explicitly all
explicit parameters (that is, all but parameter pack) this is not considered
template specialization. But the template specialization can only be considered
invalidly defined specialization, if template parameters that are passed to the
template are incorrect according to the template parameter definition in the
primary template.


[Bug c++/52008] [C++0x] ICE when adding partial specialization for variadic-templated structure

2012-04-21 Thread jason at gcc dot gnu.org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52008

--- Comment #9 from Jason Merrill jason at gcc dot gnu.org 2012-04-21 
13:06:10 UTC ---
(In reply to comment #8)
 There is no better or worse specialization - the first one is a primary
 template, not a specialization.

But if it were another partial specialization, it would not be less
specialized, and I think a partial specialization must be more specialized than
a hypothetical partial specialization form of the primary template.

 The example of tuple_slice1, int, int, int will just not match the
 specialization with first argument 0 because, simply, here the first argument
 is 1.

Right, that one isn't ambiguous, but then it leads to the instantiation of
tuple_slice0,int,int which is.

 2. The code is rejected the following way: the template specialization
 definition is itself rejected because due to not covered explicitly all
 explicit parameters (that is, all but parameter pack) this is not considered
 template specialization.

Right, because the partial specialization doesn't specialize the Type1
parameter, it is not more specialized than the primary template.

You should rewrite your code the way I did, and then do something to address
the ambiguity; possibly a third partial specialization.


[Bug c++/52008] [C++0x] ICE when adding partial specialization for variadic-templated structure

2012-04-20 Thread ethouris at gmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52008

Michal Malecki ethouris at gmail dot com changed:

   What|Removed |Added

 Status|RESOLVED|REOPENED
 Resolution|FIXED   |

--- Comment #5 from Michal Malecki ethouris at gmail dot com 2012-04-20 
13:33:35 UTC ---
Hey, guys, not too fast.

Why do you say it's not more specialized?

The primary template contains size_t B as the first template parameter, and
the specialization puts explicit 0 in this place. According to the standard,
this IS a specialization.

Of course, it works now if you change the terminal definition into:

templatetypename Type1, typename... Types
struct tuple_sliced0, Type1, Types...
{
typedef tupleType1, Types... type;
};

But it's roughly the same - the only difference is that it doesn't manage an
interesting case of slicing to 0 (actually I should change it to 1). Whether
the specialization really matches the primary template, it should be decided
when the variadic parameters are expanded, so if this is correct, the cited one
should be correct, too.


[Bug c++/52008] [C++0x] ICE when adding partial specialization for variadic-templated structure

2012-04-20 Thread paolo.carlini at oracle dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52008

Paolo Carlini paolo.carlini at oracle dot com changed:

   What|Removed |Added

 Status|REOPENED|SUSPENDED

--- Comment #6 from Paolo Carlini paolo.carlini at oracle dot com 2012-04-20 
15:40:09 UTC ---
The issue isn't whether it's a specialization or not, but whether it's
technically more specialized. I didn't personally check in detail but Jason
argued on the ISO reflector that is not ([c++std-core-21739]). And the reason
why currently other front-ends accept the code is that they pick the primary
for the instantiation. Thus this should be made more explicitly ill-formed in
the standard with a DR. Let's suspend the PR for now.


[Bug c++/52008] [C++0x] ICE when adding partial specialization for variadic-templated structure

2012-04-20 Thread jason at gcc dot gnu.org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52008

--- Comment #7 from Jason Merrill jason at gcc dot gnu.org 2012-04-21 
01:46:29 UTC ---
If you rewrite the test so that the two versions are both partial
specializations:

template size_t, typename... struct tuple_sliced;

template size_t B, typename Type1, typename... Types
struct tuple_slicedB, Type1, Types...
{
typedef typename tuple_slicedB-1, Types...::type type;
};

templatetypename... Types
struct tuple_sliced0, Types...  // -- line 18
{
typedef tupleTypes... type;
};

and then you try to instantiate it:

tuple_sliced1,int,int,int t;

the instantiation is ambiguous.  The second partial specialization is more
specialized for the first argument 0, but the first partial specialization is
more specialized for the parameter pack, because it requires at least one
argument.  So neither is more specialized than the other, and so in the same
way in the original testcase the partial specialization is not more specialized
than the primary template.


[Bug c++/52008] [C++0x] ICE when adding partial specialization for variadic-templated structure

2012-04-17 Thread jason at gcc dot gnu.org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52008

Jason Merrill jason at gcc dot gnu.org changed:

   What|Removed |Added

 Status|ASSIGNED|RESOLVED
 Resolution||FIXED
   Target Milestone|--- |4.8.0

--- Comment #4 from Jason Merrill jason at gcc dot gnu.org 2012-04-17 
15:27:31 UTC ---
4.8 will reject the testcase with a more helpful message.


[Bug c++/52008] [C++0x] ICE when adding partial specialization for variadic-templated structure

2012-04-16 Thread jason at gcc dot gnu.org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52008

Jason Merrill jason at gcc dot gnu.org changed:

   What|Removed |Added

 Status|NEW |ASSIGNED
 CC||jason at gcc dot gnu.org
 AssignedTo|unassigned at gcc dot   |jason at gcc dot gnu.org
   |gnu.org |

--- Comment #2 from Jason Merrill jason at gcc dot gnu.org 2012-04-16 
16:51:08 UTC ---
This example is problematic because the partial specialization is not more
specialized than the primary template; we should reject it with an error rather
than crashing.


[Bug c++/52008] [C++0x] ICE when adding partial specialization for variadic-templated structure

2012-04-16 Thread jason at gcc dot gnu.org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52008

--- Comment #3 from Jason Merrill jason at gcc dot gnu.org 2012-04-17 
02:29:47 UTC ---
Author: jason
Date: Tue Apr 17 02:29:43 2012
New Revision: 186521

URL: http://gcc.gnu.org/viewcvs?root=gccview=revrev=186521
Log:
PR c++/52008
* pt.c (process_partial_specialization): Complain about a partial
specialization with fewer args than primary template parms.

Added:
trunk/gcc/testsuite/g++.dg/cpp0x/variadic130.C
Modified:
trunk/gcc/cp/ChangeLog
trunk/gcc/cp/pt.c
trunk/gcc/testsuite/ChangeLog


[Bug c++/52008] [C++0x] ICE when adding partial specialization for variadic-templated structure

2012-01-26 Thread rguenth at gcc dot gnu.org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52008

Richard Guenther rguenth at gcc dot gnu.org changed:

   What|Removed |Added

 Status|UNCONFIRMED |NEW
   Last reconfirmed||2012-01-26
 Ever Confirmed|0   |1
  Known to fail||4.7.0

--- Comment #1 from Richard Guenther rguenth at gcc dot gnu.org 2012-01-26 
11:14:14 UTC ---
Confirmed.