public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/29704]  New: ICE: default non-type template argument of pointer-to-member type
@ 2006-11-03 22:06 jens dot maurer at gmx dot net
  2006-11-05  8:33 ` [Bug c++/29704] " pinskia at gcc dot gnu dot org
                   ` (11 more replies)
  0 siblings, 12 replies; 13+ messages in thread
From: jens dot maurer at gmx dot net @ 2006-11-03 22:06 UTC (permalink / raw)
  To: gcc-bugs

This little program:

class C;

template <void (C::*pmf)(int) = (void(C::*)(int))0 >
struct S { };

S<> s;

yields this little ICE:

440-gcc-crash.cc:6: internal compiler error: in uses_template_parms, at
cp/pt.c:5024
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://gcc.gnu.org/bugs.html> for instructions.

(I believe the program should be valid, see section 14.3.2p1 in the C++
standard.)


-- 
           Summary: ICE: default non-type template argument of pointer-to-
                    member type
           Product: gcc
           Version: 4.1.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: jens dot maurer at gmx dot net
 GCC build triplet: i686-pc-linux-gnu
  GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu


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


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug c++/29704] ICE: default non-type template argument of pointer-to-member type
  2006-11-03 22:06 [Bug c++/29704] New: ICE: default non-type template argument of pointer-to-member type jens dot maurer at gmx dot net
@ 2006-11-05  8:33 ` pinskia at gcc dot gnu dot org
  2006-11-06 20:40 ` [Bug c++/29704] [4.1 Regression] " pinskia at gcc dot gnu dot org
                   ` (10 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2006-11-05  8:33 UTC (permalink / raw)
  To: gcc-bugs

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 533 bytes --]



------- Comment #1 from pinskia at gcc dot gnu dot org  2006-11-05 08:33 -------
4.2.0 rejects the code with the following error message:
[pinskia@celery ~]$ ~/gcc-4.2/bin/gcc t1.cc
t1.cc:6: error: a cast to a type other than an integral or enumeration type
cannot appear in a constant-expression
t1.cc:6: error: template argument 1 is invalid
t1.cc:6: error: invalid type in declaration before ‘;’ token


4.0.4 accepts this code without any warning or error messages.


-- 


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


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug c++/29704] [4.1 Regression] ICE: default non-type template argument of pointer-to-member type
  2006-11-03 22:06 [Bug c++/29704] New: ICE: default non-type template argument of pointer-to-member type jens dot maurer at gmx dot net
  2006-11-05  8:33 ` [Bug c++/29704] " pinskia at gcc dot gnu dot org
@ 2006-11-06 20:40 ` pinskia at gcc dot gnu dot org
  2006-11-13  3:39 ` mmitchel at gcc dot gnu dot org
                   ` (9 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2006-11-06 20:40 UTC (permalink / raw)
  To: gcc-bugs



-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|ICE: default non-type       |[4.1 Regression] ICE:
                   |template argument of        |default non-type template
                   |pointer-to-member type      |argument of pointer-to-
                   |                            |member type
   Target Milestone|---                         |4.1.2


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


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug c++/29704] [4.1 Regression] ICE: default non-type template argument of pointer-to-member type
  2006-11-03 22:06 [Bug c++/29704] New: ICE: default non-type template argument of pointer-to-member type jens dot maurer at gmx dot net
  2006-11-05  8:33 ` [Bug c++/29704] " pinskia at gcc dot gnu dot org
  2006-11-06 20:40 ` [Bug c++/29704] [4.1 Regression] " pinskia at gcc dot gnu dot org
@ 2006-11-13  3:39 ` mmitchel at gcc dot gnu dot org
  2006-11-14  3:45 ` bangerth at dealii dot org
                   ` (8 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: mmitchel at gcc dot gnu dot org @ 2006-11-13  3:39 UTC (permalink / raw)
  To: gcc-bugs



-- 

mmitchel at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P3                          |P2


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


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug c++/29704] [4.1 Regression] ICE: default non-type template argument of pointer-to-member type
  2006-11-03 22:06 [Bug c++/29704] New: ICE: default non-type template argument of pointer-to-member type jens dot maurer at gmx dot net
                   ` (2 preceding siblings ...)
  2006-11-13  3:39 ` mmitchel at gcc dot gnu dot org
