Bug 58037 - sizeof... accepted only in some contexts
Summary: sizeof... accepted only in some contexts
Status: RESOLVED DUPLICATE of bug 57673
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.8.1
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2013-07-31 12:55 UTC by Nick Maclaren
Modified: 2013-07-31 14:07 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail: 4.7.3, 4.8.1, 4.9.0
Last reconfirmed: 2013-07-31 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Nick Maclaren 2013-07-31 12:55:40 UTC
With 4.8.1:

template<int ... Dims>
class weeble {
    static constexpr int Ranks[sizeof...(Dims)] = {Dims...};
    const int rank = sizeof...(Dims);
};

weeble<3,5> x;

produces:

junk.cpp:4:22: error: expected ';' at end of member declaration
     const int rank = sizeof...(Dims);
                      ^
junk.cpp:4:28: error: expected unqualified-id before '...' token
     const int rank = sizeof...(Dims);
                            ^
junk.cpp:4:22: error: expected primary-expression at end of input
     const int rank = sizeof...(Dims);
                      ^
That doesn't look right, especially as that use of sizeof... is almost
straight out of the standard.

For what it is worth, -v produces:

Using built-in specs.
COLLECT_GCC=/home/nmm/GCC/bin/g++
COLLECT_LTO_WRAPPER=/home/nmm/GCC/libexec/gcc/x86_64-unknown-linux-gnu/4.8.1/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: ../configure --prefix=/home/nmm/GCC --disable-bootstrap --enable-languages=c,c++,fortran --enable-werror=yes --disable-decimal-float
Thread model: posix
gcc version 4.8.1 (GCC)
Comment 1 Jonathan Wakely 2013-07-31 13:02:17 UTC
The compiler only rejects it when the member is non-static and uses = for the initializer.

As a workaround you can use a braced-init-list as the initializer for the member:

    const int rank { sizeof...(Dims) };
Comment 2 Nick Maclaren 2013-07-31 13:43:10 UTC
Thanks.  That's simpler than my workaround.
Comment 3 Paolo Carlini 2013-07-31 14:07:29 UTC
Dup. Already fixed in mainline.

*** This bug has been marked as a duplicate of bug 57673 ***