GCC Bugzilla has been upgraded from version 4.4.9 to 5.0rc3. If you see any problem, please report it to bug 64968.
Bug 39608 - [4.4/4.5 Regression] 'expr' cannot appear in a constant-expression.
Summary: [4.4/4.5 Regression] 'expr' cannot appear in a constant-expression.
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.4.0
: P3 normal
Target Milestone: 4.4.0
Assignee: Not yet assigned to anyone
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2009-04-01 08:03 IST by Pawel Sikora
Modified: 2009-04-03 18:05 IST (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work: 4.3.3
Known to fail: 4.4.0
Last reconfirmed:


Attachments
testcase (91.70 KB, application/octet-stream)
2009-04-01 08:04 IST, Pawel Sikora
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Pawel Sikora 2009-04-01 08:03:27 IST
during testing 4.4 snapshot i get an compilation error on boost-1.38.0 codebase.

% x86_64-gnu-linux-g++ t.ii -std=gnu++0x -c
t.ii: In member function 'size_t boost::dynamic_bitset<Block, Allocator>::count() const':
t.ii:30558: error: 'mode' cannot appear in a constant-expression
t.ii:30558: error: template argument 1 is invalid
t.ii:30558: error: expected '>' before '*' token
t.ii:30558: error: expected '(' before '*' token
t.ii:30558: error: expected primary-expression before '>' token

(...)
template <bool value>
struct value_to_type
{
    value_to_type() {}
};
(...)
template <typename Block, typename Allocator>
typename dynamic_bitset<Block, Allocator>::size_type
dynamic_bitset<Block, Allocator>::count() const
{
    using detail::dynamic_bitset_impl::table_width;
    using detail::dynamic_bitset_impl::access_by_bytes;
    using detail::dynamic_bitset_impl::access_by_blocks;
    using detail::dynamic_bitset_impl::value_to_type;

    const bool no_padding =
        dynamic_bitset<Block, Allocator>::bits_per_block
        == 8 * sizeof(Block);

    const bool enough_table_width = table_width >= 8;

    const bool mode = (no_padding && enough_table_width)
                          ? access_by_bytes
                          : access_by_blocks;

    return do_count(m_bits.begin(), num_blocks(), Block(0),
                                       static_cast<value_to_type<mode> *>(0));
                                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
}

4.3.3 accepts this code. is it a boost bug or 4.4 regression?
Comment 1 Pawel Sikora 2009-04-01 08:04:28 IST
Created attachment 17575 [details]
testcase
Comment 2 Richard Biener 2009-04-01 15:47:57 IST
Unless proven invalid it is.
Comment 3 Jakub Jelinek 2009-04-02 09:41:16 IST
This errors since r144618, i.e. PR9634 (DR224) commit.  The same fix has been applied to 4.3 branch, so if this is a g++ bug, it would be 4.3 regression too, if it is not, it should be closed as INVALID.

Jason?
Comment 4 Jason Merrill 2009-04-03 17:25:16 IST
Subject: Bug 39608

Author: jason
Date: Fri Apr  3 17:24:46 2009
New Revision: 145508

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=145508
Log:
        PR c++/39608
        * semantics.c (finish_id_expression): Don't assume a dependent
        member of the current instantiation isn't a valid integral
        constant expression.  Check dependent_scope_p.
        * pt.c (dependent_scope_p): Check TYPE_P.

Added:
    trunk/gcc/testsuite/g++.dg/template/const2.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/pt.c
    trunk/gcc/cp/semantics.c
    trunk/gcc/testsuite/ChangeLog

Comment 5 Jason Merrill 2009-04-03 17:27:10 IST
Subject: Bug 39608

Author: jason
Date: Fri Apr  3 17:26:50 2009
New Revision: 145509

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=145509
Log:
        PR c++/39608
        * semantics.c (finish_id_expression): Don't assume a dependent
        member of the current instantiation isn't a valid integral
        constant expression.  Check dependent_scope_p.
        * pt.c (dependent_scope_p): Check TYPE_P.
        (tsubst_copy): If args is null, just return.

Added:
    branches/gcc-4_4-branch/gcc/testsuite/g++.dg/template/const2.C
      - copied unchanged from r145508, trunk/gcc/testsuite/g++.dg/template/const2.C
Modified:
    branches/gcc-4_4-branch/gcc/cp/ChangeLog
    branches/gcc-4_4-branch/gcc/cp/pt.c
    branches/gcc-4_4-branch/gcc/cp/semantics.c
    branches/gcc-4_4-branch/gcc/testsuite/ChangeLog

Comment 6 Jason Merrill 2009-04-03 18:05:48 IST
Fixed in 4.3, 4.4 and trunk.