Bug 51373 - [C++0x] ICE for static pointer to member initialized in-class
Summary: [C++0x] ICE for static pointer to member initialized in-class
Status: RESOLVED DUPLICATE of bug 54532
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.7.0
: P3 normal
Target Milestone: 4.9.0
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-12-01 04:36 UTC by Pubby8
Modified: 2014-06-09 20:03 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work: 4.10.0, 4.9.0
Known to fail:
Last reconfirmed: 2011-12-01 00:00:00


Attachments
gcc -v result (917 bytes, text/plain)
2014-06-06 11:24 UTC, Vladimír Štill
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Pubby8 2011-12-01 04:36:03 UTC
gcc version 4.7.0 20111112 (experimental) (GCC) 

Two seemingly relate ICEs when dealing with pointer to member:

struct foo {
    int a = 42;
    static int foo::*b = &foo::a;
};
internal compiler error: Segmentation fault

struct foo {
    int a = 42;
    static int foo::*b;
    auto& c = b;
};
internal compiler error: in unify_one_argument, at cp/pt.c:15008

Not sure if the code is valid.
Comment 1 Daniel Krügler 2011-12-03 19:17:09 UTC
(In reply to comment #0)
> gcc version 4.7.0 20111112 (experimental) (GCC) 

Also in 4.7.0 20111126 (experimental)

> Two seemingly relate ICEs when dealing with pointer to member:
> 
> struct foo {
>     int a = 42;
>     static int foo::*b = &foo::a;
> };

b needs to have a constexpr specifier here, but it ICEs also with that one added. Even with the constexpr specifier that declaration should be ill-formed, because the class definition must be complete for an in-class static data member initializer. Also, the initializer for a is not needed to reproduce the error.

> struct foo {
>     int a = 42;
>     static int foo::*b;
>     auto& c = b;
> };
> internal compiler error: in unify_one_argument, at cp/pt.c:15008

The declaration of c cannot use auto (only static data members may do) and the ICE does no longer occur after the fix. In addition, the declaration of a is not needed to reproduce the problem.
Comment 2 Daniel Krügler 2011-12-03 19:33:55 UTC
(In reply to comment #1)

> Even with the constexpr specifier that declaration should be ill-formed,
> because the class definition must be complete for an in-class static data
> member initializer. 

I just recognize that the class definition must not be complete to make the pointer of member formation a constant expression. So, the code of the first example should be well-formed after addition of constexpr to the static data member.
Comment 3 Vladimír Štill 2014-06-06 11:24:57 UTC
Created attachment 32899 [details]
gcc -v result
Comment 4 Vladimír Štill 2014-06-06 11:27:00 UTC
Problem is still present in 4.8.2, reproduce with following code, which compiles in clang 3.4 (both with -std=c++11):
struct Y {
    int o;
    static constexpr int Y::* x = &Y::o;
};

gcc -v result included in previous comment. Tested on NixOS linux x86_64.
Comment 5 Jonathan Wakely 2014-06-06 11:39:35 UTC
Fixed in 4.9.0 though
Comment 6 Vladimír Štill 2014-06-06 12:14:10 UTC
(In reply to Jonathan Wakely from comment #5)
> Fixed in 4.9.0 though

I'm glad to hear that, I could not yet installed 4.9.0 in my OS.
Comment 7 Jason Merrill 2014-06-09 20:03:49 UTC
Fixed by r196852.

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