public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/34219]  New: [4.3] gcc doesn't accept const members of variadic templates as const
@ 2007-11-25  0:11 rbuergel at web dot de
  2007-11-25  1:01 ` [Bug c++/34219] " pcarlini at suse dot de
                   ` (10 more replies)
  0 siblings, 11 replies; 12+ messages in thread
From: rbuergel at web dot de @ 2007-11-25  0:11 UTC (permalink / raw)
  To: gcc-bugs

template<typename T, T a, T... Params>
struct max
{
        static const T value = a > max<T, Params>::value ? a : max<T,
Params>::value;
};

template<typename T, T a, T b>
struct max<T, a, b>
{
        static const T value = a > b ? a : b;
};

static const int value1 = max< int, 1, 2>::value;
static const int value2 = max< int, 1, 3, 5>::value;



As the initialization for value1 is accepted as valid, that should be also the
case for value2. But g++ fails with the following error:

g++-4.3.0 -std=c++0x    -c -o test.o test.cpp
test.cpp: In instantiation of 'const int max<int, 1, 3, 5>::value':
test.cpp:14:   instantiated from here
test.cpp:4: error: 'max<int, 1, 3, 5>::value' cannot be initialized by a
non-constant expression when being declared


g++ Version is "gcc version 4.3.0 20071123 (experimental) (GCC)"


-- 
           Summary: [4.3] gcc doesn't accept const members of variadic
                    templates as const
           Product: gcc
           Version: 4.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: rbuergel at web dot de


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


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

* [Bug c++/34219] gcc doesn't accept const members of variadic templates as const
  2007-11-25  0:11 [Bug c++/34219] New: [4.3] gcc doesn't accept const members of variadic templates as const rbuergel at web dot de
@ 2007-11-25  1:01 ` pcarlini at suse dot de
  2007-11-25  3:15 ` pinskia at gcc dot gnu dot org
                   ` (9 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: pcarlini at suse dot de @ 2007-11-25  1:01 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from pcarlini at suse dot de  2007-11-25 01:01 -------
Doug, can you have a look? Adding the missing definitions moves the error to
link-time but it persists: something seems indeed fishy in the front-end code
for static constant members vs variadic templates...


-- 

pcarlini at suse dot de changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |doug dot gregor at gmail dot
                   |                            |com
            Summary|[4.3] gcc doesn't accept    |gcc doesn't accept const
                   |const members of variadic   |members of variadic
                   |templates as const          |templates as const


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


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

* [Bug c++/34219] gcc doesn't accept const members of variadic templates as const
  2007-11-25  0:11 [Bug c++/34219] New: [4.3] gcc doesn't accept const members of variadic templates as const rbuergel at web dot de
  2007-11-25  1:01 ` [Bug c++/34219] " pcarlini at suse dot de
