Bug 92582 - [10 Regression] internal compiler error: Segmentation fault with concept on constructor
Summary: [10 Regression] internal compiler error: Segmentation fault with concept on c...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 10.0
: P1 normal
Target Milestone: 10.0
Assignee: Jason Merrill
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-11-19 12:28 UTC by gcc-bugs
Modified: 2020-01-14 03:06 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2019-11-26 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description gcc-bugs 2019-11-19 12:28:11 UTC
Hi gcc-team,

the following code ices:

```
#include <functional>
template <typename I>
concept bool input_or_output_iterator = std::is_same_v<I &, decltype(++I{})>;
template <class From, class To> concept convertible_to = requires(From(f)()) {
  static_cast<To>(f());
};
template <typename> struct reference;
template <typename t> using reference_t = typename reference<t>::type;
template <input_or_output_iterator it_t> struct reference<it_t> {
  using type = typename std::iterator_traits<it_t>::reference;
};
template <typename rng_t>
requires (!input_or_output_iterator<rng_t>) struct reference<rng_t> {
  using type = reference_t<decltype(begin(std::declval<rng_t &>()))>;
};
template <typename> struct b {
  template <typename f>
  static constexpr bool e = convertible_to<reference_t<f>, int>;
  template <typename f> b(std::initializer_list<f>) requires e<f>;
};
b<void> g{std::vector<int>{}};
```

> g++-git -std=c++17 -fconcepts -c ice.cpp

as well as 

> g++-git -std=c++2a -c ice.cpp 

results in

```
ice.cpp:19:62: internal compiler error: Segmentation fault
   19 |   template <typename f> b(std::initializer_list<f>) requires e<f>;
      |                                                              ^~~~
0xc4999f crash_signal
	/home/marehr/Packages/gcc-git/src/gcc/gcc/toplev.c:328
0x72e6b5 tsubst_copy_and_build(tree_node*, tree_node*, int, tree_node*, bool, bool)
	/home/marehr/Packages/gcc-git/src/gcc/gcc/cp/pt.c:18836
0x735eb6 tsubst_copy_and_build(tree_node*, tree_node*, int, tree_node*, bool, bool)
	/home/marehr/Packages/gcc-git/src/gcc/gcc/cp/pt.c:18765
0x735eb6 tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool)
	/home/marehr/Packages/gcc-git/src/gcc/gcc/cp/pt.c:18423
0x65d8e2 satisfy_constraint_r
	/home/marehr/Packages/gcc-git/src/gcc/gcc/cp/constraint.cc:2474
0x65e118 satisfy_constraint
	/home/marehr/Packages/gcc-git/src/gcc/gcc/cp/constraint.cc:2554
0x65f4cb satisfy_associated_constraints
	/home/marehr/Packages/gcc-git/src/gcc/gcc/cp/constraint.cc:2572
0x65f4cb constraints_satisfied_p
	/home/marehr/Packages/gcc-git/src/gcc/gcc/cp/constraint.cc:2656
0x627852 add_function_candidate
	/home/marehr/Packages/gcc-git/src/gcc/gcc/cp/call.c:2264
0x629e3c add_template_candidate_real
	/home/marehr/Packages/gcc-git/src/gcc/gcc/cp/call.c:3422
0x62a3c6 add_template_candidate
	/home/marehr/Packages/gcc-git/src/gcc/gcc/cp/call.c:3463
0x62a3c6 add_candidates
	/home/marehr/Packages/gcc-git/src/gcc/gcc/cp/call.c:5781
0x62a6f4 add_candidates
	/home/marehr/Packages/gcc-git/src/gcc/gcc/cp/call.c:5696
0x62a6f4 add_list_candidates
	/home/marehr/Packages/gcc-git/src/gcc/gcc/cp/call.c:3902
0x63281e build_new_method_call_1
	/home/marehr/Packages/gcc-git/src/gcc/gcc/cp/call.c:10086
0x6330d6 build_new_method_call(tree_node*, tree_node*, vec<tree_node*, va_gc, vl_embed>**, tree_node*, int, tree_node**, int)
	/home/marehr/Packages/gcc-git/src/gcc/gcc/cp/call.c:10268
0x6330d6 build_special_member_call(tree_node*, tree_node*, vec<tree_node*, va_gc, vl_embed>**, tree_node*, int, int)
	/home/marehr/Packages/gcc-git/src/gcc/gcc/cp/call.c:9706
0x6abb43 expand_default_init
	/home/marehr/Packages/gcc-git/src/gcc/gcc/cp/init.c:1970
0x6abb43 expand_aggr_init_1
	/home/marehr/Packages/gcc-git/src/gcc/gcc/cp/init.c:2085
0x6adab6 build_aggr_init(tree_node*, tree_node*, int, int)
	/home/marehr/Packages/gcc-git/src/gcc/gcc/cp/init.c:1820
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <https://bugs.archlinux.org/> for instructions.
```

```
> g++-git -v
Using built-in specs.
COLLECT_GCC=g++-git
COLLECT_LTO_WRAPPER=/opt/gcc/gcc-git/bin/../lib/gcc/x86_64-pc-linux-gnu/10.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /home/marehr/Packages/gcc-git/src/gcc/configure --prefix=/usr --libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=https://bugs.archlinux.org/ --enable-languages=c,c++ --enable-shared --enable-threads=posix --with-system-zlib --with-isl --enable-__cxa_atexit --disable-libunwind-exceptions --enable-clocale=gnu --disable-libstdcxx-pch --disable-libssp --enable-gnu-unique-object --enable-linker-build-id --enable-lto --enable-plugin --enable-install-libiberty --with-linker-hash-style=gnu --enable-gnu-indirect-function --enable-multilib --disable-werror --enable-checking=release --enable-default-pie --enable-default-ssp --enable-cet=auto --disable-boostrap
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 10.0.0 20191116 (experimental) (GCC)
```

Thank you!
Comment 1 Jakub Jelinek 2019-11-26 13:43:34 UTC
Reduced testcase:
template <class a, class> concept b = requires(a(c)) { c; };
template <typename> struct A {
  template <typename c> static constexpr bool d = b<c, int>;
  template <typename c> A(c) requires d<c>;
};
A<void> e { 0 };
With s/concept/concept bool/ and -std=c++17 -fconcepts instead of -std=c++2a this compiled before r276764 and starting with that revision ICEs.
Comment 2 GCC Commits 2020-01-14 01:31:27 UTC
The master branch has been updated by Jason Merrill <jason@gcc.gnu.org>:

https://gcc.gnu.org/g:8ca4435f431f9b8049ebf102b5659f2d3e7be198

commit r10-5937-g8ca4435f431f9b8049ebf102b5659f2d3e7be198
Author: Jason Merrill <jason@redhat.com>
Date:   Mon Jan 13 17:38:19 2020 -0500

    	PR c++/92582 - ICE with member template as requirement.
    
    Here, we weren't recognizing that the template parameter of A is used by the
    reference to d in the requires-clause of f.  Fixed by passing down the
    active template parameters in the context of normalization, and adding to
    the mapping any such parameters shared by a member template used in the
    constraint-expression.
    
    	* pt.c (struct find_template_parameter_info): Add ctx_parms.
    	(any_template_parm_r): Handle TEMPLATE_DECL.
    	(find_template_parameters): Take parms instead of their depth.
    	* constraint.cc (build_parameter_mapping): Pass them.
Comment 3 Jason Merrill 2020-01-14 03:06:27 UTC
Fixed.