@ 2006-11-14  3:45 ` bangerth at dealii dot org
  2006-11-14 20:24 ` jens dot maurer at gmx dot net
                   ` (7 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: bangerth at dealii dot org @ 2006-11-14  3:45 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from bangerth at dealii dot org  2006-11-14 03:45 -------
I believe the code is in fact invalid, based on 14.3.2/1 and this wording 
in 14.3.2/5:

--  For  a  non-type  template-parameter  of  type  pointer  to member
      function,  no  conversions  apply.

The latter reference means that there is also no way to simply say
  template <void (C::*pmf)(int) = 0 >
  struct S { };
because the argument is not converted.

W.


-- 


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


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug c++/29704] [4.1 Regression] ICE: default non-type template argument of pointer-to-member type
  2006-11-03 22:06 [Bug c++/29704] New: ICE: default non-type template argument of pointer-to-member type jens dot maurer at gmx dot net
                   ` (3 preceding siblings ...)
  2006-11-14  3:45 ` bangerth at dealii dot org
@ 2006-11-14 20:24 ` jens dot maurer at gmx dot net
  2006-11-15  2:09 ` bangerth at dealii dot org
                   ` (6 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: jens dot maurer at gmx dot net @ 2006-11-14 20:24 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from jens dot maurer at gmx dot net  2006-11-14 20:24 -------
I agree with Wolfgang's interpretation of the standard, but can't see why it
renders my original code invalid.

14.3.2/1 says that "a constant expression that evaluates to a null member
pointer value" is allowed as a non-type template argument, with an explicit
reference to 4.11, which explains how to obtain one (i.e. convert a null
pointer constant, e.g. 0, to a pointer-to-member type).  That's what my
original example does.  14.3.2/5 then says "The following conversions are
performed on each expression used as a non-type template-argument."  There are
indeed no conversions performed for pointer-to-members, but the expression I
supplied for the non-type template-argument was "(void(C::*)(int))0", not just
0 (which would have required an implicit conversion, see 4.11).  And no
conversion is necessary to convert an expression of that type to the
parameter's type, which is  void(C::*)(int).
(EDG appears to agree with me and accepts the code, FWIW.)


-- 


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


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug c++/29704] [4.1 Regression] ICE: default non-type template argument of pointer-to-member type
  2006-11-03 22:06 [Bug c++/29704] New: ICE: default non-type template argument of pointer-to-member type jens dot maurer at gmx dot net
                   ` (4 preceding siblings ...)
  2006-11-14 20:24 ` jens dot maurer at gmx dot net
