https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124952
Bug ID: 124952
Summary: [reflection] various problems with throw and
reflection
Product: gcc
Version: 16.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: mpolacek at gcc dot gnu.org
Target Milestone: ---
Reported by Dan Katz:
```
using info = decltype(^^::);
template <typename T>
consteval info do_an_error() { throw 42; }
template<typename T>
concept C1 =
requires { typename [:do_an_error<int>():]; }; // bad diagnostic
template<typename T>
concept C2 =
requires { typename [:do_an_error<T>():]; };
static_assert(!C2<int>); // should be able to SFINAE on this, right?
// 'info{}' not usable as a type; assertion should fail.
static_assert(requires { typename [:info{}:]; });
// spurious consteval-only error; lambda should escalate.
static_assert(requires { typename [: [] -> info{throw 1;}() :]; });
// spurious error re: "expression of type 'std::meta::info'"; assertion should
pass.
static_assert(!requires { typename [: [] consteval -> info{throw 1;}() :]; });
```
results in:
t.C:10:41: error: splice argument must be an expression of type
‘std::meta::info’
10 | requires { typename [:do_an_error<int>():]; }; // bad diagnostic
| ~~~~~~~~~~~~~~~~^~
t.C:10:41: error: splice argument must be an expression of type
‘std::meta::info’
t.C:10:41: error: splice argument must be an expression of type
‘std::meta::info’
t.C:10:43: error: expected a reflection of a type
10 | requires { typename [:do_an_error<int>():]; }; // bad diagnostic
| ^~
t.C:15:23: error: uncaught exception ‘42’
15 | requires { typename [:do_an_error<T>():]; };
| ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~
t.C:20:43: error: cannot splice a null reflection
20 | static_assert(requires { typename [:info{}:]; });
| ^~
t.C:20:43: error: cannot splice a null reflection
t.C:20:43: error: cannot splice a null reflection
t.C:20:43: error: expected a reflection of a type
t.C: In static member function ‘static constexpr info<lambda()>::_FUN()’:
t.C:24:57: error: consteval-only expressions are only allowed in a
constant-evaluated context
24 | static_assert(requires { typename [: [] -> info{throw 1;}() :]; });
| ^
t.C: In member function ‘constexpr<lambda()>::operator info (*)()() const’:
t.C:24:57: error: consteval-only expressions are only allowed in a
constant-evaluated context
t.C: At global scope:
t.C:24:58: error: splice argument must be an expression of type
‘std::meta::info’
24 | static_assert(requires { typename [: [] -> info{throw 1;}() :]; });
| ~~~~~~~~~~~~~~~~~~~~^~
t.C:24:58: error: splice argument must be an expression of type
‘std::meta::info’
t.C:24:58: error: splice argument must be an expression of type
‘std::meta::info’
t.C:24:61: error: expected a reflection of a type
24 | static_assert(requires { typename [: [] -> info{throw 1;}() :]; });
| ^~
t.C:28:69: error: splice argument must be an expression of type
‘std::meta::info’
28 | static_assert(!requires { typename [: [] consteval -> info{throw 1;}()
:]; });
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~
t.C:28:69: error: splice argument must be an expression of type
‘std::meta::info’
t.C:28:69: error: splice argument must be an expression of type
‘std::meta::info’
t.C:28:72: error: expected a reflection of a type
28 | static_assert(!requires { typename [: [] consteval -> info{throw 1;}()
:]; });
|
^~