https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123681
Bug ID: 123681
Summary: [13/14/15/16 Regression] ICE in
synthesized_method_walk (at cp/method.cc) while
explaining constexpr failure of function with
try-catch
Product: gcc
Version: 16.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: jirehguo at tju dot edu.cn
Target Milestone: ---
Compiler Explorer: https://godbolt.org/z/3oGh63ve5
The following c++ code crash gcc trunk with -std=c++20 flag.
Goes back to 12.1 with checking.
Code:
```cpp
#include <exception>
struct B {
~B() ;
};
template <typename T> struct Composite {
T b;
};
template <typename T> struct is_nothrow_callable {
static constexpr bool test(int i, bool b) {
auto createComposite = []() -> Composite<B> {
return {};
};
try {
Composite<B> c = createComposite();
} catch ( std::exception e) {
}
return false;
}
static constexpr bool value = test(1, false);
};
bool b = is_nothrow_callable<decltype(0)>::value;
```
Stack dump:
```
<source>: In instantiation of 'constexpr const bool
is_nothrow_callable<int>::value':
required from here
<source>:22:44:
22 | bool b = is_nothrow_callable<decltype(0)>::value;
| ^~~~~
<source>:19:37: error: 'static constexpr bool is_nothrow_callable<T>::test(int,
bool) [with T = int]' called in a constant expression
19 | static constexpr bool value = test(1, false);
| ~~~~^~~~~~~~~~
<source>:9:25: note: 'static constexpr bool is_nothrow_callable<T>::test(int,
bool) [with T = int]' is not usable as a 'constexpr' function because:
9 | static constexpr bool test(int i, bool b) {
| ^~~~
<source>:15:5: error: call to non-'constexpr' function
'Composite<B>::~Composite()'
15 | } catch ( std::exception e) {
| ^
<source>:5:30: note: 'Composite<B>::~Composite()' is not usable as a
'constexpr' function because:
5 | template <typename T> struct Composite {
| ^~~~~~~~~
<source>:5:30: internal compiler error: in synthesized_method_walk, at
cp/method.cc:2952
0x2950a78 diagnostics::context::diagnostic_impl(rich_location*,
diagnostics::metadata const*, diagnostics::option_id, char const*,
__va_list_tag (*) [1], diagnostics::kind)
???:0
0x294583b internal_error(char const*, ...)
???:0
0xb1ec34 fancy_abort(char const*, int, char const*)
???:0
0xc90f13 explain_implicit_non_constexpr(tree_node*)
???:0
0xba3d77 explain_invalid_constexpr_fn(tree_node*)
???:0
0xba3756 require_potential_rvalue_constant_expression(tree_node*)
???:0
0xba3905 explain_invalid_constexpr_fn(tree_node*)
???:0
0xb8c554 cxx_eval_constant_expression(constexpr_ctx const*, tree_node*,
value_cat, bool*, bool*, tree_node**)
???:0
0xe6dd5e store_init_value(tree_node*, tree_node*, vec<tree_node*, va_gc,
vl_embed>**, int)
???:0
0xc285d6 cp_finish_decl(tree_node*, tree_node*, bool, tree_node*, int,
cp_decomp*)
???:0
0xdc7c3d instantiate_decl(tree_node*, bool, bool)
???:0
0xc383ef mark_used(tree_node*, int)
???:0
0xe153c4 finish_id_expression(tree_node*, tree_node*, tree_node*, cp_id_kind*,
bool, bool, bool*, bool, bool, bool, bool, char const**, unsigned long)
???:0
0xd64c03 c_parse_file()
???:0
0xeeed49 c_common_parse_file()
???:0
Please submit a full bug report, with preprocessed source (by using
-freport-bug).
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.
Compiler returned: 1
```