[Bug c++/90799] New: noexcept specification dependent on template argument throws internal compiler error when trying to deduce it from a function argument

2019-06-09 Thread franwade33 at googlemail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90799

Bug ID: 90799
   Summary: noexcept specification dependent on template argument
throws internal compiler error when trying to deduce
it from a function argument
   Product: gcc
   Version: 9.1.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: franwade33 at googlemail dot com
  Target Milestone: ---

If you have a non-type template argument `bool is_noexcept` that is deduced
from `noexcept(is_noexcept)` on a function pointer / member function pointer,
it gives an internal compiler error if the function was instantiated from a
template and the noexcept specifier is dependent on a template parameter.

For example, the following compiled with or without `-DMEMBER` both give the
same output:

template
void foo() noexcept(T::value);

struct S {
static constexpr const bool value = true;

template
void bar() noexcept(T::value);
};

template
constexpr bool is_noexcept_function(void(Args...) noexcept(is_noexcept))
noexcept {
return is_noexcept;
}

template
constexpr bool is_noexcept_member_function(void(S::*)(Args...)
noexcept(is_noexcept)) noexcept {
return is_noexcept;
}

#ifdef MEMBER
static_assert(is_noexcept_member_function(&S::bar));
#else
static_assert(is_noexcept_function(foo));
#endif

Expected behaviour:

Nothing happens (static_assert is successful, as `is_noexcept` is deduced to be
true) in both cases.

Actual behaviour:

(Error with `g++ -std=c++17`)

test.cpp: In substitution of 'template
constexpr bool is_noexcept_function(void (*)(Args ...) noexcept (is_noexcept))
[with Args = ; bool is_noexcept = ]':
test.cpp:24:42:   required from here
test.cpp:24:42: internal compiler error: in structural_comptypes, at
cp/typeck.c:1236
   24 | static_assert(is_noexcept_function(foo));
  |  ^
Please submit a full bug report,
with preprocessed source if appropriate.
See <https://gcc.gnu.org/bugs/> for instructions.

(Error with `g++ -std=c++17 -DMEMBER`)

test.cpp: In substitution of 'template
constexpr bool is_noexcept_member_function(void (S::*)(Args ...) noexcept
(is_noexcept)) [with Args = ; bool is_noexcept = ]':
test.cpp:22:53:   required from here
test.cpp:22:53: internal compiler error: in structural_comptypes, at
cp/typeck.c:1236
   22 | static_assert(is_noexcept_member_function(&S::bar));
  | ^
Please submit a full bug report,
with preprocessed source if appropriate.
See <https://gcc.gnu.org/bugs/> for instructions.

There also seems to be a problem deducing argument types, as if I replace
`template` and `void(Args...)
noexcept(is_noexcept)` with just `template` and `void()
noexcept(is_noexcept)`, I don't get an internal compiler error but I get a
substitution failure:

error: no matching function for call to
'is_noexcept_(member_)function()'
note: candidate: 'template ...'
note:   template argument deduction/substitution failed:
note:   couldn't deduce template parameter 'is_noexcept'

This is also the error I get in g++-8 (8.3.0 (Ubuntu 8.3.0-6ubuntu1~18.04)) in
all 4 cases (So no internal compiler error in g++-8).

[Bug c++/90799] noexcept specification dependent on template argument throws internal compiler error when trying to deduce it from a function argument

2019-06-10 Thread franwade33 at googlemail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90799

--- Comment #2 from franwade33 at googlemail dot com ---
It throws a different compiler error if you give the template parameter (Move
`bool is_noexcept` to the start of the template list and call
`is_noexcept_function(foo)`). To my knowledge, this is not a gcc
extension (And it works fine in MSVC++ and with clang++).

: In substitution of 'template
constexpr bool is_noexcept_function(void (*)(Args ...) noexcept (is_noexcept))
[with bool is_noexcept = true; Args = ]':
:24:48:   required from here
:24:48: internal compiler error: in nothrow_spec_p, at
cp/except.c:LINE
   24 | static_assert(is_noexcept_function(foo));
  |^

https://godbolt.org/z/cjhCQp

Where the line number is 1238 in gcc 10.0.0, 1241 in gcc 9.1.0, and 1148 in gcc
8.3.0 (It is an ICE in all 3 versions)

[Bug c++/104403] New: ICE while optimizing lambda that returns address of a static variable hidden in a switch

2022-02-05 Thread franwade33 at googlemail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104403

Bug ID: 104403
   Summary: ICE while optimizing lambda that returns address of a
static variable hidden in a switch
   Product: gcc
   Version: 12.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: franwade33 at googlemail dot com
  Target Milestone: ---

On gcc 12.0.1, the following gives an internal compiler error:

// g++-12 -std=c++17 -O1
// g++-12 -std=c++20 -O1
int main() {
[]{
switch (0) {
case 0:
static int value;
return &value;
}
};
}

Reproduced here: https://godbolt.org/z/5PKGjGo33

This is the compiler output:

: In static member function 'static constexpr int*
main()_FUN()':
:8:5:   in 'constexpr' expansion of '0->main()::()'
:8:5: internal compiler error: in cxx_eval_constant_expression,
at cp/constexpr.cc:6652
8 | };
  | ^
0x2169b09 internal_error(char const*, ...)
???:0
0x73cd21 fancy_abort(char const*, int, char const*)
???:0
0x7bc242 maybe_constant_value(tree_node*, tree_node*, bool)
???:0
0x87d5db fold_for_warn(tree_node*)
???:0
0xa9048e check_return_expr(tree_node*, bool*)
???:0
0xa19a9e finish_return_stmt(tree_node*)
???:0
0x8997f3 maybe_add_lambda_conv_op(tree_node*)
???:0
0x97f7ed c_parse_file()
???:0
0xb0f1c2 c_common_parse_file()
???:0

It compiles fine on gcc 11.2.0, and it also compiles fine with -std=c++2b (and
-std=c++14, where a closure type's operator() can't be implicitly constexpr).

Probably has something to do with C++2b P2242R3 allowing static variables in
constexpr functions.