@ 2007-11-25  3:15 ` pinskia at gcc dot gnu dot org
  2007-12-20 21:07 ` dgregor at gcc dot gnu dot org
                   ` (8 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2007-11-25  3:15 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from pinskia at gcc dot gnu dot org  2007-11-25 03:15 -------
value = MAX_EXPR <(int) value, 1>


Which means we did not "inline" the value of the other value.

Confirmed.


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|0                           |1
           Keywords|                            |rejects-valid
   Last reconfirmed|0000-00-00 00:00:00         |2007-11-25 03:15:38
               date|                            |


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


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

* [Bug c++/34219] gcc doesn't accept const members of variadic templates as const
  2007-11-25  0:11 [Bug c++/34219] New: [4.3] gcc doesn't accept const members of variadic templates as const rbuergel at web dot de
  2007-11-25  1:01 ` [Bug c++/34219] " pcarlini at suse dot de
  2007-11-25  3:15 ` pinskia at gcc dot gnu dot org
@ 2007-12-20 21:07 ` dgregor at gcc dot gnu dot org
  2008-01-19 22:52 ` rbuergel at web dot de
                   ` (7 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: dgregor at gcc dot gnu dot org @ 2007-12-20 21:07 UTC (permalink / raw)
  To: gcc-bugs



-- 

dgregor at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|unassigned at gcc dot gnu   |dgregor at gcc dot gnu dot
                   |dot org                     |org
             Status|NEW                         |ASSIGNED
   Last reconfirmed|2007-11-25 03:15:38         |2007-12-20 21:07:30
               date|                            |


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


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

* [Bug c++/34219] gcc doesn't accept const members of variadic templates as const
  2007-11-25  0:11 [Bug c++/34219] New: [4.3] gcc doesn't accept const members of variadic templates as const rbuergel at web dot de
                   ` (2 preceding siblings ...)
  2007-12-20 21:07 ` dgregor at gcc dot gnu dot org
@ 2008-01-19 22:52 ` rbuergel at web dot de
  2008-01-29  0:11 ` [Bug c++/34219] gcc doesn't accept const members of variadic templates as const (regression) dgregor at gcc dot gnu dot org
                   ` (6 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: rbuergel at web dot de @ 2008-01-19 22:52 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from rbuergel at web dot de  2008-01-19 22:38 -------
another testcase:

template<template<typename... T> class Comp, typename... T> void f( T... Value)
{
  static_assert( Comp<T>::value > 0, "" );
}

template <typename... T>
struct Foo
{
        static const int value=1;
};

int main()
{
        f<Foo>( 2 );
}


-- 


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


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

* [Bug c++/34219] gcc doesn't accept const members of variadic templates as const (regression)
  2007-11-25  0:11 [Bug c++/34219] New: [4.3] gcc doesn't accept const members of variadic templates as const rbuergel at web dot de
                   ` (3 preceding siblings ...)
  2008-01-19 22:52 ` rbuergel at web dot de
@ 2008-01-29  0:11 ` dgregor at gcc dot gnu dot org
  2008-01-29 10:27 ` rbuergel at web dot de
                   ` (5 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: dgregor at gcc dot gnu dot org @ 2008-01-29  0:11 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from dgregor at gcc dot gnu dot org  2008-01-28 23:40 -------
There are some problems with the example code. For example, the expression
max<T, Params> does not expand the parameter pack "Params". The compiler should
have warned you about this, both in this case and in the static_assert case.


-- 

dgregor at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|rejects-valid               |error-recovery, ice-on-
                   |                            |invalid-code
            Summary|gcc doesn't accept const    |gcc doesn't accept const
                   |members of variadic         |members of variadic
                   |templates as const          |templates as const
                   |                            |(regression)


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


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

* [Bug c++/34219] gcc doesn't accept const members of variadic templates as const (regression)
  2007-11-25  0:11 [Bug c++/34219] New: [4.3] gcc doesn't accept const members of variadic templates as const rbuergel at web dot de
                   ` (4 preceding siblings ...)
  2008-01-29  0:11 ` [Bug c++/34219] gcc doesn't accept const members of variadic templates as const (regression) dgregor at gcc dot gnu dot org
@ 2008-01-29 10:27 ` rbuergel at web dot de
  2008-01-29 14:23 ` dgregor at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: rbuergel at web dot de @ 2008-01-29 10:27 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from rbuergel at web dot de  2008-01-29 10:17 -------
for #3, using static_assert( Comp<T...>::value > 0, "" ); makes it work.

using max<T, Params...> for #1 leads gcc to an error: "cannot expand 'Params
...' into a fixed-length argument list"


updated testcase:

template<typename T, T a, T... Params>
struct max
{
        static const T value = a > max<T, Params...>::value ? a : max<T,
Params...>::value;
};

template<typename T, T a, T b>
struct max<T, a, b>
{
        static const T value = a > b ? a : b;
};

static const int value1 = max< int, 1, 2>::value;
static const int value2 = max< int, 1, 3, 5>::value;

If there are no more errors in thats code, this is a rejects-valid, not an
error-recovery


-- 


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


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

* [Bug c++/34219] gcc doesn't accept const members of variadic templates as const (regression)
  2007-11-25  0:11 [Bug c++/34219] New: [4.3] gcc doesn't accept const members of variadic templates as const rbuergel at web dot de
                   ` (5 preceding siblings ...)
  2008-01-29 10:27 ` rbuergel at web dot de
@ 2008-01-29 14:23 ` dgregor at gcc dot gnu dot org
  2008-01-29 14:26 ` dgregor at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: dgregor at gcc dot gnu dot org @ 2008-01-29 14:23 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from dgregor at gcc dot gnu dot org  2008-01-29 14:01 -------
Subject: Bug 34219

Author: dgregor
Date: Tue Jan 29 13:59:59 2008
New Revision: 131938

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=131938
Log:
2008-01-29  Douglas Gregor  <doug.gregor@gmail.com>

        PR c++/34055
        PR c++/34103
        PR c++/34219
        PR c++/34606
        PR c++/34753
        PR c++/34754
        PR c++/34755
        PR c++/34919
        PR c++/34961
        * c-pretty-print.c (pp_c_type_qualifier_list): Don't try to print
        qualifiers for an ERROR_MARK_NODE or a NULL_TREE.


2008-01-29  Douglas Gregor  <doug.gregor@gmail.com>

        PR c++/34055
        PR c++/34103
        PR c++/34219
        PR c++/34606
        PR c++/34753
        PR c++/34754
        PR c++/34755
        PR c++/34919
        PR c++/34961
        * typeck.c (check_return_expr): Tweak call to
        check_for_bare_parameter_packs.
        * class.c (add_method): Be careful with error_mark_nodes.
        * cp-tree.h (check_for_bare_parameter_packs): Remove "*" from
        signature.
        * pt.c (struct find_parameter_pack_data): Remove
        SET_PACKS_TO_ERROR.
        (find_parameter_packs_r): Don't use SET_PACKS_TO_ERROR.
        (uses_parameter_packs): Don't set SET_PACKS_TO_ERROR.
        (make_pack_expansion): Ditto.
        (check_for_bare_parameter_packs): Parameter is now a tree, not a
        tree*.
        (process_template_parm): Tweak call to
        check_for_bare_parameter_packs.  
        (push_template_decl_real): Tweak calls to
        check_for_bare_parameter_packs. If bare parameter packs are found
        in the list of exceptions, clear out that list after giving an
        error.
        * semantics.c (finish_cond): Tweak call to
        check_for_bare_parameter_packs.
        (finish_expr_stmt): Ditto.
        (finish_for_expr): Ditto.
        (finish_switch_cond): Ditto.
        (finish_mem_initializers): Ditto.
        (finish_member_declaration): Ditto.
        (finish_static_assert): Check for bare parameter packs in the
        condition.
        * decl2.c (cplus_decl_attributes): Check for bare parameter packs in
the
        attributes of a declaration.
        * parser.c (cp_parser_using_declaration): Tweak call to
        check_for_bare_parameter_packs.
        (cp_parser_base_clause): Ditto.


2008-01-29  Douglas Gregor  <doug.gregor@gmail.com>

        PR c++/34055
        PR c++/34103
        PR c++/34219
        PR c++/34606
        PR c++/34753
        PR c++/34754
        PR c++/34755
        PR c++/34919
        PR c++/34961
        * g++.dg/cpp0x/vt-34219-2.C: New.
        * g++.dg/cpp0x/pr32126.C: Tweak expected error messages.
        * g++.dg/cpp0x/vt-34961.C: New.
        * g++.dg/cpp0x/vt-34055.C: Tweak error messages; add new test
        cases from the re-opened PR.
        * g++.dg/cpp0x/vt-34753.C: New.
        * g++.dg/cpp0x/vt-34919.C: New.
        * g++.dg/cpp0x/vt-34754.C: New.
        * g++.dg/cpp0x/vt-34606.C: New.
        * g++.dg/cpp0x/vt-34219.C: New.
        * g++.dg/cpp0x/pr32125.C: Tweak expected error messages.
        * g++.dg/cpp0x/vt-34755.C: New.
        * g++.dg/cpp0x/pr31438.C: Ditto.
        * g++.dg/cpp0x/variadic81.C: Ditto.

Added:
    trunk/gcc/testsuite/g++.dg/cpp0x/vt-34219-2.C
    trunk/gcc/testsuite/g++.dg/cpp0x/vt-34219.C
    trunk/gcc/testsuite/g++.dg/cpp0x/vt-34606.C
    trunk/gcc/testsuite/g++.dg/cpp0x/vt-34753.C
    trunk/gcc/testsuite/g++.dg/cpp0x/vt-34754.C
    trunk/gcc/testsuite/g++.dg/cpp0x/vt-34755.C
    trunk/gcc/testsuite/g++.dg/cpp0x/vt-34919.C
    trunk/gcc/testsuite/g++.dg/cpp0x/vt-34961.C
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/c-pretty-print.c
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/class.c
    trunk/gcc/cp/cp-tree.h
    trunk/gcc/cp/decl.c
    trunk/gcc/cp/decl2.c
    trunk/gcc/cp/parser.c
    trunk/gcc/cp/pt.c
    trunk/gcc/cp/semantics.c
    trunk/gcc/cp/typeck.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/g++.dg/cpp0x/pr31438.C
    trunk/gcc/testsuite/g++.dg/cpp0x/pr32125.C
    trunk/gcc/testsuite/g++.dg/cpp0x/pr32126.C
    trunk/gcc/testsuite/g++.dg/cpp0x/variadic81.C
    trunk/gcc/testsuite/g++.dg/cpp0x/vt-34055.C


-- 


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


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

* [Bug c++/34219] gcc doesn't accept const members of variadic templates as const (regression)
  2007-11-25  0:11 [Bug c++/34219] New: [4.3] gcc doesn't accept const members of variadic templates as const rbuergel at web dot de
                   ` (6 preceding siblings ...)
  2008-01-29 14:23 ` dgregor at gcc dot gnu dot org
@ 2008-01-29 14:26 ` dgregor at gcc dot gnu dot org
  2008-01-29 14:26 ` dgregor at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: dgregor at gcc dot gnu dot org @ 2008-01-29 14:26 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #8 from dgregor at gcc dot gnu dot org  2008-01-29 14:24 -------
Fixed on mainline


-- 


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


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

* [Bug c++/34219] gcc doesn't accept const members of variadic templates as const (regression)
  2007-11-25  0:11 [Bug c++/34219] New: [4.3] gcc doesn't accept const members of variadic templates as const rbuergel at web dot de
                   ` (7 preceding siblings ...)
  2008-01-29 14:26 ` dgregor at gcc dot gnu dot org
@ 2008-01-29 14:26 ` dgregor at gcc dot gnu dot org
  2008-12-02 17:59 ` jason at gcc dot gnu dot org
  2009-10-07 19:50 ` [Bug c++/34219] [C++0x] " jason at gcc dot gnu dot org
  10 siblings, 0 replies; 12+ messages in thread
From: dgregor at gcc dot gnu dot org @ 2008-01-29 14:26 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #7 from dgregor at gcc dot gnu dot org  2008-01-29 14:22 -------
Actually, I don't know whether max<T, Params...> is valid or not. My
inclination is that it is invalid, because when Params is empty, it becomes an
invalid specialization max<T>. (This happens, for example, if we try to compute
max<int, 17>::value. However, it's not clear to me whether the wording in the
C++0x working draft supports that view or not. We say this about function
parameter pack arguments not matching to normal function parameters in partial
ordering, but we don't talk about this case at all.

I am going to submit an issue to the C++ Core Working Group to get this
clarified. Until then, I'm going to suspend this bug: then we'll either close
it (if the committee deems this code ill-formed) or re-open it to be fixed in
GCC 4.4.


-- 

dgregor at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |SUSPENDED


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


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

* [Bug c++/34219] gcc doesn't accept const members of variadic templates as const (regression)
  2007-11-25  0:11 [Bug c++/34219] New: [4.3] gcc doesn't accept const members of variadic templates as const rbuergel at web dot de
                   ` (8 preceding siblings ...)
  2008-01-29 14:26 ` dgregor at gcc dot gnu dot org
@ 2008-12-02 17:59 ` jason at gcc dot gnu dot org
  2009-10-07 19:50 ` [Bug c++/34219] [C++0x] " jason at gcc dot gnu dot org
  10 siblings, 0 replies; 12+ messages in thread
From: jason at gcc dot gnu dot org @ 2008-12-02 17:59 UTC (permalink / raw)
  To: gcc-bugs



-- 

jason at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|dgregor at gcc dot gnu dot  |unassigned at gcc dot gnu
                   |org                         |dot org
             Status|SUSPENDED                   |NEW


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


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

* [Bug c++/34219] [C++0x] gcc doesn't accept const members of variadic templates as const (regression)
  2007-11-25  0:11 [Bug c++/34219] New: [4.3] gcc doesn't accept const members of variadic templates as const rbuergel at web dot de
                   ` (9 preceding siblings ...)
  2008-12-02 17:59 ` jason at gcc dot gnu dot org
@ 2009-10-07 19:50 ` jason at gcc dot gnu dot org
  10 siblings, 0 replies; 12+ messages in thread
From: jason at gcc dot gnu dot org @ 2009-10-07 19:50 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #9 from jason at gcc dot gnu dot org  2009-10-07 19:50 -------
This was fixed long ago.


-- 

jason at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED


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


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

end of thread, other threads:[~2009-10-07 19:50 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-11-25  0:11 [Bug c++/34219] New: [4.3] gcc doesn't accept const members of variadic templates as const rbuergel at web dot de
2007-11-25  1:01 ` [Bug c++/34219] " pcarlini at suse dot de
2007-11-25  3:15 ` pinskia at gcc dot gnu dot org
2007-12-20 21:07 ` dgregor at gcc dot gnu dot org
2008-01-19 22:52 ` rbuergel at web dot de
2008-01-29  0:11 ` [Bug c++/34219] gcc doesn't accept const members of variadic templates as const (regression) dgregor at gcc dot gnu dot org
2008-01-29 10:27 ` rbuergel at web dot de
2008-01-29 14:23 ` dgregor at gcc dot gnu dot org
2008-01-29 14:26 ` dgregor at gcc dot gnu dot org
2008-01-29 14:26 ` dgregor at gcc dot gnu dot org
2008-12-02 17:59 ` jason at gcc dot gnu dot org
2009-10-07 19:50 ` [Bug c++/34219] [C++0x] " jason 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).