@ 2006-11-15  2:09 ` bangerth at dealii dot org
  2006-11-15 21:01 ` jens dot maurer at gmx dot net
                   ` (5 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: bangerth at dealii dot org @ 2006-11-15  2:09 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from bangerth at dealii dot org  2006-11-15 02:09 -------
(In reply to comment #3)
> 14.3.2/1 says that "a constant expression that evaluates to a null member
> pointer value" is allowed as a non-type template argument, with an explicit
> reference to 4.11, which explains how to obtain one

Uh, where is that from? 14.3.2/1 doesn't appear to contain this in neither the
C++98 standard not in the TC edition. I have this code here:

  14.3.2  Template non-type arguments                 [temp.arg.nontype]

1 A  template-argument  for  a non-type, non-template template-parameter
  shall be one of:
  [...]
  --  a pointer to member expressed as described in _expr.unary.op_ .

_expr.unary.op_ is 5.3.1, and in 5.3.1/2, it talks about taking the address
of member functions. It doesn't appear to say anything about conversions...

W.


-- 

bangerth at dealii dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bangerth at dealii dot org


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


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug c++/29704] [4.1 Regression] ICE: default non-type template argument of pointer-to-member type
  2006-11-03 22:06 [Bug c++/29704] New: ICE: default non-type template argument of pointer-to-member type jens dot maurer at gmx dot net
                   ` (5 preceding siblings ...)
  2006-11-15  2:09 ` bangerth at dealii dot org
@ 2006-11-15 21:01 ` jens dot maurer at gmx dot net
  2007-02-14  9:19 ` mmitchel at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: jens dot maurer at gmx dot net @ 2006-11-15 21:01 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from jens dot maurer at gmx dot net  2006-11-15 21:01 -------
Oops, you're right.  I was looking at N2134, the current working paper (not yet
approved as a standard).

Indeed, at the October 2005 meeting of WG21, the resolution for core issue 354
was  voted for incorporation into the working paper, and that resolution added
the sentence I quoted, see
http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#354 .

It's still an ICE, but I admit that ICE-on-valid-code is probably more
important than ICE-on-invalid-code.


-- 


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


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug c++/29704] [4.1 Regression] ICE: default non-type template argument of pointer-to-member type
  2006-11-03 22:06 [Bug c++/29704] New: ICE: default non-type template argument of pointer-to-member type jens dot maurer at gmx dot net
                   ` (6 preceding siblings ...)
  2006-11-15 21:01 ` jens dot maurer at gmx dot net
@ 2007-02-14  9:19 ` mmitchel at gcc dot gnu dot org
  2007-06-07 15:48 ` brolley at redhat dot com
                   ` (3 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: mmitchel at gcc dot gnu dot org @ 2007-02-14  9:19 UTC (permalink / raw)
  To: gcc-bugs



-- 

mmitchel at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|4.1.2                       |4.1.3


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


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug c++/29704] [4.1 Regression] ICE: default non-type template argument of pointer-to-member type
  2006-11-03 22:06 [Bug c++/29704] New: ICE: default non-type template argument of pointer-to-member type jens dot maurer at gmx dot net
                   ` (7 preceding siblings ...)
  2007-02-14  9:19 ` mmitchel at gcc dot gnu dot org
@ 2007-06-07 15:48 ` brolley at redhat dot com
  2007-06-07 15:50 ` brolley at redhat dot com
                   ` (2 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: brolley at redhat dot com @ 2007-06-07 15:48 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from brolley at redhat dot com  2007-06-07 15:48 -------
As Andrew Pinski has noted, 4.2.0 rejects the code with a proper error message.
The latest trunk does the same. The change which fixes this is

2006-08-20  Mark Mitchell  <mark@codesourcery.com>

        PR c++/28341
        * tree.c (cast_valid_in_integral_constant_expression_p): New
        function.
        * cp-tree.h (tsubst_copy_and_build): Adjust prototype.
        * pt.c (tsubst_expr): Add integral_constant_expression_p
        parameter.
        (fold_non_dependent_expr): Adjust callers of
        tsubst_{expr,copy_and_build}.
        (tsubst_friend_function): Likewise.
        (tsubst_template_arg): Likewise.
        (tsubst_default_argument): Likewise.
        (tsubst_decl): Likewise.
        (tsubst): Likewise.
        (tsubst_omp_clasuses): Likewise.
        (regenerate_decl_fromp_template): Likewise.
        (instantiate_decl): Likewise.
        (tsubst_initializer_list): Likewise.
        (tsubst_enum): Likewise.
        (tsubst_expr): Use RECUR throughout.
        (tsubst_copy_and_build): Change definition of RECUR.  Do not allow
        invalid casts in integral constant expressions.

I'm attaching a patch for gcc-4_1_branch which brings in this change.


-- 

brolley at redhat dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |brolley at redhat dot com


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


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug c++/29704] [4.1 Regression] ICE: default non-type template argument of pointer-to-member type
  2006-11-03 22:06 [Bug c++/29704] New: ICE: default non-type template argument of pointer-to-member type jens dot maurer at gmx dot net
                   ` (8 preceding siblings ...)
  2007-06-07 15:48 ` brolley at redhat dot com
@ 2007-06-07 15:50 ` brolley at redhat dot com
  2008-01-13 13:23 ` rguenth at gcc dot gnu dot org
  2008-07-04 15:54 ` jsm28 at gcc dot gnu dot org
  11 siblings, 0 replies; 13+ messages in thread
