Bug 54466 - [C++11] Recursive Type Alias, Member Function Pointer, Segmentation Fault
Summary: [C++11] Recursive Type Alias, Member Function Pointer, Segmentation Fault
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.7.0
: P3 normal
Target Milestone: 4.8.0
Assignee: Dodji Seketeli
URL:
Keywords: rejects-valid
: 53026 57152 (view as bug list)
Depends on:
Blocks:
 
Reported: 2012-09-03 11:07 UTC by Matt Clarkson
Modified: 2013-05-03 09:06 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2012-10-16 00:00:00


Attachments
The preprocessed dump from the error. (53.84 KB, application/octet-stream)
2012-09-03 11:07 UTC, Matt Clarkson
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Matt Clarkson 2012-09-03 11:07:13 UTC
Created attachment 28122 [details]
The preprocessed dump from the error.

The following code fails with a segmentation fault:

#include <memory>

template<typename T>
using CallbackPtr = const std::shared_ptr<const T>;

template<typename C, typename T>
using CallbackFunPtr = void (C::*)(CallbackPtr<T>);

int main () {
    return 0;
}

[matt test] g++ --std=c++11 -Wall -Wextra -Werror -pedantic -pedantic-errors main.cpp
main.cpp:7:49: internal compiler error: Segmentation fault
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://bugzilla.redhat.com/bugzilla> for instructions.
Preprocessed source stored into /tmp/ccuw4zjD.out file, please attach this to your bugreport.

However changing CallbackFunPtr to:

template<typename C, typename T>
using CallbackFunPtr = void (C::*)(const std::shared_ptr<const T>);

It's OK.

[matt test] uname -r
3.5.2-3.fc17.x86_64
[matt test] gcc --version
gcc (GCC) 4.7.0 20120507 (Red Hat 4.7.0-5)
Copyright (C) 2012 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Comment 1 Matt Clarkson 2012-10-16 15:46:31 UTC
This is still an error on 4.7.2.

It is the const before the std::shared_ptr<const T> that is the problem:

        template<typename T>
#if (__GNUC__ <= 4) && (__GNUC_MINOR__ <= 7) && (__GNUC_PATCHLEVEL__ <= 2)
        using CallbackPtr = std::shared_ptr<const T>;
#else
        // This causes a segmentation fault on G++ 4.7.2
        // Bug Report: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54466
        using CallbackPtr = const std::shared_ptr<const T>;
#endif
Comment 2 Jonathan Wakely 2012-10-16 15:55:41 UTC
confirmed
Comment 3 Paolo Carlini 2012-10-16 22:32:02 UTC
A shorter self contained testcase, not involving the whole std::shared_ptr, would certainly help. Dodji, are there any chances you can look into this issue? The alias decls seem determinant.
Comment 4 Jonathan Wakely 2012-10-16 23:09:30 UTC
template<typename T>
  struct X { };

template<typename T>
  using Y = const X<T>;

template<typename T>
  using Z = Y<T>;
Comment 5 Paolo Carlini 2012-10-16 23:13:18 UTC
Excellent.
Comment 6 Jonathan Wakely 2012-10-16 23:16:48 UTC
The second alias doesn't even have to be a template to show the problem:

template<typename T>
  struct X { };

template<typename T>
  using Y = const X<T>;

using Z = Y<int>;
Comment 7 Matt Clarkson 2012-10-17 08:19:20 UTC
Sorry about the bloated bug report - that was how I came across it.  In the future I'll submit smaller test cases.

Thanks for looking into this.
Comment 8 dodji@seketeli.org 2012-10-26 15:13:10 UTC
"paolo.carlini at oracle dot com" <gcc-bugzilla@gcc.gnu.org> a écrit:

> Dodji, are there any chances you can look into this
> issue? The alias decls seem determinant.

Sure.  Sorry for the delay, I was buried into something else.  I am
looking into this now.
Comment 9 dodji@seketeli.org 2012-10-27 07:59:12 UTC
A candidate patch has been sent to
http://gcc.gnu.org/ml/gcc-patches/2012-10/msg02472.html.
Comment 10 Dodji Seketeli 2012-11-13 16:07:50 UTC
Author: dodji
Date: Tue Nov 13 16:07:39 2012
New Revision: 193479

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=193479
Log:
PR c++/54466 - ICE with alias template which type-id is const qualified

Consider this short example:

    template<typename T>
      struct X { };

    template<typename T>
      using Y = const X<T>;

    using Z = Y<int>;

G++ crashes in lookup_class_template_1 while trying to build the alias
template instantiation Y<int>.

I think this is indirectly due to the fact that that
lookup_class_template_1 can now yield a const qualified type like
'const X<T>'.

As a consequence, the code in lookup_template_class_1 that was trying
to access the TYPE_STUB_DECL field of the result of
lookup_template_class_1 should now be adjusted to access the
TYPE_STUB_DECL of the main variant of the resulting type instead (and
that is TYPE_MAIN_DECL); because qualified types (constructed with
build_qualified_type) have their TYPE_STUB_DECL set to NULL.

Fixed thus and tested on x86_64-unknown-linux-gnu against trunk.

gcc/cp

	PR c++/54466
	* pt.c (lookup_template_class_1): TYPE_STUB_DECL should be
	accessed on the main variant of the type.

gcc/testsuite/

	* g++.dg/cpp0x/alias-decl-26.C: New test file.

In the example of this patch, g++ crashes when trying to build the
alias template Y<int

Added:
    trunk/gcc/testsuite/g++.dg/cpp0x/alias-decl-26.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/pt.c
    trunk/gcc/testsuite/ChangeLog
Comment 11 Dodji Seketeli 2012-11-13 16:09:27 UTC
Fixed in trunk (4.8).
Comment 12 Matt Clarkson 2012-11-14 14:24:11 UTC
@Dodji, thanks for fixing this :)  What release will this be in? 4.8.1?
Comment 13 Jonathan Wakely 2012-11-14 14:29:19 UTC
4.8.0
Comment 14 dodji@seketeli.org 2012-11-15 13:52:18 UTC
"mattyclarkson at gmail dot com" <gcc-bugzilla@gcc.gnu.org> a écrit:

> @Dodji, thanks for fixing this :)

You are welcome.  Sorry for the delay.

>  What release will this be in? 4.8.1?

As Jon said, 4.8.0.

Cheers.
Comment 15 Paolo Carlini 2012-12-05 13:05:34 UTC
*** Bug 53026 has been marked as a duplicate of this bug. ***
Comment 16 Paolo Carlini 2013-05-03 09:06:07 UTC
*** Bug 57152 has been marked as a duplicate of this bug. ***