From: brolley at redhat dot com @ 2007-06-07 15:50 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #7 from brolley at redhat dot com  2007-06-07 15:49 -------
Created an attachment (id=13665)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=13665&action=view)
Proposed Patch


-- 


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


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug c++/29704] [4.1 Regression] ICE: default non-type template argument of pointer-to-member type
  2006-11-03 22:06 [Bug c++/29704] New: ICE: default non-type template argument of pointer-to-member type jens dot maurer at gmx dot net
                   ` (9 preceding siblings ...)
  2007-06-07 15:50 ` brolley at redhat dot com
@ 2008-01-13 13:23 ` rguenth at gcc dot gnu dot org
  2008-07-04 15:54 ` jsm28 at gcc dot gnu dot org
  11 siblings, 0 replies; 13+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2008-01-13 13:23 UTC (permalink / raw)
  To: gcc-bugs

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1283 bytes --]



------- Comment #8 from rguenth at gcc dot gnu dot org  2008-01-13 12:57 -------
3.4 rejects this with

t.C:6: error: `((void (C::*)(int)))0)' is not a valid template argument
t.C:6: error: it must be a pointer-to-member of the form `&X::Y'
t.C:6: error: invalid type in declaration before ';' token

4.0 wrongly accepts it.  4.2 rejects it with:

t.C:6: error: a cast to a type other than an integral or enumeration type
cannot appear in a constant-expression
t.C:6: error: template argument 1 is invalid
t.C:6: error: invalid type in declaration before ‘;’ token


-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|0                           |1
           Keywords|                            |accepts-invalid, ice-on-
                   |                            |invalid-code
      Known to fail|                            |4.0.4 4.1.3
      Known to work|                            |3.4.6 4.2.0
   Last reconfirmed|0000-00-00 00:00:00         |2008-01-13 12:57:48
               date|                            |


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


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug c++/29704] [4.1 Regression] ICE: default non-type template argument of pointer-to-member type
  2006-11-03 22:06 [Bug c++/29704] New: ICE: default non-type template argument of pointer-to-member type jens dot maurer at gmx dot net
                   ` (10 preceding siblings ...)
  2008-01-13 13:23 ` rguenth at gcc dot gnu dot org
@ 2008-07-04 15:54 ` jsm28 at gcc dot gnu dot org
  11 siblings, 0 replies; 13+ messages in thread
From: jsm28 at gcc dot gnu dot org @ 2008-07-04 15:54 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #9 from jsm28 at gcc dot gnu dot org  2008-07-04 15:54 -------
Closing 4.1 branch.


-- 

jsm28 at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED
   Target Milestone|4.1.3                       |4.2.0


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


^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2008-07-04 15:54 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-11-03 22:06 [Bug c++/29704] New: ICE: default non-type template argument of pointer-to-member type jens dot maurer at gmx dot net
2006-11-05  8:33 ` [Bug c++/29704] " pinskia at gcc dot gnu dot org
2006-11-06 20:40 ` [Bug c++/29704] [4.1 Regression] " pinskia at gcc dot gnu dot org
2006-11-13  3:39 ` mmitchel at gcc dot gnu dot org
2006-11-14  3:45 ` bangerth at dealii dot org
2006-11-14 20:24 ` jens dot maurer at gmx dot net
2006-11-15  2:09 ` bangerth at dealii dot org
2006-11-15 21:01 ` jens dot maurer at gmx dot net
2007-02-14  9:19 ` mmitchel at gcc dot gnu dot org
2007-06-07 15:48 ` brolley at redhat dot com
2007-06-07 15:50 ` brolley at redhat dot com
2008-01-13 13:23 ` rguenth at gcc dot gnu dot org
2008-07-04 15:54 ` jsm28 at gcc dot gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).